Class: Health

Phaser.Component. Health

new Health()

The Health component provides the ability for Game Objects to have a health property that can be damaged and reset through game code. Requires the LifeSpan component.

Source:
src/gameobjects/components/Health.js line 14

Members

health : number

The Game Objects health value. This is a handy property for setting and manipulating health on a Game Object.

It can be used in combination with the damage method or modified directly.

Type:
  • number
Default Value:
  • 1
Source:
src/gameobjects/components/Health.js line 26

maxHealth : number

The Game Objects maximum health value. This works in combination with the heal method to ensure the health value never exceeds the maximum.

Type:
  • number
Default Value:
  • 100
Source:
src/gameobjects/components/Health.js line 35

Methods

damage(amount)

Damages the Game Object. This removes the given amount of health from the health property.

If health is taken below or is equal to zero then the kill method is called.

Parameters:
Name Type Description
amount number

The amount to subtract from the current health value.

Source:
src/gameobjects/components/Health.js line 46
Returns:

This instance.

Type
Phaser.Sprite

heal(amount)

Heal the Game Object. This adds the given amount of health to the health property.

Parameters:
Name Type Description
amount number

The amount to add to the current health value. The total will never exceed maxHealth.

Source:
src/gameobjects/components/Health.js line 88
Returns:

This instance.

Type
Phaser.Sprite

setHealth(amount)

Sets the health property of the Game Object to the given amount. Will never exceed the maxHealth value.

Parameters:
Name Type Description
amount number

The amount to set the health value to. The total will never exceed maxHealth.

Source:
src/gameobjects/components/Health.js line 69
Returns:

This instance.

Type
Phaser.Sprite

phaser-ce@2.20.1 is on GitHub and NPM

Documentation generated by JSDoc 3.6.11 on 2024-10-05 using Tomorrow.