Sign in to follow this  

"SDL_KEYDOWN" what does it reperesent?

This topic is 3633 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

Hello, Does "SDL_KEYDOWN" mean the transition from unpushed -- to --> pushed? Or does it mean the state of the key being DOWN "de-pressed"? If it would be said in computer logic, then is it the transition from 1 to 0? Or is it the steady state of it being at 1? I believe it is the first. Because if it was the second possibility then SDL_KEYUP would invoke all unpressed keys to be true all the time, no? --------------- I have another question that is relating to this one. I am currently writing a Tic Tac Toe game. And I implementing the controls. I wrote it in two different ways. currentPosition[ 0 ] is the x coordinate on the Tic Tac Toe board. --- Type one --- if( event.type == SDL_KEYDOWN ) { switch( event.key.keysym.sym ) { case SDLK_LEFT: if( currentPosition[ 0 ] > 0 ) { currentPosition[ 0 ]--; } break; . . . --- End --- --- Type two --- if( event.type == SDL_KEYDOWN ) { switch( event.key.keysym.sym ) { case SDLK_LEFT: xDisposition -= 1; break; . . . if( event.type == SDL_KEYUP ) { switch( event.key.keysym.sym ) { case SDLK_LEFT: xDisposition += 1; break; . . . move_courser( xDisposition, yDisposition ); void move_courser( int xShift, int yShift ) { currentPosition[ 0 ] += xShift; currentPosition[ 1 ] += yShift; if( ( currentPosition[ 0 ] < 0 ) | ( currentPosition[ 0 ] > 2 ) ) { currentPosition[ 0 ] -= xShift; } } --- End --- I left out the y movement for simplicity The first type yields the better result. The result there is when a key is pressed (even kept de-pressed) the shift is always one cell at a time. The second type yields an unusable result for a Tic Tac Toe control. When a key is pressed (de-pressed) it goes VERY fast over the board, and only stops when the key becomes unpressed. I read in lazy foo's tutorials that event handling and logic must be separated. The first type I wrote by my own way. But then I felt that I didn't separate the logic from the event handling so I had to change it. I went reading through his tutorials again, and I rewrote it in this way trying to imitate his method. Could someone kindly explain why are the results differ in these two types of code? Regards

Share this post


Link to post
Share on other sites

This topic is 3633 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.

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