JavaFX Animations: Quit an infinite transition by fading out - animation

Have an animation like this starting with the program:
tr = new FadeTransition(Duration.millis(1000), rect);
tr.setFromValue(0.5);
tr.setToValue(0.1);
tr.setCycleCount(Timeline.INDEFINITE);
tr.setAutoReverse(true);
Obviously it loops endlessly. Now I want a function which stops this, but only after it has faded out. that means just the next time it reaches its "to value" (or the "from value") it should stop animating.
Now I know that I can end the animation on the next iteration by setting the cycle count to 1. However that only works when the animation has been stopped before.
tr.stop();
tr.setCycleCount(1);
tr.play();
But that means the .play() function restarts the animation, causing a flicker which isn't really pretty. This last cycle doesn't continue where it had been before.
How can I end the animation smoothly?
Huge thanks in advance!

Have found a smooth solution myself after all.
Instead of using infinite cycle, it uses a cycle of 2 and a finish-event which just restarts the animation:
tr = new FadeTransition(Duration.millis(1000), rect);
tr.setFromValue(0.1);
tr.setToValue(0.5);
tr.setAutoReverse(true);
tr.setCycleCount(2);
tr.play();
tr.setOnFinished((ActionEvent event) -> tr.play());
Then a simple call of
tr.setOnFinished(null);
Suffices to smoothly quit the animation at the end of the last transition.

Related

How to get a death animation for my character in ActionScript 3 (Adobe Animate)

So basically I have two questions. I am also copying off this video from 2014: https://www.youtube.com/watch?v=w8JgpEjm8i8&t=2792s
Question 1
At the end of the video above the guys computer completely crashed and he wasnt able to show the end of how to setup a death animation for my player (link). So currently I have setup a movie clip of the death animation - just the playing spinning around - and put it in another movie clip called 'All Sprites' in which I have my other movie clips such as the different walking directions. So I have placed it in there, labelled it with "Link Death Frame". I then went back to the main script and added code so that once my player dies, the animation will play. Such as:
~
if(linkHealthBarMC.scaleX <= 0.01)
{
linkAlive = false;
}
trace(linkAlive);
if(linkAlive == false)
{
linkMC.gotoAndStop("Link Death Frame");
}
~
However, the issue comes in which the animation doesnt actually play, it just goes straight to the first frame and doesnt play. I have tested it and I know for sure that it gets stuck on the first frame and that something must be wrong with the animation as I tested it with another animation and it worked fine (once I met the requirements for the animation to play). So does anyone have any idea how I can fix this issue so that my character can play a death animation?
Question 2
How do I stop time? Like just completely freeze everything after my character is dead? Because at the moment I am just going to the first frame of the death animation and can still move and attack.
I'd assume this is on an EnterFrame loop. Then you would have two possible causes for this:
1.) You're loop is constantly checking if the 'linkAlive' if statement is false (which it is) and setting your Animation to the first frame. You can check this method by putting a Trace statement in your if statement and if the output window overflows, then that's your culprit.
2.) What you want is gotoAndPlay(-insert label here-)
Tho it is outside the scope of the question you have, I create a variable~Switch State machine to control states for me:
1.) Current State as a number (int, number, or uint)
2.) function with a switch statement (Switch is kind of a fancy if Statement)
3.) inside the cases are instructions
switch(current_state){
case 1:
linkMC.gotoAndPlay('death animation');
break;
}
if (current_state != 1){
-put movement code here-
}
This is close to what I use for my game. Just checking states or you can have a variable like the one above that explicitly checks for the death state and remove the ability to move. If you use a mouse (and I assume event listener) then you can remove the event listener for the mouse. If you use a solution like keyboard inputs then an if statement would be more what you are looking for.

Scratch walking animation broken

