-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: add ping pong animation mode (#25)
BREAKING CHANGE: add a new variant (`PingPong`) to the `AnimationMode` BREAKING CHANGE: the `mode` field of `SpriteSheetAnimation` is no longer public
- Loading branch information
Showing
4 changed files
with
139 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use std::time::Duration; | ||
|
||
use bevy::prelude::*; | ||
|
||
use benimator::*; | ||
|
||
fn main() { | ||
App::new() | ||
.add_plugins(DefaultPlugins) | ||
.add_plugin(AnimationPlugin) | ||
.add_startup_system(spawn.system()) | ||
.run(); | ||
} | ||
|
||
fn spawn( | ||
mut commands: Commands, | ||
asset_server: Res<AssetServer>, | ||
mut textures: ResMut<Assets<TextureAtlas>>, | ||
mut animations: ResMut<Assets<SpriteSheetAnimation>>, | ||
) { | ||
// Don't forget the camera ;-) | ||
commands.spawn_bundle(OrthographicCameraBundle::new_2d()); | ||
|
||
// Create an animation | ||
// Here we use an index-range (from 0 to 4) where each frame has the same duration | ||
let animation_handle = animations | ||
.add(SpriteSheetAnimation::from_range(0..=4, Duration::from_millis(100)).ping_pong()); | ||
|
||
commands | ||
// Spawn a bevy sprite-sheet | ||
.spawn_bundle(SpriteSheetBundle { | ||
texture_atlas: textures.add(TextureAtlas::from_grid( | ||
asset_server.load("coin.png"), | ||
Vec2::new(16.0, 16.0), | ||
5, | ||
1, | ||
)), | ||
transform: Transform::from_scale(Vec3::splat(10.0)), | ||
..Default::default() | ||
}) | ||
.insert(animation_handle) | ||
.insert(Play); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters