Skip to content

Level ​

bare.level loads and saves levels for the current scene. Levels are JSON files in public/data/levels/.

ts
await bare.level.Load('level1');
await bare.level.Restart();
MethodBehavior
Load(nameOrData = "")Clears the scene, preserving persistent objects, then loads the level.
LoadOnly(nameOrData)Load a level without clearing the scene first.
LoadData(name: string)Reads cached level data without loading it.
LoadCurrent() / Restart()Reloads the current level.
Save()Save the current level.
Serialize(level: LevelData)Turn the scene's objects into level data.
Clear()Clear the loaded level.

See saving destinations for an explicit recipe to persist gameplay changes, and the level editor for writes to project files.

From a scene, this.LoadLevel(name) does the same as bare.level.Load(name). Override OnPreLoadLevel(level) and OnPostLoadLevel(level) to run code around loading.

Only GameObjects with persistent = true survive loading a new level.

Examples: the Platformer loads its level. The RPG loads the player's saved level, and fetches neighbouring levels ahead of time with LoadData.

Bare Engine is open source under the MIT license.