Struct rusty_engine::game::Engine

source ·
pub struct Engine {
Show 18 fields pub sprites: HashMap<String, Sprite>, pub texts: HashMap<String, Text>, pub should_exit: bool, pub show_colliders: bool, pub collision_events: Vec<CollisionEvent>, pub mouse_state: MouseState, pub mouse_button_events: Vec<MouseButtonInput>, pub mouse_location_events: Vec<CursorMoved>, pub mouse_motion_events: Vec<MouseMotion>, pub mouse_wheel_events: Vec<MouseWheel>, pub keyboard_state: KeyboardState, pub keyboard_events: Vec<KeyboardInput>, pub delta: Duration, pub delta_f32: f32, pub time_since_startup: Duration, pub time_since_startup_f64: f64, pub audio_manager: AudioManager, pub window_dimensions: Vec2, /* private fields */
}
Expand description

Engine is the primary way that you will interact with Rusty Engine. Each frame this struct is provided to the “logic” functions (or closures) that you provided to Game::add_logic. The fields in this struct are divided into two groups:

  1. SYNCED fields.

These fields are marked with SYNCED. These fields are shared between you and the engine. Each frame Rusty Engine will populate these fields, then provide them to the user’s game logic function, and then examine any changes the user made and sync those changes back to the engine.

  1. INFO fields

INFO fields are provided as fresh, readable information to you each frame. Since information in these fields are overwritten every frame, any changes to them are ignored. Thus, you can feel free to, e.g. consume all the events out of the collision_events vector.

Fields§

§sprites: HashMap<String, Sprite>

SYNCED - The state of all sprites this frame. To add a sprite, use the add_sprite method. Modify & remove sprites as you like.

§texts: HashMap<String, Text>

SYNCED - The state of all texts this frame. For convenience adding a text, use the add_text method. Modify & remove text as you like.

§should_exit: bool

SYNCED - If set to true, the game exits. Note: the current frame will run to completion first.

§show_colliders: bool

SYNCED - If set to true, then debug lines are shown depicting sprite colliders

§collision_events: Vec<CollisionEvent>

INFO - All the collision events that occurred this frame. For collisions to be generated between sprites, both sprites must have [Sprite.collision] set to true and both sprites must have colliders (use the collider example to create a collider for your own images). Collision events are generated when two sprites’ colliders begin or end overlapping in 2D space.

§mouse_state: MouseState

INFO - The current state of mouse location and buttons. Useful for input handling that only cares about the final state of the mouse each frame, and not the intermediate states.

§mouse_button_events: Vec<MouseButtonInput>

INFO - All the mouse button events that occurred this frame.

§mouse_location_events: Vec<CursorMoved>

INFO - All the mouse location events that occurred this frame. The events are Bevy CursorMoved structs, but despite the name they represent the location of the mouse during this frame.

§mouse_motion_events: Vec<MouseMotion>

INFO - All the mouse motion events that occurred this frame. These represent the relative movements of the mouse, not the location of the mouse.

§mouse_wheel_events: Vec<MouseWheel>

INFO - All the mouse wheel events that occurred this frame.

§keyboard_state: KeyboardState

INFO - The current state of all the keys on the keyboard. Use this to control movement in your games! A KeyboardState has helper methods you should use to query the state of specific KeyCodes.

§keyboard_events: Vec<KeyboardInput>

INFO - All the keyboard input events. These are text-processor-like events. If you are looking for keyboard events to control movement in a game character, you should use Engine::keyboard_state instead. For example, one pressed event will fire when you start holding down a key, and then after a short delay additional pressed events will occur at the same rate that additional letters would show up in a word processor. When the key is finally released, a single released event is emitted.

§delta: Duration

INFO - The delta time (time between frames) for the current frame as a Duration, perfect for use with Timers

§delta_f32: f32

INFO - The delta time (time between frames) for the current frame as an f32, perfect for use in math with other f32’s. A cheap and quick way to approximate smooth movement (velocity, accelleration, etc.) is to multiply it by delta_f32.

§time_since_startup: Duration

INFO - The amount of time the game has been running since startup as a Duration

§time_since_startup_f64: f64

INFO - The amount of time the game has been running as an f64. This needs to be an f64, since it gets to be large enough that an f32 would lose precision. For best results, do your math on the f64 and get it to a smaller value before casting it to an f32.

§audio_manager: AudioManager

A struct with methods to play sound effects and music

§window_dimensions: Vec2

INFO - Window dimensions in logical pixels. On high DPI screens, there will often be four physical pixels per logical pixel. On low DPI screens, one logical pixel is one physical pixel.

Implementations§

source§

impl Engine

source

pub fn add_sprite<T: Into<String>, P: Into<PathBuf>>( &mut self, label: T, file_or_preset: P ) -> &mut Sprite

Create and add a Sprite to the game. Use the &mut Sprite that is returned to adjust the translation, rotation, etc. Use a unique label for each sprite. Attempting to add two sprites with the same label will cause a crash.

source

pub fn add_text<T, S>(&mut self, label: T, text: S) -> &mut Text
where T: Into<String>, S: Into<String>,

Create and add a Text to the game. Use the &mut Text that is returned to adjust the translation, rotation, etc. Use a unique label for each text. Attempting to add two texts with the same label will cause a crash.

Trait Implementations§

source§

impl Debug for Engine

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Engine

source§

fn default() -> Engine

Returns the “default value” for a type. Read more
source§

impl Resource for Engine
where Self: Send + Sync + 'static,

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
§

impl<T, U> AsBindGroupShaderType<U> for T
where U: ShaderType, &'a T: for<'a> Into<U>,

§

fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U

Return the T [ShaderType] for self. When used in [AsBindGroup] derives, it is safe to assume that all images in self exist.
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
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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

§

impl<T> FromWorld for T
where T: Default,

§

fn from_world(_world: &mut World) -> T

Creates Self using data from the given World.
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

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

§

fn into_sample(self) -> T

§

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

§

fn to_sample_(self) -> U

source§

impl<T, U> TryFrom<U> for T
where 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 T
where 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>

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
§

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

§

impl<T> Settings for T
where T: 'static + Send + Sync,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSync for T
where T: Sync,