Jump to content
  • Advertisement
Sign in to follow this  
Ngoles

Problems using KeyBoard Events ?

This topic is 4119 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!