Class object2d
Extends
component.
object2d
Defined in: object2d.js.
Constructor Attributes | Constructor Name and Description |
---|---|
object2d()
A component that gives movement and collision-detection
related attributes to an Entity in 2D space
Known component events:
- on-move: Called - on-collide: |
Field Attributes | Field Name and Description |
---|---|
When set, redefines the collider
for the object.
|
|
Returns the direction that the obejct is traveling in degress.
|
|
Sets the amount of resistance to speed measured as a percentile.
|
|
Same as frinctionX, but is applied in the vertical direction.
|
|
Sets/Gets the collision group.
|
|
Returns the entity that this object last collided with.
|
|
Returns the previous position that was used before the current position
when this object2d was attached.
|
|
Based on the objects current velocity, returns the position that will be used
as the new position next frame.
|
|
Returns the speed of the object.
|
|
Horizontal velocity of the object.
|
|
Vertical velocity of the object.
|
- Fields borrowed from class component:
- host, info, isDrawing, isStepping, onAttach, onDraw, onStep, tag
Method Attributes | Method Name and Description |
---|---|
addVelocity(factor, direction)
Compounds a velocity vector with the current velocity
|
|
addVelocityTowards(factor, target)
Compounds a velocity vector with the current velocity towards a point.
|
|
disableGroupInteraction(src, dest)
Disables collisions between the given groups.
|
|
enableGroupInteraction(src, dest)
Enables collisions between the given groups.
|
|
halt()
Reduces the speed of the Entity to 0.
|
|
Stops continuous motion consideration for the collider for the next frame.
|
|
setVelocity(factor, direction)
Sets the velocity vector of an object.
|
|
setVelocityTowards(factor, target)
Sets the velocity vector of an object.
|
- Methods borrowed from class component:
- canHandleEvent, draw, emitEvent, getKnownEvents, installEvent, installHandler, installHook, step, uninstallEvent, uninstallHandler, uninstallHook
Class Detail
object2d()
A component that gives movement and collision-detection
related attributes to an Entity in 2D space
Known component events:
- on-move: Called - on-collide:
Field Detail
collider
When set, redefines the collider
for the object. The array should be pairs of xy values
to define the colled polygon object.
direction
Returns the direction that the obejct is traveling in degress.
frictionX
Sets the amount of resistance to speed measured as a percentile.
Every frame, only the amount percent of the host Entity's velocity is retained. For example,
if amt is specified to be .95, every frame 5% of the Entity's speed will be lost.
This is applied in the horizontal direction.
frictionY
Same as frinctionX, but is applied in the vertical direction.
group
Sets/Gets the collision group. Groups can be used to ignore sets of object2D colliders
efficently before collisions are processed. The default for all groups is sandboxe.object2d.group.a)
lastCollided
Returns the entity that this object last collided with.
lastPosition
Returns the previous position that was used before the current position
when this object2d was attached.
nextPosition
Based on the objects current velocity, returns the position that will be used
as the new position next frame. Note that if the object moves by other means
(i.e. the host's node is modified), the nextPosition will also change.
speed
Returns the speed of the object.
velocityX
Horizontal velocity of the object.
velocityY
Vertical velocity of the object.
Method Detail
addVelocity(factor, direction)
Compounds a velocity vector with the current velocity
- Parameters:
- {Number} factor
- The velocity amount to add. Can be negative.
- {Number} direction
- The direction to apply the velocity in degrees.
addVelocityTowards(factor, target)
Compounds a velocity vector with the current velocity towards a point.
- Parameters:
- {Number} factor
- The velocity amount to add. Can be negative.
- {vector} target
- The point to add velocity towards
disableGroupInteraction(src, dest)
Disables collisions between the given groups.
- Parameters:
- {Number} src
- Group in question
- {Number} dest
- Group to prevent collisions with in future collisions
enableGroupInteraction(src, dest)
Enables collisions between the given groups. By default, all groups can collide
with all other groups, including itself.
- Parameters:
- {Number} src
- Group in question
- {Number} dest
- Group to collide with in future collisions
halt()
Reduces the speed of the Entity to 0.
ResetMotion()
Stops continuous motion consideration for the collider for the next frame.
setVelocity(factor, direction)
Sets the velocity vector of an object.
- Parameters:
- {Number} factor
- The velocity to set.
- {Number} direction
- The direction to set the velocity in degrees.
setVelocityTowards(factor, target)
Sets the velocity vector of an object.
- Parameters:
- {Number} factor
- The velocity to set.
- {vector} target
- The point to set velocity towards