mirror of
https://github.com/bevyengine/bevy
synced 2024-11-29 16:10:19 +00:00
57f9ac18d7
* add normalized orthographic projection * custom scale for ScaledOrthographicProjection * allow choosing base axis for ScaledOrthographicProjection * cargo fmt * add general (scaled) orthographic camera bundle FIXME: does the same "far" trick from Camera2DBundle make any sense here? * fixes * camera bundles: rename and new ortho constructors * unify orthographic projections * give PerspectiveCameraBundle constructors like those of OrthographicCameraBundle * update examples with new camera bundle syntax * rename CameraUiBundle to UiCameraBundle * update examples * ScalingMode::None * remove extra blank lines * sane default bounds for orthographic projection * fix alien_cake_addict example * reorder ScalingMode enum variants * ios example fix
41 lines
1.4 KiB
Rust
41 lines
1.4 KiB
Rust
use bevy::prelude::*;
|
|
|
|
fn main() {
|
|
App::build()
|
|
.add_plugins(DefaultPlugins)
|
|
.add_startup_system(setup.system())
|
|
.add_system(animate_sprite_system.system())
|
|
.run();
|
|
}
|
|
|
|
fn animate_sprite_system(
|
|
time: Res<Time>,
|
|
texture_atlases: Res<Assets<TextureAtlas>>,
|
|
mut query: Query<(&mut Timer, &mut TextureAtlasSprite, &Handle<TextureAtlas>)>,
|
|
) {
|
|
for (mut timer, mut sprite, texture_atlas_handle) in query.iter_mut() {
|
|
timer.tick(time.delta_seconds());
|
|
if timer.finished() {
|
|
let texture_atlas = texture_atlases.get(texture_atlas_handle).unwrap();
|
|
sprite.index = ((sprite.index as usize + 1) % texture_atlas.textures.len()) as u32;
|
|
}
|
|
}
|
|
}
|
|
|
|
fn setup(
|
|
commands: &mut Commands,
|
|
asset_server: Res<AssetServer>,
|
|
mut texture_atlases: ResMut<Assets<TextureAtlas>>,
|
|
) {
|
|
let texture_handle = asset_server.load("textures/rpg/chars/gabe/gabe-idle-run.png");
|
|
let texture_atlas = TextureAtlas::from_grid(texture_handle, Vec2::new(24.0, 24.0), 7, 1);
|
|
let texture_atlas_handle = texture_atlases.add(texture_atlas);
|
|
commands
|
|
.spawn(OrthographicCameraBundle::new_2d())
|
|
.spawn(SpriteSheetBundle {
|
|
texture_atlas: texture_atlas_handle,
|
|
transform: Transform::from_scale(Vec3::splat(6.0)),
|
|
..Default::default()
|
|
})
|
|
.with(Timer::from_seconds(0.1, true));
|
|
}
|