tryhardprojects Posted May 18, 2018 Share Posted May 18, 2018 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 More sharing options...
kvazmatik Posted May 18, 2018 Share Posted May 18, 2018 @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); samme, blackhawx and tryhardprojects 3 Link to comment Share on other sites More sharing options...
tryhardprojects Posted May 21, 2018 Author Share Posted May 21, 2018 Thanks for your help. Solve my question perfectly! Wish you all the best! Link to comment Share on other sites More sharing options...
Recommended Posts