Skip to content

Commit 2d05df0

Browse files
committed
WIP
1 parent be84863 commit 2d05df0

35 files changed

Lines changed: 1089 additions & 1802 deletions

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 5.0.0 - 2025-??-??
4+
5+
### Changed
6+
7+
- ???
8+
39
## 4.0.0 - 2025-10-09
410

511
### Added

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fn setup(
4848
mut atlas_layouts: ResMut<Assets<TextureAtlasLayout>>,
4949
assets: Res<AssetServer>,
5050
) {
51-
// Create a clip
51+
// Create a clip from a row of an 8x8 spritesheet
5252

5353
let spritesheet = Spritesheet::new(8, 8);
5454

@@ -82,7 +82,7 @@ fn setup(
8282
Sprite::from_atlas_image(image, atlas),
8383

8484
// Add a SpritesheetAnimation component that references our newly created animation
85-
SpritesheetAnimation::from_id(animation_id),
85+
SpritesheetAnimation::new(animation_handle),
8686
));
8787

8888
commands.spawn(Camera2d);
@@ -156,7 +156,7 @@ fn create_animation(mut commands: Commands, mut library: ResMut<AnimationLibrary
156156

157157
commands.spawn((
158158
Sprite::from_atlas_image(image, atlas),
159-
SpritesheetAnimation::from_id(animation_id),
159+
SpritesheetAnimation::new(animation_handle),
160160
));
161161
}
162162
```
@@ -184,7 +184,7 @@ fn spawn_characters(mut commands: Commands, mut library: ResMut<AnimationLibrary
184184

185185
commands.spawn((
186186
Sprite::from_atlas_image(/* .... */),
187-
SpritesheetAnimation::from_id(animation_id),
187+
SpritesheetAnimation::new(animation_handle),
188188
));
189189
}
190190
}
@@ -229,7 +229,7 @@ fn spawn_enemies(mut commands: Commands, library: Res<AnimationLibrary>) {
229229
for _ in 0..100 {
230230
commands.spawn((
231231
Sprite::from_atlas_image(/* .... */),
232-
SpritesheetAnimation::from_id(animation_id),
232+
SpritesheetAnimation::new(animation_handle),
233233
));
234234
}
235235
}
@@ -256,7 +256,7 @@ fn spawn_character(mut commands: Commands, mut library: ResMut<AnimationLibrary>
256256
.with_atlas(atlas_layout)
257257
.with_anchor(Anchor::BottomRight)
258258
.build(),
259-
SpritesheetAnimation::from_id(animation_id),
259+
SpritesheetAnimation::new(animation_handle),
260260
));
261261
}
262262
```
@@ -282,7 +282,7 @@ fn create_animated_cursor(
282282
texture_atlas: Some(atlas),
283283
..default()
284284
})),
285-
SpritesheetAnimation::from_id(animation_id),
285+
SpritesheetAnimation::new(animation_handle),
286286
));
287287
}
288288
```

examples/3d.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ fn main() {
2020

2121
fn spawn_sprites(
2222
mut commands: Commands,
23-
mut library: ResMut<AnimationLibrary>,
2423
mut atlas_layouts: ResMut<Assets<TextureAtlasLayout>>,
24+
mut animations: ResMut<Assets<Animation>>,
2525
assets: Res<AssetServer>,
2626
) {
2727
// 3D sprites require a 3D camera
@@ -37,11 +37,9 @@ fn spawn_sprites(
3737

3838
let clip = Clip::from_frames(spritesheet.row(3));
3939

40-
let clip_id = library.register_clip(clip);
40+
let animation = Animation::from_clip(clip);
4141

42-
let animation = Animation::from_clip(clip_id);
43-
44-
let animation_id = library.register_animation(animation);
42+
let animation_handle = animations.add(animation);
4543

4644
// Create an image and a texture atlas like you would for any Bevy sprite
4745

@@ -79,7 +77,7 @@ fn spawn_sprites(
7977
for (i, sprite) in sprites.into_iter().enumerate() {
8078
commands.spawn((
8179
sprite,
82-
SpritesheetAnimation::from_id(animation_id),
80+
SpritesheetAnimation::new(animation_handle.clone()),
8381
Orbit {
8482
start_angle: i as f32 * std::f32::consts::TAU / sprite_count as f32,
8583
},

examples/basic.rs

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn main() {
1010
App::new()
1111
.add_plugins(DefaultPlugins)
1212
// Add the plugin to enable animations.
13-
// This makes the AnimationLibrary resource available to your systems.
13+
// This makes the Assets<Animation> resource available to your systems.
1414
.add_plugins(SpritesheetAnimationPlugin)
1515
.add_systems(
1616
Startup,
@@ -19,7 +19,12 @@ fn main() {
1919
.run();
2020
}
2121

22-
fn create_animation(mut commands: Commands, mut library: ResMut<AnimationLibrary>) {
22+
#[derive(Resource)]
23+
struct MyAnimation {
24+
handle: Handle<Animation>,
25+
}
26+
27+
fn create_animation(mut commands: Commands, mut animations: ResMut<Assets<Animation>>) {
2328
commands.spawn(Camera2d);
2429

2530
// Create a clip that references some frames from a spritesheet
@@ -28,49 +33,52 @@ fn create_animation(mut commands: Commands, mut library: ResMut<AnimationLibrary
2833

2934
let clip = Clip::from_frames(spritesheet.row(3));
3035

31-
let clip_id = library.register_clip(clip);
32-
3336
// Create an animation that uses the clip
37+
//
38+
// This is a simple animation with a single clip but we can create more sophisticated
39+
// animations with multiple clips, each one having different parameters.
40+
//
41+
// See the `composition` example for more details.
3442

35-
let animation = Animation::from_clip(clip_id);
36-
37-
let animation_id = library.register_animation(animation);
43+
let animation = Animation::from_clip(clip);
3844

3945
// Name the animation to retrieve it from other systems
4046

41-
library.name_animation(animation_id, "walk").unwrap();
47+
let animation_handle = animations.add(animation);
4248

43-
// This is a simple animation with a single clip but we can create more sophisticated
44-
// animations with multiple clips, each one having different parameters.
45-
//
46-
// See the `composition` example for more details.
49+
commands.insert_resource(MyAnimation {
50+
handle: animation_handle,
51+
});
4752
}
4853

4954
// We split the setup in two separate systems to show how to retrieve animations from their name
5055

5156
fn spawn_sprite(
5257
mut commands: Commands,
53-
library: Res<AnimationLibrary>,
54-
mut atlas_layouts: ResMut<Assets<TextureAtlasLayout>>,
5558
assets: Res<AssetServer>,
59+
mut atlas_layouts: ResMut<Assets<TextureAtlasLayout>>,
60+
my_animation: Res<MyAnimation>,
5661
) {
5762
// Retrieve our animation from the library
5863

59-
if let Some(animation_id) = library.animation_with_name("walk") {
60-
// Create an image and a texture atlas like you would for any Bevy sprite
64+
// Create an image and a texture atlas like you would for any Bevy sprite
65+
//
66+
// However, here we use the Spritesheet helper to easily generate the atlas.
67+
// This is optional and you may prefer to build the atlas manually.
68+
69+
let image = assets.load("character.png");
6170

62-
let image = assets.load("character.png");
71+
let spritesheet = Spritesheet::new(8, 8);
6372

64-
let atlas = TextureAtlas {
65-
layout: atlas_layouts.add(Spritesheet::new(8, 8).atlas_layout(96, 96)),
66-
..default()
67-
};
73+
let atlas = TextureAtlas {
74+
layout: atlas_layouts.add(spritesheet.atlas_layout(96, 96)),
75+
..default()
76+
};
6877

69-
// Spawn a sprite with a SpritesheetAnimation component that references our animation
78+
// Spawn a sprite with a SpritesheetAnimation component that references our animation
7079

71-
commands.spawn((
72-
Sprite::from_atlas_image(image, atlas),
73-
SpritesheetAnimation::from_id(animation_id),
74-
));
75-
}
80+
commands.spawn((
81+
Sprite::from_atlas_image(image, atlas),
82+
SpritesheetAnimation::new(my_animation.handle.clone()),
83+
));
7684
}

0 commit comments

Comments
 (0)