Cocos2d-x  v3.17
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Groups Pages
PhysicsBody Class Reference

A body affect by physics. More...

Inherits Component.

Public Member Functions

virtual PhysicsShapeaddShape (PhysicsShape *shape, bool addMassAndMoment=true)
 Add a shape to body. More...
 
void removeShape (PhysicsShape *shape, bool reduceMassAndMoment=true)
 Remove a shape from body. More...
 
var removeShape ( var shape, var true)
 Remove a shape from body. More...
 
local removeShape ( local shape, local true)
 Remove a shape from body. More...
 
void removeShape (int tag, bool reduceMassAndMoment=true)
 Remove a shape from body. More...
 
var removeShape ( var tag, var true)
 Remove a shape from body. More...
 
local removeShape ( local tag, local true)
 Remove a shape from body. More...
 
void removeAllShapes (bool reduceMassAndMoment=true)
 Remove all shapes. More...
 
var removeAllShapes ( var true)
 Remove all shapes. More...
 
local removeAllShapes ( local true)
 Remove all shapes. More...
 
const Vector< PhysicsShape * > & getShapes () const
 Get the body shapes. More...
 
local getShapes ()
 Get the body shapes. More...
 
PhysicsShapegetFirstShape () const
 Get the first shape of the body shapes. More...
 
var getFirstShape ()
 Get the first shape of the body shapes. More...
 
local getFirstShape ()
 Get the first shape of the body shapes. More...
 
PhysicsShapegetShape (int tag) const
 get the shape of the body. More...
 
local getShape ( local tag)
 get the shape of the body. More...
 
virtual void applyForce (const Vec2 &force, const Vec2 &offset=Vec2::ZERO)
 Applies a continuous force to body. More...
 
var applyForce ( var force, var ZERO)
 Applies a continuous force to body. More...
 
local applyForce ( local force, local ZERO)
 Applies a continuous force to body. More...
 
virtual void resetForces ()
 reset all the force applied to body.
 
virtual void applyImpulse (const Vec2 &impulse, const Vec2 &offset=Vec2::ZERO)
 Applies a immediate force to body. More...
 
var applyImpulse ( var impulse, var ZERO)
 Applies a immediate force to body. More...
 
local applyImpulse ( local impulse, local ZERO)
 Applies a immediate force to body. More...
 
virtual void applyTorque (float torque)
 Applies a torque force to body. More...
 
local applyTorque ( local torque)
 Applies a torque force to body. More...
 
virtual void setVelocity (const Vec2 &velocity)
 Set the velocity of a body. More...
 
local setVelocity ( local velocity)
 Set the velocity of a body. More...
 
virtual Vec2 getVelocity ()
 Get the velocity of a body. More...
 
var getVelocity ()
 Get the velocity of a body. More...
 
local getVelocity ()
 Get the velocity of a body. More...
 
virtual void setAngularVelocity (float velocity)
 Set the angular velocity of a body. More...
 
virtual Vec2 getVelocityAtLocalPoint (const Vec2 &point)
 Get the angular velocity of a body at a local point. More...
 
var getVelocityAtLocalPoint ( var point)
 Get the angular velocity of a body at a local point. More...
 
local getVelocityAtLocalPoint ( local point)
 Get the angular velocity of a body at a local point. More...
 
virtual Vec2 getVelocityAtWorldPoint (const Vec2 &point)
 get the angular velocity of a body at a world point
 
virtual float getAngularVelocity ()
 get the angular velocity of a body
 
virtual void setVelocityLimit (float limit)
 set the max of velocity
 
local setVelocityLimit ( local limit)
 set the max of velocity
 
virtual float getVelocityLimit ()
 get the max of velocity
 
var getVelocityLimit ()
 get the max of velocity
 
local getVelocityLimit ()
 get the max of velocity
 
virtual void setAngularVelocityLimit (float limit)
 set the max of angular velocity
 
virtual float getAngularVelocityLimit ()
 get the max of angular velocity
 
void removeFromWorld ()
 remove the body from the world it added to
 
var removeFromWorld ()
 remove the body from the world it added to
 
local removeFromWorld ()
 remove the body from the world it added to
 
PhysicsWorldgetWorld () const
 get the world body added to. More...
 
local getWorld ()
 get the world body added to. More...
 
const std::vector
< PhysicsJoint * > & 
getJoints () const
 get all joints the body have
 
local getJoints ()
 get all joints the body have
 
NodegetNode () const
 get the node the body set to. More...
 
void setCategoryBitmask (int bitmask)
 A mask that defines which categories this physics body belongs to. More...
 
void setContactTestBitmask (int bitmask)
 A mask that defines which categories of bodies cause intersection notifications with this physics body. More...
 
void setCollisionBitmask (int bitmask)
 A mask that defines which categories of physics bodies can collide with this physics body. More...
 
int getCategoryBitmask () const
 Return bitmask of first shape. More...
 
var getCategoryBitmask ()
 Return bitmask of first shape. More...
 
local getCategoryBitmask ()
 Return bitmask of first shape. More...
 
int getContactTestBitmask () const
 Return bitmask of first shape. More...
 
int getCollisionBitmask () const
 Return bitmask of first shape. More...
 
var getCollisionBitmask ()
 Return bitmask of first shape. More...
 
local getCollisionBitmask ()
 Return bitmask of first shape. More...
 
void setGroup (int group)
 Set the group of body. More...
 
int getGroup () const
 Return group of first shape. More...
 
Vec2 getPosition () const
 get the body position. More...
 
var getPosition ()
 get the body position. More...
 
local getPosition ()
 get the body position. More...
 
float getRotation ()
 get the body rotation. More...
 
var getRotation ()
 get the body rotation. More...
 
local getRotation ()
 get the body rotation. More...
 
void setPositionOffset (const Vec2 &position)
 set body position offset, it's the position witch relative to node
 
var setPositionOffset ( var position)
 set body position offset, it's the position witch relative to node
 
local setPositionOffset ( local position)
 set body position offset, it's the position witch relative to node
 
const Vec2getPositionOffset () const
 get body position offset. More...
 
