[SDL] esc detector wont run -- 'out of scope'

capehill juha.niemimaki at gmail.com
Sat Mar 25 12:07:10 PDT 2017


Here is something that I use in a puzzle game. First I poll for events which triggers the event pump, and then I check the keyboard state. This happens at 60 Hz rate, each time game logic is ran.


Code:

static void readKeyboard(InputState * inputState)
{
	const Uint8 *state = SDL_GetKeyboardState(NULL);

	inputState->fireButtonPressed = state[SDL_SCANCODE_SPACE];
	inputState->leftButtonPressed = state[SDL_SCANCODE_LEFT];
	inputState->rightButtonPressed = state[SDL_SCANCODE_RIGHT];
	inputState->upButtonPressed = state[SDL_SCANCODE_UP];
	inputState->downButtonPressed = state[SDL_SCANCODE_DOWN];
	inputState->rotateLeftButtonPressed = state[SDL_SCANCODE_Z];
	inputState->rotateRightButtonPressed = state[SDL_SCANCODE_X];

	if (state[SDL_SCANCODE_ESCAPE])
	{
		inputState->quitButtonPressed = SDL_TRUE;
	}
}

void handleEvents(InputState * inputState)
{
	SDL_Event event;

	while (SDL_PollEvent(&event))
	{
		switch (event.type)
		{
			case SDL_QUIT:
				inputState->quitButtonPressed = SDL_TRUE;
				break;
		}
	}

	readKeyboard(inputState);
}







-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20170325/951fdb5c/attachment-0001.htm>


More information about the SDL mailing list