目前,当我在 d-pad(sdl 中的帽子)上按住一个方向时,我的代码只执行一次,这是我的代码:
while (SDL_PollEvent( &event ))
{
switch (event.type)
{
case SDL_QUIT:
exitapp = 1;
break;
case SDL_KEYDOWN:
if (event.key.keysym.sym == SDLK_ESCAPE)
{
exitapp = 1;
// find other keys here: http://sdl.beuc.net/sdl.wiki/SDLKey
}
game->KeyDown( event.key.keysym.scancode );
break;
case SDL_KEYUP:
game->KeyUp( event.key.keysym.scancode );
break;
case SDL_MOUSEMOTION:
game->MouseMove( event.motion.x, event.motion.y );
break;
case SDL_MOUSEBUTTONUP:
game->MouseUp( event.button.button );
break;
case SDL_MOUSEBUTTONDOWN:
game->MouseDown( event.button.button );
break;
case SDL_JOYHATMOTION: /* Handle Hat Motion */
if ( event.jhat.value & SDL_HAT_UP )
{
game->HatUp();
}
if ( event.jhat.value & SDL_HAT_LEFT )
{
game->HatLeft();
}
if ( event.jhat.value & SDL_HAT_RIGHT )
{
game->HatRight();
}
if (event.jhat.value & SDL_HAT_DOWN )
{
game->HatDown();
}
break;
default:
// more info on events in SDL: http://sdl.beuc.net/sdl.wiki/SDL_Event
break;
}
}
理想情况下,当我按下 d-pad 时,它会继续调用 game->HatUp()。
我怎样才能让它工作?