var getPositionOffset ()
 get body position offset. More...
 
local getPositionOffset ()
 get body position offset. More...
 
void setRotationOffset (float rotation)
 set body rotation offset, it's the rotation witch relative to node
 
float getRotationOffset () const
 set the body rotation offset
 
var getRotationOffset ()
 set the body rotation offset
 
bool isDynamic () const
 Test the body is dynamic or not. More...
 
var isDynamic ()
 Test the body is dynamic or not. More...
 
local isDynamic ()
 Test the body is dynamic or not. More...
 
void setDynamic (bool dynamic)
 Set dynamic to body. More...
 
void setMass (float mass)
 Set the body mass. More...
 
var setMass ( var mass)
 Set the body mass. More...
 
local setMass ( local mass)
 Set the body mass. More...
 
float getMass () const
 Get the body mass. More...
 
var getMass ()
 Get the body mass. More...
 
local getMass ()
 Get the body mass. More...
 
void addMass (float mass)
 Add mass to body. More...
 
local addMass ( local mass)
 Add mass to body. More...
 
void setMoment (float moment)
 Set the body moment of inertia. More...
 
var setMoment ( var moment)
 Set the body moment of inertia. More...
 
local setMoment ( local moment)
 Set the body moment of inertia. More...
 
float getMoment () const
 Get the body moment of inertia. More...
 
var getMoment ()
 Get the body moment of inertia. More...
 
local getMoment ()
 Get the body moment of inertia. More...
 
void addMoment (float moment)
 Add moment of inertia to body. More...
 
local addMoment ( local moment)
 Add moment of inertia to body. More...
 
float getLinearDamping () const
 get linear damping. More...
 
var getLinearDamping ()
 get linear damping. More...
 
local getLinearDamping ()
 get linear damping. More...
 
void setLinearDamping (float damping)
 Set linear damping. More...
 
float getAngularDamping () const
 Get angular damping. More...
 
void setAngularDamping (float damping)
 Set angular damping. More...
 
bool isResting () const
 Whether the body is at rest. More...
 
void setResting (bool rest) const
 set body to rest
 
var setResting ( var rest)
 set body to rest
 
local setResting ( local rest)
 set body to rest
 
virtual void setEnabled (bool enable) override
 Set the enable value. More...
 
local setEnabled ( local enable)
 Set the enable value. More...
 
bool isRotationEnabled () const
 Whether the body can rotation. More...
 
void setRotationEnable (bool enable)
 Set the body is allow rotation or not.
 
var setRotationEnable ( var enable)
 Set the body is allow rotation or not.
 
local setRotationEnable ( local enable)
 Set the body is allow rotation or not.
 
bool isGravityEnabled () const
 Whether this physics body is affected by the physics world's gravitational force. More...
 
void setGravityEnable (bool enable)
 Set the body is affected by the physics world's gravitational force or not. More...
 
var setGravityEnable ( var enable)
 Set the body is affected by the physics world's gravitational force or not. More...
 
local setGravityEnable ( local enable)
 Set the body is affected by the physics world's gravitational force or not. More...
 
int getTag () const
 Get the body's tag. More...
 
void setTag (int tag)
 set the body's tag. More...
 
var setTag ( var tag)
 set the body's tag. More...
 
local setTag ( local tag)
 set the body's tag. More...
 
Vec2 world2Local (const Vec2 &point)
 Convert the world point to local. More...
 
var world2Local ( var point)
 Convert the world point to local. More...
 
local world2Local ( local point)
 Convert the world point to local. More...
 
Vec2 local2World (const Vec2 &point)
 Convert the local point to world. More...
 
var local2World ( var point)
 Convert the local point to world. More...
 
local local2World ( local point)
 Convert the local point to world. More...
 
cpBody * getCPBody () const
 Get the rigid body of chipmunk. More...
 
var getCPBody ()
 Get the rigid body of chipmunk. More...
 
local getCPBody ()
 Get the rigid body of chipmunk. More...
 

Static Public Member Functions

static PhysicsBodycreate ()
 Create a body with default mass and moment. More...
 
static PhysicsBodycreate (float mass)
 Create a body with mass and default moment. More...
 
var create ( var mass)
 Create a body with mass and default moment. More...
 
local create ( local mass)
 Create a body with mass and default moment. More...
 
static PhysicsBodycreate (float mass, float moment)
 Create a body with mass and moment. More...
 
static PhysicsBodycreateCircle (float radius, const PhysicsMaterial &material=PHYSICSBODY_MATERIAL_DEFAULT, const Vec2 &offset=Vec2::ZERO)
 Create a body contains a circle. More...
 
var createCircle ( var radius, var PHYSICSBODY_MATERIAL_DEFAULT, var ZERO)
 Create a body contains a circle. More...
 
local createCircle ( local radius, local PHYSICSBODY_MATERIAL_DEFAULT, local ZERO)
 Create a body contains a circle. More...
 
static PhysicsBodycreateBox (const Size &size, const PhysicsMaterial &material=PHYSICSBODY_MATERIAL_DEFAULT, const Vec2 &offset=Vec2::ZERO)
 Create a body contains a box shape. More...
 
var createBox ( var size, var PHYSICSBODY_MATERIAL_DEFAULT, var ZERO)
 Create a body contains a box shape. More...
 
local createBox ( local size, local PHYSICSBODY_MATERIAL_DEFAULT, local ZERO)
 Create a body contains a box shape. More...
 
static PhysicsBodycreatePolygon (const Vec2 *points, int count, const PhysicsMaterial &material=PHYSICSBODY_MATERIAL_DEFAULT, const Vec2 &offset=Vec2::ZERO)
 Create a body contains a polygon shape. More...
 
var createPolygon ( var points, var count, var PHYSICSBODY_MATERIAL_DEFAULT, var ZERO)
 Create a body contains a polygon shape. More...
 
local createPolygon ( local points, local count, local PHYSICSBODY_MATERIAL_DEFAULT, local ZERO)
 Create a body contains a polygon shape. More...
 
