I’m working on having my sprite move, and I’m trying to keep key overlap from happening. What I mean is that, when I hit the “Right” key, I want ONLY that key command to work. But when I hit right and inadvertently hit “Up,” “Down,” etc., the sprite will act wonky. How do I ensure that no other keys interfere with the operation of a key command?
Use a variable string to keep track of the key command. Set it to “” when no key is pressed, and set it to whatever command is for the key press only if it’s “”.
I tried that out. The only problem comes when I hit a pair of keys simultaneously, like the left/up key or the right/down key. The initial player stops, and I get a “ghost” that continues in the direction of the second hit key, and won’t stop.
What I basically need to do is to make the Key command exclusionary to any other key that would mess things up (in this case, preventing another direction key for movement from being inadvertently hit and causing the “character split” like I’m getting.
To take advantage of the diagonal directions you have to add other triggers after the ones already written:
If “Up” and “Right” are pressed > change KeyCommand set to “UpRight”
(and the other diagonal triggers)
The OP does not want diagonals. They want one key press to be registered, and only that one keypress to be actioned until it is released. Any other key is pressed during that time is ignored.
Your “Any key is pressed” at the bottom of the 2nd screen shot is incorrect. If you look at my image, it’s inverted. It reads “If there are no keys being pressed”, whereas yours reads “If there are keys being pressed”.
Also, why you are creating a new image for each keypress? You can do this with animations. Have one sling object with an animation for each key press, direction or action. Give each animation a name for the keypress/action. It’ll make your events a whole lot cleaner and easier to work with.
Aha! Making all of the animations for one object and then consolidating movements to those animations instead of four separate sprites made all the difference in working the bugs out!