Struct rusty_engine::sprite::Sprite
source · pub struct Sprite {
pub label: String,
pub filepath: PathBuf,
pub collider_filepath: PathBuf,
pub translation: Vec2,
pub layer: f32,
pub rotation: f32,
pub scale: f32,
pub collision: bool,
pub collider: Collider,
pub collider_dirty: bool,
}
Expand description
A Sprite
is the basic abstraction for something that can be seen and interacted with.
Players, obstacles, etc. are all sprites.
Fields§
§label: String
READONLY: A way to identify a sprite. This must be unique, or else the game will crash.
filepath: PathBuf
READONLY: File used for this sprite’s image
collider_filepath: PathBuf
READONLY: File used for this sprite’s collider. Note that this file will not exist if the
sprite does not have a collider, but if you set the collider
field to a collider and then
call the write_collider
method, the file will be written for you!
translation: Vec2
SYNCED: Where you are in 2D game space. Positive x is right. Positive y is up. (0.0, 0.0) is the center of the screen.
layer: f32
SYNCED: Depth of the sprite. 0.0 (back) to 999.0 (front)
rotation: f32
SYNCED: Direction you face in radians. See constants UP, DOWN, LEFT, RIGHT
scale: f32
SYNCED: 1.0 is the normal 100%
collision: bool
Whether or not to calculate collisions
collider: Collider
The actual collider for this sprite
collider_dirty: bool
If set to true
, then the collider shown for this sprite will be regenerated (see also
Engine.show_colliders
). Normally you shouldn’t touch this, but
if you manually replace a Sprite
’s Collider
in a game logic function, then you need to
set this to true.
Implementations§
source§impl Sprite
impl Sprite
sourcepub fn new<S: Into<String>, P: Into<PathBuf>>(
label: S,
file_or_preset: P
) -> Self
pub fn new<S: Into<String>, P: Into<PathBuf>>( label: S, file_or_preset: P ) -> Self
label
should be a unique string (it will be used as a key in the hashmap
Engine::sprites
). file_or_preset
should either be a
SpritePreset
variant, or a relative path to an image file inside the assets/
directory. If a collider definition exists in a file with the same name as the image file,
but with the .collider
extension, then the collider will be loaded automatically. To
create a collider file you can either run the collider
example, or
programmatically create a Collider
, set the sprite’s .collider
field to it, and call
the sprite’s .write_collider()
method. All presets have collider files already.
sourcepub fn write_collider(&self) -> bool
pub fn write_collider(&self) -> bool
Attempt to take the current collider and write it to collider_filepath. If there isn’t a
collider, or writing fails, then false
is returned. Otherwise true
is returned.
sourcepub fn add_collider_point(&mut self, p: Vec2)
pub fn add_collider_point(&mut self, p: Vec2)
Add a collider point. p
is a Vec2
in worldspace (usually the mouse coordinate). See the
collider
example.
sourcepub fn change_last_collider_point(&mut self, p: Vec2)
pub fn change_last_collider_point(&mut self, p: Vec2)
Change the last collider point. p
is a Vec2
in worldspace (usually the mouse
coordinate). See the collider
example.
Trait Implementations§
source§impl Component for Sprite
impl Component for Sprite
§type Storage = TableStorage
type Storage = TableStorage
TableStorage
or SparseStorage
.source§impl PartialEq for Sprite
impl PartialEq for Sprite
impl StructuralPartialEq for Sprite
Auto Trait Implementations§
impl RefUnwindSafe for Sprite
impl Send for Sprite
impl Sync for Sprite
impl Unpin for Sprite
impl UnwindSafe for Sprite
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<C> Bundle for Cwhere
C: Component,
impl<C> Bundle for Cwhere
C: Component,
fn component_ids( components: &mut Components, storages: &mut Storages, ids: &mut impl FnMut(ComponentId) )
unsafe fn from_components<T, F>(ctx: &mut T, func: &mut F) -> C
§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.