static PhysicsBodycreateEdgeSegment (const Vec2 &a, const Vec2 &b, const PhysicsMaterial &material=PHYSICSBODY_MATERIAL_DEFAULT, float border=1)
 Create a body contains a EdgeSegment shape. More...
 
var createEdgeSegment ( var a, var b, var PHYSICSBODY_MATERIAL_DEFAULT, var 1)
 Create a body contains a EdgeSegment shape. More...
 
local createEdgeSegment ( local a, local b, local PHYSICSBODY_MATERIAL_DEFAULT, local 1)
 Create a body contains a EdgeSegment shape. More...
 
static PhysicsBodycreateEdgeBox (const Size &size, const PhysicsMaterial &material=PHYSICSBODY_MATERIAL_DEFAULT, float border=1, const Vec2 &offset=Vec2::ZERO)
 Create a body contains a EdgeBox shape. More...
 
local createEdgeBox ( local size, local PHYSICSBODY_MATERIAL_DEFAULT, local 1, local ZERO)
 Create a body contains a EdgeBox shape. More...
 
static PhysicsBodycreateEdgePolygon (const Vec2 *points, int count, const PhysicsMaterial &material=PHYSICSBODY_MATERIAL_DEFAULT, float border=1)
 Create a body contains a EdgePolygon shape. More...
 
static PhysicsBodycreateEdgeChain (const Vec2 *points, int count, const PhysicsMaterial &material=PHYSICSBODY_MATERIAL_DEFAULT, float border=1)
 Create a body contains a EdgeChain shape. More...
 

Detailed Description

A body affect by physics.

It can attach one or more shapes. If you create body with createXXX, it will automatically compute mass and moment with density your specified(which is PHYSICSBODY_MATERIAL_DEFAULT by default, and the density value is 0.1f), and it based on the formula: mass = density * area. If you create body with createEdgeXXX, the mass and moment will be PHYSICS_INFINITY by default. And it's a static body. You can change mass and moment with setMass() and setMoment(). And you can change the body to be dynamic or static by use function setDynamic().

Member Function Documentation

static PhysicsBody* create ( )
static

Create a body with default mass and moment.

This default mass value is 1.0. This default moment value is 200.

Returns
An autoreleased PhysicsBody object pointer.
var create ( )
static

Create a body with default mass and moment.

This default mass value is 1.0. This default moment value is 200.

Returns
An autoreleased PhysicsBody object pointer.
local create ( )
static

Create a body with default mass and moment.

This default mass value is 1.0. This default moment value is 200.

Returns
An autoreleased PhysicsBody object pointer.
static PhysicsBody* create ( float  mass)
static

Create a body with mass and default moment.

Parameters
massThis body's mass.
Returns
An autoreleased PhysicsBody object pointer.
var create ( var  mass)
static

Create a body with mass and default moment.

Parameters
massThis body's mass.
Returns
An autoreleased PhysicsBody object pointer.
local create ( local  mass)
static

Create a body with mass and default moment.

Parameters
massThis body's mass.
Returns
An autoreleased PhysicsBody object pointer.
static PhysicsBody* create ( float  mass,
float  moment 
)
static

Create a body with mass and moment.

Parameters
massThis body's mass.
momentThis body's moment.
Returns
An autoreleased PhysicsBody object pointer.
var create ( var  mass,
var  moment 
)
static

Create a body with mass and moment.

Parameters
massThis body's mass.
momentThis body's moment.
Returns
An autoreleased PhysicsBody object pointer.
local create ( local  mass,
local  moment 
)
static

Create a body with mass and moment.

Parameters
massThis body's mass.
momentThis body's moment.
Returns
An autoreleased PhysicsBody object pointer.
static PhysicsBody* createCircle ( float  radius,
const PhysicsMaterial &  material = PHYSICSBODY_MATERIAL_DEFAULT,
const Vec2 offset = Vec2::ZERO 
)
static

Create a body contains a circle.

Parameters
radiusA float number, it is the circle's radius.
materialA PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
offsetA Vec2 object, it is the offset from the body's center of gravity in body local coordinates.
Returns
An autoreleased PhysicsBody object pointer.
var createCircle ( var  radius,
var  material = PHYSICSBODY_MATERIAL_DEFAULT,
var  offset = Vec2::ZERO 
)
static

Create a body contains a circle.

Parameters
radiusA float number, it is the circle's radius.
materialA PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
offsetA Vec2 object, it is the offset from the body's center of gravity in body local coordinates.
Returns
An autoreleased PhysicsBody object pointer.
local createCircle ( local  radius,
local  material = PHYSICSBODY_MATERIAL_DEFAULT,
local  offset = Vec2::ZERO 
)
static

Create a body contains a circle.

Parameters
radiusA float number, it is the circle's radius.
materialA PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
offsetA Vec2 object, it is the offset from the body's center of gravity in body local coordinates.
Returns
An autoreleased PhysicsBody object pointer.
static PhysicsBody* createBox ( const Size &  size,
const PhysicsMaterial &  material = PHYSICSBODY_MATERIAL_DEFAULT,
const Vec2 offset = Vec2::ZERO 
)
static

Create a body contains a box shape.

Parameters
sizeSize contains this box's width and height.
materialA PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
offsetA Vec2 object, it is the offset from the body's center of gravity in body local coordinates.
Returns
An autoreleased PhysicsBody object pointer.
var createBox ( var  size,
var  material = PHYSICSBODY_MATERIAL_DEFAULT,
var  offset = Vec2::ZERO 
)
static

Create a body contains a box shape.

Parameters
sizeSize contains this box's width and height.
materialA PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
offsetA Vec2 object, it is the offset from the body's center of gravity in body local coordinates.
Returns
An autoreleased PhysicsBody object pointer.
local createBox ( local  size,
local  material = PHYSICSBODY_MATERIAL_DEFAULT,
local  offset = Vec2::ZERO 
)
static

Create a body contains a box shape.

Parameters
sizeSize contains this box's width and height.
materialA PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
offsetA Vec2 object, it is the offset from the body's center of gravity in body local coordinates.
Returns
An autoreleased PhysicsBody object pointer.
static PhysicsBody* createPolygon ( const Vec2 points,
int  count,
const PhysicsMaterial &  material = PHYSICSBODY_MATERIAL_DEFAULT,
const Vec2 offset = Vec2::ZERO 
)
static

