Class: HealthBar

HealthBar()

new HealthBar()

Source:

Extends

Members

IMAGES :Array.<string>

Array of image paths for different health levels (0–100%). Used to reflect the player's current health visually.
Type:
  • Array.<string>
Source:

height :number

Height of the status bar in pixels.
Type:
  • number
Inherited From:
Source:

percentage :number

Current percentage value represented by the bar (0–100). Determines which image is displayed.
Type:
  • number
Inherited From:
Source:

width :number

Width of the status bar in pixels.
Type:
  • number
Inherited From:
Source:

x :number

Horizontal position of the status bar on the screen.
Type:
  • number
Inherited From:
Source:

y :number

Vertical position of the health bar on the canvas. Usually fixed to the top edge of the screen.
Type:
  • number
Source:

Methods

resolveImageIndex() → {number}

Resolves the image index based on the current percentage value. Used to determine which visual state of the bar to display.
Inherited From:
Source:
Returns:
Index of the image corresponding to the percentage.
Type
number

setPercentage(percentage)

Updates the current percentage and sets the corresponding image. The image is chosen based on the percentage value using resolveImageIndex().
Parameters:
Name Type Description
percentage number The new percentage value (0–100).
Inherited From:
Source:

HealthBar(percentage)

new HealthBar(percentage)

Creates a new HealthBar instance and sets the initial health percentage.
Parameters:
Name Type Description
percentage number Initial health value (0–100).
Source:

Members

IMAGES :Array.<string>

Array of image paths for different health levels (0–100%). Used to reflect the player's current health visually.
Type:
  • Array.<string>
Source:

height :number

Height of the status bar in pixels.
Type:
  • number
Inherited From:
Source:

percentage :number

Current percentage value represented by the bar (0–100). Determines which image is displayed.
Type:
  • number
Inherited From:
Source:

width :number

Width of the status bar in pixels.
Type:
  • number
Inherited From:
Source:

x :number

Horizontal position of the status bar on the screen.
Type:
  • number
Inherited From:
Source:

y :number

Vertical position of the health bar on the canvas. Usually fixed to the top edge of the screen.
Type:
  • number
Source:

Methods

resolveImageIndex() → {number}

Resolves the image index based on the current percentage value. Used to determine which visual state of the bar to display.
Inherited From:
Source:
Returns:
Index of the image corresponding to the percentage.
Type
number

setPercentage(percentage)

Updates the current percentage and sets the corresponding image. The image is chosen based on the percentage value using resolveImageIndex().
Parameters:
Name Type Description
percentage number The new percentage value (0–100).
Inherited From:
Source: