diff --git a/crates/bevy_sprite/src/render/mod.rs b/crates/bevy_sprite/src/render/mod.rs index 70ccd029e2d9a..95d3b9e3f6662 100644 --- a/crates/bevy_sprite/src/render/mod.rs +++ b/crates/bevy_sprite/src/render/mod.rs @@ -257,8 +257,7 @@ pub fn extract_sprites( entity, color: sprite.color, transform: *transform, - // Use the full texture - rect: None, + rect: sprite.rect, // Pass the custom size custom_size: sprite.custom_size, flip_x: sprite.flip_x, diff --git a/crates/bevy_sprite/src/sprite.rs b/crates/bevy_sprite/src/sprite.rs index 56dc1b86c935d..da2a6de1c2cf1 100644 --- a/crates/bevy_sprite/src/sprite.rs +++ b/crates/bevy_sprite/src/sprite.rs @@ -1,5 +1,5 @@ use bevy_ecs::component::Component; -use bevy_math::Vec2; +use bevy_math::{Rect, Vec2}; use bevy_reflect::Reflect; use bevy_render::color::Color; @@ -15,6 +15,9 @@ pub struct Sprite { /// An optional custom size for the sprite that will be used when rendering, instead of the size /// of the sprite's image pub custom_size: Option, + /// An optional rectangle representing the region of the sprite's image to render, instead of + /// rendering the full image. This is an easy one-off alternative to using a texture atlas. + pub rect: Option, /// [`Anchor`] point of the sprite in the world pub anchor: Anchor, }