Create a body contains a polygon shape.

Parameters
pointsPoints is an array of Vec2 structs defining a convex hull with a clockwise winding.
countAn integer number, contains the count of the points array.
materialA PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
offsetA Vec2 object, it is the offset from the body's center of gravity in body local coordinates.
Returns
An autoreleased PhysicsBody object pointer.
var createPolygon ( var  points,
var  count,
var  material = PHYSICSBODY_MATERIAL_DEFAULT,
var  offset = Vec2::ZERO 
)
static

Create a body contains a polygon shape.

Parameters
pointsPoints is an array of Vec2 structs defining a convex hull with a clockwise winding.
countAn integer number, contains the count of the points array.
materialA PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
offsetA Vec2 object, it is the offset from the body's center of gravity in body local coordinates.
Returns
An autoreleased PhysicsBody object pointer.
local createPolygon ( local  points,
local  count,
local  material = PHYSICSBODY_MATERIAL_DEFAULT,
local  offset = Vec2::ZERO 
)
static

Create a body contains a polygon shape.

Parameters
pointsPoints is an array of Vec2 structs defining a convex hull with a clockwise winding.
countAn integer number, contains the count of the points array.
materialA PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
offsetA Vec2 object, it is the offset from the body's center of gravity in body local coordinates.
Returns
An autoreleased PhysicsBody object pointer.
static PhysicsBody*
createEdgeSegment
( const Vec2 a,
const Vec2 b,
const PhysicsMaterial &  material = PHYSICSBODY_MATERIAL_DEFAULT,
float  border = 1 
)
static

Create a body contains a EdgeSegment shape.

Parameters
aIt's the edge's begin position.
bIt's the edge's end position.
materialA PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
borderIt's a edge's border width.
Returns
An autoreleased PhysicsBody object pointer.
var createEdgeSegment ( var  a,
var  b,
var  material = PHYSICSBODY_MATERIAL_DEFAULT,
var  border = 1 
)
static

Create a body contains a EdgeSegment shape.

Parameters
aIt's the edge's begin position.
bIt's the edge's end position.
materialA PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
borderIt's a edge's border width.
Returns
An autoreleased PhysicsBody object pointer.
local createEdgeSegment ( local  a,
local  b,
local  material = PHYSICSBODY_MATERIAL_DEFAULT,
local  border = 1 
)
static

Create a body contains a EdgeSegment shape.

Parameters
aIt's the edge's begin position.
bIt's the edge's end position.
materialA PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
borderIt's a edge's border width.
Returns
An autoreleased PhysicsBody object pointer.
static PhysicsBody* createEdgeBox ( const Size &  size,
const PhysicsMaterial &  material = PHYSICSBODY_MATERIAL_DEFAULT,
float  border = 1,
const Vec2 offset = Vec2::ZERO 
)
static

Create a body contains a EdgeBox shape.

Parameters
sizeSize contains this box's width and height.
materialA PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
borderIt's a edge's border width.
offsetA Vec2 object, it is the offset from the body's center of gravity in body local coordinates.
Returns
An autoreleased PhysicsBody object pointer.
var createEdgeBox ( var  size,
var  material = PHYSICSBODY_MATERIAL_DEFAULT,
var  border = 1,
var  offset = Vec2::ZERO 
)
static

Create a body contains a EdgeBox shape.

Parameters
sizeSize contains this box's width and height.
materialA PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
borderIt's a edge's border width.
offsetA Vec2 object, it is the offset from the body's center of gravity in body local coordinates.
Returns
An autoreleased PhysicsBody object pointer.
local createEdgeBox ( local  size,
local  material = PHYSICSBODY_MATERIAL_DEFAULT,
local  border = 1,
local  offset = Vec2::ZERO 
)
static

Create a body contains a EdgeBox shape.

Parameters
sizeSize contains this box's width and height.
materialA PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
borderIt's a edge's border width.
offsetA Vec2 object, it is the offset from the body's center of gravity in body local coordinates.
Returns
An autoreleased PhysicsBody object pointer.
static PhysicsBody*
createEdgePolygon
( const Vec2 points,
int  count,
const PhysicsMaterial &  material = PHYSICSBODY_MATERIAL_DEFAULT,
float  border = 1 
)
static

Create a body contains a EdgePolygon shape.

Parameters
pointsPoints is an array of Vec2 structs defining a convex hull with a clockwise winding.
countAn integer number, contains the count of the points array.
materialA PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
borderIt's a edge's border width.
Returns
An autoreleased PhysicsBody object pointer.
var createEdgePolygon ( var  points,
var  count,
var  material = PHYSICSBODY_MATERIAL_DEFAULT,
var  border = 1 
)
static

Create a body contains a EdgePolygon shape.

Parameters
pointsPoints is an array of Vec2 structs defining a convex hull with a clockwise winding.
countAn integer number, contains the count of the points array.
materialA PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
borderIt's a edge's border width.
Returns
An autoreleased PhysicsBody object pointer.
local createEdgePolygon ( local  points,
local  count,
local  material = PHYSICSBODY_MATERIAL_DEFAULT,
local  border = 1 
)
static

Create a body contains a EdgePolygon shape.

Parameters
pointsPoints is an array of Vec2 structs defining a convex hull with a clockwise winding.
countAn integer number, contains the count of the points array.
materialA PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
borderIt's a edge's border width.
Returns
An autoreleased PhysicsBody object pointer.
static PhysicsBody* createEdgeChain ( const Vec2 points,
int  count,
const PhysicsMaterial &  material = PHYSICSBODY_MATERIAL_DEFAULT,
float  border = 1 
)
static

Create a body contains a EdgeChain shape.

Parameters
pointsA Vec2 object pointer, it contains an array of points.
countAn integer number, contains the count of the points array.
materialA PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
borderIt's a edge's border width.
Returns
An autoreleased PhysicsBody object pointer.
var createEdgeChain ( var  points,
var  count,
var  material = PHYSICSBODY_MATERIAL_DEFAULT,
var  border = 1 
)
static

