settingsData.json
public/data/settingsData.json holds your game's data: prefabs, base prefabs, presets, animations, layers, and settings for physics, saving and the level editor. You can edit it by hand, but the Chrome extension is made for it.
Pass it to your scene to use it:
import settingsData from '../public/data/settingsData.json';
export class Game extends Scene
{
constructor()
{
super(settingsData);
}
}A scene without settingsData gets the built-in defaults only.
Example: the Platformer's settingsData.json.
Overview
Every key is optional. A small file using most of them:
{
"gravity": 5000,
"layers": ["background", "objects", "ui"],
"layersInfo": {
"background": { "showInEditor": false }
},
"basePrefabs": [
{ "name": "block", "baseClass": "ArcadeObject", "hitbox": "FULL", "static": true }
],
"prefabs": [
{ "name": "player", "texture": "player", "components": { "animation": {} } },
{ "name": "grass", "extends": "block" }
],
"animations": {
"player_walk": { "frames": ["player/player_walk#2"], "framesPerSecond": 10 }
},
"categories": {
"blocks": { "entries": ["grass"], "expanded": true }
},
"saveVars": {
"ArcadeObject": ["color"]
},
"settings": { "gridEnabled": true, "gridSize": 32 }
}| Key | Default | Description |
|---|---|---|
prefabs | [] | Named GameObject definitions. See Prefabs. |
basePrefabs | ANY and NONE | Building blocks for other prefabs. See Base prefabs. |
presets | FULL, CENTER | Reusable property values. See Presets. |
animations | Named frame animations, used by AnimationComponent. See Animations. | |
layers | ["objects"] | Layer names, in draw order. See Layers. |
layersInfo | Settings per layer. See Layers. | |
gravity | 0 | Downward gravity for physics. |
saveVars | position, children, components | Properties saved per GameObject class when a level is saved while playing. See What gets saved. |
categories | How prefabs are grouped in the level editor's sidebar. | |
settings | grid off, size 64 | Level editor grid: gridEnabled and gridSize. See Grid. |
editorObjectSnapToPivot | true | false makes objects fill the level editor grid cell instead of snapping their pivot to the lines. |
name | The file name the editor saves to. See More than one settings file. |
Layers
layers lists your layer names. Later layers draw on top. objects always exists: if you leave it out, it's added at the start, below your own layers. See Levels & Layers for using them.
"layers": ["background", "objects"]Settings per layer go in layersInfo, keyed by layer name:
"layersInfo": {
"background": {
"save": false,
"showInEditor": false
}
}| Setting | Default | Description |
|---|---|---|
collidesWith | Layers this layer's objects collide with. See collision layers. | |
save | true | Save this layer's objects into the level file. |
showInEditor | true | Show the layer in the level editor. |
pointerCollisionType | "POINT" | How the pointer picks objects: "POINT" takes the top object, "RADIUS" the nearest one. In code: CollisionHandlingType.POINT / CollisionHandlingType.RADIUS. See Mobile & Touch. |
Example: the Shmup defines a layer per kind of object and which of them collide.
Defaults
When a scene loads its settings, the built-in defaults are merged into a copy of your data, so they don't end up in your file:
- A missing key gets its default.
- Lists get the default items they're missing. That's how
objectsends up inlayers. - Objects like
presets,layersInfoandsaveVarskeep all your entries and get the default entries you don't have. An entry you share with the defaults is merged with it, so your ownFULLpreset replaces the built-in one key by key, and aGameObjectlist insaveVarsstill includesposition,childrenandcomponents.
ANY and NONE are added to basePrefabs if you don't define them. See Base prefabs.
Editing
The Chrome extension edits prefabs and the level editor's settings while your game runs, and the dev server writes them back to settingsData.json.
Generated names
While the dev server runs, the Data object in src/generated/assets.ts is generated from settingsData.json, so you get autocomplete and typo checks:
import { Data } from './generated/assets';
this.AddGameObject(Data.Prefab.PLAYER);
this.AddGameObject('cloud', Data.Layer.BACKGROUND);
anim.Play(Data.Animation.PLAYER_WALK);| Map | From |
|---|---|
Data.Prefab | prefabs |
Data.BasePrefab | basePrefabs |
Data.Animation | animations |
Data.Layer | layers, as layer indices, including objects |
Each also has a list, like Data.Prefabs, which is emptied in production builds. See stripGeneratedAssets.
More than one settings file
Each scene has its own settings, so scenes can use different files:
import menuData from '../public/data/menuData.json';
export class Menu extends Scene
{
constructor()
{
super(menuData);
}
}Give every extra file a name, like "name": "menuData". The editor saves to <name>.json in public/data/, and without a name it would overwrite settingsData.json.
The Data object is only generated from settingsData.json.
Example: the RPG's map editor uses its own mapData.json. See Example: the RPG's map editor.