Sign in to follow this  
Fric

How to not loop animation

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

Share this post


Link to post
Share on other sites
On 11/16/2018 at 12:41 AM, Fric said:

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

you can replace false instead of adding true.

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

Like this,

And also in repeat param you assign value 0.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.