Create a body contains a EdgeChain shape.

Parameters
pointsA Vec2 object pointer, it contains an array of points.
countAn integer number, contains the count of the points array.
materialA PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
borderIt's a edge's border width.
Returns
An autoreleased PhysicsBody object pointer.
local createEdgeChain ( local  points,
local  count,
local  material = PHYSICSBODY_MATERIAL_DEFAULT,
local  border = 1 
)
static

Create a body contains a EdgeChain shape.

Parameters
pointsA Vec2 object pointer, it contains an array of points.
countAn integer number, contains the count of the points array.
materialA PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
borderIt's a edge's border width.
Returns
An autoreleased PhysicsBody object pointer.
virtual PhysicsShape* addShape ( PhysicsShape shape,
bool  addMassAndMoment = true 
)
virtual

Add a shape to body.

Parameters
shapeThe shape to be added.
addMassAndMomentIf this is true, the shape's mass and moment will be added to body. The default is true.
Returns
This shape's pointer if added success or nullptr if failed.
var addShape ( var  shape,
var  addMassAndMoment = true 
)
virtual

Add a shape to body.

Parameters
shapeThe shape to be added.
addMassAndMomentIf this is true, the shape's mass and moment will be added to body. The default is true.
Returns
This shape's pointer if added success or nullptr if failed.
local addShape ( local  shape,
local  addMassAndMoment = true 
)
virtual

Add a shape to body.

Parameters
shapeThe shape to be added.
addMassAndMomentIf this is true, the shape's mass and moment will be added to body. The default is true.
Returns
This shape's pointer if added success or nullptr if failed.
void removeShape ( PhysicsShape shape,
bool  reduceMassAndMoment = true 
)

Remove a shape from body.

Parameters
shapeShape the shape to be removed.
reduceMassAndMomentIf this is true, the body mass and moment will be reduced by shape. The default is true.
var removeShape ( var  shape,
var  reduceMassAndMoment = true 
)

Remove a shape from body.

Parameters
shapeShape the shape to be removed.
reduceMassAndMomentIf this is true, the body mass and moment will be reduced by shape. The default is true.
local removeShape ( local  shape,
local  reduceMassAndMoment = true 
)

Remove a shape from body.

Parameters
shapeShape the shape to be removed.
reduceMassAndMomentIf this is true, the body mass and moment will be reduced by shape. The default is true.
void removeShape ( int  tag,
bool  reduceMassAndMoment = true 
)

Remove a shape from body.

Parameters
tagThe tag of the shape to be removed.
reduceMassAndMomentIf this is true, the body mass and moment will be reduced by shape. The default is true.
var removeShape ( var  tag,
var  reduceMassAndMoment = true 
)

Remove a shape from body.

Parameters
tagThe tag of the shape to be removed.
reduceMassAndMomentIf this is true, the body mass and moment will be reduced by shape. The default is true.
local removeShape ( local  tag,
local  reduceMassAndMoment = true 
)

Remove a shape from body.

Parameters
tagThe tag of the shape to be removed.
reduceMassAndMomentIf this is true, the body mass and moment will be reduced by shape. The default is true.
void removeAllShapes ( bool  reduceMassAndMoment = true)

Remove all shapes.

Parameters
reduceMassAndMomentIf this is true, the body mass and moment will be reduced by shape. The default is true.
var removeAllShapes ( var  reduceMassAndMoment = true)

Remove all shapes.

Parameters
reduceMassAndMomentIf this is true, the body mass and moment will be reduced by shape. The default is true.
local removeAllShapes ( local  reduceMassAndMoment = true)

Remove all shapes.

Parameters
reduceMassAndMomentIf this is true, the body mass and moment will be reduced by shape. The default is true.
const Vector<PhysicsShape*>
& getShapes
( ) const
inline

Get the body shapes.

Returns
A Vector<PhysicsShape*> object contains PhysicsShape pointer.
var getShapes ( )
inline

Get the body shapes.

Returns
A Vector<PhysicsShape*> object contains PhysicsShape pointer.
local getShapes ( )
inline

Get the body shapes.

Returns
A Vector<PhysicsShape*> object contains PhysicsShape pointer.
PhysicsShape* getFirstShape ( ) const
inline

Get the first shape of the body shapes.

Returns
The first shape in this body.
var getFirstShape ( )
inline

Get the first shape of the body shapes.

Returns
The first shape in this body.
local getFirstShape ( )
inline

Get the first shape of the body shapes.

Returns
The first shape in this body.
PhysicsShape* getShape ( int  tag) const

get the shape of the body.

Parameters
tagAn integer number that identifies a PhysicsShape object.
Returns
A PhysicsShape object pointer or nullptr if no shapes were found.
var getShape ( var  tag)

get the shape of the body.

Parameters
tagAn integer number that identifies a PhysicsShape object.
Returns
A PhysicsShape object pointer or nullptr if no shapes were found.
local getShape ( local  tag)

get the shape of the body.

Parameters
tagAn integer number that identifies a PhysicsShape object.
Returns
A PhysicsShape object pointer or nullptr if no shapes were found.
virtual void applyForce ( const Vec2 force,
const Vec2 offset = Vec2::ZERO 
)
virtual

Applies a continuous force to body.

Parameters
forceThe force is applies to this body.
offsetA Vec2 object, it is the offset from the body's center of gravity in world coordinates.
var applyForce ( var  force,
var  offset = Vec2::ZERO 
)
virtual

Applies a continuous force to body.

Parameters
forceThe force is applies to this body.
offsetA Vec2 object, it is the offset from the body's center of gravity in world coordinates.
local applyForce ( local  force,
local  offset = Vec2::ZERO 
)
virtual

Applies a continuous force to body.

Parameters
forceThe force is applies to this body.
offsetA Vec2 object, it is the offset from the body's center of gravity in world coordinates.
virtual void applyImpulse ( const Vec2 impulse,
const Vec2 offset = Vec2::ZERO 
)
virtual

Applies a immediate force to body.

