Confused by SDL_KEYDOWN event!

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.

here is my code:
:snip:

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.

I think you want to put your Move() function in some sort of 'update’
function that’s called from the game loop (or a timer) irrespective
of the event handling. As it is, it seems your object will only move
if your app is receiving keyboard events, which is not an ideal input
method.

chazOn Oct 11, 2007, at 8:29 AM, dh11111 wrote:

Hey,

My suggestion would be to use SDL_PollEvent() in a while loop so that you catch and handle every event that hops on the queue. You’re probably ignoring all events but one each frame.

void Tank::HandleInput( SDL_Event &event,bool &run){
while(SDL_PollEvent(&event))
{

}

}

Jonny D

here is my code:
void Tank::HandleInput( SDL_Event &event,bool &run){
SDL_PollEvent(&event);


}

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.Date: Thu, 11 Oct 2007 22:29:32 +0800From: dh11111 at 126.comTo: sdl at lists.libsdl.orgSubject: [SDL] confused by SDL_KEYDOWN event!!!


News, entertainment and everything you care about at Live.com. Get it now!
http://www.live.com/getstarted.aspx

Good job! your suggestion has do a lot good to my application.thank you very much.Pehaps the SDL doc doesn’t descript this good lib perfectly !
?2007-10-12?“Jonathan Dearborn” ???
Hey,

My suggestion would be to use SDL_PollEvent() in a while loop so that you catch and handle every event that hops on the queue. You’re probably ignoring all events but one each frame.

void Tank::HandleInput( SDL_Event &event,bool &run)
{
while(SDL_PollEvent(&event)) { … }
} Jonny DDate: Thu, 11 Oct 2007 22:29:32 +0800
From:@dh11111
To:sdl at lists.libsdl.org
Subject: [SDL] confused by SDL_KEYDOWN event!!!
here is my code:
void Tank::HandleInput( SDL_Event &event,bool &run)
{ SDL_PollEvent(&event); …
} 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.
Get news, entertainment and everything you care about at Live.com.Check it out!

good advise.but this snip of code is just a small test app.I have solved the problem that i mentioned before by using “while(SDl_PollEvent(&event))”.thank you all the same :)?2007-10-11?“Charles McGarvey” ???
On Oct 11, 2007, at 8:29 AM, dh11111 wrote: > here is my code: > :snip: > > 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. I think you want to put your Move() function in some sort of ‘update’ function that’s called from the game loop (or a timer) irrespective of the event handling. As it is, it seems your object will only move if your app is receiving keyboard events, which is not an ideal input method. chaz _______________________________________________ SDL mailing list SDL at lists.libsdl.org http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

? Fri, 12 Oct 2007 03:18:34 +0800 (CST)
dh11111 <dh11111 at 126.com> ??:> Good job! your suggestion has do a lot good to my application.thank

you very much.Pehaps the SDL doc doesn’t descript this good lib
perfectly ! ?2007-10-12?“Jonathan Dearborn”
??? Hey,
My suggestion would be to use SDL_PollEvent() in a while loop so that
you catch and handle every event that hops on the queue. You’re
probably ignoring all events but one each frame. void
Tank::HandleInput( SDL_Event &event,bool &run) {
while(SDL_PollEvent(&event)) { … }
} Jonny D
Date: Thu, 11 Oct 2007 22:29:32 +0800
From:dh11111 at 126.com
To:sdl at lists.libsdl.org
Subject: [SDL] confused by SDL_KEYDOWN event!!!
here is my code:
void Tank::HandleInput( SDL_Event &event,bool &run)
{ SDL_PollEvent(&event); …
} 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. Get news, entertainment and
everything you care about at Live.com.Check it out!

What kind of client do you use for replying this mail?

All the text is confusingly.

Regards!

/*
*Welcome to cocobear’s home!
*http://cocobear.cn
*/