Closed ItsStolas closed 6 years ago
A better idea would be some way to notify the entities that a button has been pressed maybe. Can entities subscribe to events from the scene?
I would like to know how this will make the movement smoother ? What other benefits do you think this will provide ?
Will it not be save as current implementation if we keep adding and clearing the inputs list on every update of gameloop ( animationtimer ).
Well currently there’s a delay when you try to move your character, and if you press space while running your character will stop. I thought this way would handle those better.
From what I read online, it looks like the most common solution to the problem. Have you tested it yet? Instead of using an arraylist, you can use a set data structure to avoid checking for duplicates in the list. I believe the linkedhashset will work, since it maintains insertion order.
Not yet I wanted to give someone else a chance to contribute and implement the update() to entities. Feel free to take a stab at it :)
I’ve implemented the list, but it’s still in a PR. Just haven’t implemented the update to read from list, to be clear. Also the hashset is a great idea, it would also be a tiny bit faster haha.
I have tried to implement the player movement using this new type of input handling in #39 I must say the animation is really very smooth now. Also please see if it looks good enough to be merged with master.
Nice work :)
I've been thinking over EventHandler for input.
If the make it more generic like my proposed PR, we run into the problem of implementing KeyPressed and KeyReleased (KeyIsPressed is fine, though).
Maybe we could, inside @ashish2199 suggest update() for the whole game, put for 1 update loop which keys were pressed and which were released, then wipe them in the next loop. Each entity can then watch those lists to events that need KeyPressed (like placing a bomb).
Eg:
and at the END of hypothetical update() loop (after all entities have run their update()'s, just
Thoughts?