SDL movement problem

Started by
24 comments, last by evillive2 19 years, 4 months ago
I try'd this:
case SDLK_DOWN:while(!SDL_KEYUP){   if(paddle1Y < screen->h-10)   {     paddle1Y++;   }}    break;

but it won't work :(
what am I doing wrong?
-----------------------------Sismondi GamesStarted c++ in October 2004...
Advertisement
finally made it work, but now I want to add speed. I am trying to increase the speed by hitting the shift button and decreasing speed by hitting ctrl buttun. what are the functions in SDL for that? SDLK_CTRL and SDLK_SHIFT didn't work :(
-----------------------------Sismondi GamesStarted c++ in October 2004...
lol, I just try'd some stuff and LSHIFT and LCTRL worked :D
-----------------------------Sismondi GamesStarted c++ in October 2004...
Quote:Original post by Joshnathan
lol, I just try'd some stuff and LSHIFT and LCTRL worked :D

That's the best way to learn, to try some stuff [smile].
Rob Loach [Website] [Projects] [Contact]
Quote:Original post by Joshnathan
finally made it work, but now I want to add speed. I am trying to increase the speed by hitting the shift button and decreasing speed by hitting ctrl buttun. what are the functions in SDL for that? SDLK_CTRL and SDLK_SHIFT didn't work :(

i'm curious... how did you get it to work?
show code please.

Beginner in Game Development?  Read here. And read here.

 

In SDL unlike the Win32 equivilent, an SDL_KEYDOWN event is only sent once when the key is pressed and is not repeated while the key is down. This results in a lot of people asking "why do I have to keep hitting the arrow key to move?". There are a lot of ways to handle this but basicly it comes down to something similar to setting a movement flag on an SDL_KEYDOWN event and unsetting it on an SDL_KEYUP event. I have used an array of boolean values before for the arrow keys and that seems to work in simple cases like space invaders, pong, tetris etc. I have a simple tilemap program I just made using plain SDL that does some pretty simple things. The code isn't well commented but should be pretty obvious and it isn't optimised at all but it should give you some ideas on how to handle some things.

Here is a link to the source and a compiled version of it just in case it might help.

Evillive2

This topic is closed to new replies.

Advertisement