为了平台游戏,我需要在左侧或右侧跳跃。
我在跳到同一个地方做得很好
我唯一的问题是,如何在同一时间捕获两个键?
任何提示?或例如?
答案 0 :(得分:1)
使用@immibis建议您可以检查是否在任何时间点按下了任意数量的键。在您的情况下,您可以通过以下方式执行此操作(基本示例代码取自here和密钥常量来自here):
// Get the state array
Uint8 *keystate = SDL_GetKeyState(NULL);
// Update the state array before checking the keys as per the note in the docs.
SDL_PumpEvents();
if (keystate[SDLK_UP] && keystate[SDLK_LEFT])
printf("Jumping going left.\n");
else if (keystate[SDLK_UP] && keystate[SDLK_RIGHT])
printf("Jumping going right.\n");
else if (keystate[SDLK_UP])
printf("Just jumping.\n");
修改强>
根据文档中的以下说明:
注意:使用
SDL_PumpEvents
更新状态数组。