Grape.Physical Class
Provides simple physics: velocity. In the future more features can be added like friction or acceleration
Item Index
Methods
accelerate
-
plus
Increases the speed by a given amount, keeping the original direction.
Parameters:
-
plus
NumberThe amount the speed is increased with
Returns:
this
getGame
()
Grape.Game | Null
Gets the current game instance through the current layer.
Returns:
The current game, or null, if the lookup fails.
getScene
()
Grape.Scene | Null
Gets the root layer.
Returns:
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:
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
StringEvent
-
handler
FunctionEvent listener
remove
()
Removes the instance from the layer.
setSpeed
-
speed
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
Numbernew Speed
Returns:
this
Properties
x
Number
X coordinate
Default: 0
y
Number
Y coordinate
Default: 0