From d851eb7676bb96d4d264270bc3da6e88e2681b15 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Fri, 22 Dec 2023 21:43:16 -0600 Subject: [PATCH] Fix pixel art --- src/assets.rs | 8 ++++---- src/main.rs | 24 ++++++++++++++++-------- src/player.rs | 2 +- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/assets.rs b/src/assets.rs index 1e14904..0728ee4 100644 --- a/src/assets.rs +++ b/src/assets.rs @@ -27,11 +27,11 @@ fn load_assets( let player_img = asset_server.load("img/Player.png"); let player_atlas = TextureAtlas::from_grid( player_img, - Vec2::new(21.0, 48.0), - 7, + Vec2::new(32.0, 64.0), + 3, 1, - Some(Vec2 { x: 33., y: 0. }), - Some(Vec2 { x: 6., y: 10. }), + Some(Vec2 { x: 0., y: 0. }), + Some(Vec2 { x: 0., y: 0. }), ); let player_atlas_handle = texture_atlases.add(player_atlas); *assets = AssetLoader { diff --git a/src/main.rs b/src/main.rs index 8f22dff..9dc64ad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,14 +7,18 @@ mod player; fn main() { let mut app = App::new(); - app.add_plugins(DefaultPlugins.set(WindowPlugin { - primary_window: Some(Window { - title: "Kodo Tag".into(), - resolution: (800., 600.).into(), - ..Default::default() - }), - ..Default::default() - })) + app.add_plugins( + DefaultPlugins + .set(WindowPlugin { + primary_window: Some(Window { + title: "Kodo Tag".into(), + resolution: (800., 600.).into(), + ..Default::default() + }), + ..Default::default() + }) + .set(ImagePlugin::default_nearest()), + ) .add_plugins(( camera::Camera, assets::AssetPlugin, @@ -32,10 +36,14 @@ fn main() { } fn keyboard_input_system( + mut query: Query<&mut TextureAtlasSprite, With>, keyboard_input: Res>, mut app_exit_events: ResMut>, ) { if keyboard_input.pressed(KeyCode::Escape) { app_exit_events.send(bevy::app::AppExit); + } else if keyboard_input.pressed(KeyCode::N) { + let mut sprite = query.single_mut(); + sprite.index += 1; } } diff --git a/src/player.rs b/src/player.rs index 7745cff..619072a 100644 --- a/src/player.rs +++ b/src/player.rs @@ -22,7 +22,7 @@ fn spawn_player(mut commands: Commands, assets: Res) { Player, SpriteSheetBundle { texture_atlas: assets.sprites.player.clone(), - sprite: TextureAtlasSprite::new(1), + sprite: TextureAtlasSprite::new(0), transform: Transform::from_scale(Vec3::splat(3.0)), ..Default::default() },