JavaScript
class GameScene extends Phaser.Scene
{
constructor ()
{
super();
}
preload ()
{
this.load.spritesheet('brawler', 'https://labs.phaser.io/assets/animations/brawler48x48.png', { frameWidth: 48, frameHeight: 48 });
}
create ()
{
// Text section
const current = this.add.text(48, 300, 'ANIMATION TIME (should be close to 2400): ', { color: '#00ff00' });
// Animation set
this.anims.create({
key: 'walk',
frames: [
{ key: 'brawler', frame: 0, duration: 200 },
{ key: 'brawler', frame: 1, duration: 100 },
{ key: 'brawler', frame: 2, duration: 200 },
{ key: 'brawler', frame: 3, duration: 100 },
{ key: 'brawler', frame: 0, duration: 200 },
{ key: 'brawler', frame: 1, duration: 100 },
{ key: 'brawler', frame: 2, duration: 200 },
{ key: 'brawler', frame: 3, duration: 100 },
{ key: 'brawler', frame: 0, duration: 200 },
{ key: 'brawler', frame: 1, duration: 100 },
{ key: 'brawler', frame: 2, duration: 200 },
{ key: 'brawler', frame: 3, duration: 100 },
{ key: 'brawler', frame: 0, duration: 200 },
{ key: 'brawler', frame: 1, duration: 100 },
{ key: 'brawler', frame: 2, duration: 200 },
{ key: 'brawler', frame: 3, duration: 100 }
],
repeat: 0
});
const cody = this.add.sprite(600, 100);
cody.setScale(8);
cody.play('walk');
const currentTime = Date.now()
cody.on('animationcomplete', () => {
const time = Date.now() - currentTime
current.setText(`ANIMATION TIME (should be close to 2400): ${time}`);
})
}
}
new Phaser.Game({
type: Phaser.AUTO,
width: 800,
height: 400,
pixelArt: true,
scene:...