Parameters
impulseThe impulse is applies to this body.
offsetA Vec2 object, it is the offset from the body's center of gravity in world coordinates.
var applyImpulse ( var  impulse,
var  offset = Vec2::ZERO 
)
virtual

Applies a immediate force to body.

Parameters
impulseThe impulse is applies to this body.
offsetA Vec2 object, it is the offset from the body's center of gravity in world coordinates.
local applyImpulse ( local  impulse,
local  offset = Vec2::ZERO 
)
virtual

Applies a immediate force to body.

Parameters
impulseThe impulse is applies to this body.
offsetA Vec2 object, it is the offset from the body's center of gravity in world coordinates.
virtual void applyTorque ( float  torque)
virtual

Applies a torque force to body.

Parameters
torqueThe torque is applies to this body.
var applyTorque ( var  torque)
virtual

Applies a torque force to body.

Parameters
torqueThe torque is applies to this body.
local applyTorque ( local  torque)
virtual

Applies a torque force to body.

Parameters
torqueThe torque is applies to this body.
virtual void setVelocity ( const Vec2 velocity)
virtual

Set the velocity of a body.

Parameters
velocityThe velocity is set to this body.
var setVelocity ( var  velocity)
virtual

Set the velocity of a body.

Parameters
velocityThe velocity is set to this body.
local setVelocity ( local  velocity)
virtual

Set the velocity of a body.

Parameters
velocityThe velocity is set to this body.
virtual Vec2 getVelocity ( )
virtual

Get the velocity of a body.

var getVelocity ( )
virtual

Get the velocity of a body.

local getVelocity ( )
virtual

Get the velocity of a body.

virtual void setAngularVelocity ( float  velocity)
virtual

Set the angular velocity of a body.

Parameters
velocityThe angular velocity is set to this body.
var setAngularVelocity ( var  velocity)
virtual

Set the angular velocity of a body.

Parameters
velocityThe angular velocity is set to this body.
local setAngularVelocity ( local  velocity)
virtual

Set the angular velocity of a body.

Parameters
velocityThe angular velocity is set to this body.
virtual Vec2
getVelocityAtLocalPoint
( const Vec2 point)
virtual

Get the angular velocity of a body at a local point.

var getVelocityAtLocalPoint ( var  point)
virtual

Get the angular velocity of a body at a local point.

local getVelocityAtLocalPoint ( local  point)
virtual

Get the angular velocity of a body at a local point.

PhysicsWorld* getWorld ( ) const
inline

get the world body added to.

var getWorld ( )
inline

get the world body added to.

local getWorld ( )
inline

get the world body added to.

Node* getNode ( ) const
inline

get the node the body set to.

var getNode ( )
inline

get the node the body set to.

local getNode ( )
inline

get the node the body set to.

void setCategoryBitmask ( int  bitmask)

A mask that defines which categories this physics body belongs to.

Every physics body in a scene can be assigned to up to 32 different categories, each corresponding to a bit in the bit mask. You define the mask values used in your game. In conjunction with the collisionBitMask and contactTestBitMask properties, you define which physics bodies interact with each other and when your game is notified of these interactions.

Parameters
bitmaskAn integer number, the default value is 0xFFFFFFFF (all bits set).
var setCategoryBitmask ( var  bitmask)

A mask that defines which categories this physics body belongs to.

Every physics body in a scene can be assigned to up to 32 different categories, each corresponding to a bit in the bit mask. You define the mask values used in your game. In conjunction with the collisionBitMask and contactTestBitMask properties, you define which physics bodies interact with each other and when your game is notified of these interactions.

Parameters
bitmaskAn integer number, the default value is 0xFFFFFFFF (all bits set).
local setCategoryBitmask ( local  bitmask)

A mask that defines which categories this physics body belongs to.

Every physics body in a scene can be assigned to up to 32 different categories, each corresponding to a bit in the bit mask. You define the mask values used in your game. In conjunction with the collisionBitMask and contactTestBitMask properties, you define which physics bodies interact with each other and when your game is notified of these interactions.

Parameters
bitmaskAn integer number, the default value is 0xFFFFFFFF (all bits set).
void setContactTestBitmask ( int  bitmask)

A mask that defines which categories of bodies cause intersection notifications with this physics body.

When two bodies share the same space, each body's category mask is tested against the other body's contact mask by performing a logical AND operation. If either comparison results in a non-zero value, an PhysicsContact object is created and passed to the physics world’s delegate. For best performance, only set bits in the contacts mask for interactions you are interested in.

Parameters
bitmaskAn integer number, the default value is 0x00000000 (all bits cleared).
var setContactTestBitmask ( var  bitmask)

A mask that defines which categories of bodies cause intersection notifications with this physics body.

When two bodies share the same space, each body's category mask is tested against the other body's contact mask by performing a logical AND operation. If either comparison results in a non-zero value, an PhysicsContact object is created and passed to the physics world’s delegate. For best performance, only set bits in the contacts mask for interactions you are interested in.

Parameters
bitmaskAn integer number, the default value is 0x00000000 (all bits cleared).
local setContactTestBitmask ( local  bitmask)

A mask that defines which categories of bodies cause intersection notifications with this physics body.

When two bodies share the same space, each body's category mask is tested against the other body's contact mask by performing a logical AND operation. If either comparison results in a non-zero value, an PhysicsContact object is created and passed to the physics world’s delegate. For best performance, only set bits in the contacts mask for interactions you are interested in.

Parameters
bitmaskAn integer number, the default value is 0x00000000 (all bits cleared).
void setCollisionBitmask ( int  bitmask)

A mask that defines which categories of physics bodies can collide with this physics body.

When two physics bodies contact each other, a collision may occur. This body's collision mask is compared to the other body's category mask by performing a logical AND operation. If the result is a non-zero value, then this body is affected by the collision. Each body independently chooses whether it wants to be affected by the other body. For example, you might use this to avoid collision calculations that would make negligible changes to a body's velocity.

Parameters
bitmaskAn integer number, the default value is 0xFFFFFFFF (all bits set).
var setCollisionBitmask ( var  bitmask)

A mask that defines which categories of physics bodies can collide with this physics body.

