Struct crankstart::sprite::RotatedSprite
source · pub struct RotatedSprite { /* private fields */ }
Expand description
This is a helper type for rotating and scaling an image in a sprite.
After creation with new
, you can set_rotation
to update the parameters, and use
get_sprite
or get_sprite_mut
to access the Sprite
for other operations like move_to
and get_bounds
(which can tell you the height and width of the generated bitmap).
Note: the image is rotated around its center point. If you want to rotate around another point, there are a few options:
- Extend the image with transparent pixels in one direction so it appears to be rotating about another point.
- Rotate about the center, then move the sprite to an equivalent position.
- Manage the image and sprite manually: do the math to find the size after rotation, create a fresh Bitmap of that size, and use Graphics.draw_rotated() to draw into it, since draw_rotated allows specifying the center point.
Implementations§
source§impl RotatedSprite
impl RotatedSprite
sourcepub fn new(
bitmap: Bitmap,
angle: f32,
scaling: Vector2D<f32>
) -> Result<Self, Error>
pub fn new( bitmap: Bitmap, angle: f32, scaling: Vector2D<f32> ) -> Result<Self, Error>
Creates a RotatedSprite
, draws the rotated and scaled image into it, and adds the
underlying sprite to the SpriteManager
.
pub fn get_sprite(&self) -> &Sprite
pub fn get_sprite_mut(&mut self) -> &mut Sprite
Trait Implementations§
source§impl Clone for RotatedSprite
impl Clone for RotatedSprite
source§fn clone(&self) -> RotatedSprite
fn clone(&self) -> RotatedSprite
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for RotatedSprite
impl !Send for RotatedSprite
impl !Sync for RotatedSprite
impl Unpin for RotatedSprite
impl !UnwindSafe for RotatedSprite
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more