Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use pause() in Phaser 3 to stop at a specific frame?

I have a sprite with 6 frames, and when I click on a button I want to show the frame 3, for example. I'm try this code, but it's still stopping in frame 1.

function preload (){
    this.load.spritesheet('info', 'images/info.png', { frameWidth: 550, frameHeight: 400 });
}

function create (){
    var infos = this.add.sprite(275,200,"info")
    this.anims.create({
    key: "informations",
    frames: this.anims.generateFrameNumbers("info", { start: 0, end: 6 }),
    frameRate: 10,
    repeat: -1
    });

    // I'm try to show the frame 3 here.
    informations.pause(3);
    
    // When I play, the animation work!
    //infos.anims.play("informations", true);

}

I found the documentation for pause( [atFrame] ), but it isn't working.

like image 738
A. Ivo Avatar asked Sep 13 '25 20:09

A. Ivo


1 Answers

atFrame is actually of type Phaser.Animations.AnimationFrame. So you need to pass one of those.

You can get one of these types by calling infos.anims.currentAnim.frames[0] for example, where 0 is the index of the frame you want.

// Assuming you want the third actual frame:
infos.anims.pause(infos.anims.currentAnim.frames[2]);
like image 51
James Skemp Avatar answered Sep 17 '25 21:09

James Skemp