Physics2D
|
A 2D Physics enabled screen. More...
Public Member Functions | |
PhysicsScreen (Number worldScale, Number freq) | |
Creates a new physics screen. | |
PhysicsScreen () | |
Default constructor. | |
PhysicsScreenEntity * | addPhysicsChild (ScreenEntity *newEntity, int entType, bool isStatic, Number friction=0.1, Number density=1, Number restitution=0, bool isSensor=false, bool fixedRotation=false) |
Adds a ScreenEntity as a physics enabled child. | |
void | removePhysicsChild (ScreenEntity *entityToRemove) |
Removes a physics child from the screen. | |
PhysicsScreenEntity * | addCollisionChild (ScreenEntity *newEntity, int entType) |
Begins tracking collisions for a ScreenEntity. | |
void | destroyJoint (PhysicsJoint *joint) |
Removes an existing joint. | |
PhysicsJoint * | createDistanceJoint (ScreenEntity *ent1, ScreenEntity *ent2, bool collideConnected) |
Creates a new distance joint. | |
PhysicsJoint * | createPrismaticJoint (ScreenEntity *ent1, ScreenEntity *ent2, Vector2 worldAxis, Number ax, Number ay, bool collideConnected=false, Number lowerTranslation=0, Number upperTranslation=0, bool enableLimit=false, Number motorSpeed=0, Number motorForce=0, bool motorEnabled=false) |
Creates a new prismatic joint. | |
PhysicsJoint * | createRevoluteJoint (ScreenEntity *ent1, ScreenEntity *ent2, Number ax, Number ay, bool collideConnected=false, bool enableLimit=false, Number lowerLimit=0, Number upperLimit=0, bool motorEnabled=false, Number motorSpeed=0, Number maxTorque=0) |
Creates a new revolute joint. | |
void | applyForce (ScreenEntity *ent, Number fx, Number fy) |
Applies linear force to an entity. | |
void | applyImpulse (ScreenEntity *ent, Number fx, Number fy) |
Applies an impulse to an entity. | |
void | setGravity (Vector2 newGravity) |
Sets the gravity for this screen. | |
void | setTransform (ScreenEntity *ent, Vector2 pos, Number angle) |
Warps an entity to the specified location and angle. | |
void | setVelocity (ScreenEntity *ent, Number fx, Number fy) |
Sets the linear velocity of an entity. | |
void | setVelocityX (ScreenEntity *ent, Number fx) |
Sets the linear velocity of an entity on the X axis. | |
void | setVelocityY (ScreenEntity *ent, Number fy) |
Sets the linear velocity of an entity on the Y axis. | |
void | setSpin (ScreenEntity *ent, Number spin) |
Sets the spin of an entity. | |
Vector2 | getVelocity (ScreenEntity *ent) |
Returns the velocity of an entity. | |
void | wakeUp (ScreenEntity *ent) |
Wake up a sleeping entity. | |
ScreenEntity * | getEntityAtPosition (Number x, Number y) |
Returns the entity at the specified position. | |
bool | testEntityAtPosition (ScreenEntity *ent, Number x, Number y) |
Returns true if the specified entity is at the specified position. | |
bool | testEntityCollision (ScreenEntity *ent1, ScreenEntity *ent2) |
Tests collision between two entities. | |
PhysicsScreenEntity * | getPhysicsByScreenEntity (ScreenEntity *ent) |
Returns the physics entity for the specified screen entity. |
A 2D Physics enabled screen.
A PhysicsScreen acts like a normal screen, except that entities added to it with addPhysicsChild have physics automatically simulated. You can also use it to check collisions using addCollisionChild.
PhysicsScreenEntity * PhysicsScreen::addCollisionChild | ( | ScreenEntity * | newEntity, |
int | entType | ||
) |
Begins tracking collisions for a ScreenEntity.
newEntity | Entity to track collisions for. |
entType | Physics shape of the entity. Possible values are PhysicsScreenEntity::ENTITY_RECT or PhysicsScreenEntity::ENTITY_CIRCLE. |
entityToRemove | Entity to remove from the screen. |
PhysicsScreenEntity * PhysicsScreen::addPhysicsChild | ( | ScreenEntity * | newEntity, |
int | entType, | ||
bool | isStatic, | ||
Number | friction = 0.1 , |
||
Number | density = 1 , |
||
Number | restitution = 0 , |
||
bool | isSensor = false , |
||
bool | fixedRotation = false |
||
) |
Adds a ScreenEntity as a physics enabled child.
newEntity | Screen entity to add. |
entType | Physics entity type to add as. Possible values are PhysicsScreenEntity::ENTITY_RECT, PhysicsScreenEntity::ENTITY_CIRCLE and PhysicsScreenEntity::ENTITY_MESH. If the type is ENTITY_MESH, the ScreenEntity passed must be a ScreenMesh! |
isStatic | If this parameter is true, the body is static (doesn't move on its own). |
friction | Friction of the physics entity. Friction controls how entities drag along each other. |
density | Density of the physics entity. Density controls how heavy the entity is. |
restitution | Restitution of the physics entity. Restitution controls how bouncy the entity is. |
isSensor | If this is set to true, the entity won't collide with other entities, but its collision will register. |
fixedRotation | If this is set to true, the entity will always have a locked rotation. |
void PhysicsScreen::applyForce | ( | ScreenEntity * | ent, |
Number | fx, | ||
Number | fy | ||
) |
Applies linear force to an entity.
ent | Entity to apply force to. |
fx | X value of the force direction vector. |
fy | Y value of the force direction vector. |
void PhysicsScreen::applyImpulse | ( | ScreenEntity * | ent, |
Number | fx, | ||
Number | fy | ||
) |
Applies an impulse to an entity.
ent | Entity to apply force to. |
fx | X value of the impulse direction vector. |
fy | Y value of the impulse direction vector. |
PhysicsJoint * PhysicsScreen::createDistanceJoint | ( | ScreenEntity * | ent1, |
ScreenEntity * | ent2, | ||
bool | collideConnected | ||
) |
Creates a new distance joint.
Distance joints keep the two entities at a fixed distance.
ent1 | First entity to join. |
ent2 | Second entity to join. |
collideConnected | If set to true, both entities will collide with each other, if false, they will not. |
PhysicsJoint * PhysicsScreen::createPrismaticJoint | ( | ScreenEntity * | ent1, |
ScreenEntity * | ent2, | ||
Vector2 | worldAxis, | ||
Number | ax, | ||
Number | ay, | ||
bool | collideConnected = false , |
||
Number | lowerTranslation = 0 , |
||
Number | upperTranslation = 0 , |
||
bool | enableLimit = false , |
||
Number | motorSpeed = 0 , |
||
Number | motorForce = 0 , |
||
bool | motorEnabled = false |
||
) |
Creates a new prismatic joint.
Prismatic joints provide one degree of freedom between two entities.
ent1 | First entity to join. |
ent2 | Second entity to join. |
collideConnected | If set to true, both entities will collide with each other, if false, they will not. |
ax | Anchor point x (relative to first entity) |
ay | Anchor point y (relative to first entity) |
enableLimit | If true, the rotation will be limited to the specified values |
lowerTranslation | If enableLimit is true, specifies the lower translation limit. |
upperTranslation | If enableLimit is true, specifies the upper translation limit. |
motorEnabled | If enabled, applies a constant motor to the rotation joint. |
motorSpeed | If motorEnabled is true, controls the speed at which the motor rotates. |
maxTorque | If motorEnabled is true, specifies the maximum force applied. |
worldAxis | Specifies the relative world axis for the prismatic joint. |
PhysicsJoint * PhysicsScreen::createRevoluteJoint | ( | ScreenEntity * | ent1, |
ScreenEntity * | ent2, | ||
Number | ax, | ||
Number | ay, | ||
bool | collideConnected = false , |
||
bool | enableLimit = false , |
||
Number | lowerLimit = 0 , |
||
Number | upperLimit = 0 , |
||
bool | motorEnabled = false , |
||
Number | motorSpeed = 0 , |
||
Number | maxTorque = 0 |
||
) |
Creates a new revolute joint.
Revolute joints enable one entity to rotate around a point on another entity.
ent1 | Entity to anchor to. |
ent2 | Entity to anchor. |
ax | Anchor point x (relative to first entity) |
ay | Anchor point y (relative to first entity) |
enableLimit | If true, the rotation will be limited to the specified values |
lowerLimit | If enableLimit is true, specifies the lower limit of the rotation in degrees. |
upperLimit | If enableLimit is true, specifies the upper limit of the rotation in degrees. |
motorEnabled | If enabled, applies a constant torque to the rotation joint. |
motorSpeed | If motorEnabled is true, controls the speed at which the motor rotates. |
maxTorque | If motorEnabled is true, specifies the maximum torque applied. |
void PhysicsScreen::destroyJoint | ( | PhysicsJoint * | joint | ) |
Removes an existing joint.
joint | Joint to remove. |
ScreenEntity * PhysicsScreen::getEntityAtPosition | ( | Number | x, |
Number | y | ||
) |
Returns the entity at the specified position.
x | X position. |
y | Y position. |
PhysicsScreenEntity * PhysicsScreen::getPhysicsByScreenEntity | ( | ScreenEntity * | ent | ) |
Returns the physics entity for the specified screen entity.
When you add ScreenEntities to the physics screen, these physics entities are created to track the physics status of the screen entities. You don't need to deal with these ever, but if you want, you can get them anyway.
ent | ScreenEntity instance to return the physics entity for. |
Vector2 PhysicsScreen::getVelocity | ( | ScreenEntity * | ent | ) |
Returns the velocity of an entity.
ent | Entity to return velocity for |
void PhysicsScreen::removePhysicsChild | ( | ScreenEntity * | entityToRemove | ) |
Removes a physics child from the screen.
entityToRemove | Entity to remove from the screen. |
void PhysicsScreen::setGravity | ( | Vector2 | newGravity | ) |
Sets the gravity for this screen.
newGravity | The new gravity vector. |
void PhysicsScreen::setSpin | ( | ScreenEntity * | ent, |
Number | spin | ||
) |
Sets the spin of an entity.
ent | Entity to apply spin to. |
spin | Spin value. |
void PhysicsScreen::setTransform | ( | ScreenEntity * | ent, |
Vector2 | pos, | ||
Number | angle | ||
) |
Warps an entity to the specified location and angle.
ent | Entity to transform. |
pos | New position to set. |
angle | New angle to set. |
void PhysicsScreen::setVelocity | ( | ScreenEntity * | ent, |
Number | fx, | ||
Number | fy | ||
) |
Sets the linear velocity of an entity.
ent | Entity to set velocity to. |
fx | X direction of velocity vector. |
fy | Y direction of velocity vector. |
void PhysicsScreen::setVelocityX | ( | ScreenEntity * | ent, |
Number | fx | ||
) |
Sets the linear velocity of an entity on the X axis.
ent | Entity to set velocity to. |
fx | X direction of velocity vector. |
void PhysicsScreen::setVelocityY | ( | ScreenEntity * | ent, |
Number | fy | ||
) |
Sets the linear velocity of an entity on the Y axis.
ent | Entity to set velocity to. |
fy | Y direction of velocity vector. |
bool PhysicsScreen::testEntityAtPosition | ( | ScreenEntity * | ent, |
Number | x, | ||
Number | y | ||
) |
Returns true if the specified entity is at the specified position.
ent | Entity to test. |
x | X position. |
y | Y position. |
void PhysicsScreen::wakeUp | ( | ScreenEntity * | ent | ) |
Wake up a sleeping entity.
The physics engine puts non-moving entities to sleep automatically. Use this to wake them up.
ent | Entity to wake up. |