PYBLOCKS / DOCS
Scenes and objects
A game is made of scenes, and a scene is made of objects. Learn to create, arrange and transform them, and to move between scenes while the game runs.
#Scenes
A scene is one screen or level of your game: a title menu, a level, a battle. Each scene is a .pbscene.json file in the project's scenes/ folder, and it stores every object with its properties and its blocks.
| CtrlN | Scene → New Scene |
|---|---|
| CtrlO | Scene → Open Scene |
| CtrlS | Save Scene |
| CtrlShiftS | Save Scene As... |
New Sceneasks for a name and starts an empty scene. It gets a file the first time you save it; the save dialog suggests thescenes/folder.- You can also open a scene by double-clicking it in the
Projectpanel. - Only one scene is open at a time. PyBlocks asks you to save before switching if there are unsaved changes.
The scene an exported game starts with is set in Project → Project Settings (Start Scene:). See Export.
#Create objects and use the Hierarchy
Create objects from the GameObject menu or the Add button above the scene view:
Create Empty(Ctrl+Shift+A): an invisible object, useful as a parent, a spawn point or a script holder.Create Square: a visible rectangle. Give it a sprite to turn it into a character, a platform or a background.Create Camera: decides what part of the world the game shows and at what resolution.GameObject → UI → Text / Image / Button: interface elements. See UI and fonts.
The Hierarchy lists every object. Click one to select it (the scene view and Inspector follow). Right-click for Locate (Ctrl+W, centres the scene view on it), Copy, Paste, Duplicate and Delete (Del). Cameras also have Camera Settings... for the resolution.
Parenting: drag an object onto another in the Hierarchy to make it a child, or use GameObject → Make Child Of.... Children move with their parent. Drag it back to the top level or use GameObject → Clear Parent to detach it. Deleting a parent also deletes its children (PyBlocks asks first).
#Inspector and transform
The Inspector shows the selected object's properties in groups: Transform (Name, Visible, Position X, Position Y, Rotation, Width, Height), Collider, Rigidbody, Sprite Renderer and Animator, plus UI Text, UI Image or UI Button for UI objects. Type a value or use the arrows of each field.
In the scene view you can also transform the selected object directly:
- Move: drag the object.
- Resize: drag one of the eight square handles. Hold Shift to keep the proportions and Alt to resize from the centre.
- Rotate: drag the round knob. Hold Shift to snap to 15° steps.
- Press Esc during a handle drag to cancel it.
| Arrow keys | Nudge the selected object 1 pixel |
|---|---|
| Shift+Arrow keys | Nudge 10 pixels |
| Ctrl+Mouse wheel | Zoom the scene view |
| Middle mouse drag / Spacedrag | Pan the scene view |
| CtrlHome | Frame the camera |
Y grows downwards: a larger Position Y places the object lower on the screen. Rotation is in degrees, clockwise.
#Shapes, sprites and cameras
A new square is drawn as a plain rectangle. To give it an image:
- Import the image: in the
Projectpanel, right-click a folder (for exampleassets/sprites) and chooseImport Files. PNG, JPG, WEBP, BMP and GIF files are accepted. - Select the object and, in
Sprite Renderer, clickSelect From Project. - Pick the image and click
Select. The object keeps itsWidthandHeight, so resize it if needed.
For sprite sheets, right-click the image in the Project panel and open Tile Editor. Set Tile Width and Tile Height (plus Margin and Spacing if the sheet has gaps), click Auto Slice and then Save Tileset Metadata. Then use Select Tile/Slice in the Inspector to show one tile. Tiles are also used for animation frames (see Animation). Clear and Clear Slice remove the image or the tile.
The camera decides what the game shows. Right-click it in the Hierarchy and choose Camera Settings... to pick a resolution (HD 1280 x 720, Full HD 1920 x 1080, ...) and the scale of the game view. Camera blocks can follow objects, zoom and shake it while the game runs.
#Switching scenes while the game runs
Use the Scene blocks to move between scenes:
- Load Scene loads a scene by name. Fade to scene fades out first and fades the new scene in.
- Load Next Scene and Load Previous Scene follow the alphabetical order of the files in
scenes/, wrapping around at the ends. - Reload Scene restarts the current scene.
Scenes are loaded from disk, so save every scene you want to reach. Object variables start fresh in each scene; global variables (Set global variable) come along to the next scene.
When you press Stop, the editor goes back to the scene you pressed Play from, with any unsaved edits intact.
#Undo and redo
| CtrlZ | Undo |
|---|---|
| CtrlY or CtrlShiftZ | Redo |
Undo covers every scene change: creating, moving, renaming and deleting objects, Inspector edits, parenting and block edits. A whole drag counts as one step. Undoing back to the last save marks the scene as saved again.
- Undo is paused while the game runs. Stop the game first.
- Each scene has its own history, which starts over when you open another scene.
- In the
Animateworkspace, Ctrl+Z and Ctrl+Y undo animation edits instead (see Animation).