Class: Body

me. Body

new Body(ancestor, shapes, onBodyUpdate)

a Generic Body Object
Parameters:
Name Type Argument Description
ancestor me.Renderable the parent object this body is attached to
shapes Array.<me.Rect> | Array.<me.Polygon> | Array.<me.Line> | Array.<me.Ellipse> <optional>
the initial list of shapes
onBodyUpdate function <optional>
callback for when the body is updated (e.g. add/remove shapes)
Source:
body.js, line 20

Extends

Classes

Error

Members

<static> accel :me.Vector2d

body acceleration
Type:
Default Value:
  • <0,0>
Source:
body.js, line 84

<static> bounce :Number

the body bouciness level when colliding with other solid bodies : a value of 0 will not bounce, a value of 1 will fully rebound.
Type:
  • Number
Default Value:
  • 0
Source:
body.js, line 110

<static> collisionType :Number

define the collision type of the body for collision filtering
Type:
  • Number
Default Value:
  • me.collision.types.ENEMY_OBJECT
Source:
body.js, line 57
See:
Example
// set the body collision type
myEntity.body.collisionType = me.collision.types.PLAYER_OBJECT;

<static, readonly> falling :Boolean

falling state of the body
true if the object is falling
false if the object is standing on something
Type:
  • Boolean
Default Value:
  • false
Source:
body.js, line 147

<static> friction :me.Vector2d

body friction
Type:
Default Value:
  • <0,0>
Source:
body.js, line 97

<static> gravity :Number

Default gravity value for this body
to be set to 0 for RPG, shooter, etc...
Note: Gravity can also globally be defined through me.sys.gravity
Type:
  • Number
Default Value:
  • 0.98
Source:
body.js, line 134
See:

<static, readonly> jumping :Boolean

jumping state of the body
equal true if the body is jumping
Type:
  • Boolean
Default Value:
  • false
Source:
body.js, line 160

<static> maxVel :me.Vector2d

max velocity (to limit body velocity)
Type:
Default Value:
  • <1000,1000>
Source:
body.js, line 121

<static> vel :me.Vector2d

body velocity
Type:
Default Value:
  • <0,0>
Source:
body.js, line 71

ancestor :me.Renderable

a reference to the parent object that contains this bodt, or undefined if it has not been added to one.
Type:
Default Value:
  • undefined
Source:
body.js, line 26

Methods

<static> addShape(shape) → {Number}

add a collision shape to this body
(note: me.Rect objects will be converted to me.Polygon before being added)
Parameters:
Name Type Description
shape me.Rect | me.Polygon | me.Line | me.Ellipse a shape object
Source:
body.js, line 196
Returns:
the shape array length
Type
Number

<static> addShapesFromJSON(json, id, scale) → {Number}

add collision mesh based on a given Physics Editor JSON object
Parameters:
Name Type Argument Default Description
json Object a JSON object as exported from the a Physics Editor tool
id String the shape identifier within the given the json object
scale String <optional>
1 the desired scale of the body (physic-body-editor only)
Source:
body.js, line 223
See:
Returns:
the shape array length
Type
Number
Example
this.body.addShapesFromJSON(me.loader.getJSON("shapesdef1"), settings.banana);

<static> getShape(index) → {me.Polygon|me.Line|me.Ellipse}

return the collision shape at the given index
Parameters:
Name Type Argument Default Description
index Number <optional>
0 the shape object at the specified index
Source:
body.js, line 303
Returns:
shape a shape object if defined
Type
me.Polygon | me.Line | me.Ellipse

<static> removeShape(shape) → {Number}

remove the specified shape from the body shape list
Parameters:
Name Type Description
shape me.Polygon | me.Line | me.Ellipse a shape object
Source:
body.js, line 316
Returns:
the shape array length
Type
Number

<static> removeShapeAt(index) → {Number}

remove the shape at the given index from the body shape list
Parameters:
Name Type Description
index Number the shape object at the specified index
Source:
body.js, line 335
Returns:
the shape array length
Type
Number

<protected, static> respondToCollision(response)

the built-in function to solve the collision response
Parameters:
Name Type Description
response me.collision.ResponseObject the collision response object
Source:
body.js, line 369

<static> setCollisionMask(bitmask)

By default all entities are able to collide with all other entities,
but it's also possible to specificy 'collision filters' to provide a finer
control over which entities can collide with each other.
Parameters:
Name Type Description
bitmask Number the collision mask
Source:
body.js, line 348
See:
Example
// filter collision detection with collision shapes, enemies and collectables
myEntity.body.setCollisionMask(me.collision.types.WORLD_SHAPE | me.collision.types.ENEMY_OBJECT | me.collision.types.COLLECTABLE_OBJECT);
...
// disable collision detection with all other objects
myEntity.body.setCollisionMask(me.collision.types.NO_OBJECT);

<protected, static> setFriction(x, y)

set the body default friction
Parameters:
Name Type Description
x Number horizontal friction
y Number vertical friction
Source:
body.js, line 467

<protected, static> setMaxVelocity(x, y)

cap the body velocity to the specified value
Parameters:
Name Type Description
x Number max velocity on x axis
y Number max velocity on y axis
Source:
body.js, line 453

<protected, static> setVelocity(x, y)

set the body default velocity
note : velocity is by default limited to the same value, see setMaxVelocity if needed
Parameters:
Name Type Description
x Number velocity on x axis
y Number velocity on y axis
Source:
body.js, line 434

<static> update() → {boolean}

update the body position
Source:
body.js, line 533
Returns:
true if resulting velocity is different than 0
Type
boolean