# core/scene (vanilla-engine 0.4.0)

> https://vanillapunch.com/docs/vanilla-engine/0.4.0/api/core/scene/

Scene.
- The original inherits the Scene class and overrides create / tick / draw.
- The Rust version implements the Scene trait and keeps the common scene state (node tree, touch target) in SceneBase.
- Nodes are held by SceneBase's NodeTree, and game code points to them with NodeId handles. (get_node_tree_mut().create_child(...))
  In place of the original super.tick() / super.draw(), call get_scene_base_mut().tick() / .draw().
- The original GameScene's pre_draw (filling the whole canvas with the background color and applying the view coordinate system) moved to SceneBase::draw_scene_background.
- Like the original, the scene holds tweens in a list (start_tween), runs them on tick after nodes → touch, and removes finished ones.
  The original points to them by tween object, but the Rust version takes ownership of the tween and returns a TweenId. (stop_tween(tween_id))
- The original SceneManager.unloadScene(scene) points by scene object. In the Rust version the engine holds the scenes, so it points by the SceneId returned from load_scene or
  by the common scene state (&SceneBase, by scene as in the original). A scene knows its own handle with get_scene_base().get_scene_id().
- When unloading, like the original it calls finalize then unload, and the Rust version additionally calls destroy right before dropping the scene.
- In place of the original async load(engine): in load, hand the loading work to Engine::spawn_scene_task and entrust it to the scene with track_task.
  Inside the task, await assets as in the original and touch the scene and engine inside SceneContext::with. initialize is called only after all entrusted tasks and assets finish.
  The synchronous form of entrusting asset handles with track_asset still works. (the two can be mixed)
  In place of the original await unload(engine): the scene stays in the list receiving tick, draw until the tasks entrusted in unload (track_task) finish, then leaves the list.
  If that scene's tasks still remain after that, the scene value lives until they all finish, like the original's Promise chain (it receives no tick, draw), and a scene unloaded while loading
  receives initialize once loading finishes, like the original SceneManager.loadScene. When everything is done, the engine calls destroy and drops it.
- What the original Scene.load does to fit the root to the view size (position 0, top-left pivot, content size is the view size) is done by the engine between create and load.
  Like the original SceneManager.loadScene, after all entrusted assets finish it keeps showing the loading screen (draw_on_load) for at least 0.3 seconds more, then calls initialize.
