Sprite

Struct Sprite 

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

Implementations§

Source§

impl Sprite

Source

pub fn new() -> Self

Allocates and returns a new Sprite.

Source

pub fn get_position(&self) -> Vec2<f32>

Gets x and y to the current position of sprite. This is the position of the sprite rectangle’s center.

Source

pub fn set_bounds(&self, bounds: Rect<f32>)

Sets the bounds of the given sprite with bounds. This is the position of the sprite rectangle’s center.

Source

pub fn get_bounds(&self) -> Rect<f32>

Returns the bounds of the given sprite as an PDRect; The (x, y) refers to the top-left corner of the sprite rectangle.

Source

pub fn move_to(&self, pos: Vec2<f32>)

Moves the given sprite to x, y and resets its bounds based on the bitmap dimensions and center.

Source

pub fn move_by(&self, delta: Vec2<f32>)

Moves the given sprite to by offsetting its current position by dx, dy.

Source

pub fn set_image(&self, image: Bitmap, flip: LCDBitmapFlip)

Sets the given sprite’s image to the given bitmap.

Source

pub fn get_image(&self) -> Option<Ref<'_, Bitmap>>

Returns the LCDBitmap currently assigned to the given sprite.

Source

pub fn set_size(&self, width: f32, height: f32)

Sets the size. The size is used to set the sprite’s bounds when calling moveTo().

Source

pub fn set_z_index(&self, z_index: i16)

Sets the Z order of the given sprite. Higher Z sprites are drawn on top of those with lower Z order.

Source

pub fn get_z_index(&self) -> i16

Returns the Z index of the given sprite.

Source

pub fn set_draw_mode(&self, mode: LCDBitmapDrawMode)

Sets the mode for drawing the sprite’s bitmap.

Source

pub fn set_image_flip(&self, flip: LCDBitmapFlip)

Flips the bitmap.

Source

pub fn get_image_flip(&self) -> LCDBitmapFlip

Returns the flip setting of the sprite’s bitmap.

Source

pub fn set_stencil(&self, stencil: impl AsRef<Bitmap>)

Specifies a stencil image to be set on the frame buffer before the sprite is drawn.

Source

pub fn set_clip_rect(&self, clip_rect: SideOffsets<i32>)

Sets the clipping rectangle for sprite drawing.

Source

pub fn clear_clip_rect(&self)

Clears the sprite’s clipping rectangle.

Source

pub fn set_updates_enabled(&self, flag: bool)

Set the updatesEnabled flag of the given sprite (determines whether the sprite has its update function called).

Source

pub fn updates_enabled(&self) -> bool

Get the updatesEnabled flag of the given sprite.

Source

pub fn set_collisions_enabled(&self, flag: bool)

Set the collisionsEnabled flag of the given sprite (along with the collideRect, this determines whether the sprite participates in collisions). Set to true by default.

Source

pub fn collisions_enabled(&self) -> bool

Get the collisionsEnabled flag of the given sprite.

Source

pub fn set_visible(&self, flag: bool)

Set the visible flag of the given sprite (determines whether the sprite has its draw function called).

Source

pub fn is_visible(&self) -> bool

Get the visible flag of the given sprite.

Source

pub fn set_opaque(&self, flag: bool)

Marking a sprite opaque tells the sprite system that it doesn’t need to draw anything underneath the sprite, since it will be overdrawn anyway. If you set an image without a mask/alpha channel on the sprite, it automatically sets the opaque flag.

Source

pub fn mark_dirty(&self)

Forces the given sprite to redraw.

Source

pub fn set_tag(&self, tag: u8)

Sets the tag of the given sprite. This can be useful for identifying sprites or types of sprites when using the collision API.

Source

pub fn get_tag(&self) -> u8

Returns the tag of the given sprite.

Source

pub fn set_ignores_draw_offset(&self, flag: i32)

When flag is set to 1, the sprite will draw in screen coordinates, ignoring the currently-set drawOffset.

This only affects drawing, and should not be used on sprites being used for collisions, which will still happen in world-space.

Source

pub fn set_update_function(&self, func: impl Fn(&Sprite) + 'static)

Sets the update function for the given sprite.

Source

pub fn set_draw_function( &self, func: impl Fn(&Sprite, Rect<f32>, Rect<f32>) + 'static, )

Sets the draw function for the given sprite.

Source

pub fn set_collide_rect(&self, collide_rect: Rect<f32>)

Marks the area of the given sprite, relative to its bounds, to be checked for collisions with other sprites’ collide rects.

Source

pub fn get_collide_rect(&self) -> Rect<f32>

Returns the given sprite’s collide rect.

Source

pub fn clear_collide_rect(&self)

Clears the given sprite’s collide rect.

Source

pub fn set_collision_response_function( &self, func: impl Fn(&Sprite, &Sprite) -> SpriteCollisionResponseType + 'static, )

Set a callback that returns a SpriteCollisionResponseType for a collision between sprite and other.

Source

pub fn set_stencil_pattern(&self, pattern: LCDPattern)

Sets the sprite’s stencil to the given pattern.

Source

pub fn clear_stencil(&self)

Clears the sprite’s stencil.

Source

pub fn set_stencil_image(&self, stencil: impl AsRef<Bitmap>, tile: i32)

Specifies a stencil image to be set on the frame buffer before the sprite is drawn. If tile is set, the stencil will be tiled. Tiled stencils must have width evenly divisible by 32.

Source

pub fn check_collisions( &self, move_goal: Vec2<f32>, ) -> Vec<SpriteCollisionInfo<'_>>

Returns the same values as playdate->sprite->moveWithCollisions() but does not actually move the sprite.

Source

pub fn move_with_collisions( &self, goal: Vec2<f32>, ) -> (Vec2<f32>, Vec<SpriteCollisionInfo<'_>>)

Moves the given sprite towards goalX, goalY taking collisions into account and returns an array of SpriteCollisionInfo. len is set to the size of the array and actualX, actualY are set to the sprite’s position after collisions. If no collisions occurred, this will be the same as goalX, goalY.

Source

pub fn overlapping_sprites(&self) -> Vec<Ref<'_, Sprite>>

Returns an array of sprites that have collide rects that are currently overlapping the given sprite’s collide rect.

Trait Implementations§

Source§

impl AsRef<Sprite> for Sprite

Source§

fn as_ref(&self) -> &Self

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Sprite

Source§

fn clone(&self) -> Self

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

Source§

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

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

impl Default for Sprite

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for Sprite

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl PartialEq for Sprite

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Sprite

Source§

impl Send for Sprite

Source§

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