provideLoadMap
TheprovideLoadMap 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 componentcomponent- 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 dataid- Map identifier (defaults to the mapId parameter)hitboxes- Array of collision hitboxes for the mappositions- Named positions, used byplayer.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, usedefineProps() to access the map data:
Event Layer Integration
To display game events (NPCs, interactive objects, etc.), include theEventLayerComponent in your map component:
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 clientsceneMap.component and wrap the built-in SceneMap component:
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 insideEventLayerComponent that will be automatically sorted by zIndex with the rest of the elements:
Hitboxes Configuration
Thehitboxes 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:id is provided, a unique identifier will be automatically generated for each hitbox.