Scenes
A scene file (.scene.json) is a level laid out instead of typed out:
its pictures, its layers and maps, its walls and floors, and every sprite,
with where it stands and what it does. Your game builds one with
SCENE "level" !! from("level.scene.json"), and Scenes from files in
Making Games with Crash is all about using them.
Right-click in the file list and pick New scene…, and it opens in the scene editor. What you see there is what your game will draw: the editor builds the scene with the same loader the game uses, and draws it with the game’s own renderer.
Around the scene editor
- On the left, the scene’s tree, with a section for each thing a scene holds: Sprites (every sprite, with the sprites attached to them underneath), Layers, Images, Boundaries and Behaviors. Click a heading to fold it, and its + to add one. An item’s ×, or Delete on its right-click menu, takes it out.
- In the middle, the scene, to lay it out.
- On the right, the fields of what you picked, in the tree or on the scene, and nothing else.
- Along the top, Undo and Redo, the zoom (Fit shows it all), the Select and Boundary tools, and ▶ Preview.
The castle from Scenes from files: the tree on the left, the hero picked on the canvas with his hitbox, and his fields on the right.
Pictures and layers
Start with Images: its + adds a picture for the scene’s sprites to use, or a Block, a plain block of one color, its size and color yours to pick (or Clear, to see through), for roughing a scene out before its pictures are drawn. An image your program makes itself can have a Stand-in block too: the editor can’t run your program to make it, so it shows the block in its place. A sprite can get a block of its own straight from its Image list in its fields: + New block makes one, named after the sprite. Then Layers: its + puts down a map you’ve made, drawn with its own tiles, or a Plain layer to draw on. Pick one for its settings: how see-through it is, whether it wraps, where it’s clipped.
Sprites
The + on Sprites adds a sprite, or drag a picture in from the file list and drop it on the scene. Then:
- drag it to move it, and use its handles to turn it and size it,
- pick it to see its collision box, and set everything else in its fields: its Name, its Image, its Tag, its Metadata, whether it’s Solid, what it’s Solid against, One way, Flip X and Flip Y, how it starts moving, its behaviors and its pattern.
Solid stops a sprite at the boundaries. Solid against is the tags of
the sprites it bumps into as well, the list SET SPRITE’s sprites takes.
Type a tag and press Enter, or pick one from +, which offers the tags the
sprites in this file already have. The × on a tag takes it off. A sprite with
no tags here passes through other sprites.
Velocity is how far it moves each tick, across and down, when the scene
starts; its behaviors carry on from there, as after SET SPRITE’s
velocity. Max velocity is the most it ever moves in a tick on each
axis, and Max acceleration the most speed its ACCELERATION builds up.
Leave a box unticked and it has none.
Metadata holds the values META sets and GETSPRITEMETA reads back.
+ Value adds a keyed one; type its key and its value. Unkeyed is the
one value without a key. A value is a number, true or false, a point like
(10, 20), or else text.
Shift-click (or Command-click, Ctrl-click on Windows and Linux) more sprites, on the scene or in the tree, to pick them too, and drag any of them to move them all. Shift-click one again to let it go. The fields are the first one you picked.
Snap puts what you move, drop or add on a grid, and boundaries you draw, move or size too. The grid is drawn on the scene while it’s on. Beside it, pick its size: the map’s tiles (or every 8 pixels, if there’s no map), 4, 8, 16, 32 or 64, or type any size. Hold Alt while you drag to place something freely.
The Name is how your game finds the sprite: scenenode("hero").
The tree
Drag a node in the tree to put it in a different order, or drop it onto another node to attach it there. An attached node moves with the one it’s attached to, and its Offset is how far it is from it. Tick Rigid: turns with its parent for a sword that turns with the hand that holds it.
Right-click a node for Add child, Duplicate, Move to the top and Delete.
Command-C (Ctrl-C on Windows and Linux) copies the picked sprites, with everything attached to them; Command-V pastes them a step down and to the right, picked so you can drag them into place (one whose name the file already has gets a new one, as Duplicate gives); Command-X cuts them. A pasted sprite goes beside the one it was copied from, on the same parent; in another scene file it goes where it was on the screen, and brings the pictures, behaviors and patterns it uses along.
Rigging
Under Rigging in a node’s fields are the constraints SET SPRITE gives
a rig:
- IK makes an attached node the tip of a chain, turning its parents so
it reaches a target. Length is how many parents it turns. Ticking it
makes the chain’s links Rigid, as
SET SPRITE IKdoes. Drag any link of the chain on the canvas and the links above it turn to follow it: what the file keeps is the pose, each link’s Rotation. Dragging never stretches a bone; to make one longer or shorter, type the link’s Offset. - Pin pulls a node toward a target.
- Limit keeps an attached node’s offset in a range, or on one axis. Dragging it, or typing its offset, stops at the limit, where the game would put it.
An IK or a pin can have a Target: another node it follows wherever it
is (IK TARGET SPRITE, PIN TARGET SPRITE). The editor shows the chain
reaching for it, so drag the target around and the chain follows. Renaming
the target keeps it followed; deleting it leaves the IK or pin with none.
With no target, your program aims it (IK TARGET, PIN TARGET): the file
keeps how the constraint is set up, and until the program aims it, it does
nothing. With a target, the tip stays on it while you drag the links
between: dragging an elbow across makes the arm bend the other way.
Prefabs
A node can be a whole other scene file, a prefab: a door, a tree, a little house, built once and put down as many times as you like. Each one is drawn from its own file, and Open prefab opens that file to change it. Change the door, and every door changes.
Walls and floors
Pick the Boundary tool and draw. Drag a boundary to move it, and drag its edges and corners to size it. Click one, on the scene or in the Boundaries section of the tree, and its settings are on the right. The + on Boundaries adds one in the middle of the view. Command-C (Ctrl-C on Windows and Linux) copies the picked boundary and Command-V pastes it a step down and to the right, picked so you can drag it into place; Command-X cuts it. It pastes into another scene file too. A slope is drawn as the solid triangle it is, and a one-way floor is drawn heavy, with arrows the way it stops you. Boundaries in the toolbar shows or hides them all.
Behaviors
A scene can carry behaviors of its own, so it works the same in any game, whatever language it’s in, even one that never defined them. The + on Behaviors makes one, and + Command, in its fields, puts commands in it.
Each number in a command can be:
- = a value: just that number,
- ~ give or take (
VARIANCE): a random amount either side, picked for each sprite, - ~# give or take whole numbers (
VARIANCEINT), - @ a parameter: a value each sprite gives for itself, with a default.
Then give a sprite the behavior in its fields, with its values for the parameters.
Planes
A layer can be a plane, AFFINE or PERSPECTIVE, for a floor that goes off into the distance. You lay a plane out flat, seen from above, with its camera drawn on it: where the camera stands, which way it looks, and the floor it sees. Camera view shows it through that camera, the way the game will. You can look in Camera view, but you lay things out in the flat one.
For several players
In a game for several players, the Authority in a sprite’s fields says whose a sprite is: host (the shared world, which is what it is unless you say), player (one for each player, like an avatar), or local (only on one player’s screen). Its fields show a sprite’s authority even when it gets it from its parent, so a forgotten avatar is easy to spot.
Preview
▶ Preview runs the scene in the game player, at the screen size you pick beside it. It shows the scene as it stands on its own, whatever language your game is in: the behaviors the file carries move, and nothing of your program runs. A behavior that only your program defines is left off, and the editor tells you which: a notice in the toolbar says how many notes there are, and clicking it opens them. If the file can’t be built at all, the notice says Not built, the scene shows the last version that built, and the notes say what’s wrong.
Crash-tan’s Tip: Patterns can be picked for a sprite here, but not made: make them in your code, or let a scene carry ones you saved with
SAVE SCENE ... !! definitions(TRUE).