Constructor
new Physics(game)
The Physics object offers physics related functions like collision detection.
Parameters:
Name | Type | Description |
---|---|---|
game |
Carrot.Game | The core game object. |
Classes
Methods
collide(entity1, entity2, callbackopt) → {boolean}
Checks for collision between entities which can be sprites or groups.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
entity1 |
Carrot.Group | Carrot.Sprite | |||
entity2 |
Carrot.Group | Carrot.Sprite | |||
callback |
function |
<optional> |
null | The function that shall be executed when the collision happens. |
Returns:
If a collision was detected.
- Type
- boolean
disable(entity)
Disables physics on a sprite by setting its body to null.
Parameters:
Name | Type | Description |
---|---|---|
entity |
Carrot.Sprite | The sprite to get its physics disabled. |
enable(entity)
Enables physics on a sprite by adding a physics body to it.
Parameters:
Name | Type | Description |
---|---|---|
entity |
Carrot.Sprite | The sprite to get its physics enabled. |
overlap(entity1, entity2, callbackopt) → {boolean}
Checks for overlaps between entities which can be sprites or groups.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
entity1 |
Carrot.Group | Carrot.Sprite | |||
entity2 |
Carrot.Group | Carrot.Sprite | |||
callback |
function |
<optional> |
null | The function that shall be executed when the overlap happens. |
Returns:
If an overlap was detected.
- Type
- boolean
setCircle()
Changes the shape of the body and its parent sprite into a circle.
setRectangle()
Changes the shape of the body and its parent sprite into a rectangle.