[SDL] confused by SDL_KEYDOWN event!!!
dh11111
dh11111 at 126.com
Thu Oct 11 07:29:32 PDT 2007
here is my code:
void Tank::HandleInput( SDL_Event &event,bool &run)
{ SDL_PollEvent(&event);
if(event.type==SDL_QUIT)
{
run=false;
std::cout<<"you have pressed X button\n";
}
if(event.type==SDL_KEYDOWN)//if you type event.type=SDL_KEYDOWN there will always be true for the state below
{
switch(event.key.keysym.sym)
{
case SDLK_a:
dir=LEFT;
current=surfacebox[0];
break;
case SDLK_s:
dir=DOWN;
current=surfacebox[1];
break;
case SDLK_d:
dir=RIGHT;
current=surfacebox[2];
break;
case SDLK_w:
dir=UP;
current=surfacebox[3];
break;
case SDLK_SPACE:
manager.AddBullet(this->Shot());
break;
default:
dir=STAY;
break; } Move(); } if(event.type==SDL_KEYUP) {
if(event.key.keysym.sym != SDLK_a
&&event.key.keysym.sym != SDLK_s
&&event.key.keysym.sym != SDLK_d
&&event.key.keysym.sym != SDLK_w)//ignore any other key-unpressed event
{
Move();
}
else
{
ResetVel();
Move();
}
}} problem is that when i keep pressing a key such as "a", the tank in my game keeps moving left,but if i move the mouse during the tank's moving,the tank stops moving.In the doc it seems that there are some differences between SDL_KEYDOWN and SDL_MouseMotionEvent,but in my application ,it seems there no differences between them! what's the difference between these two event type? it seems a little confused.PS: My OS is Windows xp,SDL version is 1.2.12,IDE is VS 2005 PRO.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20071011/16d4ca8e/attachment.htm
More information about the SDL
mailing list