moveFrom(duration, speed, direction) → {boolean}
Note: This method is experimental, and may be changed or removed in a future release.
This method moves the Body in the given direction, for the duration specified.
It works by setting the velocity on the Body, and an internal timer, and then
monitoring the duration each frame. When the duration is up the movement is
stopped and the Body.onMoveComplete
signal is dispatched.
Movement also stops if the Body collides or overlaps with any other Body.
You can control if the velocity should be reset to zero on collision, by using
the property Body.stopVelocityOnCollide
.
Stop the movement at any time by calling Body.stopMovement
.
You can optionally set a speed in pixels per second. If not specified it
will use the current Body.speed
value. If this is zero, the function will return false.
Please note that due to browser timings you should allow for a variance in
when the duration will actually expire. Depending on system it may be as much as
+- 50ms. Also this method doesn't take into consideration any other forces acting
on the Body, such as Gravity, drag or maxVelocity, all of which may impact the
movement.
Parameters
Name | Type | Argument | Description |
---|---|---|---|
duration | integer | The duration of the movement, in ms. | |
speed | integer | <optional> | The speed of the movement, in pixels per second. If not provided |
direction | integer | <optional> | The angle of movement. If not provided |
Returns
True if the movement successfully started, otherwise false.
- Source code: physics/arcade/Body.js (Line 879)
Please login to continue.