Jump to content

  • Log In with Google      Sign In   
  • Create Account

SDL Event Queue


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 MoBaT   Members   -  Reputation: 115

Like
0Likes
Like

Posted 31 January 2013 - 09:10 PM

I have a problem with the SDL Events. I have a code which looks like:

while (SDL_PollEvent(&Event)){
	OnEvent(&Event);
}

 

then the OnEvent processes the event and directs it to the proper virtual function. So If I were to hold down the right key button, it would go here.
 


void Engine::OnKeyDown(SDLKey sym){
	switch(sym) {
		case SDLK_RIGHT:
			x1 += 1;
			break;
	}
}

 

The problem is that when I am holding the right button key, it is only running one time. The queue does not stack and keep processing the keydown button. What could be the problem?



Sponsor:

#2 kidman171   Members   -  Reputation: 498

Like
1Likes
Like

Posted 31 January 2013 - 10:40 PM

What you should do is keep track of when the key gets pressed and when it gets released. You could have a simple array of bools, one for each key. When you get an SDL_Keydown event, switch the key in your bool array to true. When you get an SDL_Keyup event, switch the key in your bool array to false. Then in your update loop, you can just check your bool array to see if x is pressed and move your sprite accordingly.


Edited by kidman171, 31 January 2013 - 10:41 PM.


#3 BeerNutts   Crossbones+   -  Reputation: 2944

Like
1Likes
Like

Posted 31 January 2013 - 10:54 PM

SDL_PollEvent() Only signals when a Key State changes, so, you'll only get it on Press and Release (as kidman points out).  If you would rather poll the KeyState, you can do that instead.  Check SDL manual for function, I don't remeber exactly which one it is.


My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

#4 Chad Smith   Members   -  Reputation: 1133

Like
0Likes
Like

Posted 01 February 2013 - 01:48 AM

This tutorial will help you if you're interested in the keystates likes has been just described: http://lazyfoo.net/SDL_tutorials/lesson10/index.php






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS