Jump to content

How to not loop animation


Fric
 Share

Recommended Posts

I have animation 

this.anims.create({
    key: 'left',
    frames: this.anims.generateFrameNumbers('man', { start: 1, end: 3 }),
    frameRate: 10,
    repeat: -1
});

and when i press left key, i play it

if (cursors.left.isDown)
{
    player.setVelocityX(-160);
    player.anims.play('left', true);
}

I understand that repeat param is responsible for looping animation, but i tried 0, 1, false, -1 and the animation still loops.

I didn't find any DOC with all objects and there parameters, so i'm asking here

Link to comment
Share on other sites

On 11/19/2018 at 1:14 AM, Ananth said:

you can replace false instead of adding true.

player.anims.play('left', false);

Like this,

And also in repeat param you assign value 0.

Just wanted to expound upon this answer, for anyone who stumbles across this in the future. That second parameter on `anims.play` is named "ignoreIfPlaying." If false, whichever animation is currently playing will stop, even if it's the animation you intend to play. If true, then if you're already playing that animation it will continue.

It's false by default, so you can omit the second argument entirely.

Secondly, `repeat` determines the number of times the animation will play. When you have it as -1, Phaser interprets that as "loop indefinitely." The default value is 0, in which case the animation will play once, and repeat zero times.

For more info, see the API docs: https://photonstorm.github.io/phaser3-docs/Phaser.GameObjects.Components.Animation.html

And: https://photonstorm.github.io/phaser3-docs/Phaser.GameObjects.Components.Animation.html#play__anchor

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...