Skip to content

Commit 7fb555e

Browse files
Adds Heal Method to Phaser.Components.Health
Ideal when used in games with health packs, bonus items, or healing sprites. In fact: Doing a negative damage causes the same effect, but as a new method is better for documentation.
1 parent 63c9d2e commit 7fb555e

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

src/gameobjects/components/Health.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,22 @@ Phaser.Component.Health.prototype = {
4949

5050
}
5151

52+
/**
53+
* Heal the Game Object. This adds the given amount of health from the `health` property.
54+
*
55+
* @member
56+
* @param {number} amount - The amount to add from the current `health` value.
57+
* @return {Phaser.Sprite} This instance.
58+
*/
59+
heal: function(amount) {
60+
61+
if (this.alive)
62+
{
63+
this.health += amount;
64+
}
65+
66+
return this;
67+
68+
}
69+
5270
};

0 commit comments

Comments
 (0)