Struct playdate::sprite::Sprite

source ·
pub struct Sprite<Userdata = (), Api = Default, const FREE_ON_DROP: bool = true>(/* private fields */)
where
    Api: Api;

Implementations§

source§

impl<UD, Api> Sprite<UD, Api>
where Api: Api + Copy,

source

pub fn into_shared(self) -> Sprite<UD, Api, false>

Convert this sprite into the same sprite that will not be freed on drop. That means that only C-part of the sprite will be freed.

Safety is guaranteed by the caller.

source§

impl<UD, Api, const FOD: bool> Sprite<UD, Api, FOD>
where Api: Default + Api,

source

pub fn new() -> Sprite<UD, Api, FOD>

Allocates and returns a new Sprite with default api access-point.

To create a sprite with a custom api access-point, use new_with.

See also sys::ffi::playdate_sprite::newSprite

source§

impl<UD, Api, const FOD: bool> Sprite<UD, Api, FOD>
where Api: Api,

source

pub fn new_with(api: Api) -> Sprite<UD, Api, FOD>

Allocates and returns a new Sprite with given api.

See also sys::ffi::playdate_sprite::newSprite

source§

impl<Userdata, Api, const FOD: bool> Sprite<Userdata, Api, FOD>
where Api: Api,

source

pub fn add(&self)

Adds the this sprite to the display list, so that it is drawn in the current scene.

Equivalent to sys::ffi::playdate_sprite::addSprite

source

pub fn remove(&self)

Removes the this sprite from the display list.

Equivalent to sys::ffi::playdate_sprite::removeSprite

source

pub fn set_bounds(&self, bounds: PDRect)

Sets the bounds of the sprite with bounds.

Equivalent to sys::ffi::playdate_sprite::setBounds

source

pub fn bounds(&self) -> PDRect

Returns the bounds of the sprite.

Equivalent to sys::ffi::playdate_sprite::getBounds

source

pub fn move_to(&self, x: f32, y: f32)

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

Equivalent to sys::ffi::playdate_sprite::moveTo

source

pub fn move_by(&self, dx: f32, dy: f32)

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

Equivalent to sys::ffi::playdate_sprite::moveBy

source

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

Sets the sprite’s image to the given bitmap.

⚠️ Caution: Using with draw function, call this method before set callback. Setting image after setting draw callback is mostly crashes with SIGBUS.

See also set_opaque.

Equivalent to sys::ffi::playdate_sprite::setImage

source

pub fn image<'t>(&'t self) -> Option<BitmapRef<'t>>

Returns the bitmap currently assigned to the given sprite.

Equivalent to sys::ffi::playdate_sprite::getImage

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

Equivalent to sys::ffi::playdate_sprite::setSize

source

pub fn set_z_index(&self, z_index: i16)

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

Equivalent to sys::ffi::playdate_sprite::setZIndex

source

pub fn z_index(&self) -> i16

Returns the Z index of the sprite.

Equivalent to sys::ffi::playdate_sprite::getZIndex

source

pub fn set_draw_mode(&self, mode: LCDBitmapDrawMode)

Sets the mode for drawing the sprite’s bitmap.

Equivalent to sys::ffi::playdate_sprite::setDrawMode

source

pub fn set_image_flip(&self, flip: LCDBitmapFlip)

Flips the sprite’s bitmap.

Equivalent to sys::ffi::playdate_sprite::setImageFlip

source

pub fn image_flip(&self) -> LCDBitmapFlip

Returns the flip setting of the sprite’s bitmap.

Equivalent to sys::ffi::playdate_sprite::getImageFlip

source

pub fn set_stencil(&self, stencil: impl AnyBitmap)

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

Equivalent to sys::ffi::playdate_sprite::setStencil

source

pub fn set_clip_rect(&self, clip: LCDRect)

Sets the clipping rectangle for sprite drawing.

Equivalent to sys::ffi::playdate_sprite::setClipRect

source

pub fn clear_clip_rect(&self)

Clears the sprite’s clipping rectangle.

Equivalent to sys::ffi::playdate_sprite::clearClipRect

source

pub fn set_updates_enabled(&self, value: bool)

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

Equivalent to sys::ffi::playdate_sprite::setUpdatesEnabled

source

pub fn updates_enabled(&self) -> bool

Get the updates_enabled flag of the sprite.

Equivalent to sys::ffi::playdate_sprite::updatesEnabled

source

pub fn set_collisions_enabled(&self, value: bool)

Set the collisions_enabled flag of the sprite (along with the collide_rect, this determines whether the sprite participates in collisions).

Set to true by default.

See also collide_rect, set_collide_rect, clear_collide_rect.

Equivalent to sys::ffi::playdate_sprite::setCollisionsEnabled

source

pub fn collisions_enabled(&self) -> bool

Get the collisions_enabled flag of the sprite.

Equivalent to sys::ffi::playdate_sprite::collisionsEnabled

source

pub fn set_visible(&self, value: bool)

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

Equivalent to sys::ffi::playdate_sprite::setVisible

source

pub fn is_visible(&self) -> bool

Get the visible flag of the sprite.

Equivalent to sys::ffi::playdate_sprite::isVisible

source

pub fn set_opaque(&self, value: 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.

Equivalent to sys::ffi::playdate_sprite::setOpaque

source

pub fn mark_dirty(&self)

Forces the sprite to redraw.

Equivalent to sys::ffi::playdate_sprite::markDirty

source

pub fn set_tag(&self, tag: u8)

Sets the tag of the sprite.

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

Equivalent to sys::ffi::playdate_sprite::setTag

source

pub fn tag(&self) -> u8

Returns the tag of the given sprite.

Equivalent to sys::ffi::playdate_sprite::getTag

source

pub fn set_ignores_draw_offset(&self, value: bool)

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

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

See also gfx::set_draw_offset.

Equivalent to sys::ffi::playdate_sprite::setIgnoresDrawOffset

source

pub fn position(&self) -> (f32, f32)

Sets x and y to the current position of sprite.

Equivalent to get_position_to and sys::ffi::playdate_sprite::getPosition

source

pub fn position_to(&self, x: &mut f32, y: &mut f32)

Sets x and y to the current position of sprite.

Equivalent to sys::ffi::playdate_sprite::getPosition

source

pub fn set_collide_rect(&self, collide: PDRect)

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

Equivalent to sys::ffi::playdate_sprite::setCollideRect

source

pub fn collide_rect(&self) -> PDRect

Returns the sprite’s collide rect.

Equivalent to sys::ffi::playdate_sprite::getCollideRect

source

pub fn clear_collide_rect(&self)

Clears the sprite’s collide rect.

Equivalent to sys::ffi::playdate_sprite::clearCollideRect

source

pub fn check_collisions( &self, goal_x: f32, goal_y: f32, actual_x: &mut f32, actual_y: &mut f32 ) -> &[SpriteCollisionInfo]

Returns the same values as [move_with_collisions] but does not actually move the sprite.

Equivalent to sys::ffi::playdate_sprite::checkCollisions

source

pub fn move_with_collisions<'t>( &'t self, goal_x: f32, goal_y: f32, actual_x: &mut f32, actual_y: &mut f32 ) -> &'t [SpriteCollisionInfo]

Moves the sprite towards goal_x, goal_y taking collisions into account and returns a slice of SpriteCollisionInfo.

actual_x, actual_y are set to the sprite’s position after collisions. If no collisions occurred, this will be the same as goal_x, goal_y.

Resulting slice with entire content can be freely dropped.

Equivalent to sys::ffi::playdate_sprite::moveWithCollisions

source

pub fn overlapping_sprites(&self) -> &[SpriteRef]

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

Equivalent to sys::ffi::playdate_sprite::overlappingSprites

source

pub fn set_stencil_pattern(&self, pattern: &mut [u8; 8])

Sets the sprite’s stencil to the given pattern.

Equivalent to sys::ffi::playdate_sprite::setStencilPattern

source

pub fn set_stencil_image(&self, stencil: impl AnyBitmap, tile: bool)

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.

Equivalent to sys::ffi::playdate_sprite::setStencilImage

source

pub fn clear_stencil(&self)

Clears the sprite’s stencil.

Equivalent to sys::ffi::playdate_sprite::clearStencil

source

pub fn set_center(&self, x: f32, y: f32)

Sets the sprite’s drawing center as a fraction (ranging from 0.0 to 1.0) of the height and width.

Default is 0.5, 0.5 (the center of the sprite).

This means that when you call Sprite::move_to(x, y), the center of your sprite will be positioned at x, y.

If you want x and y to represent the upper left corner of your sprite, specify the center as 0, 0.

Equivalent to sys::ffi::playdate_sprite::setCenter.

source

pub fn center(&self) -> (f32, f32)

Returns the sprite’s drawing center as a fraction (ranging from 0.0 to 1.0) of the height and width.

Equivalent to sys::ffi::playdate_sprite::getCenter.

source

pub fn set_userdata(&self, data: Userdata)

Sets custom data to the sprite.

Used for associating the sprite with other data.

Equivalent to sys::ffi::playdate_sprite::setUserdata

source

pub fn userdata(&self) -> Option<&mut Userdata>

Gets the mutable_ reference to sprite’s userdata.

Used for associating the sprite with other data.

Equivalent to sys::ffi::playdate_sprite::getUserdata

source§

impl<UD, Api, const FOD: bool> Sprite<UD, Api, FOD>
where Api: Api,

source

pub fn into_draw_handler<T>(self) -> Handle<FOD, Sprite<UD, Api, FOD>, T>
where T: SpriteDraw<Userdata = UD>, <T as SpriteType>::Api: Default,

Sets the draw function for the this sprite.

⚠️ Caution: Do not forget to set bounds before setting draw function, default zero bounds causes UB in the system.

source§

impl<UD, Api, const FOD: bool> Sprite<UD, Api, FOD>
where Api: Api,

source

pub fn into_update_handler<T>(self) -> Handle<FOD, Sprite<UD, Api, FOD>, T>
where T: SpriteUpdate<Userdata = UD>, <T as SpriteType>::Api: Default,

Sets the update function for the this sprite.

source§

impl<UD, Api, const FOD: bool> Sprite<UD, Api, FOD>
where Api: Api,

source

pub fn into_collision_response_handler<T>( self ) -> Handle<FOD, Sprite<UD, Api, FOD>, T>
where T: SpriteCollisionResponse<Userdata = UD>, <T as SpriteType>::Api: Default,

Sets the collision response function for the this sprite.

Trait Implementations§

source§

impl<const FOD: bool, T, H> AsMut<Sprite<<T as TypedSprite>::Userdata, <T as SpriteApi>::Api, FOD>> for Handle<FOD, T, H>
where T: TypedSprite + AsMut<Sprite<<T as TypedSprite>::Userdata, <T as SpriteApi>::Api, FOD>>, H: SpriteCollisionResponse,

source§

fn as_mut( &mut self ) -> &mut Sprite<<T as TypedSprite>::Userdata, <T as SpriteApi>::Api, FOD>

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl<const FOD: bool, T, H> AsMut<Sprite<<T as TypedSprite>::Userdata, <T as SpriteApi>::Api, FOD>> for Handle<FOD, T, H>
where T: TypedSprite + AsMut<Sprite<<T as TypedSprite>::Userdata, <T as SpriteApi>::Api, FOD>>, H: SpriteDraw,

source§

