pub fn subsprite(&self, source_rect: &Rect<f32>) -> Self {
        let mut translated_source = source_rect.clone();
        translated_source.location = translated_source.location + self.source_rect.location;

        WGPUSprite {
            renderer: self.renderer.clone(),
            texture: self.texture.clone(),
            source_rect: self
                .source_rect
                .intersect(&translated_source)
                .unwrap_or_else(|| Rect::new(self.source_rect.location, vec2(0.0, 0.0))),
        }
    }
/// Build a sprite that shares the same underlying texture but represents a different portion
/// of the texture.
///
/// # Arguments
///
/// * **source_rect** - The portion of the texture that the new sprite will render, relative to
///                     the current sprite's bounds. The bounds of the output sprite will be
///                     the intersection of the sprite's rect and the source_rect, so the dimensions
///                     of the output sprite may not match the `source_rect` dimensions.
///
/// # Example
///
/// ```no_run
/// # use riddle::{common::Color, image::*, platform::*, renderer::*, math::*, *};
/// # fn main() -> Result<(), RiddleError> {
/// # let rdl =  RiddleLib::new()?; let window = WindowBuilder::new().build(rdl.context())?;
/// let renderer = Renderer::new_from_window(&window)?;
///
/// // Load an image and create a sprite from it
/// let img = Image::new(100, 100);
/// let sprite = SpriteBuilder::new(img).build(&renderer)?;
///
/// // Take a portion of the sprite as a new sprite.
/// let subsprite = sprite.subsprite(&Rect::new(vec2(75.0, 75.0), vec2(50.0, 50.0)));
///
/// // The subsprite dimensions will be the size of the intersection between the
/// // source sprite and the new bounds.
/// assert_eq!(vec2(25.0, 25.0), subsprite.dimensions());
/// # Ok(()) }
/// ```
Build a sprite that shares the same underlying texture but represents a different portion
of the texture.
Build a sprite that shares the same underlying texture but represents a different portion of the texture .
pub fn subsprite(&self, source_rect: &Rect<f32>) -> Self {
        let mut translated_source = source_rect.clone();
        translated_source.location = translated_source.location + self.source_rect.location;
        WGPUSprite {
            renderer: self.renderer.clone(),
            texture: self.texture.clone(),
            source_rect: self
                .source_rect
                .intersect(&translated_source)
                .unwrap_or_else(|| Rect::new(self.source_rect.location, vec2(0.0, 0.0))),
        }
    }
pub fn subsprite ( & self , source_rect : & Rect < f32 > ) -> Self { let mut translated_source = source_rect . clone ( ) ; translated_source . location = translated_source . location + self . source_rect . location ; WGPUSprite { renderer : self . renderer . clone ( ) , texture : self . texture . clone ( ) , source_rect : self . source_rect . intersect ( & translated_source ) . unwrap_or_else ( | | Rect :: new ( self . source_rect . location , vec2 ( 0.0 , 0.0 ) ) ) , } }
Build a sprite that shares the same underlying texture but represents a different portion
of the texture.
Build a sprite that shares the same underlying texture but represents a different portion of the texture .
&self
source_rect
&Rect<f32>
&self
source_rect
&Rect<f32>
example
None
use riddle::{common::color, image::*, platform::*, renderer::*, math::*, *};
None
fn main() -> result<(), riddleerror> {
None
let rdl =  riddlelib::new()?; let window = windowbuilder::new().build(rdl.context())?;
let renderer = Renderer::new_from_window(&window)?.

Load an image and create a sprite from it
let img = Image::new(100, 100);
let sprite = SpriteBuilder::new(img).build(&renderer)?.

Take a portion of the sprite as a new sprite.

The subsprite dimensions will be the size of the intersection between the
source sprite and the new bounds.
let renderer = Renderer :: new_from_window ( &window ) ? . Load an image and create a sprite from it let img = Image :: new ( 100 100 ) ; let sprite = SpriteBuilder :: new ( img ) . build ( &renderer ) ? . Take a portion of the sprite as a new sprite . The subsprite dimensions will be the size of the intersection between the source sprite and the new bounds .
ok(()) }
None