Construct a HealthBehavior
OptionalhitPoints?: numberStarting hit points (default 1)
OptionalonDefeated?: (a: Actor, defeatedBy?: Actor<unknown>) => voidCode to run when this actor is defeated
OptionalonHitPointsChange?: (a: Actor) => voidCode to run on any change to hit points
Optionalteam?: numberThe team this actor belongs to (default 0)
Protected Optional_The actor associated with this Behavior
OptionalonCode to run when this actor's health drops to 0 and it is defeated
OptionalonCode to run when this actor's hit points change
Which "team" this Behavior belongs to. A team is just a number, and for
the most part it's only when user code consults teams that teams have
meaning. The only exception is that HazardBehavior uses team to prevent
team attack damage.
The actor associated with this Behavior
Remaining hit points
Setting this fires onHitPointsChange (if provided) when the value actually changes
Time (seconds) until invincibility runs out
Setting a positive value fires an INV_Y state-change event, so an
AnimatedSprite observing this actor can switch to an invincibility
animation. Setting it back to 0 (e.g. to cancel invincibility early,
rather than letting it decay naturally) fires INV_N, so that animation is
cleared.
Apply damage. While invincible, damage is ignored (unless
ignoreInvincibility is set). If hit points drop to 0 or below, the
actor is defeated (removed, and onDefeated runs).
How much damage to apply
OptionaldefeatedBy: Actor<unknown>
The actor responsible for the damage, if any
Apply the damage even if the actor is currently invincible
Indicate that this Behavior should ignore collisions with some other property
ProtecteddisableTurn off physical collisions for actor. Used by Behaviors that are only
ever passed through, not physically collided with, like coins.
The actor being attached (may be undefined, if this Behavior is being detached)
ProtectedrequireIf actor's body isn't dynamic, warn and upgrade it to dynamic. Used
by every Behavior whose whole point requires a dynamic body (e.g.
setVelocity/forces actually doing something).
The actor being attached (may be undefined, if this Behavior is being detached)
The name to use in the warning message
HealthBehavior tracks hit points for anything that can be hurt / defeated. It also provides invincibility.