Skip to main content

Sprite

Struct Sprite 

Source
pub struct Sprite {
    pub image: ImageId,
    pub src: PxRect,
    pub dest: PxRect,
    pub clip: PxRect,
    pub layer: Layer,
    pub flip_x: bool,
    pub opacity: u8,
    pub brightness: u8,
    pub paint: Paint,
    pub base: Option<PxRect>,
}
Expand description

A picture on top of the cell grid (game ADR-0038): part of an image file, scaled into a rectangle of console pixels. app draws it from a texture with nearest-pixel sampling, so whole-number scales stay sharp.

Fields§

§image: ImageId

Which image (ImageTable::id).

§src: PxRect

The part of the image shown, in image pixels. It must lie inside the image.

§dest: PxRect

Where src is stretched to, in console pixels.

§clip: PxRect

The part of dest that is drawn. Clipping and cutting only ever shrink this; src and dest stay as given, so the picture never shifts or rescales.

§layer: Layer

Under or over the glyphs.

§flip_x: bool

Mirrored left to right within dest.

§opacity: u8

255 = solid; lower lets what is under it show through.

§brightness: u8

How bright its pixels are drawn: 255 = as the image and the paint have them, lower = that much darker, 0 = black where it shows. Unlike a lower opacity, a picture over another (a tile’s edge over its ground) darkens as much as one alone (GlyphBuffer::fade).

§paint: Paint

How its pixels are coloured.

§base: Option<PxRect>

The console pixels it stands on, for a picture that reaches above them (a unit’s head over the tile above its own): where cells replace its base up to one of the base’s edges, what it shows past that edge goes too, so a menu over a unit doesn’t leave its head showing above the menu.

Implementations§

Source§

impl Sprite

Source

pub const fn new( image: ImageId, src: PxRect, dest: PxRect, layer: Layer, ) -> Self

A solid, unflipped sprite showing all of dest.

Source

pub const fn painted(self, paint: Paint) -> Self

This sprite coloured as paint.

Source

pub fn clipped_src(&self) -> [f32; 4]

The part of src that maps to clip, as [x, y, w, h] in image pixels (fractions of a pixel when clip cuts through a scaled one). With flip_x, the left of clip shows the right of src.

Trait Implementations§

Source§

impl Clone for Sprite

Source§

fn clone(&self) -> Sprite

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

Source§

impl Debug for Sprite

Source§

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

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

impl Eq for Sprite

Source§

impl Hash for Sprite

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Sprite

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
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
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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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