Skip to main content

SpriteView

Trait SpriteView 

Source
pub trait SpriteView<'a> {
    // Required methods
    fn width(&self) -> u32;
    fn height(&self) -> u32;
    fn rotate(&'a self, rotation: Rotation) -> SpriteViewImpl<'a>;
    fn flip_horizontally(
        &'a self,
        flip_horizontally: bool,
    ) -> SpriteViewImpl<'a>;
    fn flip_vertically(&'a self, flip_vertically: bool) -> SpriteViewImpl<'a>;
    fn clip(
        &'a self,
        src_x: u32,
        src_y: u32,
        width: u32,
        height: u32,
    ) -> SpriteViewImpl<'a>;
    fn blit(&self, x: i32, y: i32);
}
Expand description

A generic view over a sprite or a sprite transformation

Further transformations can be applied to a generic sprite view, or it can be drawn to the screen.

This trait allows to define functions that accept both “original” sprites (i.e. of type Sprite) or their transformations (e.g. of type SpriteViewImpl).

Required Methods§

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

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

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<'a> SpriteView<'a> for Sprite<'a>

Source§

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