How do you pause a sprite animation on a specific image?

Hi, I am unsure of how to pause a sprite on a specific image. By image I mean like a certain part of the animation clip.

So when the bird in my game is falling, I’m currently using this code to pause the animation:


   var zrot = pc.math.clamp(this.velocity, -2, -0.75);
            zrot += 1;
            this.entity.setLocalEulerAngles(0, 0, zrot * 90);    
            
            var pos1;
            pos1 = this.entity.getEulerAngles();
            
            if (pos1.z < -60) {
            
                
                this.entity.sprite.pause();
                
            } else {
            this.entity.sprite.resume();
            }

This works ok, it’s just I need it to pause when it hits a certain part of the animation. Thanks for any help :slight_smile:

Hi @ThePastaNebula,

So, if you know the frame (e.g. 5) at which you want to pause the animation, you can do something like this in your script update method:

MyScript.prototype.initialize = function(){

   this.clipPlaying = this.entity.sprite.play();
};

MyScript.prototype.update = function(dt){

   if( this.clipPlaying.frame === 5 ){

      this.clipPlaying.pause();
   }

};
1 Like

Hey, thanks! This works now as intended :slight_smile:

1 Like