Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualptrrf

Posted 04 December 2012 - 06:09 AM

(First of all, I say sorry for my english)

You just need to draw the scene. Put the apply_surface() function after the SDL_PollEvent while and will work (remember this logic order on games: update logic -> user input -> draw scene to the user).

Another thing is: you want the sprite moving while the key is pressed? or you just want to move him few pixels every time you press the key?
There's 2 ways to do this things:

The way you are doing, you will press the key, then the sprite y will be set to y+1. If you press the key, and keep it pressed, the sprite will not move more than 1 pixel until you press the key again.

The other way is use the function SDL_GetKeyState():


[source lang="cpp"]Uint8* keystate = SDL_GetKeyState(NULL);if(keystate[SDLK_DOWN]){ y = y+1;}[/source]

The SDL_GetKeyState() function get a snapshot of the current keyboard state.
What's the difference? The SDL_KEYDOWN it's an event that just occurs when you press that key, and the way above, it's to check if the current key is pressed, if it's pressed, increments y. (This case will be true until you release the key)

#1ptrrf

Posted 03 December 2012 - 04:45 PM

You just need to draw the scene. Put the apply_surface() function after the SDL_PollEvent while and will work (remember this logic order on games: update logic -> user input -> draw scene to the user).

Another thing is: you want the sprite moving while the key is pressed? or you just want to move him few pixels every time you press the key?
There's 2 ways to do this things:

The way you are doing, you will press the key, then the sprite y will be set to y+1. If you press the key, and keep it pressed, the sprite will not move more than 1 pixel until you press the key again.

The other way is use the function SDL_GetKeyState():


[source lang="cpp"]Uint8* keystate = SDL_GetKeyState(NULL);if(keystate[SDLK_DOWN]){ y = y+1;}[/source]

The SDL_GetKeyState() function get a snapshot of the current keyboard state.
What's the difference? The SDL_KEYDOWN it's an event that just occurs when you press that key, and the way above, it's to check if the current key is pressed, if it's pressed, increments y. (This case will be true until you release the key)

PARTNERS