Skip to content

Commit 10209dc

Browse files
committed
GameObject.revive used to add the health amount given to the Game Object (via heal) instead of setting it as the new health amount. It now calls setHealth instead, giving it the exact amount (thanks @netgfx phaserjs#2231)
GameObject.revive will now set the health amount to 100 instead of 1, bringing it in-line with the `maxHealth` default value.
1 parent a1c3050 commit 10209dc

3 files changed

Lines changed: 29 additions & 7 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ If you are an exceptional JavaScript developer and would like to join the Phaser
295295
* Tweens with 'yoyo' set on them couldn't be re-used again because the start and end properties were left in a reversed state. When a yoyo tween ends it now restores the reversed values (thanks @SBCGames #2307)
296296
* The width and height values passed to the Game constructor are now passed through Math.floor first. This ensures you can never create a game width non-integer dimensions, which has all kinds of implications - from browser performance to breaking things like TileSprite rendering (#2262)
297297
* Tilemap.getObjectIndex has been removed as it didn't work correctly in most cases, and it's easier to just scan the Tilemap.objects object directly anyway (#2242)
298-
298+
* GameObject.revive will now set the health amount to 100 instead of 1, bringing it in-line with the `maxHealth` default value.
299299

300300
### Bug Fixes
301301

@@ -319,6 +319,7 @@ If you are an exceptional JavaScript developer and would like to join the Phaser
319319
* BitmapText would load and parse the kerning data from the font, but would never use it when rendering. The kerning values are now applied on rendering as well (thanks @veu #2165)
320320
* SinglePad.callbackContext is now set through addCallbacks method (thanks @puzzud #2161)
321321
* Both `transparent` and `antialias` were ignored if set to `false` in a Game configuration object, as the `parseConfig` method didn't check for falsey values (thanks @amadeus #2302)
322+
* GameObject.revive used to add the health amount given to the Game Object (via `heal`) instead of setting it as the new health amount. It now calls `setHealth` instead, giving it the exact amount (thanks @netgfx #2231)
322323

323324
### Pixi Updates
324325

src/gameobjects/components/Health.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Phaser.Component.Health.prototype = {
4343
* @param {number} amount - The amount to subtract from the current `health` value.
4444
* @return {Phaser.Sprite} This instance.
4545
*/
46-
damage: function(amount) {
46+
damage: function (amount) {
4747

4848
if (this.alive)
4949
{
@@ -59,14 +59,35 @@ Phaser.Component.Health.prototype = {
5959

6060
},
6161

62+
/**
63+
* Sets the health property of the Game Object to the given amount.
64+
* Will never exceed the `maxHealth` value.
65+
*
66+
* @member
67+
* @param {number} amount - The amount to set the `health` value to. The total will never exceed `maxHealth`.
68+
* @return {Phaser.Sprite} This instance.
69+
*/
70+
setHealth: function (amount) {
71+
72+
this.health = amount;
73+
74+
if (this.health > this.maxHealth)
75+
{
76+
this.health = this.maxHealth;
77+
}
78+
79+
return this;
80+
81+
},
82+
6283
/**
6384
* Heal the Game Object. This adds the given amount of health to the `health` property.
6485
*
6586
* @member
6687
* @param {number} amount - The amount to add to the current `health` value. The total will never exceed `maxHealth`.
6788
* @return {Phaser.Sprite} This instance.
6889
*/
69-
heal: function(amount) {
90+
heal: function (amount) {
7091

7192
if (this.alive)
7293
{

src/gameobjects/components/LifeSpan.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,20 @@ Phaser.Component.LifeSpan.prototype = {
7272
* It will dispatch the `onRevived` event. Listen to `events.onRevived` for the signal.
7373
*
7474
* @method
75-
* @param {number} [health=1] - The health to give the Game Object. Only set if the GameObject has the Health component.
75+
* @param {number} [health=100] - The health to give the Game Object. Only set if the GameObject has the Health component.
7676
* @return {PIXI.DisplayObject} This instance.
7777
*/
7878
revive: function (health) {
7979

80-
if (health === undefined) { health = 1; }
80+
if (health === undefined) { health = 100; }
8181

8282
this.alive = true;
8383
this.exists = true;
8484
this.visible = true;
8585

86-
if (typeof this.heal === 'function')
86+
if (typeof this.setHealth === 'function')
8787
{
88-
this.heal(health);
88+
this.setHealth(health);
8989
}
9090

9191
if (this.events)

0 commit comments

Comments
 (0)