Struct Sprite

Source
pub struct Sprite { /* private fields */ }
Expand description

Specs component representing a sprite that can be drawn.

use blit::{BlitBuffer, Color};
use specs::prelude::*;
use specs_blit::{load, Sprite};

const MASK_COLOR: u32 = 0xFF00FF;

// Setup the specs world
let mut world = World::new();

// Load the blit components into the world
world.register::<Sprite>();

let sprite_ref = {
    // Create a sprite of 4 pixels
    let sprite = BlitBuffer::from_buffer(&[0, MASK_COLOR, 0, 0], 2, MASK_COLOR);

    // Load the sprite and get a reference
    load(sprite)?
};

// Create a new sprite entity in the ECS system
world.create_entity()
    .with(Sprite::new(sprite_ref))
    .build();

Implementations§

Source§

impl Sprite

Source

pub fn new(sprite_reference: SpriteRef) -> Self

Instantiate a new sprite from a loaded sprite index.

use blit::{BlitBuffer, Color};
use specs_blit::{load, Sprite};

const MASK_COLOR: u32 = 0xFF00FF;

let sprite_ref = {
    // Create a sprite of 4 pixels
    let sprite = BlitBuffer::from_buffer(&[0, MASK_COLOR, 0, 0], 2, MASK_COLOR);

    // Load the sprite and get a reference
    load(sprite)?
};

// Create a specs sprite from the image
let sprite = Sprite::new(sprite_ref);
Source

pub fn set_pos(&mut self, x: i32, y: i32)

Set the pixel position of where the sprite needs to be rendered.

Source

pub fn pos(&self) -> (i32, i32)

Get the pixel position as an (x, y) tuple of where the sprite will be rendered.

Source

pub fn set_rot(&mut self, rotation: i16)

Set the rotation in degrees of the sprite. The rotation will attempt to match the nearest degrees of rotation divisor.

Source

pub fn rot(&self) -> i16

Get the pixel rotation as degrees.

Trait Implementations§

Source§

impl Clone for Sprite

Source§

fn clone(&self) -> Sprite

Returns a duplicate 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

Source§

type Storage = VecStorage<Sprite>

Associated storage type for this component.
Source§

impl Debug for Sprite

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Sprite

§

impl RefUnwindSafe for Sprite

§

impl Send for Sprite

§

impl Sync for Sprite

§

impl Unpin for Sprite

§

impl UnwindSafe for Sprite

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> Any for T
where T: Any,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

Source§

fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result
where T: Parameter<Self>,

Sets value as a parameter of self.
Source§

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

Source§

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

Source§

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