I’m trying to modify the standard looping animation example (Phaser - Examples - Create Animation From Sprite Sheet) so that I can use a variable to control the number of times the animation loops.
I have tried two different ways to do this:
this.anims.create({
key: 'walk',
frames: this.anims.generateFrameNumbers('brawler', { frames: [ 0, 1, 2, 3 ] }),
frameRate: 8,
repeat: 7
});
const cody = this.add.sprite(400, 300);
cody.setScale(2);
cody.play('walk');
and
this.anims.create({
key: 'walk',
frames: this.anims.generateFrameNumbers('brawler', { frames: [ 0, 1, 2, 3 ] }),
frameRate: 8,
});
const cody = this.add.sprite(400, 300);
cody.setScale(2);
cody.play({key: 'walk', repeat: 7});
In both cases, the animation will loop according to the value (7 in both examples). However, if I replace ‘7’ with a variable that is equal to 7, it will only loop once.
Is there a better way to handle this?
Thanks!