Console::SceneDef
console 0.2.0 · app/console/scene.rb · 319 lines · view source
Also defined here:
Console::SceneController
Console::Scene -- the scene controller.
DragonRuby has no scene system; every sample hand-rolls a current_scene / next_scene pair. This module formalises that, adds a stack, and gives each scene four optional hooks:
enter called once when the scene becomes active update every frame while active render every frame while active leave called once when the scene stops being active
The hook is called render, not draw: draw is the console's rendering object (draw.rect, draw.sprite), and a scene that defined draw would shadow it and recurse.
A scene can be a Symbol paired with a class, a class, or a bare block set:
scene :title, TitleScene scene :play, PlayScene
goto :play # replace the whole stack push :pause # overlay, keeps :play underneath pop # back to :play
Scene changes are committed at the END of the frame, so calling goto from inside update never leaves the frame half-run. Each scene gets its own state hash under args.state.console.scenes[name], so leaving a scene and coming back does not lose data.
def initialize(name, klass = nil, options = {})- line 34
def kind-
Build the per-scene instance.
kindis :class, :block, or :none. def initialize(args)- line 52
def args- line 67
def tick_count- line 71
registration
def define(name, klass = nil, options = {})- line 77
def mix_in_api(klass)-
Give a scene class the console's API as bare method calls, so a scene can say
draw.rect/spawn/sfxinstead ofConsole.draw.rect. def defined?(name)- line 94
def names- line 98
def store(name)-
Per-scene state, created on first access.
hooks
def on_enter(name, &block)-
Run a block whenever a scene is entered.
def on_leave(name, &block)-
Run a block whenever a scene is left.
navigation
def pending?- line 122
def goto(name)-
Replace the entire stack with
name. def push(name)-
Push a scene on top of the current one.
def pop- line 144
def unwind-
Quit back to the first scene.
def depth- line 158
def current_name- line 162
def instance- line 166
def active?(name)- line 170
def underneath?(name)- line 174
frame
def run(draw_enabled = true)-
Update and draw the active scene, then commit any pending change. Called once per frame by Console#tick.
def draw_below(draw_arg)-
Draw the scenes underneath the top one, dimmed. Used by pause overlays.
def dispatch(hook, inst)- line 212
def activate(name)- line 228
def leave(name)- line 242
def dispatch_leave(d, inst)- line 253
def instance_for(name, d)- line 265
def commit- line 276