API Docs for: 1.0.1

Grape.Alarm Class

A utility class for creating timeouts in a game.

Constructor

Grape.Alarm

()

Methods

getAlarm

(
  • name
)
Number

Returns the remaining frames of a timeout

Parameters:

  • name String

    Alarm name

Returns:

Number:

The remaining time

getGame

() Grape.Game | Null

Gets the current game instance through the current layer.

Returns:

Grape.Game | Null:

The current game, or null, if the lookup fails.

getLayer

() Grape.Layer

Returns the layer the instance is added to.

Returns:

Grape.Layer:

The layer

getScene

() Grape.Scene | Null

Gets the root layer.

Returns:

Grape.Scene | Null:

The root layer, or null, if the lookup fails.

hasAlarm

(
  • id
)
Boolean

Tells whether a timeout with a given name exists.

Parameters:

  • id String

    Name of the timeout

Returns:

Boolean:

true, if the timeout exists

increaseAlarm

(
  • name
  • frames
)

Increases the duration of a timeout by a given amount. If timeout does not exist, the method creates it.

Parameters:

  • name String

    Alarm name

  • frames Number

    Number of frames to increase with

onGlobal

(
  • event
  • handler
)

Subscribes to an event on the layer the instance is added to. If the instance is not yet added to any layers, it will subscribe when added.

Parameters:

  • event String

    Event

  • handler Function

    Event listener

remove

()

Removes the instance from the layer.

setAlarm

(
  • name
  • frames
)

Sets a timeout with a given name in frames.

Parameters:

  • name String

    Alarm name

  • frames Number

    The number of frames after the alarm triggers

Events

alarm

When a timeout ends, this event occurs. The parameter is the name of the timeout.

alarm.<name>

When a timeout ends, this event occurs too.