Ive got a normal Animation, and if the user presses (for example) ‘d’ another Animation shows up.
So when the user releases ‘d’, the standard Animation should return.
So I want to know from you, how I can listen for not pressing a key.
I already tried to trigger an Action with if(!keyPressed)
inside the onAction Method of the ActionListener, because there I can acess the keyPressed Bool, but, of course, the onAction Method only gets called if the user presses a button that leads to it. So what can I do?
I solved the same issue with animantion layering. I had a class which handled that layering (just names of the animation). Means the normal animation was on layer 0 (lowest prio) and if somebody did for example press space to beat some one I layered the beat’em animation on layer 1. The class handling the layers now spit out beat’em and as soon I released the key it removed the layer 1 action and the action an layer 0 took place again.
You might even handle that the full cycle is played of an animation until you pop it. Yeah like stack like thing
EDIT: I would not relay on key pressed or not to swtich from one animation to another but capsulate that in a easy to test class, which you can than isolated improve. Doing it on key stroke directly will end in something messy pretty soon IMHO (at least in my case).
I don’t know but he IMO he tries to use the released key as a state and if you never pressed that key you will not get a ket released event. I understood it that way. That’s why I would organize the animations in a class. Default is idle, as soon you press wasd it is walking. jumping, shooting is then just something with a higher prio or maybe even merged somehow.
I did it that way so I had an object where you just could add remove animation names (just strings in my case) on key press/release.
@pspeed yeah, the keyPressed Bool. But how do work with it? onAction() only gets called when a key that leads to it gets pressed (I mentioned before)
I like @ia97lies idea, but that doesnt help anything at all. You said, when someone presses space animation layer 1 should appear, and when you release the key layer 1 should be removed. So, how to log, when i released the key? Did I lost something? That doesnt help :c
Add a subclass that implements AnimEventListener where the onAnimCycleDone method looks for changes in the UserData variable of your choice. This Listener will change the animation based off that variable.
In your ActionListener use isPressed Boolean to set the UserData variable and use !isPressed to change it. As long as they keep key pressed the UserData variable will not change. Upon release it will change your UserData variable. After the animation finishes AnimEventListener will check the variable.
You can use an Enum class with getters so you can easily set your UserData variable.
What are you doing that requires the user to press a key to start an animation?
Ok got that I miss interpreted your question totally
What you state does not work normally just work. There are working one class examples in the wikis beginner section which do exactlly what you want…
But in the end you have to write a one class test sample to get valuable help as @pspeed already said in a previous post.