Working with sprites & the stage
Targets are the heart of a project. This guide covers the task-level workflows;
for an exhaustive member list see the Sprite,
Stage and Target references.
Finding targets
sprite() only matches sprites; target() matches the stage too. Each call
returns a fresh wrapper over the same underlying JSON.
Moving and styling a sprite
A Sprite exposes its spatial state as plain properties. Read or assign them
directly:
Every setter coerces its input (Number(...), Boolean(...), String(...)), so
assigning cat.x = '120' is safe.
Stacking order
layerOrder controls which sprite draws on top — higher is nearer the front.
When you addSprite, it is automatically given a layer
above every existing target, so new sprites appear in front by default.
The stage
The stage is a target too, so it shares all the costume/sound/variable/list machinery. It adds a few stage-only properties:
The stage's "costumes" are the project's backdrops — add and remove them exactly like sprite costumes (see Costumes & sounds).
Adding a sprite
A sprite created by addSprite starts with no costumes. Scratch and
TurboWarp expect every sprite to have at least one, so add one with
addCostume before opening the project in an editor.
The optional second argument lets you override any initial property (x, y,
size, direction, visible, …). Names must be unique among sprites — adding a
duplicate name throws.
Renaming and removing
Removing a sprite also drops any costume or sound bytes that only it used; assets shared with another target are kept.