Class: ValueBar

ValueBar()

new ValueBar()

A UI element to visually represent a quantifiable value as a proportion of a maximum, such as health, mana, progress, etc.
Source:

Extends

  • BaseUIElement

Methods

(protected) _drawSelf(context, engine)

Specific drawing logic for the ValueBar. Called by BaseUIElement.render after visibility and context checks.
Parameters:
Name Type Description
context CanvasRenderingContext2D The rendering context.
engine
Source:

setPercentage(percentage)

Sets the fill level of the bar based on a percentage.
Parameters:
Name Type Description
percentage number The percentage (0 to 100) to fill the bar.
Source:

setValue(current, maxopt)

Sets the current and maximum values of the bar.
Parameters:
Name Type Attributes Description
current number The new current value.
max number <optional>
The new maximum value. If undefined, maxValue remains unchanged.
Source:

update(deltaTime, engine, mousePosopt)

Update logic for the ValueBar.
Parameters:
Name Type Attributes Description
deltaTime number The time elapsed since the last frame.
engine
mousePos Object <optional>
Current canvas-relative mouse position.
Source:

ValueBar(options)

new ValueBar(options)

Creates an instance of ValueBar.
Parameters:
Name Type Description
options object Configuration options for the value bar.
Properties
Name Type Attributes Default Description
x number <optional>
0 The x-coordinate.
y number <optional>
0 The y-coordinate.
width number <optional>
100 The width of the bar.
height number <optional>
10 The height of the bar.
maxValue number <optional>
100 The maximum value the bar can represent.
currentValue number <optional>
options.maxValue The current value to display.
backgroundColor string <optional>
'#444444' Color of the bar's background (empty part).
fillColor string <optional>
'skyblue' Color of the bar's fill (current value part).
borderColor string <optional>
'black' Color of the bar's border.
borderWidth number <optional>
1 Width of the border.
showText boolean <optional>
false Whether to display text value on the bar.
font string <optional>
Font for the text (if shown). Defaults to a calculated size.
textColor string <optional>
'white' Color for the text (if shown).
textFormatFunction function <optional>
Function to format the text. Receives (current, max). Defaults to `current / max`.
visible boolean <optional>
true Whether the bar is visible.
id string <optional>
Optional ID.
Source:

Methods

(protected) _drawSelf(context, engine)

Specific drawing logic for the ValueBar. Called by BaseUIElement.render after visibility and context checks.
Parameters:
Name Type Description
context CanvasRenderingContext2D The rendering context.
engine
Source:

setPercentage(percentage)

Sets the fill level of the bar based on a percentage.
Parameters:
Name Type Description
percentage number The percentage (0 to 100) to fill the bar.
Source:

setValue(current, maxopt)

Sets the current and maximum values of the bar.
Parameters:
Name Type Attributes Description
current number The new current value.
max number <optional>
The new maximum value. If undefined, maxValue remains unchanged.
Source:

update(deltaTime, engine, mousePosopt)

Update logic for the ValueBar.
Parameters:
Name Type Attributes Description
deltaTime number The time elapsed since the last frame.
engine
mousePos Object <optional>
Current canvas-relative mouse position.
Source: