gpt4 book ai didi

c++ - C++ 中的 glutIdleFunc() 变量值未递增

转载 作者:行者123 更新时间:2023-11-28 01:28:25 24 4
gpt4 key购买 nike

我试图在单击键盘上的字母“b”后不断增加变量 bulletY 直到最大 y 值窗口大小以产生射击效果。但是,bulletY 只会递增一次。

这里是 bool flags 和 double 使用的初始值:

bool shoot = false;
bool isDone = false;
double bulletX = 8000 ;
double bulletY = -1;
double plusX = 0;
double plusY = 0;

下面是用于处理按键输入的方法

void key(unsigned char k, int x, int y)//keyboard function, takes 3 parameters
// k is the key pressed from the keyboard
// x and y are mouse postion when the key was pressed.
{
if (k == 'b') { //SHOO
shoot = true;
}

glutPostRedisplay();//redisplay to update the screen with the changes
}

最后这是我创建的 Anim 函数,它被传递给空闲函数 glutIdleFunc(Anim)

void Anim(){
if (shoot==true) {
bulletX = plusX;
bulletY = plusY;
isDone = true;
}

if (isDone&& bulletY<450) {
bulletY += 1;
std::cout << "bullet Y is currently at : " << bulletY << "\n";
}
else {
isDone = false;
shoot = false;
}
glutPostRedisplay();
}

最佳答案

似乎 bulletY 在你的 Anim() 函数中总是重置为 0,然后它递增 1,所以 bulletY始终为 1。

删除 bulletY = plusY(即 0),它应该在每次迭代中递增。

关于c++ - C++ 中的 glutIdleFunc() 变量值未递增,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52769299/

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