SDL2_pollevent() 控制器 dpad 连续保持?
SDL2_pollevent() Controller dpad continuous hold?
我正在尝试注册控制器按钮/dpad按下并连续按住所述按钮,这样它就会连续吐出输出,而不是一次按下一次,然后退出轮询事件循环。现在我有一小段虚拟代码,如果我按住按钮,我会尝试在流中打印。对这个问题有什么帮助吗?
while( !quit_program )
{
//Handle events on queue
while( SDL_PollEvent( &e ))
{
//User requests quit
if( e.type == SDL_QUIT )
{
quit_program = true;
}
else if(e.type == SDL_CONTROLLERBUTTONDOWN)
{
count++;
cout<<"button pushed# "<<count<<endl;
}
}
}
直到你得到一个SDL_CONTROLLERBUTTONUP(当然是同一个按钮(,你可以认为按钮被按下了。然后要计数,您可以执行以下操作(对于单个按钮(:
bool that_button_pressed{false};
while(!quit_program) {
//Handle events on queue
while(SDL_PollEvent(&e)) {
// User requests quit
if(e.type == SDL_QUIT)
quit_program = true;
if (e.type == SDL_CONTROLLERBUTTONDOWN && e.button == a_button_of_your_choice) {
that_button_pressed = true;
}
if (e.type == SDL_CONTROLLERBUTTONUP && e.button == a_button_of_your_choice) {
that_button_pressed = false;
}
}
if (that_button_pressed) {
count++;
// Print or implement your logic
}
}
当然,这个计数器也取决于您的循环时序。在这里,that_button_pressed将代表SDL_GameControllerButton之一。
相关文章:
- 模板元程序查找相似的连续类型名称
- EASTL矢量<向量<int>>连续的
- 当需要超过16GB的连续内存时,内存分配失败
- 我应该如何表示我拥有的连续元素序列?
- 蛇在C++不会连续转两次
- 有没有一种优雅而快速的方法来测试整数中的 1 位是否位于连续区域
- 如何知道n!是否可以表示为三个连续数字的乘法?
- 连续枚举 C++11
- 两个连续的 OpenMP 并行区域会相互减慢速度
- 可以将两个相同类型的连续数组视为一个数组吗?
- C++,您能否设计一种数据结构,将指针保存在连续内存中并且不会使它们失效?
- 我已经建立了递归关系,它找到了两个字符串之间最长的连续公共字符串,我怎么能跳过其中一个字符串中的一个字符
- 这种用于查找连续子数组中最大和的递归算法有什么优势吗?
- std::stack 是连续的吗?
- 检查连续对的字符串C++
- 如何使用 fprintf 将连续的 512 字节保存到文件中
- 使用连续字符及其路径查找矩阵中最长路径的长度
- 是否确保 2 个连续的 std::chrono::steady_clock::now() 不相等?
- 向量的内存位置不连续
- SDL2_pollevent() 控制器 dpad 连续保持?