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_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 {

View file

@ -7,14 +7,18 @@ mod player;
fn main() {
let mut app = App::new();
app.add_plugins(DefaultPlugins.set(WindowPlugin {
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<player::Player>>,
keyboard_input: Res<Input<KeyCode>>,
mut app_exit_events: ResMut<Events<bevy::app::AppExit>>,
) {
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;
}
}

View file

@ -22,7 +22,7 @@ fn spawn_player(mut commands: Commands, assets: Res<AssetLoader>) {
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()
},