Hello.
To begin, I would like to apologize for my English.
So sorry.
I write my first SDL game and I have problem with player movement.
This is my code:
if ((Game::event.type == SDL_KEYDOWN || Game::event.type == SDL_CONTROLLERBUTTONDOWN) && Game::pause == false) {
if (Game::event.key.keysym.sym == SDLK_w || Game::event.key.keysym.sym == SDLK_UP || Game::event.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_UP) {
transform->position.y -= 32;
}
else if (Game::event.key.keysym.sym == SDLK_s || Game::event.key.keysym.sym == SDLK_DOWN || Game::event.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN) {
transform->position.y += 32;
}
else if (Game::event.key.keysym.sym == SDLK_d || Game::event.key.keysym.sym == SDLK_RIGHT || Game::event.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT) {
transform->position.x += 32;
}
else if (Game::event.key.keysym.sym == SDLK_a || Game::event.key.keysym.sym == SDLK_LEFT || Game::event.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT) {
transform->position.x -= 32;
}
}
But if I press, for example, W key the player move slowly than if I press up button. And if I press up button on my gamepad the player make move only once.
I can’t explain why buttons behave differently when they do the same thing.