tryhardprojects

Repeat the animation with only last two frames

Recommended Posts

Hello developers, I just start using phaser 3, and I bump into a question with the animation. Here is my code.


  var characterAnimConfig = {
    key: 'key-name',
    frames: scene.anims.generateFrameNumbers('spritenamehere', { start: 0, end: 7 }),
    repeat: -1,
    frameRate: 10,
  };

this means the animation will keep repeating from the first(frame 0) to the end(frame 7), my question is is there a way to let the animation only repeat the last two frame?
expected frame goes like this: (0,1,2,3,4,5,6,7,6,7,6,7,6,7...). Thanks.

Share this post


Link to post
Share on other sites

@tryhardprojects

This should work. You create 2 animations, first will be played once and when ends, event "animationcomplete" trigger second animation which will be played repeatedly.

this.anims.create(
{
  key: 'character_create',
  frames: this.anims.generateFrameNumbers('spritenamehere', { start: 0, end: 5 }),
  frameRate: 10,
});

this.anims.create(
{
  key: 'character_repeat',
  frames: this.anims.generateFrameNumbers('spritenamehere', { start: 6, end: 7 }),
  frameRate: 10,
  repeat: -1,
});

var character = this.add.sprite(x, z, 'character');
character.play('character_create');

character.on('animationcomplete', function (sprite)
{
  if (sprite.key === 'character_create')
  {
     character.play('character_repeat');
  }
}, this);

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.