From 7499b74bbf65521a335cb99d0ac97da25020e679 Mon Sep 17 00:00:00 2001 From: Kees van Beilen <76178905+Kees-van-Beilen@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:24:16 +0200 Subject: [PATCH] Added Sprite::sized(custom_size) (#14849) # Objective add a quick shorthand for creating a sprite with an custom size. This is often desired when working with custom units or scaled sprites and allows for a cleaner syntax in those cases/ ## Solution Implemented a `sized` function on the Sprite struct which creates a Sprite, sets the custom size and leaves the rest at their default values --- ## Changelog - Added `Sprite::sized(custom_size: Vec2)` --- crates/bevy_sprite/src/sprite.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crates/bevy_sprite/src/sprite.rs b/crates/bevy_sprite/src/sprite.rs index ae57eb760c..a0ce5071ec 100644 --- a/crates/bevy_sprite/src/sprite.rs +++ b/crates/bevy_sprite/src/sprite.rs @@ -31,6 +31,16 @@ pub struct Sprite { pub anchor: Anchor, } +impl Sprite { + /// Create a Sprite with a custom size + pub fn sized(custom_size: Vec2) -> Self { + Sprite { + custom_size: Some(custom_size), + ..Default::default() + } + } +} + /// Controls how the image is altered when scaled. #[derive(Component, Debug, Clone, Reflect)] #[reflect(Component)]