use bevy::prelude::*;
use seldom_pixel::prelude::*;
fn main() {
App::new()
.add_plugins((
DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
resolution: Vec2::splat(512.).into(),
..default()
}),
..default()
}),
PxPlugin::<Layer>::new(UVec2::new(51, 35), "palette/palette_1.palette.png"),
))
.insert_resource(ClearColor(Color::BLACK))
.add_systems(Startup, init)
.run();
}
fn init(assets: Res<AssetServer>, mut commands: Commands) {
commands.spawn(Camera2d);
let runner = assets.load("sprite/runner.px_sprite.png");
commands.spawn((
PxSprite(runner.clone()),
PxAnchor::BottomLeft,
PxAnimation::default(),
));
commands.spawn((
PxSprite(runner.clone()),
PxPosition(IVec2::new(13, 0)),
PxAnchor::BottomLeft,
PxAnimation {
on_finish: PxAnimationFinishBehavior::Mark,
..default()
},
));
commands.spawn((
PxSprite(runner.clone()),
PxPosition(IVec2::new(26, 0)),
PxAnchor::BottomLeft,
PxAnimation {
on_finish: PxAnimationFinishBehavior::Loop,
..default()
},
));
commands.spawn((
PxSprite(runner.clone()),
PxPosition(IVec2::new(39, 0)),
PxAnchor::BottomLeft,
PxAnimation {
direction: PxAnimationDirection::Backward,
on_finish: PxAnimationFinishBehavior::Loop,
..default()
},
));
commands.spawn((
PxSprite(runner.clone()),
PxPosition(IVec2::new(13, 18)),
PxAnchor::BottomLeft,
PxAnimation {
duration: PxAnimationDuration::millis_per_animation(500),
on_finish: PxAnimationFinishBehavior::Loop,
..default()
},
));
commands.spawn((
PxSprite(runner.clone()),
PxPosition(IVec2::new(0, 18)),
PxAnchor::BottomLeft,
PxAnimation {
duration: PxAnimationDuration::millis_per_animation(2000),
on_finish: PxAnimationFinishBehavior::Loop,
..default()
},
));
commands.spawn((
PxSprite(runner.clone()),
PxPosition(IVec2::new(26, 18)),
PxAnchor::BottomLeft,
PxAnimation {
duration: PxAnimationDuration::millis_per_frame(1000),
on_finish: PxAnimationFinishBehavior::Loop,
..default()
},
));
commands.spawn((
PxSprite(runner),
PxPosition(IVec2::new(39, 18)),
PxAnchor::BottomLeft,
PxAnimation {
on_finish: PxAnimationFinishBehavior::Loop,
frame_transition: PxAnimationFrameTransition::Dither,
..default()
},
));
}
#[px_layer]
struct Layer;