PhysicsTarget Class
Physics mixin. This will add physics capabilities to the class it mixes into.
Constructor
PhysicsTarget
()
Item Index
Methods
disablePhysics
()
Mixed
chainable
async
Disbales physics for this sprite
Returns:
Returns itself.
disablePhysics
()
Mixed
chainable
async
Reindexes the collisions for this sprite, useful when moving the sprite a great deal (like to a new world)
Returns:
Returns itself.
enablePhysics
-
system
Enables physics for this sprite
Parameters:
-
system
PhysicsSystemThe system for the sprite to be in
Returns:
Returns itself.
setMass
-
mass
Sets the mass of this sprite
Parameters:
-
mass
NumberThe new mass of the object
Returns:
Returns itself.
setPosition
-
x
-
y
Sets the position of this sprite
Parameters:
-
x
Number -
y
Number
Returns:
Returns itself.
setRotation
-
rotation
Sets the rotation of this sprite
Parameters:
-
rotation
NumberThe new rotation of the object in radians
Returns:
Returns itself.
setVelocity
-
velocity
Sets the velocity of this sprite
Parameters:
-
velocity
VectorThe new velocity of the object
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: {}
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:
-
obj
SpriteColliding sprite
-
colShape
cp.ShapeThe colliding physics shape
-
myShape
cp.ShapeYour physics shape that caused the collision