Jump to content
  • Advertisement
Sign in to follow this  
sjoerd222

SDL keyevent

This topic is 4398 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 I want that my player moves when a Key is pressed. But he makes only one step when I press the Key (He should go on moving till I realese the key). This should be very easy to fix but I do not get it. Could somebody help me Thank PS: I'm new to this Forum, if I made something wrong SORRY
while ( !end ) { // handle the events in the queue while ( SDL_PollEvent( &event ) ) { switch( event.type ) { case SDL_KEYDOWN: handleKeyPress(&event.key.keysym ); break; case SDL_QUIT: end = TRUE; break; default: break; } } if ( runlevel=4 ) draw_GL( ); } quit(); }[/QUOTE]

Share this post


Link to post
Share on other sites
Advertisement
A quick fix would be to call:

SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL );

In your initialization code. This will cause SDL to keep sending your app the Key Down events when a user holds a key.

Probably a better fix would involve setting the object's velocity rather than just incrementing its position (which I assume is what you're doing).

Hope that helps.

Share this post


Link to post
Share on other sites
I'm changing the position of a camera in OpenGL. If I would have something like velocity, the application would allways try to move the camera with velocity=0. That would use more Power than my solution I think.

Thank you!!! it will help

Share this post


Link to post
Share on other sites
"Best" solution I think is to work with gametime passed, a velocity and keystates.

On keydown you put this keystate on "pressed", so you don't always have to resend this item.

When the keystate is not pressed, you do nothing, which is fairly fast enough I guess, what you would do for moving forward is e.g. something like this:

if(forward_key_pressed)
{
translate(VelocityVector*passed_time_since_previous_frame);
}

offcourse, in order to let it work decently you need a clear system that manages frames and such.

The repeat is good for a quick fix, but isn't the nicest solution.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!