The level editor, open it to pause the game and edit its level, close it to play on with the changes
- One of it, levelEditor, 0 on the debug overlay opens and closes it too
- A game makes it its own: it sets the hooks, adds keys, panel buttons and tools, or extends this class and
gives its own with setLevelEditor; the same calls work in the 2D editor and the 3D one, see EDITOR.md
- In release builds LevelEditor is a stub that never opens: what a game adds is taken and never called
levelEditor.onRestart = ()=> loadLevel(); // adds a Restart button that rebuilds the level
levelEditor.onTile = (layer, pos, tile)=> layer.setCollisionData(pos, tile === ladderTile ? -1 : tile ? 1 : 0);
levelEditor.addKey('k', ()=> clearEnemies(), 'K: clear the enemies');
// or as a class of the game's own
class MyEditor extends LevelEditor
{
onRestart() { loadLevel(); }
onDraw() { drawSpawnZones(); }
}
setLevelEditor(new MyEditor);
The 2D editor's edit functions, for a key, a button or a tool of the game's own: map, the Tiled map; layer,
the selected TileLayer; objects, a copy of the selected object layer's; hover, the cell under the mouse;
selection, the selected objects' ids; paint(cell, tile, direction, mirror), a tile index, -1 erases;
changeObjects((list)=> ...); strokeEnd() and strokeCancel(); bulk(()=> ...); undo(redo); toJSON()
The 3D editor's edit functions, undefined without the 3D plugins: level; objects; selection, a Set of ids;
selected(); made(id); change((list)=> ...); changePart(name, (part)=> ...); strokeEnd() and strokeCancel();
place(type, pos3D); setTransform(object, pos3D, rotationDegrees, scale3D); setProperty(object, name, value);
pos(object), rotation(object) and scale(object); mousePoint(); undo(redo); toJSON()
True when the editor in use is the 3D one, as use3D says or since a 3D level was loaded
True while the editor is open, the game is paused under it
The tiles the palette shows, in its order, for a sheet that also holds
sprites and art that are not level tiles; undefined shows every tile of the sheet
Which level editor opens: true the 3D one, false the 2D one, undefined the
3D one when a level was loaded with level3DLoad and there is a Render3DPlugin
Add a key of the game's own to the editor, the 2D and the 3D one
- Escape and 0 are the editor's own, to play and to exit, and Ctrl is the one modifier: Shift is given to
the action
key stringA letter or digit, 'k', or a key's name in any case, 'Delete', 'F2', 'Enter', 'Space';
'ctrl+k' with Ctrl or Cmd
action functionCalled with whether Shift is held; returning false says it did
nothing, and the key is left to the browser
helpLine string optionalA line for the editor's help
Close the editor and end its session, the game carries on with the changes and Escape opens the debug
overlay again
Called when the editor closes and the game plays on, to set or override
Called while the editor draws the level, to draw overlays of the game's own in it, to set or override
Called when the editor opens, to set or override
Called once when the editor's panel is made, with a box in it for the game's own controls, to set or override
element HTMLElement
Put the player at a position, a Vector2 in the 2D editor and a Vector3 in the 3D one; set it or override it
and the editor has Play from mouse, which starts play there
pos anyA Vector2 from the 2D editor, a Vector3 from the 3D one
Rebuild the level from what the editor changed; set it or override it and the editor has a Restart button,
which calls it after switching to play
Called by Save with the text of the file and its name; return true when the game kept it itself, and the
editor writes no file, to set or override; it may be async
text stringfileName string
What the game does when the 2D editor paints a tile, like setting its collision or its look the way the
game does when it loads the level; set it or override it, without one the collision layer gets collision 1
where there is a tile
layer TileLayerThe layer painted
pos Vector2The cell's position in the layer
tile number|undefinedThe tile painted, undefined when erased
Called each frame while the editor is open, to set or override
Open the editor, pausing the game; until close(), Escape (the debug key) switches between playing and editing