Reference guide
Start
How a Scena script starts — the import, the window, the game loop — and the rules and words the rest of the Guide uses.
Minimal script / init → Minimal script
Coming from Scratch, Unity or Pygame → From another engine
Rules → Rules
Units, Entity, point, frame… → Vocabulary
PNG / SVG file → Image files
st / canvas / clock… → Global singletons
setup / update / on_key → Script callbacks
Formula, check, event or process? → Which to use
The Guide's examples assume from scena import * and init(…) at the start and run() at the end. from scena import * is the only import: everything the Guide shows comes from it.
From another engine
The Scratch, Unity, Godot or Pygame way, and the Scena way. The idea is the same; the spelling changes.
| You would write | In Scena |
|---|---|
“forever” (Scratch), while running: with pygame.event.get() | def update(dt): runs every frame; Scena runs the loop. A while inside update freezes the window: use if. A sequence with waits is a task (async def + await wait(1), with run_task) |
“wait 1 seconds”, time.sleep(1) | after(1, f); in a task, await wait(1). time.sleep stops the whole game |
clock.tick(60) | Not needed: update(dt) receives the frame's time. The rate is canvas.framerate = 60 |
Update() / FixedUpdate() in a class | on_update(self, dt) |
Start() / Awake() | setup(self) |
Godot: _process(delta), _ready(), queue_free() | on_update(self, dt), setup(self), self.destroy(). A child that moves with its parent: child["center"] @= lambda: parent.center + Vec2(20, 0) |
OnTriggerEnter2D(other), OnCollisionEnter2D, rect.colliderect(other) every frame | on_collide(self, other) in the class, or @collide("hero", "coin"): runs when they start touching. To ask right now: test_collision(a, b) |
OnMouseDown(), “when this sprite clicked” | on_click(self), or @click(obj). A click anywhere: def on_mouse_click(x, y, button): at the top of the file |
Destroy(obj, 0.4), “delete this clone” | obj.destroy(); after a while, after(0.4, obj.destroy) |
transform.position, transform.rotation | .center (move it with move_to / move_by), .angle, .scale |
“hide” / “show”, SetActive(false) | visible = False / True hides only the drawing (it still collides); active = False stops everything |
| “glide 1 secs to x: y:” | move_to(x, y, time=1) (the time goes by name) |
| “point towards” | obj.rotate_to(heading(obj, target)) |
| “broadcast message” / “when I receive” | Call the function. Or count: st.waves += 1 with @on_change(st["waves"]), which compares once per frame (two writes that go back to the old value in the same frame do not fire it) |
| “create clone of myself” | obj.clone(); see what the copy takes along in the clone table |
x += vel * dt | Works: obj.move_by(obj.vel.x * dt, obj.vel.y * dt) in update (or on_update). Scena does not move anything by its vel on its own; vel is the velocity that bounce= reads and rewrites |
self.vel = 200 (the speed, a number) | vel is every object's 2D velocity (self.vel = (200, 0)), the one resolve(…, bounce=) uses; you do the moving, with move_by(vel.x * dt, vel.y * dt). A number of your own needs another name: self.speed = 200 |
cooldown -= dt … if cooldown <= 0: cooldown = 0.6 | Works, but it throws away whatever went past zero, and the rhythm changes with the frame rate. @every(0.6) or ready("shot", 0.6) keep the remainder |
Minimal script
Every script has three parts. from scena import * and init(…) set up the game's space. The body of the file creates the objects — each constructor already puts its object on the screen. run() opens the window and runs the game, calling update(dt) every frame.
from scena import *
init(width=1200, height=800)
SkyGradient("night")
Stars()
Vignette()
t = Triangle(center=(400, 300), radius=50, color="cyan")
def update(dt):
t.rotate_by(30 * dt)
run()
init
init(width=2000, height=1200, title="Scena", window_scale=0.8, display="windowed", ui_scale=, ui_font=)
Sets up the design space and the window; it does not open the window (run() does). It already runs on its own at import scena, with the defaults. Call it again right after from scena import * if the script reads canvas.width / .height before run(). run() takes no size.
| Parameter | Pass | Type (default) | Meaning |
|---|---|---|---|
width | name= | number2000 | Width of the design space (canvas.width). Not the OS window in pixels. |
height | name= | number1200 | Height of the design space (canvas.height). y-up, origin at the bottom-left corner. |
title | name= | str"Scena" | The OS window's title. |
window_scale | name= | number0.8 | Fraction of the largest windowed window that fits the desktop (the design's aspect, decorations on, taskbar visible). 1.0 = as large as the area allows. 0.8 = 80% of that, centered. Startup only: used up when the window opens. There is no canvas.window_scale. |
display | name= | str"windowed" | Shortcut for canvas.display. Only "windowed" · "maximized" · "fullscreen". The windowed window is created first (scale, centered); then it switches to the mode. |
ui_scale | name= | numbercurrent | Writes ui.scale. Leaving it out keeps the current value (import default: 1). |
ui_font | name= | strcurrent | Writes ui.font (a family, or a .ttf / .otf file). Leaving it out keeps the current value. |
The OS window follows from the design's aspect, the monitor's desktop area, the window's real borders and window_scale. It always starts centered. There is no x= / y= / window_width= in pixels — drag the window if you need a specific spot.
Don't confuse
| Looks like | It is | It is not |
|---|---|---|
init(width=, height=) is the OS window's size | the design space. The windowed window fits the desktop with the same aspect; window_scale=1 is the largest windowed fit. display="maximized" fills the area (black bars). display="fullscreen" covers the monitor. | canvas.window_scale |
Rules
Five rules that hold everywhere in Scena.
-
A constructor places.
Circle()shows up right away. So doRain(),Vignette(),Slider(). -
Materials and effects only show up applied to an object (or to the background).
Gradient,Color,Blur,Neon,Sheetdraw nothing on their own: they go in.fill,.visual,set_color,Sprite(sheet)orcanvas.background. -
=copies now.@=links live.c.radius = 10·c["radius"] @= lambda: player.hp * 10— see Reactive. -
A property is state. A method is an action.
c.visible = False·c.move_by(20, 0) - Sizes in design units, y up, angles in degrees. The origin is the bottom-left corner; 0° points right. See units. Widgets are pinned to the window and ignore the camera.
Each parameter table explains itself: common parameters (layer=, group=, a widget's 1st argument) appear again in every table, so you never have to jump to another section.
Vocabulary
The words the Guide always uses in the same sense. When a section says “units”, “point”, “Graphic” or “frame”, this is what it means.
| Term | What it is |
|---|---|
| design unit (“units”) | The measure of everything in Scena: position, size, radius, thickness, speed (units per second). The space runs from 0 to the width and from 0 to the height given to init: with init(width=2000, height=1200), the center of the screen is (1000, 600). The window scales that whole space to fit the monitor, so 1 unit is not 1 pixel — the game looks the same on any screen. y grows upward; (0, 0) is the bottom-left corner; angles are in degrees, 0 = to the right, counterclockwise. |
| frame | One turn of the game: read the keyboard and mouse, run update(dt) and the on_updates, move, collide, draw. About 60 per second. dt is how many seconds have passed since the previous frame — multiply speeds by it (200 * dt = 200 units per second). |
| Entity | Every game object: Shape, Sprite, Text, SpatialFx, widgets and the Entity() with no drawing. Every Entity can have its own fields (ship.hp), timers (after / every), a mode, groups and destroy(). |
| Graphic | An Entity with a drawn body and a pose: Shape, Sprite (and Svg) and Text. Only a Graphic can be clicked or dragged, travel with move_to and have a .box. SpatialFx and widgets are not Graphics. |
| pose | Where the object is and which way it faces: center, angle, scale and the mirror (flip_x / flip_y). The verbs in Move change the pose; color and visual are not part of it. |
| Shape | A geometric Graphic: Circle, Rect, Square, Concave, Line, Ellipse, Polygon, RegularPolygon, Triangle, Point, Track. |
| point | Wherever the API asks for a place (move_to, center=, about=, query_point…), any of these works: a tuple (x, y), a Point, a Vec2, a Graphic (its center counts) or mouse. The position is copied at that instant; to follow it, use lambda: (Reactive). More in Points. |
| field / Attribute | A value Scena keeps track of: st.score, ship.hp, c.radius. When it changes, whatever depends on it (an @= formula, an @when, a widget) finds out. Attribute is the name of the class behind it. |
link (@=) | Make a field follow a formula: c["radius"] @= lambda: ship.hp works it out again whenever ship.hp changes. The opposite of =, which copies the value once. |
| Handle | The object that verbs which take time return (after, tween, move_to(…, time=) or speed=, play_sound…): use it to cancel, pause or wait for that task. See Handle. |
| mode | The chapter of behavior an Entity is in right now (e.mode = e.diving). What it starts (timers, movements) stops when it ends. See Mode. |
| stage | The top of the file: what it creates (objects, timers, sounds, layers) lasts the whole game and works in every act. What an act creates leaves with it. See The stage and the act. |
slot (name=) | A name that holds a single task: after(2, hint, name="hint") called again with the same name replaces the previous one instead of adding another. A slot belongs to a place: the object of the call (ship.after(…, name=)); for a bare call, whoever is in the running mode (inside a mode's body, an act's mode included); outside a mode (the top of the script, an act's setup, callbacks), the game / the current act. The same name in two places is two slots: a bare play_sound(…, name="music") in an act's setup and another bare one in the act's mode play together. For a single task, always call from the same place — an act's soundtrack with self.play_sound(…, name="music"), which is the same slot as a bare call in the act's mode. A timer or sound of the stage (the top of the script) whose name the act reuses, from any of those places, is paused during the act and comes back after the change: the stage's soundtrack does not play along with the act's. A stage task does not pause: its name in a bare call in the act is an error. |
| a world with a floor | A game with gravity (platformer, runner) writes collision.floor = True: whatever rests on something below stands on it (it doesn't slide down the ramp, it rides along with the elevator). Without that line, the default, no side is special: a game seen from above, in space or without gravity. See A world with a floor. |
| place × travel | Placing puts the object straight in its spot (center = …, move_to without time=) and goes through walls. Traveling moves it there (move_by, move_to(…, time=) or speed=, move_along), and a resolve() wall stops it midway; the @collide of a fast traveler checks the whole path (Fast objects). Turning in place and scaling (rotate_* / scale_*) are never stopped by a wall: it only pushes the object out afterward. Turning around another point (rotate_by(…, about=)) carries the center along, and that is traveling. |
| held × on the frame it is pressed | keyp("A") is True on every frame the key is held; keyp.once("A") only on the frame it was pressed. @when fires when the condition turns from False to True, not while it stays True. |
| channel | In Transients, the place of one kind of effect: a new flash replaces the running flash, but lives alongside a pop. |
| HUD | Text and controls pinned to the window (score, lives, menus), on the "ui" layer: they don't move with the camera. |
Image files
Where Scena looks for the image files (PNG, JPG, SVG and XML / JSON atlases) you pass by name: next to the script or in its media/ folder.
Sprite, Sheet, Svg, Texture and Wallpaper use the same search. The name is used as given — the framework does not look into subfolders on its own.
- An absolute path. Only that file. It exists or it is missing.
-
The script's folder.
Next to the
.pyyou ran. -
media/next to the script.Sprite("ship.png")findsmedia/ship.png. - The folder you ran Python from. The cwd. Last resort.
Sprite("ship.png")
Sprite("sprites/ship.png") # media/sprites/ship.png next to the script
Texture("floor.png")
Wallpaper("sky.jpg")
A missing file does not stop the game: a checkerboard shows in place of the image, with a warning, and the object works normally. In the REPL or with python -c, the search starts in the current folder. Atlases: the PNG sits next to the XML / JSON that describes it. A pattern with * (Sheet and strip, File patterns) searches the same folders and uses only the first one that has a matching file.
Global singletons
These objects already exist after from scena import * — you don't build them, you just use them. The classes, functions and effects come with the same import; the search box at the top of the page indexes all of them.
| Property | Type (typical value) | Read/Write | Meaning |
|---|---|---|---|
st | State | read / write | Your game's values (score, lives, level), tracked by Scena. Keeping values. |
canvas | Canvas | read / write | The screen: camera, background, full-screen effects, layers. World. |
clock | Clock | read / write | Game time: dt, time, pause and slow motion. clock. |
keyp | KeyPressed | read | Keyboard: which key is held, which one was just pressed. Keyboard. |
mouse | Mouse | read | Pointer: position in the world, and buttons. Mouse. |
audio | mixer | read / write | Sound as a whole: master volume, mute, meters. audio. |
ui | stack | read / write | The widgets' size and font, and the column they stack in. UI. |
group | groups | read / write | Finds objects by tag: group["enemy"]. Groups. |
collision | queries | read / write | Collision questions (what is at this point?) and drawing the colliders. Collision. |
Script callbacks
Functions with fixed names that you write in the script and run() calls at the right moment: setup once, when the window opens; update every frame; on_key_down when a key is pressed; and so on. The full table is in Script callbacks.
def setup(canvas):
canvas.fx_quality = "high"
def update(dt, canvas):
if keyp("RIGHT"):
player.move_by(200 * dt, 0)
def on_key_down(key):
if key == "ESC":
canvas.reset_view()
def on_mouse_scroll(xoffset, yoffset):
factor = 1.1 if yoffset > 0 else 1 / 1.1
canvas.zoom_by(factor, about=(mouse.x, mouse.y))
Each function asks only for the parameters it wants: Scena passes the ones it declares. update(dt) and update(dt, canvas) both work. Catalog: Script callbacks and Entity callbacks.
Which to use
Your code runs in three ways: a formula stays true, a check is made every frame, an event runs once, at one instant. What takes time is a process, and every process has an owner. Choose by what the game needs: none of them is just for beginners, and a big game uses them all.
| I want | I use |
|---|---|
| something to always match something else (the lamp's color) | a formula: lambda, @= |
| to know a state every frame (is the key held?) | a check in update or in on_update |
| to react to an instant (a key, a click, a hit, leaving the screen) | an event: on_key_down, on_click, @collide, @leave_playfield |
| to react when a condition becomes true | @when |
| once, later | after |
| again and again | every |
| a sequence with waits, for what the object is doing | an async mode |
| one more sequence, or one that belongs to no object | run_task |
Check or event. For a state (is the key held?), the check; for an instant (the key just went down), the event. A flash inside if keyp("SPACE") restarts on every frame the key is held.
Processes. after, every, a movement with time=, a sound, a sequence: they all return the same Handle. One thing at the end of a process: then= / on_done=. Two waits or more: an async function — a mode, when it is what the object is doing (one at a time), or a task, when it runs alongside or belongs to no object.
Owner. A process's owner is the place where it started — the game or the act, an object, a mode — and the process ends when its owner ends: changing mode cancels what the old mode started. See scope and cancelling.
Where else to look — Reactive · Draw · Frame · Script callbacks