Create hero in map
Once your first map exists, the next step is to put the player inside it and assign a spritesheet.Spawn the player on connection
In your player hooks:- Sends the player to
simplemap - Places the player at the Tiled point named
start, if it exists - Uses the
herospritesheet on the client
maxHp are available immediately on the client.
To use the automatic start position, create an object layer in Tiled, add a point,
and set its name to start. You can also target any named point explicitly:
Avoid spawning inside an obstacle
A start point can end up under an obstacle, for example when a map is generated or when an event stands on it.map.findSpawnPosition() returns the closest
position where the player hitbox overlaps no wall, tile collision, static shape
or blocking event, or null when nothing is free nearby. It never disables
collisions.
Resolve the position once the player has joined the map, on the server:
preferred
(every step pixels, half the hitbox by default), and the closest free
position wins. By default a position is only accepted when the player can also
move to one neighboring position. Pass requireClearance: false to accept any
free position. The method exists on the client map as well, but only the server
result is authoritative. It works in standalone RPG and MMORPG modes.
Initialize default stats only when needed
Useplayer.initializeDefaultStats() if you want RPGJS to define the default
parameter curves (maxHp, maxSp, str, int, dex, agi) and initialize
HP/SP from those values.
This is useful if:
- you define the starting stats directly in your game
- you rely on RPGJS built-in default values
- you want HP/SP and parameter displays to be ready on the client as soon as the game starts
player.initializeDefaultStats() after loading player data from:
- your own database
- a save slot
- a snapshot
player.applyDefaultParameters().
Use onStart() when the game begins after a GUI
If your game starts after a title screen or another GUI interaction, initialize the
default stats in onStart() instead of onConnected().
onStart() is executed after a GUI interaction returns data.id === 'start'.
Make sure the hero graphic exists
The hero identifier must exist in your client configuration: