Using TiledMap with RPG-JS
TiledMap integration allows you to use maps created with the Tiled Map Editor in your RPG-JS games. This provides a visual way to design your game maps with layers, tilesets, collision detection, and interactive objects.Use
@rpgjs/tiledmap when you want to build maps with Tiled Map Editor.If you want your own renderer or your own map format, use Custom map rendering with provideLoadMap.Installation
First, install the TiledMap package:Vite Configuration
Configure yourvite.config.ts to handle Tiled map files:
Plugin Options
sourceFolder: Directory containing your TMX files, TSX tilesets, and imagespublicPath: URL path prefix for accessing map files (default:/data)buildOutputPath: Target folder in build output (default:assets/data)allowedExtensions: File extensions to include (default:['.tmx', '.tsx', '.png', '.jpg', '.jpeg', '.gif', '.webp', '.svg'])
Client-Side Setup
Configure the client to use TiledMap:Server-Side Setup
Configure the server to use TiledMap:File Structure
Organize your Tiled files in the configured source folder:Features
Automatic Collision Detection
TiledMap automatically detects collision tiles and applies tile rules to physics:- Set the
collisionproperty totrueon tiles in Tiled Map Editor - Collision rules are attached to entities through physics extension hooks
- The same collision logic is used on server authority and client prediction
- No additional code required for basic tile blocking
Event Integration
Place events in Tiled using point objects:- Create an Object Layer in Tiled
- Add Point objects with names matching your event names
- Events will be automatically positioned based on object coordinates
Physics Hooks Integration
The tiled module now uses shared physics hooks:- Server:
map.onPhysicsInit,map.onPhysicsEntityAdd,map.onPhysicsEntityRemove,map.onPhysicsReset - Client:
sceneMap.onPhysicsInit,sceneMap.onPhysicsEntityAdd,sceneMap.onPhysicsEntityRemove,sceneMap.onPhysicsReset