gpt4 book ai didi

捕获相同的 2 个键进行对角线跳跃

转载 作者:太空宇宙 更新时间:2023-11-04 03:48:49 26 4
gpt4 key购买 nike

为了我的平台游戏好,我需要在左边或右边跳。

我在同一个地方跳得很好

我唯一的问题是,如何同时捕获两个键?

有什么建议吗?或例子?

最佳答案

使用@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");

编辑

根据文档中的以下注释:

Note: Use SDL_PumpEvents to update the state array.

关于捕获相同的 2 个键进行对角线跳跃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22277608/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com