Skip to content

Commit

Permalink
Merge pull request #6 from BLumbye/main
Browse files Browse the repository at this point in the history
Updated to Bevy 0.14.0
  • Loading branch information
merwaaan authored Jul 6, 2024
2 parents 0f1b3ba + 6b3f3a2 commit 28c4b26
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 74 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ exclude = [
]

[dependencies]
bevy = { version = "0.13.1", default-features = false, features = ["bevy_sprite"] }
bevy = { version = "0.14.0", default-features = false, features = ["bevy_sprite"] }
itertools = "0.12.1"
visibility = "0.1.0"

[dev-dependencies]
approx = "0.5.1"
bevy = { version = "0.13.1", default-features = true }
bevy = { version = "0.14.0", default-features = true }
criterion = "0.5.1"
rand = "0.8.5"

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fn setup(
let texture = assets.load("character.png");

let layout = atlas_layouts.add(TextureAtlasLayout::from_grid(
Vec2::new(96.0, 96.0),
UVec2::new(96, 96),
8,
8,
None,
Expand Down
23 changes: 13 additions & 10 deletions benches/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,27 @@ fn basic(c: &mut Criterion) {
.add_plugins(SpritesheetAnimationPlugin)
.finish();

let assets = app.world.get_resource::<AssetServer>().unwrap();
let assets = app.world().get_resource::<AssetServer>().unwrap();

let texture = assets.load("character.png");

let mut atlas_layouts = app
.world
.world_mut()
.get_resource_mut::<Assets<TextureAtlasLayout>>()
.unwrap();

let layout = atlas_layouts.add(TextureAtlasLayout::from_grid(
Vec2::new(96.0, 96.0),
UVec2::new(96, 96),
8,
8,
None,
None,
));

let mut library = app.world.get_resource_mut::<SpritesheetLibrary>().unwrap();
let mut library = app
.world_mut()
.get_resource_mut::<SpritesheetLibrary>()
.unwrap();

let clip_id = library.new_clip(|clip| {
clip.push_frame_indices([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
Expand All @@ -39,13 +42,13 @@ fn basic(c: &mut Criterion) {
});

for _ in 0..1000 {
app.world.spawn((
SpriteSheetBundle {
app.world_mut().spawn((
SpriteBundle {
texture: texture.clone(),
atlas: TextureAtlas {
layout: layout.clone(),
..default()
},
..default()
},
TextureAtlas {
layout: layout.clone(),
..default()
},
SpritesheetAnimation::from_id(animation_id),
Expand Down
12 changes: 6 additions & 6 deletions examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn spawn_sprite(
let texture = assets.load("character.png");

let layout = atlas_layouts.add(TextureAtlasLayout::from_grid(
Vec2::new(96.0, 96.0),
UVec2::new(96, 96),
8,
8,
None,
Expand All @@ -76,12 +76,12 @@ fn spawn_sprite(
// Spawn a sprite with Bevy's built-in SpriteSheetBundle

commands.spawn((
SpriteSheetBundle {
SpriteBundle {
texture,
atlas: TextureAtlas {
layout,
..default()
},
..default()
},
TextureAtlas {
layout,
..default()
},
// Add a SpritesheetAnimation component that references our animation
Expand Down
12 changes: 6 additions & 6 deletions examples/character.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn setup(
let texture = assets.load("character.png");

let layout = atlas_layouts.add(TextureAtlasLayout::from_grid(
Vec2::new(96.0, 96.0),
UVec2::new(96, 96),
8,
8,
None,
Expand Down Expand Up @@ -86,12 +86,12 @@ fn setup(
// Spawn the character

commands.spawn((
SpriteSheetBundle {
SpriteBundle {
texture,
atlas: TextureAtlas {
layout,
..default()
},
..default()
},
TextureAtlas {
layout,
..default()
},
SpritesheetAnimation::from_id(idle_anim_id),
Expand Down
12 changes: 6 additions & 6 deletions examples/composition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn setup(
let texture = assets.load("character.png");

let layout = atlas_layouts.add(TextureAtlasLayout::from_grid(
Vec2::new(96.0, 96.0),
UVec2::new(96, 96),
8,
8,
None,
Expand Down Expand Up @@ -72,12 +72,12 @@ fn setup(
// Spawn a sprite that uses the animation

commands.spawn((
SpriteSheetBundle {
SpriteBundle {
texture,
atlas: TextureAtlas {
layout,
..default()
},
..default()
},
TextureAtlas {
layout,
..default()
},
SpritesheetAnimation::from_id(anim_id),
Expand Down
23 changes: 12 additions & 11 deletions examples/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
pub mod common;

use bevy::{
color::palettes::css::{DEEP_PINK, GRAY, YELLOW},
prelude::*,
sprite::{MaterialMesh2dBundle, Mesh2dHandle},
};
Expand Down Expand Up @@ -48,7 +49,7 @@ fn setup(
let texture = assets.load("character.png");

let layout = atlas_layouts.add(TextureAtlasLayout::from_grid(
Vec2::new(96.0, 96.0),
UVec2::new(96, 96),
8,
8,
None,
Expand Down Expand Up @@ -99,12 +100,12 @@ fn setup(
// Spawn a sprite using the animation

commands.spawn((
SpriteSheetBundle {
SpriteBundle {
texture,
atlas: TextureAtlas {
layout,
..default()
},
..default()
},
TextureAtlas {
layout,
..default()
},
SpritesheetAnimation::from_id(animation_id),
Expand Down Expand Up @@ -221,9 +222,9 @@ fn show_triggered_events(

for (mut color, event_type) in &mut squares {
if triggered_events.contains(event_type) {
color.0 = Color::PINK;
color.0 = Color::from(DEEP_PINK);
} else {
color.0 = Color::GRAY;
color.0 = Color::from(GRAY);
}
}
}
Expand Down Expand Up @@ -259,7 +260,7 @@ fn spawn_visual_effects(
commands.spawn((
MaterialMesh2dBundle {
mesh: Mesh2dHandle(meshes.add(Circle { radius: 3.0 })),
material: materials.add(Color::YELLOW),
material: materials.add(Color::from(YELLOW)),
transform: Transform::from_xyz(20.0, 15.0, 0.0),
..default()
},
Expand Down Expand Up @@ -314,11 +315,11 @@ fn animate_footsteps(
if let Some(material) = materials.get_mut(material_handle) {
material
.color
.set_a(material.color.a() - time.delta_seconds() * 4.0);
.set_alpha(material.color.alpha() - time.delta_seconds() * 4.0);

// Despawn when transparent

if material.color.a() <= 0.0 {
if material.color.alpha() <= 0.0 {
commands.entity(entity).despawn();
}
}
Expand Down
12 changes: 6 additions & 6 deletions examples/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn setup(
let texture = assets.load("ball.png");

let layout = atlas_layouts.add(TextureAtlasLayout::from_grid(
Vec2::new(100.0, 20.0),
UVec2::new(100, 20),
1,
30,
None,
Expand Down Expand Up @@ -102,15 +102,15 @@ fn setup(

commands
.spawn((
SpriteSheetBundle {
SpriteBundle {
texture: texture.clone(),
atlas: TextureAtlas {
layout: layout.clone(),
..default()
},
transform: Transform::from_translation(grid_position(6, 6, index as u32)),
..default()
},
TextureAtlas {
layout: layout.clone(),
..default()
},
SpritesheetAnimation::from_id(animation_id),
))
// Add a label describing the parameters
Expand Down
12 changes: 6 additions & 6 deletions examples/stress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn setup(
let texture = assets.load("character.png");

let layout = atlas_layouts.add(TextureAtlasLayout::from_grid(
Vec2::new(96.0, 96.0),
UVec2::new(96, 96),
8,
8,
None,
Expand Down Expand Up @@ -91,15 +91,15 @@ fn setup(
let animation = animation_ids.choose(&mut rng).unwrap();

commands.spawn((
SpriteSheetBundle {
SpriteBundle {
texture: texture.clone(),
atlas: TextureAtlas {
layout: layout.clone(),
..default()
},
transform: Transform::from_translation(random_position()),
..default()
},
TextureAtlas {
layout: layout.clone(),
..default()
},
SpritesheetAnimation::from_id(*animation),
));
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
//! let texture = assets.load("character.png");
//!
//! let layout = atlas_layouts.add(TextureAtlasLayout::from_grid(
//! Vec2::new(96.0, 96.0),
//! UVec2::new(96, 96),
//! 8,
//! 8,
//! None,
Expand Down
Loading

0 comments on commit 28c4b26

Please sign in to comment.