pub struct RcSprite { /* private fields */ }
Expand description
Drawable representation of a texture
Sprite is a drawable type that allows to easily
display a RcTexture
(or a part of it) on a render target.
Note:
This is an improvement upon the Sprite module which dissallows seperation from the texture
lifetime. The RcSprite
allows from complete seperation from the RcTexture
while still
referencing it. Underneath, it uses reference counting to ensure that the RcTexture
is alive and
well, and will throw errors messages if you try to perform function on the sprite while the
RcTexture
is no longer alive.
Implementations§
source§impl RcSprite
impl RcSprite
sourcepub fn with_texture(texture: &RcTexture) -> RcSprite
pub fn with_texture(texture: &RcTexture) -> RcSprite
Create a new sprite with a texture
sourcepub fn with_texture_and_rect(texture: &RcTexture, rect: IntRect) -> RcSprite
pub fn with_texture_and_rect(texture: &RcTexture, rect: IntRect) -> RcSprite
Create a new sprite with a texture and a source rectangle
sourcepub fn set_texture(&mut self, texture: &RcTexture, reset_rect: bool)
pub fn set_texture(&mut self, texture: &RcTexture, reset_rect: bool)
Change the source texture of a sprite
The texture argument refers to a texture that must
exist as long as the sprite uses it. Indeed, the sprite
doesn’t store its own copy of the texture, but rather keeps
a pointer to the one that you passed to this function.
If the source texture is destroyed and the sprite tries to
use it, the behaviour is undefined.
If reset_rect
is true, the texture_rect
property of
the sprite is automatically adjusted to the size of the new
texture. If it is false, the texture rect is left unchanged.
Arguments
texture
- New texturereset_rect
- Should the texture rect be reset to the size of the new texture?
sourcepub fn set_color(&mut self, color: Color)
pub fn set_color(&mut self, color: Color)
Set the global color of a sprite
This color is modulated (multiplied) with the sprite’s texture. It can be used to colorize the sprite, or change its global opacity. By default, the sprite’s color is opaque white.
Arguments
- color - New color of the sprite
sourcepub fn texture(&self) -> Option<&Texture>
pub fn texture(&self) -> Option<&Texture>
Get the source texture of a sprite
If the sprite has no source texture, None is returned. You can’t modify the texture when you retrieve it with this function.
Return an Option to the sprite’s texture
sourcepub fn color(&self) -> Color
pub fn color(&self) -> Color
Get the global color of a sprite
Return the global color of the sprite
sourcepub fn local_bounds(&self) -> FloatRect
pub fn local_bounds(&self) -> FloatRect
Get the local bounding rectangle of a sprite
The returned rectangle is in local coordinates, which means that it ignores the transformations (translation, rotation, scale, …) that are applied to the entity. In other words, this function returns the bounds of the entity in the entity’s coordinate system.
Return the local bounding rectangle of the entity
sourcepub fn global_bounds(&self) -> FloatRect
pub fn global_bounds(&self) -> FloatRect
Get the global bounding rectangle of a sprite
The returned rectangle is in global coordinates, which means that it takes in account the transformations (translation, rotation, scale, …) that are applied to the entity. In other words, this function returns the bounds of the sprite in the global 2D world’s coordinate system.
Return the global bounding rectangle of the entity
sourcepub fn texture_rect(&self) -> IntRect
pub fn texture_rect(&self) -> IntRect
Get the sub-rectangle of the texture displayed by a sprite
Return the texture rectangle of the sprite
sourcepub fn set_texture_rect(&mut self, rect: IntRect)
pub fn set_texture_rect(&mut self, rect: IntRect)
Set the sub-rectangle of the texture that a sprite will display
The texture rect is useful when you don’t want to display the whole texture, but rather a part of it. By default, the texture rect covers the entire texture.
Arguments
- rectangle - Rectangle defining the region of the texture to display