Sign in to follow this  
Ngoles

Problems using KeyBoard Events ?

Recommended Posts

Hi guys, I have a problem with this code in order to make a graphic move around the screen. The idea is to keep some of the arrows pressed, and make the graphic move, and when I release the key, the graphic should not move anymore. The thing is that it's not working. the only thing that works is when I press the SDLK_UP, then the graphic starts moving upwards... but it stops moving when I press SDLK_DOWN, not when I release SDLK_UP. See the piece of code at this link ( the ident went all wrong when pasting code here ) http://igoles.servebeer.com/code.c [Edited by - Ngoles on March 16, 2007 2:12:00 PM]

Share this post


Link to post
Share on other sites
Hmm although I can't understand exactly the problem you are getting, I would recommend you not to use the velocity system, but use SDL_GetKeyState to have continuous motion.

Share this post


Link to post
Share on other sites
I edited the original post to try to make the problem clearer...

Do you have any tutorial about SDL_GetKeyState or something like that ? It would greatly help me :)

Thanks!

Share this post


Link to post
Share on other sites
The only tutorial I know of (without googling) is my breakout clone:

[source lang = "cpp"]

Uint8 *pressedKeys = SDL_GetKeyState(NULL);
//in the main game loop:
while (!shouldQuit)
{
while (SDL_PollEvent(eventCurrent))
{
if (SDL_KEYDOWN == eventCurrent->key.type)
pressedKeys = SDL_GetKeyState(NULL);

if (pressedKeys[SDLK_LEFT])
{
//Do stuff
}
}
}



Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this