Problems using KeyBoard Events ?
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]
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.
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!
Do you have any tutorial about SDL_GetKeyState or something like that ? It would greatly help me :)
Thanks!
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 } } }
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement