Struct mooeye::scene_manager::SceneManager
source · 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
impl SceneManager
sourcepub fn new<T: Scene + 'static>(initial_scene: T) -> Self
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.
sourcepub fn new_and_run<T: Scene + 'static>(
event_loop: EventLoop<()>,
ctx: Context,
initial_scene: T
) -> !
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
impl EventHandler<GameError> for SceneManager
source§fn update(&mut self, ctx: &mut Context) -> Result<(), GameError>
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>
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
.A mouse button was pressed
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>
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>
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>
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>
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>
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>
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>
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
A gamepad button was pressed;
id
identifies which gamepad.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>
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>
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>
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>
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()
.Auto Trait Implementations§
impl !RefUnwindSafe for SceneManager
impl !Send for SceneManager
impl !Sync for SceneManager
impl Unpin for SceneManager
impl !UnwindSafe for SceneManager
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
source§impl<T> HasMut<T> for T
impl<T> HasMut<T> for T
source§fn retrieve_mut(&mut self) -> &mut T
fn retrieve_mut(&mut self) -> &mut T
Method to retrieve the context type as mutable.