When two physics bodies contact each other, a collision may occur. This body's collision mask is compared to the other body's category mask by performing a logical AND operation. If the result is a non-zero value, then this body is affected by the collision. Each body independently chooses whether it wants to be affected by the other body. For example, you might use this to avoid collision calculations that would make negligible changes to a body's velocity.

Parameters
bitmaskAn integer number, the default value is 0xFFFFFFFF (all bits set).
local setCollisionBitmask ( local  bitmask)

A mask that defines which categories of physics bodies can collide with this physics body.

When two physics bodies contact each other, a collision may occur. This body's collision mask is compared to the other body's category mask by performing a logical AND operation. If the result is a non-zero value, then this body is affected by the collision. Each body independently chooses whether it wants to be affected by the other body. For example, you might use this to avoid collision calculations that would make negligible changes to a body's velocity.

Parameters
bitmaskAn integer number, the default value is 0xFFFFFFFF (all bits set).
int getCategoryBitmask ( ) const

Return bitmask of first shape.

Returns
If there is no shape in body, return default value.(0xFFFFFFFF)
var getCategoryBitmask ( )

Return bitmask of first shape.

Returns
If there is no shape in body, return default value.(0xFFFFFFFF)
local getCategoryBitmask ( )

Return bitmask of first shape.

Returns
If there is no shape in body, return default value.(0xFFFFFFFF)
int getContactTestBitmask ( ) const

Return bitmask of first shape.

Returns
If there is no shape in body, return default value.(0x00000000)
var getContactTestBitmask ( )

Return bitmask of first shape.

Returns
If there is no shape in body, return default value.(0x00000000)
local getContactTestBitmask ( )

Return bitmask of first shape.

Returns
If there is no shape in body, return default value.(0x00000000)
int getCollisionBitmask ( ) const

Return bitmask of first shape.

Returns
If there is no shape in body, return default value.(0xFFFFFFFF)
var getCollisionBitmask ( )

Return bitmask of first shape.

Returns
If there is no shape in body, return default value.(0xFFFFFFFF)
local getCollisionBitmask ( )

Return bitmask of first shape.

Returns
If there is no shape in body, return default value.(0xFFFFFFFF)
void setGroup ( int  group)

Set the group of body.

Collision groups let you specify an integral group index. You can have all fixtures with the same group index always collide (positive index) or never collide (negative index). It have high priority than bit masks.

var setGroup ( var  group)

Set the group of body.

Collision groups let you specify an integral group index. You can have all fixtures with the same group index always collide (positive index) or never collide (negative index). It have high priority than bit masks.

local setGroup ( local  group)

Set the group of body.

Collision groups let you specify an integral group index. You can have all fixtures with the same group index always collide (positive index) or never collide (negative index). It have high priority than bit masks.

int getGroup ( ) const

Return group of first shape.

Returns
If there is no shape in body, return default value.(0)
var getGroup ( )

Return group of first shape.

Returns
If there is no shape in body, return default value.(0)
local getGroup ( )

Return group of first shape.

Returns
If there is no shape in body, return default value.(0)
Vec2 getPosition ( ) const

get the body position.

var getPosition ( )

get the body position.

local getPosition ( )

get the body position.

float getRotation ( )

get the body rotation.

var getRotation ( )

get the body rotation.

local getRotation ( )

get the body rotation.

const Vec2& getPositionOffset ( ) const
inline

get body position offset.

var getPositionOffset ( )
inline

get body position offset.

local getPositionOffset ( )
inline

get body position offset.

bool isDynamic ( ) const
inline

Test the body is dynamic or not.

A dynamic body will effect with gravity.

var isDynamic ( )
inline

Test the body is dynamic or not.

A dynamic body will effect with gravity.

local isDynamic ( )
inline

Test the body is dynamic or not.

A dynamic body will effect with gravity.

void setDynamic ( bool  dynamic)

Set dynamic to body.

A dynamic body will effect with gravity.

var setDynamic ( var  dynamic)

Set dynamic to body.

A dynamic body will effect with gravity.

local setDynamic ( local  dynamic)

Set dynamic to body.

A dynamic body will effect with gravity.

void setMass ( float  mass)

Set the body mass.

Attention
If you need add/subtract mass to body, don't use setMass(getMass() +/- mass), because the mass of body may be equal to PHYSICS_INFINITY, it will cause some unexpected result, please use addMass() instead.
var setMass ( var  mass)

Set the body mass.

Attention
If you need add/subtract mass to body, don't use setMass(getMass() +/- mass), because the mass of body may be equal to PHYSICS_INFINITY, it will cause some unexpected result, please use addMass() instead.
local setMass ( local  mass)

Set the body mass.

Attention
If you need add/subtract mass to body, don't use setMass(getMass() +/- mass), because the mass of body may be equal to PHYSICS_INFINITY, it will cause some unexpected result, please use addMass() instead.
float getMass ( ) const
inline

Get the body mass.

var getMass ( )
inline

Get the body mass.

local getMass ( )
inline

Get the body mass.

void addMass ( float  mass)

Add mass to body.

Parameters
massIf _mass(mass of the body) == PHYSICS_INFINITY, it remains. if mass == PHYSICS_INFINITY, _mass will be PHYSICS_INFINITY. if mass == -PHYSICS_INFINITY, _mass will not change. if mass + _mass <= 0, _mass will equal to MASS_DEFAULT(1.0) other wise, mass = mass + _mass;
var addMass ( var  mass)

Add mass to body.

Parameters
massIf _mass(mass of the body) == PHYSICS_INFINITY, it remains. if mass == PHYSICS_INFINITY, _mass will be PHYSICS_INFINITY. if mass == -PHYSICS_INFINITY, _mass will not change. if mass + _mass <= 0, _mass will equal to MASS_DEFAULT(1.0) other wise, mass = mass + _mass;
local addMass ( local  mass)

Add mass to body.

Parameters
massIf _mass(mass of the body) == PHYSICS_INFINITY, it remains. if mass == PHYSICS_INFINITY, _mass will be PHYSICS_INFINITY. if mass == -PHYSICS_INFINITY, _mass will not change. if mass + _mass <= 0, _mass will equal to MASS_DEFAULT(1.0) other wise, mass = mass + _mass;
void setMoment ( float  moment)

