PhysicsTarget Class
Physics mixin. This will add physics capabilities to the class it mixes into.
Constructor
PhysicsTarget
()
Item Index
Methods
disablePhysics
-
callback
Disbales physics for this sprite
Parameters:
-
callbackFunctionThe callback function to call after physics have been disabled
Returns:
Returns itself.
disablePhysics
-
callback
Reindexes the collisions for this sprite, useful when moving the sprite a great deal (like to a new world)
Parameters:
-
callbackFunctionThe callback function to call after the sprite has been reindexed
Returns:
Returns itself.
enablePhysics
-
system -
callback
Enables physics for this sprite
Parameters:
-
systemPhysicsSystemThe system for the sprite to be in
-
callbackFunctionThe callback function to call after physics have been enabled
Returns:
Returns itself.
setMass
-
mass
Sets the mass of this sprite
Parameters:
-
massNumberThe new mass of the object
Returns:
Returns itself.
setPosition
-
x -
y
Sets the position of this sprite
Parameters:
-
xNumber | VectorThe x coord to set position to, if a Vector is passed the y param is ignored
-
yNumberThe y coord to set position to
Returns:
Returns itself.
setRotation
-
rotation
Sets the rotation of this sprite
Parameters:
-
rotationNumberThe new rotation of the object in radians
Returns:
Returns itself.
setVelocity
-
x -
y
Sets the velocity of this sprite
Parameters:
-
xNumber | VectorThe x coord to set the velocity to, if a Vector is passed the y param is ignored
-
yNumberThe y coord to set the velocity to
Returns:
Returns itself.
Properties
_phys
Object
private
The physics namespace that all physics properties go into. Those properties are:
- system {PhysicsSystem} PhysicsSystem that this object is a part of.
- active {Boolean} Whether or not this target is actively having physics simulated.
Default: {}
_velocity
Vector
private
The internal velocity value, used as a reusable vector for the setVelocity function. Setting this directly has no effect.
inertia
Number
The moment of inertia of this object, only set this before enabling physics (has no effect after enabling)
Default: 0
mass
Number
The mass of this object, please use setMass to set this value
Default: 0
Events
collision
On Collision Event called when this sprite collides into another, or is being collided into by another. By default if something collides with a collectable sprite we destroy the collectable and if we collide with a solid tile we kill our velocity. This method will emit a 'collision' event that you can listen for
separate
On Seperate Event called when this sprite collides into another, or is being collided into by another. By default if something collides with a collectable sprite we destroy the collectable and if we collide with a solid tile we kill our velocity. This method will emit a 'collision' event that you can listen for
Event Payload:
-
objSpriteColliding sprite
-
colShapecp.ShapeThe colliding physics shape
-
myShapecp.ShapeYour physics shape that caused the collision