pub struct Sprite { /* private fields */ }Implementations§
Source§impl Sprite
impl Sprite
Sourcepub fn get_position(&self) -> Vec2<f32>
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.
Sourcepub fn set_bounds(&self, bounds: Rect<f32>)
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.
Sourcepub fn get_bounds(&self) -> Rect<f32>
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.
Sourcepub fn move_to(&self, pos: Vec2<f32>)
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.
Sourcepub fn move_by(&self, delta: Vec2<f32>)
pub fn move_by(&self, delta: Vec2<f32>)
Moves the given sprite to by offsetting its current position by dx, dy.
Sourcepub fn set_image(&self, image: Bitmap, flip: LCDBitmapFlip)
pub fn set_image(&self, image: Bitmap, flip: LCDBitmapFlip)
Sets the given sprite’s image to the given bitmap.
Sourcepub fn get_image(&self) -> Option<Ref<'_, Bitmap>>
pub fn get_image(&self) -> Option<Ref<'_, Bitmap>>
Returns the LCDBitmap currently assigned to the given sprite.
Sourcepub fn set_size(&self, width: f32, height: f32)
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().
Sourcepub fn set_z_index(&self, z_index: i16)
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.
Sourcepub fn get_z_index(&self) -> i16
pub fn get_z_index(&self) -> i16
Returns the Z index of the given sprite.
Sourcepub fn set_draw_mode(&self, mode: LCDBitmapDrawMode)
pub fn set_draw_mode(&self, mode: LCDBitmapDrawMode)
Sets the mode for drawing the sprite’s bitmap.
Sourcepub fn set_image_flip(&self, flip: LCDBitmapFlip)
pub fn set_image_flip(&self, flip: LCDBitmapFlip)
Flips the bitmap.
Sourcepub fn get_image_flip(&self) -> LCDBitmapFlip
pub fn get_image_flip(&self) -> LCDBitmapFlip
Returns the flip setting of the sprite’s bitmap.
Sourcepub fn set_stencil(&self, stencil: impl AsRef<Bitmap>)
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.
Sourcepub fn set_clip_rect(&self, clip_rect: SideOffsets<i32>)
pub fn set_clip_rect(&self, clip_rect: SideOffsets<i32>)
Sets the clipping rectangle for sprite drawing.
Sourcepub fn clear_clip_rect(&self)
pub fn clear_clip_rect(&self)
Clears the sprite’s clipping rectangle.
Sourcepub fn set_updates_enabled(&self, flag: bool)
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).
Sourcepub fn updates_enabled(&self) -> bool
pub fn updates_enabled(&self) -> bool
Get the updatesEnabled flag of the given sprite.
Sourcepub fn set_collisions_enabled(&self, flag: bool)
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.
Sourcepub fn collisions_enabled(&self) -> bool
pub fn collisions_enabled(&self) -> bool
Get the collisionsEnabled flag of the given sprite.
Sourcepub fn set_visible(&self, flag: bool)
pub fn set_visible(&self, flag: bool)
Set the visible flag of the given sprite (determines whether the sprite has its draw function called).
Sourcepub fn is_visible(&self) -> bool
pub fn is_visible(&self) -> bool
Get the visible flag of the given sprite.
Sourcepub fn set_opaque(&self, flag: bool)
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.
Sourcepub fn mark_dirty(&self)
pub fn mark_dirty(&self)
Forces the given sprite to redraw.
Sourcepub fn set_tag(&self, tag: u8)
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.
Sourcepub fn set_ignores_draw_offset(&self, flag: i32)
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.
Sourcepub fn set_update_function(&self, func: impl Fn(&Sprite) + 'static)
pub fn set_update_function(&self, func: impl Fn(&Sprite) + 'static)
Sets the update function for the given sprite.
Sourcepub fn set_draw_function(
&self,
func: impl Fn(&Sprite, Rect<f32>, Rect<f32>) + 'static,
)
pub fn set_draw_function( &self, func: impl Fn(&Sprite, Rect<f32>, Rect<f32>) + 'static, )
Sets the draw function for the given sprite.
Sourcepub fn set_collide_rect(&self, collide_rect: Rect<f32>)
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.
Sourcepub fn get_collide_rect(&self) -> Rect<f32>
pub fn get_collide_rect(&self) -> Rect<f32>
Returns the given sprite’s collide rect.
Sourcepub fn clear_collide_rect(&self)
pub fn clear_collide_rect(&self)
Clears the given sprite’s collide rect.
Sourcepub fn set_collision_response_function(
&self,
func: impl Fn(&Sprite, &Sprite) -> SpriteCollisionResponseType + 'static,
)
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.
Sourcepub fn set_stencil_pattern(&self, pattern: LCDPattern)
pub fn set_stencil_pattern(&self, pattern: LCDPattern)
Sets the sprite’s stencil to the given pattern.
Sourcepub fn clear_stencil(&self)
pub fn clear_stencil(&self)
Clears the sprite’s stencil.
Sourcepub fn set_stencil_image(&self, stencil: impl AsRef<Bitmap>, tile: i32)
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.
Sourcepub fn check_collisions(
&self,
move_goal: Vec2<f32>,
) -> Vec<SpriteCollisionInfo<'_>>
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.
Sourcepub fn move_with_collisions(
&self,
goal: Vec2<f32>,
) -> (Vec2<f32>, Vec<SpriteCollisionInfo<'_>>)
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.
Sourcepub fn overlapping_sprites(&self) -> Vec<Ref<'_, Sprite>>
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.