为了我的平台游戏,我需要在左边或右边跳转。
我在同一个地方跳得很好
我唯一的问题是,如何在同一时间捕获两个键?
有小费吗?或者举例?
发布于 2014-03-09 03:19:20
使用@immibis建议,您可以检查是否在任何时间点按下了任意数量的键。在您的示例中,您可以使用以下方式(从这里获取的基本示例代码和从这里获取的关键常量):
// 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更新状态数组。
https://stackoverflow.com/questions/22277608
复制相似问题