Skip to main content

SceneManager

Struct SceneManager 

Source
pub struct SceneManager { /* private fields */ }
Expand description

Manages a stack of scenes with transitions.

§Example

let mut scenes = SceneManager::new();
scenes.push(MenuScene::new());

// In game loop:
scenes.update(ctx);
scenes.render(ctx);

// From within a scene:
// scenes.push(GameScene::new(level));
// scenes.pop(); // return to previous scene
// scenes.replace(SettingsScene::new()); // replace current scene

Implementations§

Source§

impl SceneManager

Source

pub fn new() -> Self

Create a new empty scene manager.

Examples found in repository?
examples/scene_demo.rs (line 108)
106fn main() {
107    let example = SceneDemo {
108        scenes: SceneManager::new(),
109    };
110
111    Game::new()
112        .window_title("game-gem: Scene Demo")
113        .window_size(800, 600)
114        .run(example);
115}
Source

pub fn push<S: Scene>(&mut self, scene: S)

Push a new scene onto the stack.

Examples found in repository?
examples/scene_demo.rs (line 94)
93    fn on_enter(&mut self, _ctx: &mut Context) {
94        self.scenes.push(MenuScene::new());
95    }
Source

pub fn pop(&mut self)

Pop the top scene off the stack.

Source

pub fn replace<S: Scene>(&mut self, scene: S)

Replace the current scene with a new one.

Source

pub fn push_with_transition<S: Scene>( &mut self, scene: S, transition: Transition, )

Push a scene with a transition effect.

Source

pub fn pop_with_transition(&mut self, transition: Transition)

Pop with a transition effect.

Source

pub fn current(&self) -> Option<&dyn Scene>

Get a reference to the current (top) scene, if any.

Source

pub fn current_mut(&mut self) -> Option<&mut dyn Scene>

Get a mutable reference to the current scene, if any.

Source

pub fn find<S: Scene>(&self) -> Option<&S>

Get a scene by type from the stack.

Source

pub fn depth(&self) -> usize

Number of scenes on the stack.

Source

pub fn is_empty(&self) -> bool

Whether the scene stack is empty.

Source

pub fn update(&mut self, ctx: &mut Context)

Update the top scene and any active transition.

Examples found in repository?
examples/scene_demo.rs (line 98)
97    fn update(&mut self, ctx: &mut Context) {
98        self.scenes.update(ctx);
99    }
Source

pub fn render(&mut self, ctx: &mut Context)

Render all visible scenes (the top one, and the one below during transitions).

Examples found in repository?
examples/scene_demo.rs (line 102)
101    fn render(&mut self, ctx: &mut Context) {
102        self.scenes.render(ctx);
103    }

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.