Skip to main content

SpriteViewImpl

Struct SpriteViewImpl 

Source
pub struct SpriteViewImpl<'a> { /* private fields */ }
Expand description

A view of a modified sprite

A sprite view can be used to apply transformations to a sprite before drawing it to screen.

use wasm4fun_graphics::{Rotation, Sprite};

let sprite: Sprite = unimplemented!();
let clipped = sprite.clip(30, 10, 80, 20);
let rotated = sprite.rotate(Rotation::Rotate90);
let clipped_and_rotated = clipped.rotate(Rotation::Rotate90);
rotated.blit(0, 0);
clipped_and_rotated.blit(50, 50);

§Order of Operations

When applying both flipping and rotation, flipping is performed first.

Implementations§

Source§

impl<'a> SpriteViewImpl<'a>

Source

pub const fn new(sprite: &'a Sprite<'_>) -> Self

Create a view over a sprite

Source

pub const fn width(&self) -> u32

Get the sprite width

Source

pub const fn height(&self) -> u32

Get the sprite height

Source

pub const fn rotate(&self, rotation: Rotation) -> Self

Apply a rotation to the sprite view

Source

pub const fn flip_horizontally(&self, flip_horizontally: bool) -> Self

Flip the sprite view horizontally

Source

pub const fn flip_vertically(&self, flip_vertically: bool) -> Self

Flip the sprite view vertically

Source

pub const fn clip( &self, src_x: u32, src_y: u32, width: u32, height: u32, ) -> Self

Clip the sprite view to a subregion

Source

pub fn blit(&self, x: i32, y: i32)

Draw the sprite view to the screen

The sprite is drawn at the point x, y after applying all the transformations in the view.

Trait Implementations§

Source§

impl<'a> Clone for SpriteViewImpl<'a>

Source§

fn clone(&self) -> SpriteViewImpl<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for SpriteViewImpl<'a>

Source§

impl<'a> From<&'a Sprite<'a>> for SpriteViewImpl<'a>

Source§

fn from(sprite: &'a Sprite<'_>) -> Self

Converts to this type from the input type.
Source§

impl<'a> SpriteView<'a> for SpriteViewImpl<'a>

Source§

fn width(&self) -> u32

Get the sprite width
Source§

fn height(&self) -> u32

Get the sprite height
Source§

fn rotate(&'a self, rotation: Rotation) -> SpriteViewImpl<'a>

Apply a rotation to the sprite view
Source§

fn flip_horizontally(&'a self, flip_horizontally: bool) -> SpriteViewImpl<'a>

Flip the sprite view horizontally
Source§

fn flip_vertically(&'a self, flip_vertically: bool) -> SpriteViewImpl<'a>

Flip the sprite view vertically
Source§

fn clip( &'a self, src_x: u32, src_y: u32, width: u32, height: u32, ) -> SpriteViewImpl<'a>

Clip the sprite view to a subregion
Source§

fn blit(&self, x: i32, y: i32)

Draw the sprite view to the screen Read more

Auto Trait Implementations§

§

impl<'a> Freeze for SpriteViewImpl<'a>

§

impl<'a> RefUnwindSafe for SpriteViewImpl<'a>

§

impl<'a> Send for SpriteViewImpl<'a>

§

impl<'a> Sync for SpriteViewImpl<'a>

§

impl<'a> Unpin for SpriteViewImpl<'a>

§

impl<'a> UnsafeUnpin for SpriteViewImpl<'a>

§

impl<'a> UnwindSafe for SpriteViewImpl<'a>

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