Skip to content

Commit bd0c746

Browse files
authored
Fix sprite and picking examples (#15803)
# Objective Looks like #15489 broke some examples :) And there are some other issues as well. Gabe's brother Gabe is tiny in the `sprite_animation` example: ![kuva](https://github.com/user-attachments/assets/810ce110-ecd8-4ca5-94c8-a5655f381131) Gabe is not running in the `sprite_picking` example, and (unrelated) is also very blurry: (note that the screenshot is a bit zoomed in) ![kuva](https://github.com/user-attachments/assets/cb115a71-e3fe-41ed-817c-d5215c44adb5) Unrelated to sprites, the text in the `simple_picking` example is way too dark when hovered: ![kuva](https://github.com/user-attachments/assets/f0f9e331-8d03-44ea-becd-bf22ad68ea71) ## Solution Both Gabes are now the correct size: ![kuva](https://github.com/user-attachments/assets/08eb936a-0341-471e-90f6-2e7067871e5b) Gabe is crisp and running: ![kuva](https://github.com/user-attachments/assets/8fa158e8-2caa-4339-bbcd-2c14b7cfc04f) The text has better contrast: ![kuva](https://github.com/user-attachments/assets/2af09523-0bdc-45a7-9149-50aa9c754957)
1 parent f18be66 commit bd0c746

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

examples/2d/sprite_animation.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ fn setup(
129129
}),
130130
..Default::default()
131131
},
132+
Transform::from_scale(Vec3::splat(6.0)).with_translation(Vec3::new(50.0, 0.0, 0.0)),
132133
RightSprite,
133134
animation_config_2,
134135
));

examples/picking/simple_picking.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! A simple scene to demonstrate picking events
22
3-
use bevy::{color::palettes::css::*, prelude::*};
3+
use bevy::{color::palettes::tailwind::CYAN_400, prelude::*};
44

55
fn main() {
66
let mut app = App::new();
@@ -44,13 +44,13 @@ fn setup(
4444
.observe(
4545
|evt: Trigger<Pointer<Out>>, mut texts: Query<&mut TextStyle>| {
4646
let mut style = texts.get_mut(evt.entity()).unwrap();
47-
style.color = WHITE.into();
47+
style.color = Color::WHITE;
4848
},
4949
)
5050
.observe(
5151
|evt: Trigger<Pointer<Over>>, mut texts: Query<&mut TextStyle>| {
5252
let mut style = texts.get_mut(evt.entity()).unwrap();
53-
style.color = BLUE.into();
53+
style.color = CYAN_400.into();
5454
},
5555
);
5656
// circular base

examples/picking/sprite_picking.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::fmt::Debug;
66

77
fn main() {
88
App::new()
9-
.add_plugins(DefaultPlugins)
9+
.add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest()))
1010
.add_systems(Startup, (setup, setup_atlas))
1111
.add_systems(Update, (move_sprite, animate_sprite))
1212
.run();
@@ -99,15 +99,20 @@ struct AnimationTimer(Timer);
9999

100100
fn animate_sprite(
101101
time: Res<Time>,
102-
mut query: Query<(&AnimationIndices, &mut AnimationTimer, &mut TextureAtlas)>,
102+
mut query: Query<(&AnimationIndices, &mut AnimationTimer, &mut Sprite)>,
103103
) {
104104
for (indices, mut timer, mut sprite) in &mut query {
105+
let Some(texture_atlas) = &mut sprite.texture_atlas else {
106+
continue;
107+
};
108+
105109
timer.tick(time.delta());
110+
106111
if timer.just_finished() {
107-
sprite.index = if sprite.index == indices.last {
112+
texture_atlas.index = if texture_atlas.index == indices.last {
108113
indices.first
109114
} else {
110-
sprite.index + 1
115+
texture_atlas.index + 1
111116
};
112117
}
113118
}

0 commit comments

Comments
 (0)