diff --git a/assets/flappy/rewind.png b/assets/flappy/rewind.png index 7f67141..866884e 100644 --- a/assets/flappy/rewind.png +++ b/assets/flappy/rewind.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:13f1a08b90b99c24ce6d3f90ed807f3029c2eece1e2a75e2bcb67877b0346bdb -size 318 +oid sha256:f90e6ab6d1caa5991f70389c13eb203822435857b7846ea9cdc5fb3a56d41e8f +size 258 diff --git a/assets/flappy/rewind.xcf b/assets/flappy/rewind.xcf index 16d4a47..9ce9106 100644 --- a/assets/flappy/rewind.xcf +++ b/assets/flappy/rewind.xcf @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5ed4001fe6c3b1ecb04d9540f6172530e83336dd7b58b88addfe54e3534264bc -size 3501 +oid sha256:5c6f4299082a7ecb9632c9d1223cb9560bce6d868af8fec510738d58734b46a1 +size 3437 diff --git a/src/bin/flappy/main.rs b/src/bin/flappy/main.rs index 8ced864..ecba341 100644 --- a/src/bin/flappy/main.rs +++ b/src/bin/flappy/main.rs @@ -2,6 +2,7 @@ #![allow(clippy::type_complexity)] use bevy::audio::PlaybackMode; +use bevy::image::{ImageLoaderSettings, ImageSampler}; use bevy::render::view::ColorGrading; use games::physics2d::*; use games::*; @@ -417,7 +418,7 @@ struct RewindSfx; #[derive(Component)] struct RewindButton; -fn init_ui(mut commands: Commands) { +fn init_ui(mut commands: Commands, mut server: ResMut) { commands .spawn(( Node { @@ -550,6 +551,14 @@ fn init_ui(mut commands: Commands) { ..default() }) .with_children(|parent| { + let rewind_image = server.load_with_settings( + "flappy/rewind.png", + |settings: &mut ImageLoaderSettings| { + // Need to use nearest filtering to avoid bleeding between the slices with tiling + settings.sampler = ImageSampler::nearest(); + }, + ); + parent .spawn(( Node { @@ -562,13 +571,27 @@ fn init_ui(mut commands: Commands) { BackgroundColor::default(), RewindButton, children![ - Text::new("Rewind! (R)"), - TextLayout::new_with_justify(JustifyText::Center) + ( + ImageNode { color: BLACK.into(), image: rewind_image, ..default() }, + Node { height: Val::Px(50.0), ..default() }, + ), + ( + Text::new("Rewind! (R)"), + TextFont::from_font_size(30.0), + TextLayout::new_with_justify(JustifyText::Center) + ), ], )) .observe(start_rewind) .observe(end_rewind); + let play_image = server.load_with_settings( + "flappy/play.png", + |settings: &mut ImageLoaderSettings| { + // Need to use nearest filtering to avoid bleeding between the slices with tiling + settings.sampler = ImageSampler::nearest(); + }, + ); parent .spawn(( Node { @@ -580,9 +603,15 @@ fn init_ui(mut commands: Commands) { Button, FlapButton, children![ - Text::new("Flap! (Spacebar)"), - TextFont::from_font_size(30.0), - TextLayout::new_with_justify(JustifyText::Center) + ( + Text::new("Flap! (Spacebar)"), + TextFont::from_font_size(30.0), + TextLayout::new_with_justify(JustifyText::Center) + ), + ( + ImageNode { color: BLACK.into(), image: play_image, ..default() }, + Node { height: Val::Px(50.0), ..default() }, + ), ], )) .observe(flap_button); diff --git a/src/ui.rs b/src/ui.rs index 6fc7f13..b850877 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -133,6 +133,7 @@ fn add_ui_node( mut added: Query<(Entity, &mut Node), Added>, style: Res