ArcadeWorld
Extended physics world that integrates Arcade physics with Ceramic's visual system.
This class extends the base arcade.World to provide seamless collision detection
between Ceramic visuals, groups, bodies, and tilemaps. It handles the complex
type resolution needed to make different Ceramic object types work with the
physics engine.
Key features:
- Automatic type detection for Visual, Group, Body, and Tilemap objects
- Optimized collision detection with quadtree spatial partitioning
- Support for both overlap (trigger) and collide (solid) interactions
- Integration with tilemap plugin for tile-based collisions
- Specialized sorting algorithms for broad-phase optimization
Usage example:
var world = arcade.world;
world.gravity.y = 800;
world.collide(player, enemy, (body1, body2) -> {
trace("Player hit enemy!");
});
world.overlap(player, collectibles, (body1, body2) -> {
});
See: arcade.World for base physics world functionality, ArcadeSystem for the system that manages worlds
Instance Members
arcade
sweepTilemaps: Bool
Whether a body moving a lot in one frame is tested against tilemaps in several
steps along its displacement, so that it can't go through a tile without ever
overlapping it (see separateBodyVsTilemapLayersSwept()).
arcade
escapeFullTiles: Bool
Whether a body still overlapping a full tile after the regular separation is
pushed out through one of the tile's exposed faces (see escapeFromTile()).
Checks for overlaps between collidable elements without separating them.
Overlaps are useful for triggers, collectibles, and other non-solid interactions.
The overlap callback is called for each pair of overlapping bodies.
Supports all combinations of:
- Visual vs Visual
- Visual/Body vs Group
- Group vs Group
- Any vs Tilemap/TilemapLayer (with tilemap plugin)
| Name |
Type |
Default |
Description |
element1 |
arcade.Collidable |
|
First element to check |
element2 |
arcade.Collidable |
(optional) |
Second element to check (or null to check element1 against itself) |
overlapCallback |
Function |
(optional) |
Called for each overlapping pair (body1, body2) |
processCallback |
Function |
(optional) |
Optional filter to exclude certain pairs from overlap |
| Returns |
Description |
| Bool |
True if any overlaps occurred |
Checks for overlaps between all bodies in two arcade groups.
This optimized implementation uses temporary arrays to avoid modification
during iteration and applies sorting for broad-phase optimization.
| Name |
Type |
Default |
Description |
group1 |
arcade.Group |
|
First group of bodies |
group2 |
arcade.Group |
|
Second group of bodies |
overlapCallback |
Function |
(optional) |
Called for each overlapping pair |
processCallback |
Function |
(optional) |
Optional filter callback |
| Returns |
Description |
| Bool |
True if any overlaps occurred |
arcade
overlapGroupVsItself(group: arcade.Group, ?overlapCallback: Function, ?processCallback: Function): Bool
| Name |
Type |
Default |
group |
arcade.Group |
|
overlapCallback |
Function |
(optional) |
processCallback |
Function |
(optional) |
arcade
overlapBodyVsGroup(body: arcade.Body, group: arcade.Group, ?overlapCallback: Function, ?processCallback: Function): Bool
Checks for overlaps between a single body and all bodies in a group.
Uses quadtree spatial partitioning for large groups to improve performance.
Only bodies near the target body are checked for overlap.
| Name |
Type |
Default |
Description |
body |
arcade.Body |
|
The body to check |
group |
arcade.Group |
|
The group of bodies to check against |
overlapCallback |
Function |
(optional) |
Called for each overlap |
processCallback |
Function |
(optional) |
Optional filter callback |
| Returns |
Description |
| Bool |
True if any overlaps occurred |
arcade
overlapCeramicGroupVsItself(group: Group<Visual>, ?overlapCallback: Function, ?processCallback: Function): Bool
| Name |
Type |
Default |
group |
Group<Visual> |
|
overlapCallback |
Function |
(optional) |
processCallback |
Function |
(optional) |
arcade
overlapBodyVsCeramicGroup(body: arcade.Body, group: Group<Visual>, ?overlapCallback: Function, ?processCallback: Function): Bool
| Name |
Type |
Default |
body |
arcade.Body |
|
group |
Group<Visual> |
|
overlapCallback |
Function |
(optional) |
processCallback |
Function |
(optional) |
Checks for collisions between collidable elements and separates them.
Collisions prevent objects from overlapping by pushing them apart.
The collide callback is called for each pair of colliding bodies after separation.
Supports all combinations of:
- Visual vs Visual
- Visual/Body vs Group
- Group vs Group
- Any vs Tilemap/TilemapLayer (with tilemap plugin)
| Name |
Type |
Default |
Description |
element1 |
arcade.Collidable |
|
First element to check |
element2 |
arcade.Collidable |
(optional) |
Second element to check (or null to check element1 against itself) |
collideCallback |
Function |
(optional) |
Called for each colliding pair after separation (body1, body2) |
processCallback |
Function |
(optional) |
Optional filter to exclude certain pairs from collision |
| Returns |
Description |
| Bool |
True if any collisions occurred |
| Name |
Type |
Default |
group1 |
arcade.Group |
|
group2 |
arcade.Group |
|
collideCallback |
Function |
(optional) |
processCallback |
Function |
(optional) |
arcade
collideGroupVsItself(group: arcade.Group, ?collideCallback: Function, ?processCallback: Function): Bool
| Name |
Type |
Default |
group |
arcade.Group |
|
collideCallback |
Function |
(optional) |
processCallback |
Function |
(optional) |
arcade
collideBodyVsGroup(body: arcade.Body, group: arcade.Group, ?collideCallback: Function, ?processCallback: Function): Bool
| Name |
Type |
Default |
body |
arcade.Body |
|
group |
arcade.Group |
|
collideCallback |
Function |
(optional) |
processCallback |
Function |
(optional) |
arcade
collideCeramicGroupVsItself(group: Group<Visual>, ?collideCallback: Function, ?processCallback: Function): Bool
| Name |
Type |
Default |
group |
Group<Visual> |
|
collideCallback |
Function |
(optional) |
processCallback |
Function |
(optional) |
arcade
collideBodyVsCeramicGroup(body: arcade.Body, group: Group<Visual>, ?collideCallback: Function, ?processCallback: Function): Bool
| Name |
Type |
Default |
body |
arcade.Body |
|
group |
Group<Visual> |
|
collideCallback |
Function |
(optional) |
processCallback |
Function |
(optional) |
Sorts a Ceramic visual group for optimized collision detection.
Sorting bodies by position allows the collision system to exit early
when checking pairs, significantly improving performance for large groups.
Uses specialized merge sort implementations optimized for each direction.
| Name |
Type |
Default |
Description |
group |
Group<Visual> |
|
The group to sort |
sortDirection |
arcade.SortDirection |
SortDirection.INHERIT |
The direction to sort (or INHERIT to use group/world setting) |
Creates a new ArcadeWorld with the specified bounds.
The world bounds define the area where physics simulation occurs.
Bodies outside these bounds may not collide properly.
| Name |
Type |
Description |
boundsX |
Float |
Left edge of the world |
boundsY |
Float |
Top edge of the world |
boundsWidth |
Float |
Width of the world |
boundsHeight |
Float |
Height of the world |
tilemap
collideBodyVsTilemap(body: arcade.Body, tilemap: Tilemap, ?collideCallback: Function, ?processCallback: Function): Bool
Performs collision detection and separation between a body and a tilemap.
Only checks tiles that the body overlaps with for efficiency.
Each colliding tile is treated as a solid immovable body.
| Name |
Type |
Default |
Description |
body |
arcade.Body |
|
The physics body to collide |
tilemap |
Tilemap |
|
The tilemap to collide against |
collideCallback |
Function |
(optional) |
Called for each tile collision |
processCallback |
Function |
(optional) |
Optional filter for specific tiles |
| Returns |
Description |
| Bool |
True if any collisions occurred |
tilemap
overlapBodyVsTilemap(body: arcade.Body, tilemap: Tilemap, ?collideCallback: Function, ?processCallback: Function): Bool
| Name |
Type |
Default |
body |
arcade.Body |
|
tilemap |
Tilemap |
|
collideCallback |
Function |
(optional) |
processCallback |
Function |
(optional) |
tilemap
collideBodyVsTilemapLayer(body: arcade.Body, layer: TilemapLayer, ?collideCallback: Function, ?processCallback: Function): Bool
| Name |
Type |
Default |
body |
arcade.Body |
|
layer |
TilemapLayer |
|
collideCallback |
Function |
(optional) |
processCallback |
Function |
(optional) |
tilemap
overlapBodyVsTilemapLayer(body: arcade.Body, layer: TilemapLayer, ?collideCallback: Function, ?processCallback: Function): Bool
| Name |
Type |
Default |
body |
arcade.Body |
|
layer |
TilemapLayer |
|
collideCallback |
Function |
(optional) |
processCallback |
Function |
(optional) |
tilemap
collideBodyVsTilemaps(body: arcade.Body, tilemaps: Array<Tilemap>, ?layerName: String, ?collideCallback: Function, ?processCallback: Function): Bool
Collides a body with the collidable layers of several tilemaps at once, in a single
sweep (separateBodyVsTilemapLayersSwept): tilemaps placed next to each other then
behave as one continuous solid. Colliding them one after the other would not: each
sweep restarts from the body's previous position and would undo what the others did.
With layerName, only the layer of that name in each tilemap is used.
| Name |
Type |
Default |
body |
arcade.Body |
|
tilemaps |
Array<Tilemap> |
|
layerName |
String |
(optional) |
collideCallback |
Function |
(optional) |
processCallback |
Function |
(optional) |
tilemap
collideCeramicGroupVsTilemap(group: Group<Visual>, tilemap: Tilemap, ?collideCallback: Function, ?processCallback: Function): Bool
| Name |
Type |
Default |
group |
Group<Visual> |
|
tilemap |
Tilemap |
|
collideCallback |
Function |
(optional) |
processCallback |
Function |
(optional) |
tilemap
collideCeramicGroupVsTilemapLayer(group: Group<Visual>, layer: TilemapLayer, ?collideCallback: Function, ?processCallback: Function): Bool
| Name |
Type |
Default |
group |
Group<Visual> |
|
layer |
TilemapLayer |
|
collideCallback |
Function |
(optional) |
processCallback |
Function |
(optional) |
tilemap
collideArcadeGroupVsTilemap(group: arcade.Group, tilemap: Tilemap, ?collideCallback: Function, ?processCallback: Function): Bool
| Name |
Type |
Default |
group |
arcade.Group |
|
tilemap |
Tilemap |
|
collideCallback |
Function |
(optional) |
processCallback |
Function |
(optional) |
tilemap
collideArcadeGroupVsTilemapLayer(group: arcade.Group, layer: TilemapLayer, ?collideCallback: Function, ?processCallback: Function): Bool
| Name |
Type |
Default |
group |
arcade.Group |
|
layer |
TilemapLayer |
|
collideCallback |
Function |
(optional) |
processCallback |
Function |
(optional) |
tilemap
overlapCeramicGroupVsTilemap(group: Group<Visual>, tilemap: Tilemap, ?collideCallback: Function, ?processCallback: Function): Bool
| Name |
Type |
Default |
group |
Group<Visual> |
|
tilemap |
Tilemap |
|
collideCallback |
Function |
(optional) |
processCallback |
Function |
(optional) |
tilemap
overlapCeramicGroupVsTilemapLayer(group: Group<Visual>, layer: TilemapLayer, ?collideCallback: Function, ?processCallback: Function): Bool
| Name |
Type |
Default |
group |
Group<Visual> |
|
layer |
TilemapLayer |
|
collideCallback |
Function |
(optional) |
processCallback |
Function |
(optional) |
tilemap
overlapArcadeGroupVsTilemap(group: arcade.Group, tilemap: Tilemap, ?collideCallback: Function, ?processCallback: Function): Bool
| Name |
Type |
Default |
group |
arcade.Group |
|
tilemap |
Tilemap |
|
collideCallback |
Function |
(optional) |
processCallback |
Function |
(optional) |
tilemap
overlapArcadeGroupVsTilemapLayer(group: arcade.Group, layer: TilemapLayer, ?collideCallback: Function, ?processCallback: Function): Bool
| Name |
Type |
Default |
group |
arcade.Group |
|
layer |
TilemapLayer |
|
collideCallback |
Function |
(optional) |
processCallback |
Function |
(optional) |
Private Members
arcade
MAX_SWEEP_STEPS: Int
arcade
tileBody: arcade.Body
Reusable body instance for tilemap collisions.
Instead of creating a new body for each tile collision, we reuse
this single instance for performance. The body is configured as
immovable and its position/size is updated for each tile.
Determines the actual type of a collidable element for proper collision routing.
This method resolves Ceramic's visual types to their base classes so the
collision system can handle them appropriately. For example, all Visual
subclasses (Quad, Mesh, etc.) are treated as Visual for collision purposes.
| Returns |
Description |
| Class<Dynamic> |
The base class type for collision handling |
arcade
overlapCeramicGroupVsCeramicGroup(group1: Group<Visual>, group2: Group<Visual>, ?overlapCallback: Function, ?processCallback: Function): Bool
Checks for overlaps between all visuals in two Ceramic groups.
Extracts physics bodies from visuals and performs overlap checks.
Handles null bodies gracefully.
| Name |
Type |
Default |
Description |
group1 |
Group<Visual> |
|
First group of visuals |
group2 |
Group<Visual> |
|
Second group of visuals |
overlapCallback |
Function |
(optional) |
Called for each overlapping pair |
processCallback |
Function |
(optional) |
Optional filter callback |
| Returns |
Description |
| Bool |
True if any overlaps occurred |
arcade
overlapCeramicGroupVsArcadeGroup(group1: Group<Visual>, group2: arcade.Group, ?overlapCallback: Function, ?processCallback: Function): Bool
| Name |
Type |
Default |
group1 |
Group<Visual> |
|
group2 |
arcade.Group |
|
overlapCallback |
Function |
(optional) |
processCallback |
Function |
(optional) |
arcade
collideCeramicGroupVsCeramicGroup(group1: Group<Visual>, group2: Group<Visual>, ?collideCallback: Function, ?processCallback: Function): Bool
| Name |
Type |
Default |
group1 |
Group<Visual> |
|
group2 |
Group<Visual> |
|
collideCallback |
Function |
(optional) |
processCallback |
Function |
(optional) |
arcade
collideCeramicGroupVsArcadeGroup(group1: Group<Visual>, group2: arcade.Group, ?collideCallback: Function, ?processCallback: Function): Bool
| Name |
Type |
Default |
group1 |
Group<Visual> |
|
group2 |
arcade.Group |
|
collideCallback |
Function |
(optional) |
processCallback |
Function |
(optional) |
arcade
separateBodyVsTilemap(body: arcade.Body, tilemap: Tilemap, ?collideCallback: Function, ?processCallback: Function, ?overlapOnly: Bool = false): Bool
| Name |
Type |
Default |
body |
arcade.Body |
|
tilemap |
Tilemap |
|
collideCallback |
Function |
(optional) |
processCallback |
Function |
(optional) |
overlapOnly |
Bool |
false |
arcade
separateBodyVsTilemapLayersSwept(body: arcade.Body, layers: Array<TilemapLayer>, layer: TilemapLayer, collideCallback: Function, processCallback: Function, overlapOnly: Bool): Bool
Separates a body against tilemap layers (layers, or the single layer if given),
moving the body along its displacement in several steps when it moved a lot this frame.
A body is only tested against the tiles it overlaps at its current position, so a body
moving more than its own size in one frame could end up past a tile without ever
overlapping it. Stepping by at most half the body size on each axis makes sure the
first tile on the path is met. The steps only concern the collision test: velocity and
gravity were integrated once, for the whole frame, before this is called.
arcade
separateBodyVsTilemapLayers(body: arcade.Body, layers: Array<TilemapLayer>, layer: TilemapLayer, collideCallback: Function, processCallback: Function, overlapOnly: Bool): Bool
Pushes body out of tile, a full tile it is still overlapping after the regular
separation, through one of the tile's exposed faces. The face the body came through
is preferred when the body moved on that axis this step and is not deeper through
that face than its displacement, otherwise the nearest exposed face is used: a body
resting a few pixels inside a wall is pushed sideways, never lifted onto the wall.
Returns false when no face is exposed (the body is inside a thick wall).
arcade
separateBodyVsTilemapLayer(body: arcade.Body, layer: TilemapLayer, collideCallback: Function, processCallback: Function, overlapOnly: Bool): Bool
Core tilemap collision implementation for a single layer.
This method:
- Calculates which tiles the body overlaps
- Creates a temporary immovable body for each solid tile
- Performs collision/overlap detection
- Handles special cases like connected tiles and slopes
| Name |
Type |
Description |
body |
arcade.Body |
The body to check |
layer |
TilemapLayer |
The tilemap layer |
collideCallback |
Function |
Called for each collision |
processCallback |
Function |
Optional filter |
overlapOnly |
Bool |
If true, only detect overlaps without separation |