Neeraj
June 26, 2023, 3:09am
1
I created a loop animation for texture, now i want to stop can anyone suggest how to stop this when click on button.
BABYLON.Texture.prototype.animateVOffset = function (
propValue,
animSpeed,
shouldLoop
) {
var ease = new BABYLON.CubicEase();
ease.setEasingMode(BABYLON.EasingFunction.EASINGMODE_EASEINOUT);
textureAnimation = new BABYLON.Animation(
"at4",
"vOffset",
animSpeed,
BABYLON.Animation.ANIMATIONTYPE_FLOAT,
BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE
);
var keys = [];
keys.push({
frame: 0,
value: this.vOffset,
});
keys.push({
frame: 120,
value: propValue,
});
textureAnimation.setKeys(keys);
this.animations = [];
this.animations.push(textureAnimation);
if (shouldLoop) {
scene.beginAnimation(this, 0, 120, true);
} else {
scene.beginDirectAnimation(this, [textureAnimation], 0, 120, false);
}
};
Without any more info. This would be my approach:
if (shouldLoop) {
this.animatable = scene.beginAnimation(this, 0, 120, true);
} else {
this.animatable = scene.beginDirectAnimation(this, [textureAnimation], 0, 120, false);
}
In my GUI button onClickObservable:
if(myTexture.animatable) myTexture.animatable.stop()
3 Likes
Neeraj
June 26, 2023, 5:11pm
3
@Takemura is there any function for to play the animation???
function pauseAnimationFlow() {
firstCurrent = scene.getTextureByName('my-texture1');
if (firstCurrent && firstCurrent.animatable) {
firstCurrent.animatable.stop();
}
}
function resumeAnimationFlow() {
firstCurrent = scene.getTextureByName('my-texture1');
if (firstCurrent && firstCurrent.animatable) {
firstCurrent.animatable.play();
}
}
because play is not working in this case and i run the resume when pause button first clicked then resume will run
Uncaught TypeError: firstCurrent.animatable.play is not a function
Instead of stop() you might want to use pause(), if you want to resume. Then it should work to resume with restart(). The stop()-function resets to animation key frame 0.
2 Likes