- The scene's touch hooks (touch_press, touch_move, touch_release, touch_cancel, touch_wheel) are called by the engine after tick, in the original Scene.tickTouch order.
  SceneBase.tick also passes them to the frontmost interactable node regardless of the scene type. (same as the original Scene.tickTouch passing them to the scene's TouchRaycaster)
- Unlike the original, scene hooks receive the engine (&Engine). (it is the same engine as the global engine Engine::get_engine)

## SceneId (struct) (Clone, Copy, Debug, PartialEq, Eq, Hash, From<&SceneBase>)

Scene handle. (returned by Engine::load_scene and taken by Engine::unload_scene)

Example: Load two scenes and unload only one by handle

```rust
use vanilla::{Engine, EngineConfiguration, Scene, SceneBase, SceneId};

struct EmptyScene {
	scene_base: SceneBase,
}

impl Scene for EmptyScene {
	fn get_scene_base(&self) -> &SceneBase {
		&self.scene_base
	}

	fn get_scene_base_mut(&mut self) -> &mut SceneBase {
		&mut self.scene_base
	}
}

let engine = Engine::new(EngineConfiguration::new());
let first_scene_id: SceneId = engine.load_scene(Box::new(EmptyScene { scene_base: SceneBase::new() }));
let second_scene_id: SceneId = engine.load_scene(Box::new(EmptyScene { scene_base: SceneBase::new() }));
assert_ne!(first_scene_id, second_scene_id);
engine.unload_scene(second_scene_id);
```

## SceneBase (struct) (Default)

Common scene state.
- Holds the node tree, tween list, entrusted assets and tasks, touch target and background color. A scene struct holds one and exposes it via get_scene_base.

Example: Create a node and move it with a tween

```rust
use vanilla::{SceneBase, Tween, TweenProperty, Vector2};

let mut scene_base = SceneBase::new();
let root_id = scene_base.get_root_id();
let player_id = scene_base.get_node_tree_mut().create_child(root_id, "player");
let tween = Tween::create_node_tween(player_id, TweenProperty::LocalPosition, Vector2::zero(), Vector2::create(100.0, 0.0), 1.0);
let tween_id = scene_base.start_tween(tween);
assert_eq!(scene_base.get_tween_count(), 1);
scene_base.tick_tweens(0.5);
assert_eq!(scene_base.get_node_tree()[player_id].get_local_position(), Vector2::create(50.0, 0.0));
scene_base.tick_tweens(0.5);
assert_eq!(scene_base.get_tween_count(), 0);
assert!(scene_base.get_tween(tween_id).is_none());
```

- `pub fn new() -> SceneBase` (constructor, since 0.3.2): Constructor.
  - returns SceneBase: New common scene state. (a node tree with just the root, black background, before loading, gizmos off)
- `pub fn is_wheel_handled(&self) -> bool` (method, since 0.4.0): Whether a component (scroll pane and such) consumed this frame's wheel. (read after tick_touch, if none, the game uses it for map zoom and such)
  - returns bool: True if a component consumed this frame's wheel.
- `pub fn get_scene_id(&self) -> Option<SceneId>` (method, since 0.4.0): Scene handle. (present after it is passed to the engine with load_scene)
  - returns Option<SceneId>: This scene's handle. (None before load_scene)
- `pub fn set_first_touch_callback(&mut self, first_touch_callback: Box<dyn FnMut()>)` (method, since 0.3.2): Sets the first touch callback. (once, on the first press. Where audio is unlocked on the web, the original TouchRaycaster)
  - `first_touch_callback` Box<dyn FnMut()>: Function to call on the first press. (replaces a previously set function)
- `pub fn set_touch_dispatch_enabled(&mut self, is_enabled: bool)` (method, since 0.4.0): Turns passing touches to nodes on or off. (the original Scene.setTouchDispatchEnabled, same effect as setTouchRaycaster(null))
  - When off, tick_touch does not pass press, move, release or wheel to nodes (and does not call the first touch callback), and only the scene's touch hooks are called. (for intercepting in the hooks and passing directly)
  - `is_enabled` bool: true to pass to nodes. (true by default)

  Example: Turn off the scene's default passing and receive in the hooks directly

  ```rust
  use vanilla::SceneBase;
  
  let mut scene_base = SceneBase::new();
  scene_base.set_touch_dispatch_enabled(false);
  assert!(!scene_base.is_touch_dispatch_enabled());
  ```

- `pub fn is_touch_dispatch_enabled(&self) -> bool` (method, since 0.4.0): Whether touches are passed to nodes.
  - returns bool: true if it passes.
- `pub fn get_touch_target(&self) -> Option<NodeId>` (method, since 0.3.2): The node currently pressed. (the original TouchRaycaster.getTouchTarget)
  - returns Option<NodeId>: The topmost pressable node found on press. (None if not pressing or an empty spot was pressed)
- `pub fn track_asset(&mut self, asset: &dyn Asset)` (method, since 0.3.2): Entrusts an asset. (an asset whose loading was requested in load. When all entrusted ones are read, the engine calls initialize)
  - `asset` &dyn Asset: Asset whose load was requested. (assets without a read handle are not entrusted)
- `pub fn track_load_handle(&mut self, load_handle: &AssetLoadHandle)` (method, since 0.3.2): Entrusts a read handle. (for things not in asset form)
  - `load_handle` &AssetLoadHandle: Read handle to wait for. (held as a clone)
- `pub fn track_audio_asset(&mut self, audio_asset: &Rc<AudioAsset>)` (method, since 0.3.2): Entrusts an audio asset. (one received from engine.load_audio_asset. On the web it counts as read only once decoding finishes)
  - `audio_asset` &Rc<AudioAsset>: Audio asset to wait for. (counts as finished when read or failed)
- `pub fn track_task(&mut self, task_handle: &TaskHandle)` (method, since 0.4.0): Entrusts a task. (in place of the original async load, a loading task entrusted with spawn_scene_task in load. The engine calls initialize only after it finishes)
  - If entrusted in unload, unloading finishes only after it finishes, like the original await scene.unload. (the scene stays in the list meanwhile)
  - `task_handle` &TaskHandle: Handle of the task to wait for. (returned by spawn_scene_task, spawn_task)

  Example: In place of the original async load: entrust a loading task in load

  ```rust
  use vanilla::{Engine, Scene, SceneBase, SceneContext};
  
  struct StageScene {
  	scene_base: SceneBase,
  	stage_byte_count: usize,
  }
  
  impl Scene for StageScene {
  	fn get_scene_base(&self) -> &SceneBase {
  		&self.scene_base
  	}
  
  	fn get_scene_base_mut(&mut self) -> &mut SceneBase {
  		&mut self.scene_base
  	}
  
  	fn load(&mut self, engine: &Engine) {
  		let task_handle = engine.spawn_scene_task(self, |mut scene_context: SceneContext<StageScene>| async move {
  			let load_handle = scene_context.with(|_scene, engine| engine.request_asset_bytes("examples/assets/scenedocument.scene.json"));
  			if let Ok(bytes) = load_handle.await {
  				scene_context.with(|scene, _engine| {
  					scene.stage_byte_count = bytes.len();
  				});
  			}
  		});
  		self.scene_base.track_task(&task_handle);
  	}
  
  	fn initialize(&mut self, _engine: &Engine) {
  		println!("{}", self.stage_byte_count);
  	}
  }
  ```

- `pub fn are_tracked_unloads_finished(&self) -> bool` (method, since 0.4.0): Whether everything entrusted in unload is finished. (read, failed, or task finished)
  - returns bool: True if everything entrusted in unload is finished. (true if nothing was entrusted)
- `pub fn are_tracked_assets_finished(&self) -> bool` (method, since 0.3.2): Whether all entrusted assets are finished. (read or failed. Keeps a failed asset from stalling the scene)
  - returns bool: True if all assets and tasks entrusted for loading are finished. (true if nothing was entrusted)
- `pub fn are_tracked_assets_finished_except(&self, excluded_load_handle: &AssetLoadHandle) -> bool` (method, since 0.4.0): Whether all tracked assets except one have finished. (used by GameSceneBase to check whether the original loadAssets has finished, excluding the loading door)
  - `excluded_load_handle` &AssetLoadHandle: Read handle not to check for completion. (all handles pointing to the same read are left out)
  - returns bool: True if all the rest except that handle are finished.
- `pub fn get_tracked_asset_progress(&self) -> f64` (method, since 0.3.2): Ratio of entrusted assets that are finished. (for the loading screen progress bar, 1 if nothing was entrusted)
  - returns f64: Finished count / entrusted count. (0 ~ 1, failed ones count as finished)

  Example: Progress ratio of two read handles

  ```rust
  use vanilla::{AssetLoadHandle, SceneBase};
  
  let mut scene_base = SceneBase::new();
  let scene_load_handle = AssetLoadHandle::create_pending("examples/assets/scenedocument.scene.json");
  let atlas_load_handle = AssetLoadHandle::create_pending("examples/assets/atlas/icons.json");
  scene_base.track_load_handle(&scene_load_handle);
  scene_base.track_load_handle(&atlas_load_handle);
  assert_eq!(scene_base.get_tracked_asset_progress(), 0.0);
  scene_load_handle.finish(Ok(b"{}".to_vec()));
  assert_eq!(scene_base.get_tracked_asset_progress(), 0.5);
  atlas_load_handle.finish(Err(String::from("not found")));
  assert!(scene_base.are_tracked_assets_finished());
  ```

- `pub fn clear_tracked_assets(&mut self)` (method, since 0.3.2): Clears the entrusted assets. (the engine calls it right before initialize)
- `pub fn has_ever_touched(&self) -> bool` (method, since 0.3.2): Whether it has ever been pressed. (the original Scene.hasEverTouched, becomes true on the first press)
  - returns bool: True if it has been pressed at least once in this scene.
- `pub fn get_node_tree(&self) -> &NodeTree` (method, since 0.3.2): Node tree.
  - returns &NodeTree: This scene's node tree.
- `pub fn get_engine(&self) -> Result<&'static crate::core::engine::Engine, crate::core::globalengine::EngineAccessError>` (method, since 0.4.0): Returns the engine. (the original Scene.getEngine, the engine that loaded this scene. The Rust version has one engine, so it gives the global engine)
  - The same as Engine::get_engine. Anywhere in scene functions, components and async tasks it gives the same engine as the engine argument of scene functions.
  - returns Result<&'static crate::core::engine::Engine, crate::core::globalengine::EngineAccessError>: The global engine, or the reason it could not be taken.
- `pub fn get_node_tree_mut(&mut self) -> &mut NodeTree` (method, since 0.3.2): Node tree. (mutable)
  - returns &mut NodeTree: This scene's node tree. (creating, attaching and removing nodes)
- `pub fn get_root_id(&self) -> NodeId` (method, since 0.3.2): Root node handle.
  - returns NodeId: Root node handle of the node tree.
- `pub fn get_root(&self) -> &WorldNode` (method, since 0.3.2): Root node.
  - returns &WorldNode: Root node. (the engine fits it to the view size between create and load)
- `pub fn get_root_mut(&mut self) -> &mut WorldNode` (method, since 0.3.2): Root node. (mutable)
  - returns &mut WorldNode: Root node.
- `pub fn set_loaded(&mut self, is_loaded: bool)` (method, since 0.3.2): Sets load completion.
  - `is_loaded` bool: Whether loading is done. (the engine sets it to true after initialize)
- `pub fn is_loaded(&self) -> bool` (method, since 0.3.2): Whether loading is complete.
  - returns bool: True if initialize is done. (before that, the engine calls draw_on_load instead of tick, draw)
- `pub fn set_gizmo_visible(&mut self, is_gizmo_visible: bool)` (method, since 0.3.2): Sets gizmo drawing.
  - `is_gizmo_visible` bool: If true, the engine calls draw_gizmos after post_draw.
- `pub fn is_gizmo_visible(&self) -> bool` (method, since 0.3.2): Whether gizmos are drawn.
  - returns bool: True if gizmos are drawn. (default false)
- `pub fn set_scene_background_color(&mut self, color: impl Into<Color>)` (method, since 0.3.2): Sets the background color. (draw_scene_background fills it)
  - `color` impl Into<Color>: Background color. (a Color or a color string like "#202020")
- `pub fn get_scene_background_color(&self) -> Color` (method, since 0.3.2): Returns the background color.
  - returns Color: Background color. (default black)
- `pub fn tick(&mut self, time_delta: f64)` (method, since 0.3.2): Default update. (root node → touch → tweens)
  - `time_delta` f64: Frame interval multiplied by the time scale. (seconds)
- `pub fn tick_tweens(&mut self, time_delta: f64)` (method, since 0.3.2): Updates the tween list. (iterates from the back as in the original, and removes finished tweens from the list)
  - If two tweens animate the same property, the one started first runs later and wins. (same as the original)
  - `time_delta` f64: Time to advance. (seconds)
- `pub fn start_tween(&mut self, mut tween: Tween) -> TweenId` (method, since 0.3.2): Starts a tween. (takes ownership of the tween, starts it and appends it to the list. Returns a handle to point to it)
  - `tween` Tween: Tween to run. (owned by the scene)
  - returns TweenId: Handle of that tween. (pass to stop_tween, get_tween)
- `pub fn stop_tween(&mut self, tween_id: TweenId)` (method, since 0.3.2): Stops a tween. (stops without the completion callback and removes it from the list. Does nothing if it already finished and was removed)
  - `tween_id` TweenId: Handle of the tween to stop. (returned by start_tween)
- `pub fn stop_all_tweens(&mut self)` (method, since 0.3.2): Stops all tweens.
- `pub fn get_tween(&self, tween_id: TweenId) -> Option<&Tween>` (method, since 0.3.2): Returns the tween. (None if it finished and was removed from the list. Where the original held the tween object to query it)
  - `tween_id` TweenId: Handle of the tween to find.
  - returns Option<&Tween>: That running tween. (None if it finished or was stopped and removed)
- `pub fn get_tween_mut(&mut self, tween_id: TweenId) -> Option<&mut Tween>` (method, since 0.3.2): Returns the tween. (mutable)
  - `tween_id` TweenId: Handle of the tween to find.
  - returns Option<&mut Tween>: That running tween. (None if it finished or was stopped and removed)
- `pub fn get_tween_count(&self) -> usize` (method, since 0.3.2): Number of running tweens.
  - returns usize: Number of tweens in the list. (including waiting ones)
- `pub fn tick_touch(&mut self, _time_delta: f64)` (method, since 0.3.2): Touch update. (finds the topmost interactable node at the pressed spot and dispatches press / move / release)
  - The wheel, regardless of pressing, is passed from the frontmost scroll pane or pressable node at that position toward the parents.
  - `_time_delta` f64: The frame interval multiplied by the time scale. (seconds, the same argument as the original tickTouch(timeDelta). Input is read from the engine's input manager)
- `pub fn draw(&mut self, graphic: &mut Graphic)` (method, since 0.3.2): Default draw. (recursive from the root node)
  - `graphic` &mut Graphic: Graphic to draw with.
- `pub fn draw_scene_background(&self, graphic: &mut Graphic)` (method, since 0.3.2): Fills the whole canvas with the background color and sets the view coordinate system. (the original GameScene.preDraw)
  - `graphic` &mut Graphic: Graphic to fill with. (the view coordinate system is applied when done)

  Example: Fill the background in pre_draw

  ```rust
  use vanilla::{Engine, Graphic, Scene, SceneBase};
  
  struct MainScene {
  	scene_base: SceneBase,
  }
  
  impl Scene for MainScene {
  	fn get_scene_base(&self) -> &SceneBase {
  		&self.scene_base
  	}
  
  	fn get_scene_base_mut(&mut self) -> &mut SceneBase {
  		&mut self.scene_base
  	}
  
  	fn load(&mut self, _engine: &Engine) {
  		self.scene_base.set_scene_background_color("#203040");
  	}
  
  	fn pre_draw(&mut self, graphic: &mut Graphic) {
  		self.scene_base.draw_scene_background(graphic);
  	}
  }
  ```

## SceneAny (trait)

Takes the scene out as its type. (used when SceneContext turns &mut dyn Scene back into the type of the scene that entrusted the task, attached to every scene automatically)

Example: Turn a `Box<dyn Scene>` back into a scene type

```rust
use vanilla::core::scene::SceneAny;
use vanilla::{Scene, SceneBase};

struct MainScene {
	scene_base: SceneBase,
	score: u32,
}

impl Scene for MainScene {
	fn get_scene_base(&self) -> &SceneBase {
		&self.scene_base
	}

	fn get_scene_base_mut(&mut self) -> &mut SceneBase {
		&mut self.scene_base
	}
}

let mut boxed_scene: Box<dyn Scene> = Box::new(MainScene { scene_base: SceneBase::new(), score: 7 });
let main_scene = boxed_scene.as_scene_any_mut().downcast_mut::<MainScene>().unwrap();
assert_eq!(main_scene.score, 7);
```

- `fn as_scene_any_mut(&mut self) -> &mut dyn std::any::Any` (method, since 0.4.0): Borrows as Any.
  - returns &mut dyn std::any::Any: This scene borrowed as `dyn Any`. (turned back into the scene type with downcast_mut)

## Scene (trait) (SceneAny)

Scene trait.
- Only get_scene_base and get_scene_base_mut must be implemented, and the other hooks are overridden only as needed.

Example: A first scene drawing one white rectangle (examples/quickstart.rs)

```rust
use vanilla::{Colors, Engine, EngineConfiguration, Graphic, Rect, Scene, SceneBase, Vector2};

struct MainScene {
	scene_base: SceneBase,
}

impl Scene for MainScene {
	fn get_scene_base(&self) -> &SceneBase {
		&self.scene_base
	}

	fn get_scene_base_mut(&mut self) -> &mut SceneBase {
		&mut self.scene_base
	}

	fn pre_draw(&mut self, graphic: &mut Graphic) {
		self.scene_base.draw_scene_background(graphic);
	}

	fn draw(&mut self, graphic: &mut Graphic) {
		graphic.set_fill_color(Colors::WHITE);
		graphic.draw_rect(Rect::create(100.0, 100.0, 200.0, 120.0));
	}
}

let mut engine_configuration = EngineConfiguration::new();
engine_configuration.reference_resolution_size = Vector2::create(1280.0, 720.0);
let engine = Engine::new(engine_configuration);
let main_scene = MainScene {
	scene_base: SceneBase::new(),
};
if let Err(error) = engine.run(Box::new(main_scene)) {
	eprintln!("{}", error);
}
```

Example: Receive the pressed position

```rust
use vanilla::{Engine, Scene, SceneBase, Vector2};

struct TouchScene {
	scene_base: SceneBase,
	last_touch_position: Vector2,
}

impl Scene for TouchScene {
	fn get_scene_base(&self) -> &SceneBase {
		&self.scene_base
	}

	fn get_scene_base_mut(&mut self) -> &mut SceneBase {
		&mut self.scene_base
	}

	fn touch_press(&mut self, view_input_position: Vector2) {
		self.last_touch_position = view_input_position;
	}
}
```

- `fn get_scene_base(&self) -> &SceneBase` (method, since 0.3.2): Returns the common scene state.
  - returns &SceneBase: The common scene state the scene holds.
- `fn get_scene_base_mut(&mut self) -> &mut SceneBase` (method, since 0.3.2): Returns the common scene state. (mutable)
  - returns &mut SceneBase: The common scene state the scene holds.
- `fn create(&mut self)` (method, since 0.3.2): Create. (once before load when the engine loads the scene, the original create)
  - SceneBase::new has already built the shared scene state. Fill fields that do not need the engine here. (Take the engine with Engine::get_engine())
- `fn load(&mut self, _engine: &Engine)` (method, since 0.4.0): Load. (once after create when the engine loads the scene, the original async load. Build the node tree and assets here)
  - In place of the original await: entrust the task given with engine.spawn_scene_task(self, |mut scene_context| async move { ... }) via get_scene_base_mut().track_task.
    It moves on to initialize only after the tracked assets and tasks have all finished. (when the original load's Promise finishes)
  - `_engine` &Engine: Engine. (reading assets, entrusting tasks, managers)
- `fn initialize(&mut self, _engine: &Engine)` (method, since 0.3.2): Initialization. (once, 0.3 seconds after the assets tracked in load have all loaded. The original initialize. Waits 0.3 seconds after load even if nothing was tracked)
  - On the web assets arrive later, so create nodes that use assets here. On desktop they may be created in load.
  - `_engine` &Engine: Engine.
- `fn draw_on_load(&mut self, _graphic: &mut Graphic)` (method, since 0.3.2): Drawing while loading. (called instead of tick / draw until initialize. The original drawOnLoad)
  - `_graphic` &mut Graphic: Graphic to draw the loading screen with.
- `fn finalize(&mut self, _engine: &Engine)` (method, since 0.4.0): Finalize. (once before unload when unloading, the original finalize)
  - `_engine` &Engine: Engine.
- `fn unload(&mut self, _engine: &Engine)` (method, since 0.4.0): Unload loading. (once after finalize when unloading, the original async unload. Unloading finishes only after tasks entrusted here with track_task finish)
  - `_engine` &Engine: Engine.
- `fn destroy(&mut self)` (method, since 0.3.2): Destroy. (once when the engine unloads the scene, after unload, right before dropping the scene. After all of that scene's remaining tasks finish)
- `fn touch_press(&mut self, _view_input_position: Vector2)` (method, since 0.4.0): Touch press. (the original Scene.touchPress, called by the engine after tick)
  - `_view_input_position` Vector2: Press position. (view coordinates)
- `fn touch_move(&mut self, _view_input_position: Vector2)` (method, since 0.4.0): Touch move. (while pressing, not called on the press frame or the release frame)
  - `_view_input_position` Vector2: Current position. (view coordinates)
- `fn touch_release(&mut self, _view_input_position: Vector2)` (method, since 0.4.0): Touch release. (right after press if pressed and released within one frame)
  - `_view_input_position` Vector2: Release position. (view coordinates)
- `fn touch_cancel(&mut self, _view_input_position: Vector2)` (method, since 0.4.0): Touch cancelled.
  - `_view_input_position` Vector2: Position at cancel. (view coordinates)
- `fn touch_wheel(&mut self, _view_input_position: Vector2, _wheel_delta: Vector2)` (method, since 0.4.0): Mouse wheel. (when there is wheel accumulated this frame)
  - `_view_input_position` Vector2: Mouse position. (view coordinates)
  - `_wheel_delta` Vector2: Wheel amount accumulated this frame. (x horizontal, y vertical, the input manager's get_wheel_delta_x, get_wheel_delta_y)
- `fn on_page_process_restored(&mut self)` (method, since 0.4.0): Restore after the page process is discarded. (resume after a Chromium freeze, pageshow returning from bfcache, etc.)
  - The engine wakes the sound again, clears the input state, then calls it on all loaded scenes.
- `fn on_page_visibility_restored(&mut self)` (method, since 0.4.0): Page visibility restored. (background → foreground, visible of the web visibilitychange, a desktop window being uncovered)
  - The engine wakes the sound again, clears the input state, then calls it on all loaded scenes.
- `fn resize(&mut self, _canvas_native_size: Vector2)` (method, since 0.3.2): Screen area changed. (when the window size changes, also once right after loading)
  - `_canvas_native_size` Vector2: Logical size of the window interior. (the view manager's get_canvas_native_size)
- `fn tick(&mut self, time_delta: f64)` (method, since 0.3.2): Periodic update.
  - The default implementation calls the common scene state's tick. If overridden, call get_scene_base_mut().tick(time_delta) directly.
  - `time_delta` f64: Frame interval multiplied by the time scale. (seconds, the time manager's get_time_delta)
- `fn pre_draw(&mut self, _graphic: &mut Graphic)` (method, since 0.3.2): Pre-draw.
  - `_graphic` &mut Graphic: Graphic to draw with.
- `fn draw(&mut self, graphic: &mut Graphic)` (method, since 0.3.2): Draw.
  - The default implementation draws the node tree with the common scene state's draw.
  - `graphic` &mut Graphic: Graphic to draw with.
- `fn post_draw(&mut self, _graphic: &mut Graphic)` (method, since 0.3.2): Post-draw.
  - `_graphic` &mut Graphic: Graphic to draw with.
- `fn draw_gizmos(&mut self, _graphic: &mut Graphic)` (method, since 0.3.2): Gizmo draw.
  - Called after post_draw only on scenes with gizmo display (set_gizmo_visible) on.
  - `_graphic` &mut Graphic: Graphic to draw with.
