SDL Key Hold

1
2
3
4
5
6
7
8
void handle_keyboard()
{
	Uint8 * keystate = SDL_GetKeyState(NULL);
	if(keystate[SDLK_UP]){
		var_game_score += 50;
	}

}


I can add 50 to var_game_score but when I hold it didn't increase anymore.need 2 press to add 100.

Plz help with a concrete example.
I guess you call handle_keyboard() from your event loop? That will not work because an event is only generated once when you press or release the key.

Just call handle_keyboard() once every frame (or handle the events some other way).
Last edited on
handle the events some other way


've been trying in vain.

every frame


Which frame ?
I mean each time you make updates (once each iteration in your game loop).
(once each iteration in your game loop).


Did you mean "main" ?

You could just say that main() loops every time...because if it is not,my problem would never be solved.

Problem solved.Worked perfectly.
Topic archived. No new replies allowed.