Class: Body

me. Body

new Body(entity, shapes)

a Generic Body Object
Parameters:
Name Type Argument Description
entity me.Entity the parent entity
shapes Array.<me.Rect> | Array.<me.Polygon> | Array.<me.Line> | Array.<me.Ellipse> <optional>
the initial list of shapes
Source:
body.js, line 19

Extends

Classes

Error

Members

<static> accel :me.Vector2d

entity current acceleration
Type:
Default Value:
  • <0,0>
Source:
body.js, line 79

<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 52
See:
Example
// set the entity body collision type
myEntity.body.collisionType = me.collision.types.PLAYER_OBJECT;

<static, readonly> falling :Boolean

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

<static> friction :me.Vector2d

entity current friction
Type:
Default Value:
  • <0,0>
Source:
body.js, line 92

<static> gravity :Number

Default gravity value of the entity
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 118
See:

<static, readonly> jumping :Boolean

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

<static> maxVel :me.Vector2d

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

<static> vel :me.Vector2d

entity current velocity
Type:
Default Value:
  • <0,0>
Source:
body.js, line 66

Methods

<static> addShape(shape) → {Number}

add a collision shape to this entity
(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 173
Returns:
the shape array length
Type
Number

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

add collision shapes based on the given PhysicsEditor JSON object
Parameters:
Name Type Argument Default Description
json Object a JSON object as exported from the PhysicsEditor 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 200
See:
Returns:
the shape array length
Type
Number

<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 278
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 291
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 310
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 344

<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 323
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 entity default friction
Parameters:
Name Type Description
x Number horizontal friction
y Number vertical friction
Source:
body.js, line 434

<protected, static> setMaxVelocity(x, y)

cap the entity 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 420

<protected, static> setVelocity(x, y)

set the entity 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 401

<static> update() → {boolean}

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

<private, static> updateBounds()

update the body bounding rect (private) the body rect size is here used to cache the total bounding rect
Source:
body.js, line 375
Copyright © 2011 - 2017, Olivier Biot, Jason Oster, Aaron McLeod
Documentation generated by JSDoc 3.4.0 on 2017-02-28T11:37:40+08:00 using the DocStrap template modified by codename-.