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(); }
SDL keyevent
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
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.
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.
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
Thank you!!! it will help
"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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement