SceneStack

Struct SceneStack 

Source
pub struct SceneStack<C> {
    pub world: C,
    /* private fields */
}
Expand description

A stack of Scene’s, together with a context object.

Fields§

§world: C

Implementations§

Source§

impl<C> SceneStack<C>

Source

pub fn new(_ctx: &mut Context, global_state: C) -> Self

Source

pub fn push(&mut self, scene: Box<dyn Scene<C>>)

Add a new scene to the top of the stack.

Source

pub fn pop(&mut self) -> Box<dyn Scene<C>>

Remove the top scene from the stack and returns it; panics if there is none.

Source

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

Returns the current scene; panics if there is none.

Source

pub fn switch( &mut self, next_scene: SceneSwitch<C>, ) -> Option<Box<dyn Scene<C>>>

Executes the given SceneSwitch command; if it is a pop or replace it returns Some(old_scene), otherwise None

Source

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

Source

pub fn draw(&mut self, ctx: &mut Context, quad_ctx: &mut GraphicsContext)

Draw the current scene.

Trait Implementations§

Source§

impl<C, E: Error> EventHandler<E> for SceneStack<C>

Source§

fn update( &mut self, ctx: &mut Context, quad_ctx: &mut GraphicsContext, ) -> Result<(), E>

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, quad_ctx: &mut GraphicsContext, ) -> Result<(), E>

Called to do the drawing of your game. You probably want to start this with graphics::clear() and end it with graphics::present().
Source§

fn resize_event( &mut self, ctx: &mut Context, quad_ctx: &mut GraphicsContext, width: f32, height: f32, )

Called when the user resizes the window, or when it is resized via graphics::set_drawable_size().
Source§

fn mouse_motion_event( &mut self, ctx: &mut Context, quad_ctx: &mut GraphicsContext, x: f32, y: f32, dx: f32, dy: f32, )

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_wheel_event( &mut self, ctx: &mut Context, quad_ctx: &mut GraphicsContext, x: f32, y: f32, )

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 mouse_button_down_event( &mut self, ctx: &mut Context, quad_ctx: &mut GraphicsContext, button: MouseButton, x: f32, y: f32, )

A mouse button was pressed.
Source§

fn mouse_button_up_event( &mut self, ctx: &mut Context, quad_ctx: &mut GraphicsContext, button: MouseButton, x: f32, y: f32, )

A mouse button was released.
Source§

fn key_down_event( &mut self, ctx: &mut Context, quad_ctx: &mut GraphicsContext, keycode: KeyCode, _keymods: KeyMods, _repeat: bool, )

A keyboard button was pressed. Read more
Source§

fn key_up_event( &mut self, ctx: &mut Context, quad_ctx: &mut GraphicsContext, keycode: KeyCode, _keymods: KeyMods, )

A keyboard button was released.
Source§

fn touch_event( &mut self, ctx: &mut Context, _quad_ctx: &mut GraphicsContext, phase: TouchPhase, _id: u64, x: f32, y: f32, )

Source§

fn text_input_event( &mut self, _ctx: &mut Context, _quad_ctx: &mut GraphicsContext, _character: char, )

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

fn gamepad_button_down_event( &mut self, _ctx: &mut Context, _quad_ctx: &mut GraphicsContext, _btn: Button, _id: GamepadId, )

A gamepad button was pressed; id identifies which gamepad. Use input::gamepad() to get more info about the gamepad.
Source§

fn gamepad_button_up_event( &mut self, _ctx: &mut Context, _quad_ctx: &mut GraphicsContext, _btn: Button, _id: GamepadId, )

A gamepad button was released; id identifies which gamepad. Use input::gamepad() to get more info about the gamepad.
Source§

fn gamepad_axis_event( &mut self, _ctx: &mut Context, _quad_ctx: &mut GraphicsContext, _axis: Axis, _value: f32, _id: GamepadId, )

A gamepad axis moved; id identifies which gamepad. Use input::gamepad() to get more info about the gamepad.
Source§

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

Something went wrong, causing a GameError. If this returns true, the error was fatal, so the event loop ends, aborting the game.

Auto Trait Implementations§

§

impl<C> Freeze for SceneStack<C>
where C: Freeze,

§

impl<C> !RefUnwindSafe for SceneStack<C>

§

impl<C> !Send for SceneStack<C>

§

impl<C> !Sync for SceneStack<C>

§

impl<C> Unpin for SceneStack<C>
where C: Unpin,

§

impl<C> !UnwindSafe for SceneStack<C>

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<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

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

Source§

fn to_sample_(self) -> U

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

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

Source§

fn vzip(self) -> V

Source§

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