Set the body moment of inertia.

Note
If you need add/subtract moment to body, don't use setMoment(getMoment() +/- moment), because the moment of body may be equal to PHYSICS_INFINITY, it will cause some unexpected result, please use addMoment() instead.
var setMoment ( var  moment)

Set the body moment of inertia.

Note
If you need add/subtract moment to body, don't use setMoment(getMoment() +/- moment), because the moment of body may be equal to PHYSICS_INFINITY, it will cause some unexpected result, please use addMoment() instead.
local setMoment ( local  moment)

Set the body moment of inertia.

Note
If you need add/subtract moment to body, don't use setMoment(getMoment() +/- moment), because the moment of body may be equal to PHYSICS_INFINITY, it will cause some unexpected result, please use addMoment() instead.
float getMoment ( ) const
inline

Get the body moment of inertia.

var getMoment ( )
inline

Get the body moment of inertia.

local getMoment ( )
inline

Get the body moment of inertia.

void addMoment ( float  moment)

Add moment of inertia to body.

Parameters
momentIf _moment(moment of the body) == PHYSICS_INFINITY, it remains. if moment == PHYSICS_INFINITY, _moment will be PHYSICS_INFINITY. if moment == -PHYSICS_INFINITY, _moment will not change. if moment + _moment <= 0, _moment will equal to MASS_DEFAULT(1.0) other wise, moment = moment + _moment;
var addMoment ( var  moment)

Add moment of inertia to body.

Parameters
momentIf _moment(moment of the body) == PHYSICS_INFINITY, it remains. if moment == PHYSICS_INFINITY, _moment will be PHYSICS_INFINITY. if moment == -PHYSICS_INFINITY, _moment will not change. if moment + _moment <= 0, _moment will equal to MASS_DEFAULT(1.0) other wise, moment = moment + _moment;
local addMoment ( local  moment)

Add moment of inertia to body.

Parameters
momentIf _moment(moment of the body) == PHYSICS_INFINITY, it remains. if moment == PHYSICS_INFINITY, _moment will be PHYSICS_INFINITY. if moment == -PHYSICS_INFINITY, _moment will not change. if moment + _moment <= 0, _moment will equal to MASS_DEFAULT(1.0) other wise, moment = moment + _moment;
float getLinearDamping ( ) const
inline

get linear damping.

var getLinearDamping ( )
inline

get linear damping.

local getLinearDamping ( )
inline

get linear damping.

void setLinearDamping ( float  damping)
inline

Set linear damping.

it is used to simulate fluid or air friction forces on the body.

Parameters
dampingThe value is 0.0f to 1.0f.
var setLinearDamping ( var  damping)
inline

Set linear damping.

it is used to simulate fluid or air friction forces on the body.

Parameters
dampingThe value is 0.0f to 1.0f.
local setLinearDamping ( local  damping)
inline

Set linear damping.

it is used to simulate fluid or air friction forces on the body.

Parameters
dampingThe value is 0.0f to 1.0f.
float getAngularDamping ( ) const
inline

Get angular damping.

var getAngularDamping ( )
inline

Get angular damping.

local getAngularDamping ( )
inline

Get angular damping.

void setAngularDamping ( float  damping)
inline

Set angular damping.

It is used to simulate fluid or air friction forces on the body.

Parameters
dampingThe value is 0.0f to 1.0f.
var setAngularDamping ( var  damping)
inline

Set angular damping.

It is used to simulate fluid or air friction forces on the body.

Parameters
dampingThe value is 0.0f to 1.0f.
local setAngularDamping ( local  damping)
inline

Set angular damping.

It is used to simulate fluid or air friction forces on the body.

Parameters
dampingThe value is 0.0f to 1.0f.
bool isResting ( ) const

Whether the body is at rest.

var isResting ( )

Whether the body is at rest.

local isResting ( )

Whether the body is at rest.

virtual void setEnabled ( bool  enable)
overridevirtual

Set the enable value.

If the body it isn't enabled, it will not has simulation by world.

var setEnabled ( var  enable)
overridevirtual

Set the enable value.

If the body it isn't enabled, it will not has simulation by world.

local setEnabled ( local  enable)
overridevirtual

Set the enable value.

If the body it isn't enabled, it will not has simulation by world.

bool isRotationEnabled ( ) const
inline

Whether the body can rotation.

var isRotationEnabled ( )
inline

Whether the body can rotation.

local isRotationEnabled ( )
inline

Whether the body can rotation.

bool isGravityEnabled ( ) const
inline

Whether this physics body is affected by the physics world's gravitational force.

var isGravityEnabled ( )
inline

Whether this physics body is affected by the physics world's gravitational force.

local isGravityEnabled ( )
inline

Whether this physics body is affected by the physics world's gravitational force.

void setGravityEnable ( bool  enable)

Set the body is affected by the physics world's gravitational force or not.

var setGravityEnable ( var  enable)

Set the body is affected by the physics world's gravitational force or not.

local setGravityEnable ( local  enable)

Set the body is affected by the physics world's gravitational force or not.

int getTag ( ) const
inline

Get the body's tag.

var getTag ( )
inline

Get the body's tag.

local getTag ( )
inline

Get the body's tag.

void setTag ( int  tag)
inline

set the body's tag.

var setTag ( var  tag)
inline

set the body's tag.

local setTag ( local  tag)
inline

set the body's tag.

Vec2 world2Local ( const Vec2 point)

Convert the world point to local.

var world2Local ( var  point)

Convert the world point to local.

local world2Local ( local  point)

Convert the world point to local.

Vec2 local2World ( const Vec2 point)

Convert the local point to world.

var local2World ( var  point)

Convert the local point to world.

local local2World ( local  point)

Convert the local point to world.

cpBody* getCPBody ( ) const
inline

Get the rigid body of chipmunk.

var getCPBody ( )
inline

Get the rigid body of chipmunk.

local getCPBody ( )
inline

Get the rigid body of chipmunk.


The documentation for this class was generated from the following file: