From f74abb1b89d567749075c909ced8463f456fb314 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Tue, 25 Mar 2025 21:14:17 +0000 Subject: [PATCH] Add sprite flipping to `testbed_2d`'s sprite scene (#18537) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Objective Add sprite flipping to `testbed_2d`'s sprite scene ## Solution Draw the sprite flipped in each axis and both axes. Changed the sprite to the rectangular bevy banner with text and made the images different colors. ## Testing ``` cargo run --example testbed_2d ``` ![image](https://github.com/user-attachments/assets/dcfe687b-2f40-4417-bb20-6c892b425228) --------- Co-authored-by: François Mockers --- examples/testbed/2d.rs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/examples/testbed/2d.rs b/examples/testbed/2d.rs index 2e7ef52546..5dca64236d 100644 --- a/examples/testbed/2d.rs +++ b/examples/testbed/2d.rs @@ -258,14 +258,30 @@ mod text { } mod sprite { + use bevy::color::palettes::css::{BLUE, LIME, RED}; use bevy::prelude::*; + use bevy::sprite::Anchor; pub fn setup(mut commands: Commands, asset_server: Res) { commands.spawn((Camera2d, StateScoped(super::Scene::Sprite))); - commands.spawn(( - Sprite::from_image(asset_server.load("branding/bevy_bird_dark.png")), - StateScoped(super::Scene::Sprite), - )); + for (anchor, flip_x, flip_y, color) in [ + (Anchor::BOTTOM_LEFT, false, false, Color::WHITE), + (Anchor::BOTTOM_RIGHT, true, false, RED.into()), + (Anchor::TOP_LEFT, false, true, LIME.into()), + (Anchor::TOP_RIGHT, true, true, BLUE.into()), + ] { + commands.spawn(( + Sprite { + image: asset_server.load("branding/bevy_logo_dark.png"), + anchor, + flip_x, + flip_y, + color, + ..default() + }, + StateScoped(super::Scene::Sprite), + )); + } } }