Call a TextureAtlasLayout a layout and not an atlas (#11783)
Make the renamings/changes regarding texture atlases a bit less confusing by calling `TextureAtlasLayout` a layout, not a texture atlas. Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
This commit is contained in:
parent
f1f83bf5bc
commit
aca71d09b1
@ -8,7 +8,7 @@ use bevy_utils::HashMap;
|
|||||||
/// Stores a map used to lookup the position of a texture in a [`TextureAtlas`].
|
/// Stores a map used to lookup the position of a texture in a [`TextureAtlas`].
|
||||||
/// This can be used to either use and look up a specific section of a texture, or animate frame-by-frame as a sprite sheet.
|
/// This can be used to either use and look up a specific section of a texture, or animate frame-by-frame as a sprite sheet.
|
||||||
///
|
///
|
||||||
/// Optionaly it can store a mapping from sub texture handles to the related area index (see
|
/// Optionally it can store a mapping from sub texture handles to the related area index (see
|
||||||
/// [`TextureAtlasBuilder`]).
|
/// [`TextureAtlasBuilder`]).
|
||||||
///
|
///
|
||||||
/// [Example usage animating sprite.](https://github.com/bevyengine/bevy/blob/latest/examples/2d/sprite_sheet.rs)
|
/// [Example usage animating sprite.](https://github.com/bevyengine/bevy/blob/latest/examples/2d/sprite_sheet.rs)
|
||||||
@ -35,7 +35,7 @@ pub struct TextureAtlasLayout {
|
|||||||
/// It stores a handle to [`TextureAtlasLayout`] and the index of the current section of the atlas.
|
/// It stores a handle to [`TextureAtlasLayout`] and the index of the current section of the atlas.
|
||||||
/// The texture atlas contains various *sections* of a given texture, allowing users to have a single
|
/// The texture atlas contains various *sections* of a given texture, allowing users to have a single
|
||||||
/// image file for either sprite animation or global mapping.
|
/// image file for either sprite animation or global mapping.
|
||||||
/// You can change the texture [`index`](Self::index) of the atlas to animate the sprite or dsplay only a *section* of the texture
|
/// You can change the texture [`index`](Self::index) of the atlas to animate the sprite or display only a *section* of the texture
|
||||||
/// for efficient rendering of related game objects.
|
/// for efficient rendering of related game objects.
|
||||||
///
|
///
|
||||||
/// Check the following examples for usage:
|
/// Check the following examples for usage:
|
||||||
@ -43,7 +43,7 @@ pub struct TextureAtlasLayout {
|
|||||||
/// - [`texture atlas example`](https://github.com/bevyengine/bevy/blob/latest/examples/2d/texture_atlas.rs)
|
/// - [`texture atlas example`](https://github.com/bevyengine/bevy/blob/latest/examples/2d/texture_atlas.rs)
|
||||||
#[derive(Component, Default, Debug, Clone, Reflect)]
|
#[derive(Component, Default, Debug, Clone, Reflect)]
|
||||||
pub struct TextureAtlas {
|
pub struct TextureAtlas {
|
||||||
/// Texture atlas handle
|
/// Texture atlas layout handle
|
||||||
pub layout: Handle<TextureAtlasLayout>,
|
pub layout: Handle<TextureAtlasLayout>,
|
||||||
/// Texture atlas section index
|
/// Texture atlas section index
|
||||||
pub index: usize,
|
pub index: usize,
|
||||||
|
@ -39,11 +39,11 @@ fn animate_sprite(
|
|||||||
fn setup(
|
fn setup(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
asset_server: Res<AssetServer>,
|
asset_server: Res<AssetServer>,
|
||||||
mut texture_atlases: ResMut<Assets<TextureAtlasLayout>>,
|
mut texture_atlas_layouts: ResMut<Assets<TextureAtlasLayout>>,
|
||||||
) {
|
) {
|
||||||
let texture = asset_server.load("textures/rpg/chars/gabe/gabe-idle-run.png");
|
let texture = asset_server.load("textures/rpg/chars/gabe/gabe-idle-run.png");
|
||||||
let atlas = TextureAtlasLayout::from_grid(Vec2::new(24.0, 24.0), 7, 1, None, None);
|
let layout = TextureAtlasLayout::from_grid(Vec2::new(24.0, 24.0), 7, 1, None, None);
|
||||||
let texture_atlas = texture_atlases.add(atlas);
|
let texture_atlas_layout = texture_atlas_layouts.add(layout);
|
||||||
// Use only the subset of sprites in the sheet that make up the run animation
|
// Use only the subset of sprites in the sheet that make up the run animation
|
||||||
let animation_indices = AnimationIndices { first: 1, last: 6 };
|
let animation_indices = AnimationIndices { first: 1, last: 6 };
|
||||||
commands.spawn(Camera2dBundle::default());
|
commands.spawn(Camera2dBundle::default());
|
||||||
@ -51,7 +51,7 @@ fn setup(
|
|||||||
SpriteSheetBundle {
|
SpriteSheetBundle {
|
||||||
texture,
|
texture,
|
||||||
atlas: TextureAtlas {
|
atlas: TextureAtlas {
|
||||||
layout: texture_atlas,
|
layout: texture_atlas_layout,
|
||||||
index: animation_indices.first,
|
index: animation_indices.first,
|
||||||
},
|
},
|
||||||
transform: Transform::from_scale(Vec3::splat(6.0)),
|
transform: Transform::from_scale(Vec3::splat(6.0)),
|
||||||
|
@ -40,7 +40,6 @@ fn check_textures(
|
|||||||
mut events: EventReader<AssetEvent<LoadedFolder>>,
|
mut events: EventReader<AssetEvent<LoadedFolder>>,
|
||||||
) {
|
) {
|
||||||
// Advance the `AppState` once all sprite handles have been loaded by the `AssetServer`
|
// Advance the `AppState` once all sprite handles have been loaded by the `AssetServer`
|
||||||
// and that the the font has been loaded by the `FontSystem`.
|
|
||||||
for event in events.read() {
|
for event in events.read() {
|
||||||
if event.is_loaded_with_dependencies(&rpg_sprite_folder.0) {
|
if event.is_loaded_with_dependencies(&rpg_sprite_folder.0) {
|
||||||
next_state.set(AppState::Finished);
|
next_state.set(AppState::Finished);
|
||||||
@ -207,7 +206,7 @@ fn create_texture_atlas(
|
|||||||
sampling: Option<ImageSampler>,
|
sampling: Option<ImageSampler>,
|
||||||
textures: &mut ResMut<Assets<Image>>,
|
textures: &mut ResMut<Assets<Image>>,
|
||||||
) -> (TextureAtlasLayout, Handle<Image>) {
|
) -> (TextureAtlasLayout, Handle<Image>) {
|
||||||
// Build a `TextureAtlas` using the individual sprites
|
// Build a texture atlas using the individual sprites
|
||||||
let mut texture_atlas_builder =
|
let mut texture_atlas_builder =
|
||||||
TextureAtlasBuilder::default().padding(padding.unwrap_or_default());
|
TextureAtlasBuilder::default().padding(padding.unwrap_or_default());
|
||||||
for handle in folder.handles.iter() {
|
for handle in folder.handles.iter() {
|
||||||
@ -223,14 +222,14 @@ fn create_texture_atlas(
|
|||||||
texture_atlas_builder.add_texture(Some(id), texture);
|
texture_atlas_builder.add_texture(Some(id), texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
let (texture_atlas, texture) = texture_atlas_builder.finish().unwrap();
|
let (texture_atlas_layout, texture) = texture_atlas_builder.finish().unwrap();
|
||||||
let texture = textures.add(texture);
|
let texture = textures.add(texture);
|
||||||
|
|
||||||
// Update the sampling settings of the texture atlas
|
// Update the sampling settings of the texture atlas
|
||||||
let image = textures.get_mut(&texture).unwrap();
|
let image = textures.get_mut(&texture).unwrap();
|
||||||
image.sampler = sampling.unwrap_or_default();
|
image.sampler = sampling.unwrap_or_default();
|
||||||
|
|
||||||
(texture_atlas, texture)
|
(texture_atlas_layout, texture)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create and spawn a sprite from a texture atlas
|
/// Create and spawn a sprite from a texture atlas
|
||||||
|
Loading…
Reference in New Issue
Block a user