API Docs for: 1.0.1

Grape.Physical Class

Provides simple physics: velocity. In the future more features can be added like friction or acceleration

Methods

accelerate

(
  • plus
)
Grape.Physical chainable

Increases the speed by a given amount, keeping the original direction.

Parameters:

  • plus Number

    The amount the speed is increased with

Returns:

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.

getSpeed

() Number

Returns the speed of the instance, calculated by the speedX and speedY properties.

Returns:

Number:

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.

setSpeed

(
  • speed
)
Grape.Physical chainable

Sets the speed of the instance, keeping the original direction (or the opposite if speed is negative). If Original speed is 0, the direction is considered as 0 (left-to right).

Parameters:

  • speed Number

    new Speed

Returns:

Properties

x

Number

X coordinate

Default: 0

y

Number

Y coordinate

Default: 0