new Body(sprite)
The Physics Body is linked to a single Sprite. All physics operations should be performed against the body rather than the Sprite itself. For example you can set the velocity, acceleration, bounce values etc all on the Body.
Parameters:
Name | Type | Description |
---|---|---|
sprite |
Phaser.Sprite | The Sprite object this physics body belongs to. |
- Source - physics/arcade/Body.js, line 15
Members
-
acceleration :Phaser.Point
-
The acceleration is the rate of change of the velocity. Measured in pixels per second squared.
- Source - physics/arcade/Body.js, line 141
-
allowGravity :boolean
-
Allow this Body to be influenced by gravity? Either world or local.
- Default Value:
- true
- Source - physics/arcade/Body.js, line 152
-
allowRotation :boolean
-
Allow this Body to be rotated? (via angularVelocity, etc)
- Default Value:
- true
- Source - physics/arcade/Body.js, line 59
-
<readonly> angle :number
-
The angle of the Body in radians, as calculated by its angularVelocity.
- Source - physics/arcade/Body.js, line 209
-
angularAcceleration :number
-
The angular acceleration is the rate of change of the angular velocity. Measured in radians per second squared.
- Default Value:
- 0
- Source - physics/arcade/Body.js, line 185
-
angularDrag :number
-
The drag applied during the rotation of the Body.
- Default Value:
- 0
- Source - physics/arcade/Body.js, line 191
-
angularVelocity :number
-
The angular velocity controls the rotation speed of the Body. It is measured in radians per second.
- Default Value:
- 0
- Source - physics/arcade/Body.js, line 179
-
blocked :object
-
This object is populated with boolean values when the Body collides with the World bounds or a Tile. For example if blocked.up is true then the Body cannot move up. An object containing on which faces this Body is blocked from moving, if any.
- Source - physics/arcade/Body.js, line 303
-
<readonly> bottom :number
-
The bottom value of this Body (same as Body.y + Body.height)
- Source - physics/arcade/Body.js, line 734
-
bounce :Phaser.Point
-
The elasticity of the Body when colliding. bounce.x/y = 1 means full rebound, bounce.x/y = 0.5 means 50% rebound velocity.
- Source - physics/arcade/Body.js, line 162
-
<readonly> center :Phaser.Point
-
The center coordinate of the Physics Body.
- Source - physics/arcade/Body.js, line 120
-
checkCollision :object
-
Set the checkCollision properties to control which directions collision is processed for this Body. For example checkCollision.up = false means it won't collide when the collision happened while moving up. An object containing allowed collision.
- Source - physics/arcade/Body.js, line 283
-
collideWorldBounds :boolean
-
A Body can be set to collide against the World bounds automatically and rebound back into the World if this is set to true. Otherwise it will leave the World. Should the Body collide with the World bounds?
- Source - physics/arcade/Body.js, line 276
-
customSeparateX :boolean
-
This flag allows you to disable the custom x separation that takes place by Physics.Arcade.separate. Used in combination with your own collision processHandler you can create whatever type of collision response you need. Use a custom separation system or the built-in one?
- Default Value:
- false
- Source - physics/arcade/Body.js, line 244
-
customSeparateY :boolean
-
This flag allows you to disable the custom y separation that takes place by Physics.Arcade.separate. Used in combination with your own collision processHandler you can create whatever type of collision response you need. Use a custom separation system or the built-in one?
- Default Value:
- false
- Source - physics/arcade/Body.js, line 252
-
deltaMax :Phaser.Point
-
The Sprite position is updated based on the delta x/y values. You can set a cap on those (both +-) using deltaMax.
- Source - physics/arcade/Body.js, line 136
-
dirty :boolean
-
If this Body in a preUpdate (true) or postUpdate (false) state?
- Source - physics/arcade/Body.js, line 315
-
drag :Phaser.Point
-
The drag applied to the motion of the Body.
- Source - physics/arcade/Body.js, line 146
-
embedded :boolean
-
If a body is overlapping with another body, but neither of them are moving (maybe they spawned on-top of each other?) this is set to true. Body embed value.
- Source - physics/arcade/Body.js, line 270
-
enable :boolean
-
A disabled body won't be checked for any form of collision or overlap or have its pre/post updates run.
- Default Value:
- true
- Source - physics/arcade/Body.js, line 36
-
facing :number
-
A const reference to the direction the Body is traveling or facing.
- Source - physics/arcade/Body.js, line 221
-
friction :Phaser.Point
-
The amount of movement that will occur if another object 'rides' this one.
- Source - physics/arcade/Body.js, line 173
-
game :Phaser.Game
-
Local reference to game.
- Source - physics/arcade/Body.js, line 25
-
gravity :Phaser.Point
-
A local gravity applied to this Body. If non-zero this over rides any world gravity, unless Body.allowGravity is set to false.
- Source - physics/arcade/Body.js, line 157
-
<readonly> halfHeight :number
-
The calculated height / 2 of the physics body.
- Source - physics/arcade/Body.js, line 114
-
<readonly> halfWidth :number
-
The calculated width / 2 of the physics body.
- Source - physics/arcade/Body.js, line 108
-
<readonly> height :number
-
The calculated height of the physics body.
- Source - physics/arcade/Body.js, line 84
-
immovable :boolean
-
An immovable Body will not receive any impacts from other bodies.
- Default Value:
- false
- Source - physics/arcade/Body.js, line 227
-
mass :number
-
The mass of the Body. When two bodies collide their mass is used in the calculation to determine the exchange of velocity.
- Default Value:
- 1
- Source - physics/arcade/Body.js, line 203
-
maxAngular :number
-
The maximum angular velocity in radians per second that the Body can reach.
- Default Value:
- 1000
- Source - physics/arcade/Body.js, line 197
-
maxVelocity :Phaser.Point
-
The maximum velocity in pixels per second sq. that the Body can reach.
- Source - physics/arcade/Body.js, line 168
-
moves :boolean
-
If you have a Body that is being moved around the world via a tween or a Group motion, but its local x/y position never actually changes, then you should set Body.moves = false. Otherwise it will most likely fly off the screen. If you want the physics system to move the body around, then set moves to true. Set to true to allow the Physics system to move this Body, otherwise false to move it manually.
- Default Value:
- true
- Source - physics/arcade/Body.js, line 236
-
<readonly> newVelocity :Phaser.Point
-
The new velocity. Calculated during the Body.preUpdate and applied to its position.
- Source - physics/arcade/Body.js, line 131
-
offset :Phaser.Point
-
The offset of the Physics Body from the Sprite x/y position.
- Source - physics/arcade/Body.js, line 41
-
overlapX :number
-
When this body collides with another, the amount of overlap is stored here. The amount of horizontal overlap during the collision.
- Source - physics/arcade/Body.js, line 258
-
overlapY :number
-
When this body collides with another, the amount of overlap is stored here. The amount of vertical overlap during the collision.
- Source - physics/arcade/Body.js, line 264
-
<readonly> position :Phaser.Point
-
The position of the physics body.
- Source - physics/arcade/Body.js, line 47
-
<readonly> preRotation :number
-
The previous rotation of the physics body.
- Source - physics/arcade/Body.js, line 72
-
<readonly> prev :Phaser.Point
-
The previous position of the physics body.
- Source - physics/arcade/Body.js, line 53
-
<readonly> right :number
-
The right value of this Body (same as Body.x + Body.width)
- Source - physics/arcade/Body.js, line 747
-
rotation :number
-
An Arcade Physics Body can have angularVelocity and angularAcceleration. Please understand that the collision Body itself never rotates, it is always axis-aligned. However these values are passed up to the parent Sprite and updates its rotation.
- Source - physics/arcade/Body.js, line 66
-
skipQuadTree :boolean
-
If true and you collide this Sprite against a Group, it will disable the collision check from using a QuadTree.
- Source - physics/arcade/Body.js, line 320
-
<readonly> sourceHeight :number
-
The un-scaled original size.
- Source - physics/arcade/Body.js, line 96
-
<readonly> sourceWidth :number
-
The un-scaled original size.
- Source - physics/arcade/Body.js, line 90
-
<readonly> speed :number
-
The speed of the Body as calculated by its velocity.
- Source - physics/arcade/Body.js, line 215
-
sprite :Phaser.Sprite
-
Reference to the parent Sprite.
- Source - physics/arcade/Body.js, line 20
-
tilePadding :Phaser.Point
-
If this is an especially small or fast moving object then it can sometimes skip over tilemap collisions if it moves through a tile in a step. Set this padding value to add extra padding to its bounds. tilePadding.x applied to its width, y to its height. Extra padding to be added to this sprite's dimensions when checking for tile collision.
- Source - physics/arcade/Body.js, line 310
-
touching :object
-
This object is populated with boolean values when the Body collides with another. touching.up = true means the collision happened to the top of this Body for example. An object containing touching results.
- Source - physics/arcade/Body.js, line 290
-
type :number
-
The type of physics system this body belongs to.
- Source - physics/arcade/Body.js, line 30
-
velocity :Phaser.Point
-
The velocity, or rate of change in speed of the Body. Measured in pixels per second.
- Source - physics/arcade/Body.js, line 125
-
wasTouching :object
-
This object is populated with previous touching values from the bodies previous collision. An object containing previous touching results.
- Source - physics/arcade/Body.js, line 296
-
<readonly> width :number
-
The calculated width of the physics body.
- Source - physics/arcade/Body.js, line 78
-
x :number
-
The x position.
- Source - physics/arcade/Body.js, line 760
-
y :number
-
The y position.
- Source - physics/arcade/Body.js, line 777
Methods
-
<internal> checkWorldBounds()
-
Internal method.
- Internal:
- This member is internal (protected) and may be modified or removed in the future.
- Source - physics/arcade/Body.js, line 554
-
deltaAbsX() → {number}
-
Returns the absolute delta x value.
Returns:
number -The absolute delta value.
- Source - physics/arcade/Body.js, line 682
-
deltaAbsY() → {number}
-
Returns the absolute delta y value.
Returns:
number -The absolute delta value.
- Source - physics/arcade/Body.js, line 692
-
deltaX() → {number}
-
Returns the delta x value. The difference between Body.x now and in the previous step.
Returns:
number -The delta value. Positive if the motion was to the right, negative if to the left.
- Source - physics/arcade/Body.js, line 702
-
deltaY() → {number}
-
Returns the delta y value. The difference between Body.y now and in the previous step.
Returns:
number -The delta value. Positive if the motion was downwards, negative if upwards.
- Source - physics/arcade/Body.js, line 712
-
deltaZ() → {number}
-
Returns the delta z value. The difference between Body.rotation now and in the previous step.
Returns:
number -The delta value. Positive if the motion was clockwise, negative if anti-clockwise.
- Source - physics/arcade/Body.js, line 722
-
destroy()
-
Removes this body's reference to its parent sprite, freeing it up for gc.
- Source - physics/arcade/Body.js, line 542
-
hitTest(x, y) → {boolean}
-
Tests if a world point lies within this Body.
Parameters:
Name Type Description x
number The world x coordinate to test.
y
number The world y coordinate to test.
Returns:
boolean -True if the given coordinates are inside this Body, otherwise false.
- Source - physics/arcade/Body.js, line 650
-
onFloor() → {boolean}
-
Returns true if the bottom of this Body is in contact with either the world bounds or a tile.
Returns:
boolean -True if in contact with either the world bounds or a tile.
- Source - physics/arcade/Body.js, line 662
-
onWall() → {boolean}
-
Returns true if either side of this Body is in contact with either the world bounds or a tile.
Returns:
boolean -True if in contact with either the world bounds or a tile.
- Source - physics/arcade/Body.js, line 672
-
<internal> postUpdate()
-
Internal method.
- Internal:
- This member is internal (protected) and may be modified or removed in the future.
- Source - physics/arcade/Body.js, line 462
-
<internal> preUpdate()
-
Internal method.
- Internal:
- This member is internal (protected) and may be modified or removed in the future.
- Source - physics/arcade/Body.js, line 382
-
render(context, body, color, filled)
-
Render Sprite Body.
Parameters:
Name Type Argument Default Description context
object The context to render to.
body
Phaser.Physics.Arcade.Body The Body to render the info of.
color
string <optional>
'rgba(0,255,0,0.4)' color of the debug info to be rendered. (format is css color string).
filled
boolean <optional>
true Render the objected as a filled (default, true) or a stroked (false)
- Source - physics/arcade/Body.js, line 795
-
renderBodyInfo(body, x, y, color)
-
Render Sprite Body Physics Data as text.
Parameters:
Name Type Argument Default Description body
Phaser.Physics.Arcade.Body The Body to render the info of.
x
number X position of the debug info to be rendered.
y
number Y position of the debug info to be rendered.
color
string <optional>
'rgb(255,255,255)' color of the debug info to be rendered. (format is css color string).
- Source - physics/arcade/Body.js, line 823
-
reset(x, y)
-
Resets all Body values (velocity, acceleration, rotation, etc)
Parameters:
Name Type Description x
number The new x position of the Body.
y
number The new y position of the Body.
- Source - physics/arcade/Body.js, line 618
-
setSize(width, height, offsetX, offsetY)
-
You can modify the size of the physics Body to be any dimension you need. So it could be smaller or larger than the parent Sprite. You can also control the x and y offset, which is the position of the Body relative to the top-left of the Sprite.
Parameters:
Name Type Argument Description width
number The width of the Body.
height
number The height of the Body.
offsetX
number <optional>
The X offset of the Body from the Sprite position.
offsetY
number <optional>
The Y offset of the Body from the Sprite position.
- Source - physics/arcade/Body.js, line 590
-
<internal> updateBounds()
-
Internal method.
- Internal:
- This member is internal (protected) and may be modified or removed in the future.
- Source - physics/arcade/Body.js, line 356