Il peut être un peu compliqué en utilisant des graphiques, mais je l'ai trouvé un exemple en utilisant BitmapData:
create: function(){
var bmd = this.game.add.bitmapData(300, 40);
bmd.ctx.beginPath();
bmd.ctx.rect(0, 0, 300, 80);
bmd.ctx.fillStyle = '#00685e';
bmd.ctx.fill();
var bglife = this.game.add.sprite(this.game.world.centerX, this.game.world.centerY, bmd);
bglife.anchor.set(0.5);
bmd = this.game.add.bitmapData(280, 30);
bmd.ctx.beginPath();
bmd.ctx.rect(0, 0, 300, 80);
bmd.ctx.fillStyle = '#FFFFFF';
bmd.ctx.fill();
this.widthLife = new Phaser.Rectangle(0, 0, bmd.width, bmd.height);
this.totalLife = bmd.width;
this.life = this.game.add.sprite(this.game.world.centerX - bglife.width/2 + 10, this.game.world.centerY, bmd);
this.life.anchor.y = 0.5;
this.life.cropEnabled = true;
this.life.crop(this.widthLife);
this.scheduler = this.game.time.events.loop(1500, this.cropLife, this);
},
cropLife: function(){
if(this.widthLife.width <= 0){
this.widthLife.width = this.totalLife;
this.scheduler.stop();
}
else{
this.game.add.tween(this.widthLife).to({ width: (this.widthLife.width - (this.totalLife/10)) }, 200, Phaser.Easing.Linear.None, true);
}
},
update: function(){
this.life.updateCrop();
}
You can see the discussion in detail here
Bienvenue sur Stack Overflow! Le contenu complet de votre question doit être ** dans ** votre question, pas seulement lié. Les liens pourrissent, rendant la question et ses réponses inutiles aux gens dans le futur, et les gens ne devraient pas avoir à quitter le site pour vous aider. Placez un [mcve] ** dans ** la question, idéalement en utilisant Stack Snippets (le bouton de barre d'outils '<>') pour le rendre exécutable. Plus: [* Comment puis-je poser une bonne question? *] (/ Help/how-to-ask) –
Thx supprimer, format de lien. –