Skip to content

Commit cfac504

Browse files
authored
Merge pull request #241 from NiklasEi/bevy-0-15
Update to Bevy 0.15
2 parents 30aaf37 + b273b13 commit cfac504

38 files changed

+491
-645
lines changed

CHANGELOG.md

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

3+
## v0.22.0 - 01.12.2024
4+
- support for Bevy 0.15
5+
- support for using sub states as loading states ([@mgi388](https://github.com/mgi388) in [#239](https://github.com/NiklasEi/bevy_asset_loader/pull/239))
6+
- support image sampler address modes for image assets ([@pcwalton](https://github.com/pcwalton) in [#238](https://github.com/NiklasEi/bevy_asset_loader/pull/238))
37
- custom `on_unimplemented` diagnostics for the `AssetCollection` trait
48
- image derive attribute `array_texture_layers`
59
- wait for dependencies of assets to load

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This [Bevy][bevy] plugin reduces boilerplate for handling game assets. The crate
1111

1212
In most cases you will want to load your asset collections during loading states (think loading screens). During such a state, all assets are loaded and their loading progress is observed. Only when asset collections can be built with fully loaded asset handles, the collections are inserted to Bevy's ECS as resources. If you do not want to use a loading state, asset collections can still result in cleaner code and improved maintainability (see the ["usage without a loading state"](#usage-without-a-loading-state) section).
1313

14-
_The `main` branch and the latest release support Bevy version `0.14` (see [version table](#compatible-bevy-versions))_
14+
_The `main` branch and the latest release support Bevy version `0.15` (see [version table](#compatible-bevy-versions))_
1515

1616
## Loading states
1717

@@ -45,10 +45,7 @@ struct AudioAssets {
4545
/// This system runs in MyStates::Next. Thus, AudioAssets is available as a resource
4646
/// and the contained handle is done loading.
4747
fn start_background_audio(mut commands: Commands, audio_assets: Res<AudioAssets>) {
48-
commands.spawn(AudioBundle {
49-
source: audio_assets.background.clone(),
50-
settings: PlaybackSettings::LOOP,
51-
});
48+
commands.spawn((AudioPlayer(audio_assets.background.clone()), PlaybackSettings::LOOP));
5249
}
5350

5451
#[derive(Clone, Eq, PartialEq, Debug, Hash, Default, States)]
@@ -540,6 +537,7 @@ Compatibility of `bevy_asset_loader` versions:
540537

541538
| Bevy version | `bevy_asset_loader` version |
542539
|:-------------|:----------------------------|
540+
| `0.15` | `0.22` |
543541
| `0.14` | `0.21` |
544542
| `0.13` | `0.20` |
545543
| `0.12` | `0.18` - `0.19` |
@@ -550,7 +548,7 @@ Compatibility of `bevy_asset_loader` versions:
550548
| `0.7` | `0.10` - `0.11` |
551549
| `0.6` | `0.8` - `0.9` |
552550
| `0.5` | `0.1` - `0.7` |
553-
| `0.13` | branch `main` |
551+
| `0.15` | branch `main` |
554552
| `main` | branch `bevy_main` |
555553

556554
## License

bevy_asset_loader/Cargo.toml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bevy_asset_loader"
3-
version = "0.21.0"
3+
version = "0.22.0"
44
authors = ["Niklas Eicker <[email protected]>"]
55
edition = "2021"
66
license = "MIT OR Apache-2.0"
@@ -15,27 +15,27 @@ readme = "README.md"
1515

1616
[features]
1717
# This feature adds support for bevy's TextureAtlas assets
18-
2d = ["bevy/bevy_sprite", "bevy_asset_loader_derive/2d"]
18+
2d = ["bevy/bevy_sprite", "bevy/png", "bevy_asset_loader_derive/2d"]
1919
# This feature adds support for bevy's StandardMaterial assets
20-
3d = ["bevy/bevy_pbr", "bevy_asset_loader_derive/3d"]
20+
3d = ["bevy/bevy_pbr", "bevy/png", "bevy_asset_loader_derive/3d"]
2121
standard_dynamic_assets = ["dep:bevy_common_assets", "dep:serde"]
2222
progress_tracking = ["dep:iyes_progress"]
2323

2424
[dependencies]
25-
bevy = { version = "0.14.0", default-features = false, features = ["bevy_asset", "bevy_state"] }
26-
bevy_asset_loader_derive = { version = "=0.21.0", path = "../bevy_asset_loader_derive" }
25+
bevy = { version = "0.15.0", default-features = false, features = ["bevy_asset", "bevy_state"] }
26+
bevy_asset_loader_derive = { version = "0.22.0", path = "../bevy_asset_loader_derive" }
2727
anyhow = "1"
2828
path-slash = "0.2"
2929

30-
bevy_common_assets = { version = "0.11.0", features = ["ron"], optional = true }
30+
bevy_common_assets = { version = "0.12.0", features = ["ron"], optional = true }
3131
serde = { version = "1", optional = true }
32-
iyes_progress = { version = "0.12.0", optional = true }
32+
iyes_progress = { version = "0.13.0", optional = true }
3333

3434
[dev-dependencies]
35-
bevy = { version = "0.14.0", features = ["vorbis"] }
35+
bevy = { version = "0.15.0", features = ["vorbis"] }
3636
anyhow = "1"
37-
iyes_progress = { version = "0.12.0" }
38-
bevy_common_assets = { version = "0.11.0", features = ["ron"] }
37+
iyes_progress = { version = "0.13.0" }
38+
bevy_common_assets = { version = "0.12.0", features = ["ron"] }
3939
serde = { version = "1" }
4040
ron = "0.8.1"
4141
trybuild = { version = "1.0" }

bevy_asset_loader/examples/atlas_from_grid.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,36 +35,33 @@ struct MyAssets {
3535
}
3636

3737
fn draw_atlas(mut commands: Commands, my_assets: Res<MyAssets>) {
38-
commands.spawn(Camera2dBundle::default());
38+
commands.spawn(Camera2d);
3939
// draw the original image (whole sprite sheet)
40-
commands.spawn(SpriteBundle {
41-
texture: my_assets.female_adventurer.clone(),
42-
transform: Transform::from_xyz(0., -150., 0.),
43-
..Default::default()
44-
});
40+
commands.spawn((
41+
Sprite::from_image(my_assets.female_adventurer.clone()),
42+
Transform::from_xyz(0., -150., 0.),
43+
));
4544
// draw animated sprite using the texture atlas layout
4645
commands.spawn((
47-
SpriteBundle {
48-
texture: my_assets.female_adventurer.clone(),
49-
transform: Transform::from_xyz(0., 150., 0.),
50-
..Default::default()
51-
},
52-
TextureAtlas::from(my_assets.female_adventurer_layout.clone()),
46+
Sprite::from_atlas_image(
47+
my_assets.female_adventurer.clone(),
48+
TextureAtlas::from(my_assets.female_adventurer_layout.clone()),
49+
),
50+
Transform::from_xyz(0., 150., 0.),
5351
AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
5452
));
5553
}
5654

5755
#[derive(Component)]
5856
struct AnimationTimer(Timer);
5957

60-
fn animate_sprite_system(
61-
time: Res<Time>,
62-
mut sprites_to_animate: Query<(&mut AnimationTimer, &mut TextureAtlas)>,
63-
) {
64-
for (mut timer, mut sprite) in &mut sprites_to_animate {
58+
fn animate_sprite_system(time: Res<Time>, mut query: Query<(&mut AnimationTimer, &mut Sprite)>) {
59+
for (mut timer, mut sprite) in &mut query {
6560
timer.0.tick(time.delta());
6661
if timer.0.finished() {
67-
sprite.index = (sprite.index + 1) % 8;
62+
if let Some(atlas) = &mut sprite.texture_atlas {
63+
atlas.index = (atlas.index + 1) % 8;
64+
}
6865
}
6966
}
7067
}

bevy_asset_loader/examples/configure_loading_state.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,18 @@ impl FromWorld for ExampleResource {
6868
}
6969

7070
fn spawn_player(mut commands: Commands, image_assets: Res<ImageAssets>) {
71-
commands.spawn(Camera2dBundle::default());
72-
commands.spawn(SpriteBundle {
73-
texture: image_assets.player.clone(),
74-
transform: Transform::from_translation(Vec3::new(0., 0., 1.)),
75-
..Default::default()
76-
});
71+
commands.spawn(Camera2d);
72+
commands.spawn((
73+
Sprite::from_image(image_assets.player.clone()),
74+
Transform::from_translation(Vec3::new(0., 0., 1.)),
75+
));
7776
}
7877

7978
fn play_background_audio(mut commands: Commands, audio_assets: Res<AudioAssets>) {
80-
commands.spawn(AudioBundle {
81-
source: audio_assets.background.clone(),
82-
settings: PlaybackSettings::LOOP,
83-
});
79+
commands.spawn((
80+
AudioPlayer(audio_assets.background.clone()),
81+
PlaybackSettings::LOOP,
82+
));
8483
}
8584

8685
#[derive(Clone, Eq, PartialEq, Debug, Hash, Default, States)]

bevy_asset_loader/examples/custom_dynamic_assets.rs

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,46 +26,42 @@ fn main() {
2626
}
2727

2828
fn render_stuff(mut commands: Commands, assets: Res<MyAssets>) {
29-
commands.spawn(Camera3dBundle {
30-
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
31-
..Camera3dBundle::default()
32-
});
33-
commands.spawn(PbrBundle {
34-
mesh: assets.cube.clone(),
35-
material: assets.tree_standard_material.clone(),
36-
transform: Transform::from_xyz(-1., 0., 1.),
37-
..default()
38-
});
39-
commands.spawn(PbrBundle {
40-
mesh: assets.cube.clone(),
41-
material: assets.player_standard_material.clone(),
42-
transform: Transform::from_xyz(1., 0., 1.),
43-
..default()
44-
});
45-
commands.spawn(PointLightBundle {
46-
point_light: PointLight {
29+
commands.spawn((
30+
Camera3d::default(),
31+
Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
32+
));
33+
commands.spawn((
34+
Mesh3d(assets.cube.clone()),
35+
MeshMaterial3d(assets.tree_standard_material.clone()),
36+
Transform::from_xyz(-1., 0., 1.),
37+
));
38+
commands.spawn((
39+
Mesh3d(assets.cube.clone()),
40+
MeshMaterial3d(assets.player_standard_material.clone()),
41+
Transform::from_xyz(1., 0., 1.),
42+
));
43+
commands.spawn((
44+
PointLight {
4745
intensity: 1500.0,
4846
shadows_enabled: true,
4947
..default()
5048
},
51-
transform: Transform::from_xyz(4.0, 8.0, 4.0),
52-
..default()
53-
});
49+
Transform::from_xyz(4.0, 8.0, 4.0),
50+
));
5451

55-
commands.spawn(Camera2dBundle {
56-
camera: Camera {
52+
commands.spawn((
53+
Camera2d,
54+
Camera {
5755
order: 1,
5856
clear_color: ClearColorConfig::None,
5957
..default()
6058
},
61-
..default()
62-
});
59+
));
6360
// Combined image as sprite
64-
commands.spawn(SpriteBundle {
65-
texture: assets.combined_image.clone(),
66-
transform: Transform::from_xyz(0.0, 200.0, 0.0),
67-
..default()
68-
});
61+
commands.spawn((
62+
Sprite::from_image(assets.combined_image.clone()),
63+
Transform::from_xyz(0.0, 200.0, 0.0),
64+
));
6965
}
7066

7167
#[derive(AssetCollection, Resource)]

bevy_asset_loader/examples/dynamic_asset.rs

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -46,41 +46,29 @@ struct AudioAssets {
4646
}
4747

4848
fn spawn_player_and_tree(mut commands: Commands, image_assets: Res<ImageAssets>) {
49-
commands.spawn(Camera2dBundle::default());
49+
commands.spawn(Camera2d);
5050
let mut transform = Transform::from_translation(Vec3::new(0., 0., 1.));
5151
transform.scale = Vec3::splat(0.5);
52-
commands
53-
.spawn((
54-
SpriteBundle {
55-
transform: Transform {
56-
translation: Vec3::new(0., 150., 0.),
57-
..Default::default()
58-
},
59-
texture: image_assets.player.clone(),
60-
..Default::default()
61-
},
62-
TextureAtlas {
63-
layout: image_assets.player_layout.clone(),
64-
index: 0,
65-
},
66-
))
67-
.insert(AnimationTimer(Timer::from_seconds(
68-
0.1,
69-
TimerMode::Repeating,
70-
)))
71-
.insert(Player);
72-
commands.spawn(SpriteBundle {
73-
texture: image_assets.tree.clone(),
74-
transform: Transform::from_translation(Vec3::new(50., 30., 1.)),
75-
..Default::default()
76-
});
52+
commands.spawn((
53+
Sprite::from_atlas_image(
54+
image_assets.player.clone(),
55+
TextureAtlas::from(image_assets.player_layout.clone()),
56+
),
57+
Transform::from_translation(Vec3::new(0., 150., 0.)),
58+
AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
59+
Player,
60+
));
61+
commands.spawn((
62+
Sprite::from_image(image_assets.tree.clone()),
63+
Transform::from_translation(Vec3::new(50., 30., 1.)),
64+
));
7765
}
7866

7967
fn play_background_audio(mut commands: Commands, audio_assets: Res<AudioAssets>) {
80-
commands.spawn(AudioBundle {
81-
source: audio_assets.background.clone(),
82-
settings: PlaybackSettings::LOOP,
83-
});
68+
commands.spawn((
69+
AudioPlayer(audio_assets.background.clone()),
70+
PlaybackSettings::LOOP,
71+
));
8472
}
8573

8674
#[derive(Clone, Eq, PartialEq, Debug, Hash, Default, States)]
@@ -96,14 +84,13 @@ struct Player;
9684
#[derive(Component)]
9785
struct AnimationTimer(Timer);
9886

99-
fn animate_sprite_system(
100-
time: Res<Time>,
101-
mut query: Query<(&mut AnimationTimer, &mut TextureAtlas)>,
102-
) {
87+
fn animate_sprite_system(time: Res<Time>, mut query: Query<(&mut AnimationTimer, &mut Sprite)>) {
10388
for (mut timer, mut sprite) in &mut query {
10489
timer.0.tick(time.delta());
10590
if timer.0.finished() {
106-
sprite.index = (sprite.index + 1) % 8;
91+
if let Some(atlas) = &mut sprite.texture_atlas {
92+
atlas.index = (atlas.index + 1) % 8;
93+
}
10794
}
10895
}
10996
}

0 commit comments

Comments
 (0)