I'm trying to make a button with cool-down animation with Phaser 3. Here is the code.
class BootScene extends Phaser.Scene {
constructor() {
super();
}
preload() {
this.load.path = 'https://raw.githubusercontent.com/liyi93319/phaser3_rpg/main/part1/assets/cooldown/';
for (var i = 0; i < 16; i++) {
this.load.image("cooldown" + i, "cooldown" + i + ".png");
}
this.load.image('magicAttack', 'magicAttack.png');
}
create() {
this.add.image(100, 100, 'magicAttack').setScale(1)
var cd = this.add.sprite(100, 100, 'cooldown1').setFlipX(false).setScale(1.5)
let ani_frames = [];
for (var i = 0; i < 16; i++) {
ani_frames.push({ key: "cooldown" + i })
}
this.anims.create({
key: 'right',
frames: ani_frames,
frameRate: 11,
repeat: 0
});
cd.play('right');
let circle2 = this.add.circle(100, 100, 150, 0x000000, 0).setScale(.2)
cd.on('animationcomplete', () => {
cd.setVisible(false)
});
// circle.lineStyle(10, 0xffffff, 0.9);
circle2.setStrokeStyle(50, 0x000000, 1);
}
}
var config = {
width: 400,
height: 300,
physics: {
default: 'arcade',
arcade: {
gravity: {
y: 0
},
debug: false // set to true to view zones
}
},
backgroundColor: 0x000000,
scene: [BootScene]
}
var game = new Phaser.Game(config);
<script src="https://cdn.jsdelivr.net/npm/phaser@3.55.2/dist/phaser.js"></script>
The code above works as expected but may be a little bit heavy-weight.
I know I can make a sprite-sheet but it's still in the image way. Is it feasible to use crop or tweens in Phaser 3 to do the job?
I know I could also put a DOM on the scene as using div to make the animation appears easier. However, it seems less Phaser style, right?