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:
Niklas Eicker 2024-02-13 17:08:03 +01:00 committed by GitHub
parent f1f83bf5bc
commit aca71d09b1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 11 deletions

View file

@ -8,7 +8,7 @@ use bevy_utils::HashMap;
/// 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.
///
/// 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`]).
///
/// [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.
/// 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.
/// 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.
///
/// 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)
#[derive(Component, Default, Debug, Clone, Reflect)]
pub struct TextureAtlas {
/// Texture atlas handle
/// Texture atlas layout handle
pub layout: Handle<TextureAtlasLayout>,
/// Texture atlas section index
pub index: usize,

View file

@ -39,11 +39,11 @@ fn animate_sprite(
fn setup(
mut commands: Commands,
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 atlas = TextureAtlasLayout::from_grid(Vec2::new(24.0, 24.0), 7, 1, None, None);
let texture_atlas = texture_atlases.add(atlas);
let layout = TextureAtlasLayout::from_grid(Vec2::new(24.0, 24.0), 7, 1, None, None);
let texture_atlas_layout = texture_atlas_layouts.add(layout);
// Use only the subset of sprites in the sheet that make up the run animation
let animation_indices = AnimationIndices { first: 1, last: 6 };
commands.spawn(Camera2dBundle::default());
@ -51,7 +51,7 @@ fn setup(
SpriteSheetBundle {
texture,
atlas: TextureAtlas {
layout: texture_atlas,
layout: texture_atlas_layout,
index: animation_indices.first,
},
transform: Transform::from_scale(Vec3::splat(6.0)),

View file

@ -40,7 +40,6 @@ fn check_textures(
mut events: EventReader<AssetEvent<LoadedFolder>>,
) {
// 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() {
if event.is_loaded_with_dependencies(&rpg_sprite_folder.0) {
next_state.set(AppState::Finished);
@ -207,7 +206,7 @@ fn create_texture_atlas(
sampling: Option<ImageSampler>,
textures: &mut ResMut<Assets<Image>>,
) -> (TextureAtlasLayout, Handle<Image>) {
// Build a `TextureAtlas` using the individual sprites
// Build a texture atlas using the individual sprites
let mut texture_atlas_builder =
TextureAtlasBuilder::default().padding(padding.unwrap_or_default());
for handle in folder.handles.iter() {
@ -223,14 +222,14 @@ fn create_texture_atlas(
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);
// Update the sampling settings of the texture atlas
let image = textures.get_mut(&texture).unwrap();
image.sampler = sampling.unwrap_or_default();
(texture_atlas, texture)
(texture_atlas_layout, texture)
}
/// Create and spawn a sprite from a texture atlas