What it's supposed to do:
I'm making a game on Scratch in which the character has a walking animation. The walking animation is supposed to switch their costume to a walking stance, wait 0.5 seconds then go to an idle stance, wait 0.5 seconds then go to a walking stance, and repeat that until they let go of the button.
The image below is an image of the animation blocks put together that play the animation when walking left.
What it does do and suspected reason for the bug:
It worked perfectly until I added a block function for the same character, when suddenly the animations broke for that character and the other one (who also has a walking animation with the same code). The second image below is an image of the blocking code.
After adding the block function, instead of waiting 0.5 seconds in between costume switches, it seems to switch to the walking stance and then immediately switch to the idle stance instead of waiting.
The image below is showing the blocking blocks and the movement it controls. While they are blocking it isn't supposed to be able to move. That part works fine but I included it in case it has something else to do with my problem.
What I have tried:
I tried running the peice of code shown individually (seperate from the other animation parts) but the bug still occurs and the animation doesn't wait 0.5 seconds. I also tried changing the other character's animation so that it wouldn't activate when the animation broadcast was sent but it still bugged, which means:
The problem isn't because it runs with another sprite too. (Because if it was it would have fixed when I deactivated the other animation).
The problem also isn't because it's connected with the right side walking and idle animations (Because if it was it would have fixed when I ran it alone).
Link to shared game:
https://scratch.mit.edu/projects/690164519/
I think the issue is with this part of your code. The forever loop is always trying to set the costume to the idle state when BlockStatus is NonBlocking.
This is then fighting with the loop that is trying to manage the swap between the idle and the walking costumes.
You may need to set a flag when the key is pressed and move the walking animation into this loop?

Playing same animation action on loop without reseting position

I am trying to run a walking animation on a gltf model from animationClip. The goal is to play the walking animation whenever the up arrow key is pressed and keep it running if the key is held down. For that i am playing the animation whenever first animation is completed but the animtion only plays once. It triggers the finished event but there is no animation.
walkAction = mixer.clipAction(walkClip);
walkAction.loop = THREE.LoopOnce;
walkAction.enabled = true;
walkAction.paused = true;
walkAction.clampWhenFinished = true;
walkAction.play();
mixer.addEventListener('finished', restoreAnim);
function restoreAnim(event){
mixer.removeEventListener('finished', restoreAnim);
walkAction.play();
}
The above code was to keep the character keep moving but it clamps up after the first time but the finished eventListener is still triggered repeatedly.
Also is there any other way to do this. I am using walking animation from mixamo and the problem persists even when using multiple animations and changing different properties.
Where you are downloading that animation. if it's a site like "mixamo.com" there will be an option called "In place". you have to check that check box before you download your selected animation. Then your animation will play without repositioning its place.
check this "In place" checkbox

Animation is not looping

Im using Unity 5.3.4 and made some animation clips in the native animation panel of Unity, using keyframes.
In the Animator, I related those clips with transitions. I set "idle" as my entry clip and y checked "Loop Time" on it's properties. Nevertheless, when I hit play, the animation is not looping. It just play once and goes to the "jump" clip. Then it keeps rotation between "jump" and "hit".
Here's how things are done:
You should control the animation behaviour with conditions for example if you want it to loop till something happened you should first add a parameter to use it for checking if something happened then use it in conditions tab for example you can make an bool parameter then use it in condition so when it was checked you will move to the next state till then it will just loop in the current state , if you put no condition so there is nothing stopping the state machine from going to the next state
animation transitions
Another tutorial

JavaFx animation start/stop loop?

is there anyway that you can start and stop an animation, so plays for 1 sec, stops for 1 sec? I have tried to implement this with a radio button toggle with thread.sleep, however I dont think its possible this way. Are there any other ways to do this? thanks.
Given your animation:
Animation animation = ... ;
create a PauseTransition and place both in a SequentialTransition:
PauseTransition pause = new PauseTransition(Duration.seconds(1));
SequentialTransition seq = new SequentialTransition(animation, pause);
and then just play the sequential transition indefinitely (or as many times as you need):
seq.setCycleCount(Animation.INDEFINITE);
seq.play();
If you are using a Timeline as your animation, another approach is to add a key frame one second after the last key frame you have, that make no changes.

Resources