fn as_mut( &mut self ) -> &mut Sprite<<T as TypedSprite>::Userdata, <T as SpriteApi>::Api, FOD>

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl<const FOD: bool, T, H> AsMut<Sprite<<T as TypedSprite>::Userdata, <T as SpriteApi>::Api, FOD>> for Handle<FOD, T, H>
where T: TypedSprite + AsMut<Sprite<<T as TypedSprite>::Userdata, <T as SpriteApi>::Api, FOD>>, H: SpriteUpdate,

source§

fn as_mut( &mut self ) -> &mut Sprite<<T as TypedSprite>::Userdata, <T as SpriteApi>::Api, FOD>

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl<UD, Api, const FOD: bool> AsMut<Sprite<UD, Api, FOD>> for Sprite<UD, Api, FOD>
where Api: Api,

source§

fn as_mut(&mut self) -> &mut Sprite<UD, Api, FOD>

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl<UD, Api, const FOD: bool> AsRaw for Sprite<UD, Api, FOD>
where Api: Api,

§

type Type = LCDSprite

source§

unsafe fn as_raw(&self) -> *mut LCDSprite

This method ia actually safe. Unsafety is because so we’re removing owners lifetime that used by some API parts.
source§

impl<const FOD: bool, Sp, T, H> AsRef<Sprite<<Sp as TypedSprite>::Userdata, <Sp as SpriteApi>::Api, FOD>> for Handle<FOD, Sp, T, H>
where T: AsRef<Sprite<<Sp as TypedSprite>::Userdata, <Sp as SpriteApi>::Api, FOD>>, Sp: TypedSprite, H: SpriteDraw,

source§

fn as_ref( &self ) -> &Sprite<<Sp as TypedSprite>::Userdata, <Sp as SpriteApi>::Api, FOD>

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

impl<const FOD: bool, Sp, T, H> AsRef<Sprite<<Sp as TypedSprite>::Userdata, <Sp as SpriteApi>::Api, FOD>> for Handle<FOD, Sp, T, H>
where T: AsRef<Sprite<<Sp as TypedSprite>::Userdata, <Sp as SpriteApi>::Api, FOD>>, Sp: TypedSprite, H: SpriteCollisionResponse,

source§

fn as_ref( &self ) -> &Sprite<<Sp as TypedSprite>::Userdata, <Sp as SpriteApi>::Api, FOD>

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

impl<const FOD: bool, Sp, T, H> AsRef<Sprite<<Sp as TypedSprite>::Userdata, <Sp as SpriteApi>::Api, FOD>> for Handle<FOD, Sp, T, H>
where T: AsRef<Sprite<<Sp as TypedSprite>::Userdata, <Sp as SpriteApi>::Api, FOD>>, Sp: TypedSprite, H: SpriteUpdate,

source§

fn as_ref( &self ) -> &Sprite<<Sp as TypedSprite>::Userdata, <Sp as SpriteApi>::Api, FOD>

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

impl<const FOD: bool, T, H> AsRef<Sprite<<T as TypedSprite>::Userdata, <T as SpriteApi>::Api, FOD>> for Handle<FOD, T, H>
where T: TypedSprite + AsRef<Sprite<<T as TypedSprite>::Userdata, <T as SpriteApi>::Api, FOD>>, H: SpriteDraw,

source§

fn as_ref( &self ) -> &Sprite<<T as TypedSprite>::Userdata, <T as SpriteApi>::Api, FOD>

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

impl<const FOD: bool, T, H> AsRef<Sprite<<T as TypedSprite>::Userdata, <T as SpriteApi>::Api, FOD>> for Handle<FOD, T, H>
where T: TypedSprite + AsRef<Sprite<<T as TypedSprite>::Userdata, <T as SpriteApi>::Api, FOD>>, H: SpriteCollisionResponse,

source§

fn as_ref( &self ) -> &Sprite<<T as TypedSprite>::Userdata, <T as SpriteApi>::Api, FOD>

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

