1
Window / Re: Why do my inputs get multiplied when my mouse moves over my window ?
« on: June 17, 2022, 05:24:08 am »It sounds like CheckBtn() is actually performing the movement based on the values set by InputHandler. Is that right?
The reason there is a while loop around pollEvent is because there can be multiple events waiting in the event queue. Every key press or release, every window event, and every small mouse movement or button press will add an event. The while loop goes through them all one at a time.
This has two effects on the code shown that you might not want:
- CheckBtn and animPlayer() are called every time the mouse moves, which might be multiple times per frame.
- InputHandler() is outside of the loop, so it will miss events, it only sees the last event in the queue. If events are coming in slow that would work, but many events coming in will make it miss some.
I'd say try swapping the inside and outside parts:Event event;
while (window.pollEvent(event))
{
input.InputHandler(event, window);
}
CheckBtn();
animPlayer();
That way the input system receives every event and CheckBtn and animPlayer only happen once per frame.
You are correct about CheckBtn(), animPlayer() simply cuts rectangles around the sprites of a sprite sheet.
I swapped the two blocks and I tweaked animPlayer() a bit and it worked ! Thank you very much for taking the time to help me with my problem.