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

source

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.

source

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.

source

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.

source

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 Clone for Sprite

source§

fn clone(&self) -> Sprite

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Component for Sprite
where Self: Send + Sync + 'static,

§

type Storage = TableStorage

A marker type indicating the storage type used for this component. This must be either TableStorage or SparseStorage.
source§

impl Debug for Sprite

source§

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

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

impl PartialEq for Sprite

source§

fn eq(&self, other: &Sprite) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for Sprite

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<C> Bundle for C
where 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
where F: for<'a> FnMut(&'a mut T) -> OwningPtr<'a>,

§

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

impl<C> DynamicBundle for C
where C: Component,

§

fn get_components(self, func: &mut impl FnMut(StorageType, OwningPtr<'_>))

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

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

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

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> TypeData for T
where T: 'static + Send + Sync + Clone,

§

fn clone_type_data(&self) -> Box<dyn TypeData>

§

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,