impl<const FOD: bool, T, H> AsRef<Sprite<<T as TypedSprite>::Userdata, <T as SpriteApi>::Api, FOD>> for Handle<FOD, T, H>
where T: TypedSprite + AsRef<Sprite<<T as TypedSprite>::Userdata, <T as SpriteApi>::Api, FOD>>, H: SpriteUpdate,

source§

fn as_ref( &self ) -> &Sprite<<T as TypedSprite>::Userdata, <T as SpriteApi>::Api, FOD>

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

impl<UD, Api, const FOD: bool> AsRef<Sprite<UD, Api, FOD>> for Sprite<UD, Api, FOD>
where Api: Api,

source§

fn as_ref(&self) -> &Sprite<UD, Api, FOD>

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

impl<UD, Api, const FOD: bool> Clone for Sprite<UD, Api, FOD>
where Api: Api + Clone,

source§

fn clone(&self) -> Sprite<UD, Api, FOD>

Returns a copy of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
source§

impl<Userdata, Api, const FREE_ON_DROP: bool> Debug for Sprite<Userdata, Api, FREE_ON_DROP>
where Userdata: Debug, Api: Debug + Api,

source§

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

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

impl<UD, Api, const FOD: bool> Drop for Sprite<UD, Api, FOD>
where Api: Api,

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<UD, Api, const FOD: bool> From<SpriteRef> for Sprite<UD, Api, FOD>
where Api: Api + Default,

source§

fn from(sprite: SpriteRef) -> Sprite<UD, Api, FOD>

Converts to this type from the input type.
source§

impl<UD, Api, const FOD: bool> SpriteApi for Sprite<UD, Api, FOD>
where Api: Api,

§

type Api = Api

Type of inner API access-point.
source§

fn api(&self) -> Api
where <Sprite<UD, Api, FOD> as SpriteApi>::Api: Copy,

Get a copy of inner api access point.
source§

fn api_ref(&self) -> &<Sprite<UD, Api, FOD> as SpriteApi>::Api

Get a ref to inner api access point.
source§

impl<UD, Api, const FOD: bool> TypedSprite for Sprite<UD, Api, FOD>
where Api: Api,

§

type Userdata = UD

Associated user-data with sprite.
source§

const FREE_ON_DROP: bool = FOD

Should be freed when sprite is dropped.
source§

impl<UD, Api, const FOD: bool> AnySprite for Sprite<UD, Api, FOD>
where Api: Api,

Auto Trait Implementations§

§

impl<Userdata, Api, const FREE_ON_DROP: bool> Freeze for Sprite<Userdata, Api, FREE_ON_DROP>
where Api: Freeze,

§

impl<Userdata, Api, const FREE_ON_DROP: bool> RefUnwindSafe for Sprite<Userdata, Api, FREE_ON_DROP>
where Api: RefUnwindSafe, Userdata: RefUnwindSafe,

§

impl<Userdata = (), Api = Default, const FREE_ON_DROP: bool = true> !Send for Sprite<Userdata, Api, FREE_ON_DROP>

§

impl<Userdata = (), Api = Default, const FREE_ON_DROP: bool = true> !Sync for Sprite<Userdata, Api, FREE_ON_DROP>

§

impl<Userdata, Api, const FREE_ON_DROP: bool> Unpin for Sprite<Userdata, Api, FREE_ON_DROP>
where Api: Unpin, Userdata: Unpin,

§

impl<Userdata, Api, const FREE_ON_DROP: bool> UnwindSafe for Sprite<Userdata, Api, FREE_ON_DROP>
where Api: UnwindSafe, Userdata: UnwindSafe,

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

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

§

type Api = <T as SpriteApi>::Api

Type of API access-point.
§

type Userdata = <T as TypedSprite>::Userdata

Associated user-data with sprite.
source§

const FREE_ON_DROP: bool = <T as TypedSprite>::FREE_ON_DROP

Should be freed when sprite is dropped.
§

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

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

Layout§

Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.