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

A SceneManager instance. When using a game with multiple scenes, the scene_handler replaces you usual game manager. SceneManager implements EventHandler as a usual gamestate would and can thus interact with ggez without problems.

Implementations§

source§

impl SceneManager

source

pub fn new<T: Scene + 'static>(initial_scene: T) -> Self

Creates a new SceneManger with the specified initial Scene. This SceneManager can then be run as any EventHandler by ggez::event::run.

source

pub fn new_and_run<T: Scene + 'static>( event_loop: EventLoop<()>, ctx: Context, initial_scene: T ) -> !

All-in-one-method to create a new SceneManger with the specified initial scene and immediately run it. If using SceneManager, calling this method should be the last line of your main function. The running of the game will end as soon as the scene stack is emptied.

Examples found in repository?
examples/ui_examples/a_setup.rs (line 56)
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
pub fn setup_and_run() -> GameResult{

    // Fetch and set resource directory.

    let resource_dir = if let Ok(manifest_dir) = env::var("CARGO_MANIFEST_DIR") {
        let mut path = path::PathBuf::from(manifest_dir);
        path.push("resources");
        path
    } else {
        path::PathBuf::from("./resources")
    };

    // Generate game context and event loop.

    let (mut ctx, event_loop): (ggez::context::Context, ggez::event::EventLoop<()>) =
        ContextBuilder::new("Mooeye Examples", "Linus Mußmächer")
            .add_resource_path(resource_dir)
            .window_setup(conf::WindowSetup::default().title("Mooeye Examples"))
            .window_mode(
                conf::WindowMode::default()
                    .fullscreen_type(conf::FullscreenType::Windowed)
                    .resizable(true)
                    .dimensions(800., 600.),
            )
            .build()?;

    // Add fonts from the resource folder.

    ctx.gfx.add_font(
        "Bahnschrift",
        graphics::FontData::from_path(&ctx, "/bahnschrift.ttf")?,
    );

    // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    // Everyting above is normal ggez initialization and not specific to mooeye.
    // Below, we will start our game loop not with event::run as one would normally, but use a SceneManager instead.


    // Create StartScene.
    
    let start_scene = super::g_selector_scene::SelectorScene::new(&ctx)?;

    // Create Scene Manager and run it immediately.

    SceneManager::new_and_run(event_loop, ctx, start_scene)
}

Trait Implementations§

source§

impl EventHandler<GameError> for SceneManager

source§

fn update(&mut self, ctx: &mut Context) -> Result<(), GameError>

Called upon each logic update to the game. This should be where the game’s logic takes place.
source§

fn draw(&mut self, ctx: &mut Context) -> Result<(), GameError>

Called to do the drawing of your game. You probably want to start this with Canvas::from_frame and end it with Canvas::finish.
source§

fn mouse_button_down_event( &mut self, _ctx: &mut Context, _button: MouseButton, _x: f32, _y: f32 ) -> Result<(), E>

A mouse button was pressed
source§

fn mouse_button_up_event( &mut self, _ctx: &mut Context, _button: MouseButton, _x: f32, _y: f32 ) -> Result<(), E>

A mouse button was released
source§

fn mouse_motion_event( &mut self, _ctx: &mut Context, _x: f32, _y: f32, _dx: f32, _dy: f32 ) -> Result<(), E>

The mouse was moved; it provides both absolute x and y coordinates in the window, and relative x and y coordinates compared to its last position.
source§

fn mouse_enter_or_leave( &mut self, _ctx: &mut Context, _entered: bool ) -> Result<(), E>

mouse entered or left window area
source§

fn mouse_wheel_event( &mut self, _ctx: &mut Context, _x: f32, _y: f32 ) -> Result<(), E>

The mousewheel was scrolled, vertically (y, positive away from and negative toward the user) or horizontally (x, positive to the right and negative to the left).
source§

fn key_down_event( &mut self, ctx: &mut Context, input: KeyInput, _repeated: bool ) -> Result<(), E>

A keyboard button was pressed. Read more
source§

fn key_up_event( &mut self, _ctx: &mut Context, _input: KeyInput ) -> Result<(), E>

A keyboard button was released.
source§

fn text_input_event( &mut self, _ctx: &mut Context, _character: char ) -> Result<(), E>

A unicode character was received, usually from keyboard input. This is the intended way of facilitating text input.
source§

fn touch_event( &mut self, ctx: &mut Context, phase: TouchPhase, x: f64, y: f64 ) -> Result<(), E>

An event from a touchscreen has been triggered; it provides the x and y location inside the window as well as the state of the tap (such as Started, Moved, Ended, etc) By default, touch events will trigger mouse behavior
source§

fn gamepad_button_down_event( &mut self, _ctx: &mut Context, _btn: Button, _id: GamepadId ) -> Result<(), E>

A gamepad button was pressed; id identifies which gamepad.
source§

fn gamepad_button_up_event( &mut self, _ctx: &mut Context, _btn: Button, _id: GamepadId ) -> Result<(), E>

A gamepad button was released; id identifies which gamepad.
source§

fn gamepad_axis_event( &mut self, _ctx: &mut Context, _axis: Axis, _value: f32, _id: GamepadId ) -> Result<(), E>

A gamepad axis moved; id identifies which gamepad.
source§

fn focus_event(&mut self, _ctx: &mut Context, _gained: bool) -> Result<(), E>

Called when the window is shown or hidden.
source§

fn quit_event(&mut self, _ctx: &mut Context) -> Result<bool, E>

Called upon a quit event. If it returns true, the game does not exit (the quit event is cancelled).
source§

fn resize_event( &mut self, _ctx: &mut Context, _width: f32, _height: f32 ) -> Result<(), E>

Called when the user resizes the window, or when it is resized via GraphicsContext::set_mode().
source§

fn on_error(&mut self, _ctx: &mut Context, _origin: ErrorOrigin, _e: E) -> bool

Something went wrong, causing a GameError (or some other kind of error, depending on what you specified). If this returns true, the error was fatal, so the event loop ends, aborting the game.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

source§

impl<T> Has<T> for T

source§

fn retrieve(&self) -> &T

Method to retrieve the context type.
source§

impl<T> HasMut<T> for T

source§

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

Method to retrieve the context type as mutable.
source§

impl<T, U> Into<U> for Twhere 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.

§

impl<F, T> IntoSample<T> for Fwhere T: FromSample<F>,

§

fn into_sample(self) -> T

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T, U> ToSample<U> for Twhere U: FromSample<T>,

§

fn to_sample_(self) -> U

source§

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

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<S, T> Duplex<S> for Twhere T: FromSample<S> + ToSample<S>,