Skip to main content

provideLoadMap

The provideLoadMap function allows you to customize how maps are loaded and displayed on the client side. It enables you to provide a custom map component and define how map data is processed before rendering.

Overview

provideLoadMap is a client-side function that takes a callback function which receives a map ID and returns map data along with a custom component for rendering. This is particularly useful when you want to:
  • Use custom map formats (like Tiled TMX files)
  • Display maps with custom rendering components
  • Process map data before rendering
  • Add custom layers or effects to your maps

Basic Usage

Return Object Properties

The callback function must return an object with the following properties:

Required Properties

  • data - The raw map data that will be passed to your component
  • component - A CanvasEngine component that will render the map

Optional Properties

  • width - Map width in pixels (used for viewport calculations)
  • height - Map height in pixels (used for viewport calculations)
  • events - Map events data
  • id - Map identifier (defaults to the mapId parameter)
  • hitboxes - Array of collision hitboxes for the map
  • positions - Named positions, used by player.changeMap("map", "name")

Creating a Map Component

Your map component should be a CanvasEngine component that receives the map data through props:

Accessing Props Data

In your component, use defineProps() to access the map data:

Event Layer Integration

To display game events (NPCs, interactive objects, etc.), include the EventLayerComponent in your map component:
The EventLayerComponent automatically handles:
  • Player character rendering
  • NPC and event rendering
  • Character animations and interactions
  • Proper layering and sorting

Composing the SceneMap

If you want to add scene-level components without changing each map renderer, define a client sceneMap.component and wrap the built-in SceneMap component:
Use SceneMap children for overlays or scene systems that should be mounted around the current map renderer. Use EventLayerComponent children when the custom elements must be sorted by zIndex with players and events.

Adding Custom Elements to EventLayerComponent

You can add custom elements inside EventLayerComponent that will be automatically sorted by zIndex with the rest of the elements:

Hitboxes Configuration

The hitboxes property allows you to define collision areas for the map. Each hitbox can be either rectangular or polygonal:

Rectangular Hitboxes

Polygonal Hitboxes

Mixed Hitboxes

You can combine both rectangular and polygonal hitboxes in the same array:
Note: If no id is provided, a unique identifier will be automatically generated for each hitbox.