Skip to content

Collision Layer

Ethan Harvey edited this page Sep 1, 2026 · 2 revisions

Collision Layer

The collision layer defines the physical behaviour of tiles in a level. Each tile in the collision layer has a TileDefinition containing a TileType, which determines its associated CollisionType. This separates the visual appearance of a tile from its gameplay behaviour, allowing the same collision logic to be reused across different levels and visual tiles.

The main collision types are:

  • SOLID — Creates a solid collider that prevents the player and other physics-enabled entities from passing through the tile.
  • PLATFORM — Creates a standable platform for the player. This can be used for floors and elevated platforms.
  • HAZARD — Creates a collider that can detect contact with the player and apply gameplay effects such as damage.
  • NONE — No collider is created, allowing entities to pass through the tile.

How It Works

When a level is loaded, LevelGameArea reads the collision layer from the LevelMapData. Each tile is inspected and its CollisionType is used to determine which collision entity should be created. The appropriate entity is created through reusable methods in ObstacleFactory, keeping the level-loading code independent of the specific collider implementation.

The collider is then positioned using the terrain's tileToWorldPosition() method so that it corresponds to the tile's location in the game world. The resulting entity uses the existing physics and collider components, allowing it to interact with the player's physics body through the game's existing Box2D collision system.

This approach means that level designers only need to specify the appropriate tile type in the JSON map data. The game automatically handles creating the corresponding physical behaviour when the level is loaded.

Clone this wiki locally