Jump to content

Repeat the animation with only last two frames


tryhardprojects
 Share

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.

Link to comment
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);

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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