Scene stack demo — title → counter → pause overlay.
Demonstrates the opt-in scene framework: the running game is split into three Scene structs that push and pop without a hand-rolled state machine. The demo is deliberately small — three screens that swap when buttons are pressed — so you can read the dispatch shape. It uses the pictures of basics/game_skeleton (the logo, the play square), so the two ways of structuring a game can be compared side by side.
Flow:
- title scene: the logo and "PRESS START". Start pushes counter.
- counter scene: the square, and a number that increments every frame. Select pushes pause (counter is suspended; numbers stop). Start pops back to title.
- pause scene: shows "PAUSED" and darkens the square beneath it (colour math): an overlay, the scene below still drawn but frozen. Select pops back to counter (numbers resume from where they stopped, no init replay).
- SNES Concepts
- Scene stack: push/pop without enum + switch boilerplate
- init runs once on first push; resume after pop does not re-init
- Suspended scenes get no callbacks (pause overlay = counter frozen)
- Text rendering through the auto-flush NMI hook, on BG3 in front
- Each scene picks its layers (setMainScreen) when it is entered or resumed
- A pause overlay by colour math: colorMathShadow() darkens BG1
- What to Observe
- Start on title: enters counter, numbers increment from 0
- Select while counting: PAUSED appears, numbers freeze
- Select in pause: counter resumes, numbers continue from where they stopped (no reset — init was not re-called)
- Start while counting: pops back to title (counter discarded; pressing Start again restarts from 0 because counter's init re-runs on the next push)
- Modules Used
- console, sprite, dma, background, text, input, scene, colormath
- See also
- scene.h, gameloop.h
The root scene's init: load everything once, then draw the title.
The title is pushed once, by sceneRun(), so its init is where the program sets up the hardware — the same layers as basics/game_skeleton: Mode 1, BG1 the square, BG2 the logo, BG3 the text in front.
< the square
< the logo
< the square
< the logo
< the text
< the text