1
General / Help using in-window key input inside KeyPressed event with switch
« on: April 20, 2023, 04:39:55 am »
Hi, I'm working on a basic game and can't figure out how to get player input to register.
I'm using sf::Event::KeyPressed with switch(event.key.code) to control WASD movement (top down grid-based turn-based dungeon crawler style) within the main window.pollEvent(event) and got it to work without errors.
I want to press another key to throw an item, but I can't figure out how to trigger another WASD switch for direction of the throw. Here's the broken code I have so far:
I got it to work using cin, but how would I get it to work in the window itself? I understand it's just skipping over the inner if statement. I believe I need to involve another Event but I'm scratching my head. Should I be relocating all of the movement/input keys outside of the while (window.pollEvent(event)) statement? I've read the Event / Input / Keyboard tutorial pages multiple times but still need some help!
First post! Haven't been using SFML very long and rusty with C++ so bear with me
I'm using sf::Event::KeyPressed with switch(event.key.code) to control WASD movement (top down grid-based turn-based dungeon crawler style) within the main window.pollEvent(event) and got it to work without errors.
I want to press another key to throw an item, but I can't figure out how to trigger another WASD switch for direction of the throw. Here's the broken code I have so far:
(click to show/hide)
I got it to work using cin, but how would I get it to work in the window itself? I understand it's just skipping over the inner if statement. I believe I need to involve another Event but I'm scratching my head. Should I be relocating all of the movement/input keys outside of the while (window.pollEvent(event)) statement? I've read the Event / Input / Keyboard tutorial pages multiple times but still need some help!
First post! Haven't been using SFML very long and rusty with C++ so bear with me