Meter

Extends: BGE.UI.UiWidget

A screen-space bar for health, stamina, boss health and the like: fills drawn on a backing, with optional extras.

  • Lag chunk: when the value drops, the lost part stays in lagColor for lagHoldSeconds, then drains away (lagEnabled).
  • Blink: the fill flashes blinkColor while empty (blinkWhenEmpty) or for a moment after refuse(), e.g. when an action needs more stamina than there is.
  • Layers: setLayer() adds more fills under the main one (e.g. a shield).
  • Label: text above the bar (e.g. a boss's name).

Add it to gameUi like any widget, or call drawAt() yourself from a draw hook (call update() each frame then).

Properties

  • fillColor (integer)
  • backColor (integer)
  • borderSize (float) — Pixels of backing showing around the fill.
  • lagEnabled (boolean) — Every drop restarts the hold, so a value that drops steadily (stamina draining) builds
  • lagColor (integer)
  • lagHoldSeconds (float)
  • lagDrainPerSecond (float) — How fast the lag chunk drains, in fractions of the bar per second.
  • blinkWhenEmpty (boolean)
  • blinkColor (integer)
  • refuseSeconds (float) — Seconds refuse() blinks for.
  • blinkRate (float) — Blinks per second.
  • label (string) — Text above the bar. "" = none.
  • labelColor (integer)
  • labelFontName (string) — Font key for the label ("body", falling back to "default").
  • labelAlign (string) — "left" or "center".

Example

CODE
health = new BGE.UI.Meter(game)
health.width = 400
health.height = 14
health.lagEnabled = true
scene.addUi(health)
' every frame:
health.setValue(player.health, player.maxHealth)

Constructor

new Meter(game: BGE.Game): Meter

Parameters


Instance Methods

setValue(value: float, maxValue?: float): void

Sets the value. The lag chunk (if enabled) starts holding on every drop.

Parameters

  • value (float)
  • maxValue (float, optional, default: "1.0")

Returns

  • void

resetValue(value: float, maxValue?: float): void

Sets the value at once, with no lag chunk.

Parameters

  • value (float)
  • maxValue (float, optional, default: "1.0")

Returns

  • void

getFraction(): float

The value as a fraction of the bar, 0 to 1.

Returns

  • float

getLagFraction(): float

Where the lag chunk ends, 0 to 1.

Returns

  • float

refuse(): void

Blinks the fill for refuseSeconds.

Returns

  • void

isBlinkOn(): boolean

Is the fill drawn in blinkColor right now?

Returns

  • boolean

setLayer(key: string, fraction: float, color: integer): void

Adds or replaces an extra fill drawn under the main one. Layers draw in key order.

Parameters

  • key (string)
  • fraction (float) — 0 to 1
  • color (integer)

Returns

  • void

removeLayer(key: string): void

Removes a layer added with setLayer().

Parameters

  • key (string)

Returns

  • void

update(dt: float): void

Advances the lag chunk and blinking. Called for you when the meter is in gameUi.

Parameters

  • dt (float) — seconds

Returns

  • void

onUpdate(deltaTime: float): void

Parameters

  • deltaTime (float)

Returns

  • void

draw(parent?: UiWidget): void

Parameters

  • parent (UiWidget, optional, default: "invalid")

Returns

  • void

drawAt( renderer: BGE.Renderer, x: float, y: float, width: float, height: float, ): void

Draws the meter with its fill area at x, y.

Parameters

  • renderer (BGE.Renderer)
  • x (float)
  • y (float)
  • width (float)
  • height (float)

Returns

  • void