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:
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.
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.
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 KeyCode
s.
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 Timer
s
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
impl Engine
sourcepub fn add_sprite<T: Into<String>, P: Into<PathBuf>>(
&mut self,
label: T,
file_or_preset: P
) -> &mut Sprite
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.
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Engine
impl Send for Engine
impl Sync for Engine
impl Unpin for Engine
impl UnwindSafe for Engine
Blanket Implementations§
§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
§fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
T
[ShaderType
] for self
. When used in [AsBindGroup
]
derives, it is safe to assume that all images in self
exist.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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSync for T
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Self
using data from the given World
.