Fix pixel art

This commit is contained in:
Daniel Flanagan 2023-12-22 21:43:16 -06:00
parent 7a064fd55a
commit d851eb7676
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4
3 changed files with 21 additions and 13 deletions

View file

@ -27,11 +27,11 @@ fn load_assets(
let player_img = asset_server.load("img/Player.png"); let player_img = asset_server.load("img/Player.png");
let player_atlas = TextureAtlas::from_grid( let player_atlas = TextureAtlas::from_grid(
player_img, player_img,
Vec2::new(21.0, 48.0), Vec2::new(32.0, 64.0),
7, 3,
1, 1,
Some(Vec2 { x: 33., y: 0. }), Some(Vec2 { x: 0., y: 0. }),
Some(Vec2 { x: 6., y: 10. }), Some(Vec2 { x: 0., y: 0. }),
); );
let player_atlas_handle = texture_atlases.add(player_atlas); let player_atlas_handle = texture_atlases.add(player_atlas);
*assets = AssetLoader { *assets = AssetLoader {

View file

@ -7,14 +7,18 @@ mod player;
fn main() { fn main() {
let mut app = App::new(); let mut app = App::new();
app.add_plugins(DefaultPlugins.set(WindowPlugin { app.add_plugins(
primary_window: Some(Window { DefaultPlugins
title: "Kodo Tag".into(), .set(WindowPlugin {
resolution: (800., 600.).into(), primary_window: Some(Window {
..Default::default() title: "Kodo Tag".into(),
}), resolution: (800., 600.).into(),
..Default::default() ..Default::default()
})) }),
..Default::default()
})
.set(ImagePlugin::default_nearest()),
)
.add_plugins(( .add_plugins((
camera::Camera, camera::Camera,
assets::AssetPlugin, assets::AssetPlugin,
@ -32,10 +36,14 @@ fn main() {
} }
fn keyboard_input_system( fn keyboard_input_system(
mut query: Query<&mut TextureAtlasSprite, With<player::Player>>,
keyboard_input: Res<Input<KeyCode>>, keyboard_input: Res<Input<KeyCode>>,
mut app_exit_events: ResMut<Events<bevy::app::AppExit>>, mut app_exit_events: ResMut<Events<bevy::app::AppExit>>,
) { ) {
if keyboard_input.pressed(KeyCode::Escape) { if keyboard_input.pressed(KeyCode::Escape) {
app_exit_events.send(bevy::app::AppExit); app_exit_events.send(bevy::app::AppExit);
} else if keyboard_input.pressed(KeyCode::N) {
let mut sprite = query.single_mut();
sprite.index += 1;
} }
} }

View file

@ -22,7 +22,7 @@ fn spawn_player(mut commands: Commands, assets: Res<AssetLoader>) {
Player, Player,
SpriteSheetBundle { SpriteSheetBundle {
texture_atlas: assets.sprites.player.clone(), texture_atlas: assets.sprites.player.clone(),
sprite: TextureAtlasSprite::new(1), sprite: TextureAtlasSprite::new(0),
transform: Transform::from_scale(Vec3::splat(3.0)), transform: Transform::from_scale(Vec3::splat(3.0)),
..Default::default() ..Default::default()
}, },