当我单击 Space 时,我希望子弹移动。首先,当按下空格键时,子弹图像会被 blitted,同时计时器会启动,当它达到 5000 毫秒时,图像的 x 值应该会改变。这是我的代码:
SDL_Rect bulletRect;
bulletRect.x = dstX+31; //dstX/Y is the source destination of another image where the bullet should be drawn
bulletRect.y = dstY+10.5;
SDL_Surface *bullet = IMG_Load(bullet.png");
if (drawBullet) //bool set to true in the space key event.
{
SDL_BlitSurface(bullet, NULL, screen, &bulletRect);
//timer
my_timer.start(); //starts the timer
if (SDL_GetTicks() == 5000) //if 5 sec
{
bulletRect.x += 10;
}
}
图像仅被 blitted,但 5 秒后没有任何反应。怎么了?