Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify Texture Atlas rework migration guide #1028

Merged
47 changes: 45 additions & 2 deletions content/learn/migration-guides/0.12-to-0.13.md
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,20 @@ Renamed `PbrInput::occlusion` to `diffuse_occlusion`, and added `specular_occlus
<div class="migration-guide-area-tag">Rendering</div>
</div>

The `TextureAtlas` asset that previously contained both the atlas layout and image handle was renamed to `TextureAtlasLayout` with the image handle portion moved to a separate `Handle<Image>` available from `SpriteSheetBundle::texture` or `AtlasImageBundle::image`.

`TextureAtlasSprite` was removed and replaced by a new component, `TextureAtlas`, which now holds the atlas index. The `Sprite` component can be used for `flip_x`, `flip_y`, `custom_size`, `anchor`, and `color`.

`SpriteSheetBundle` now uses a `Sprite` instead of a `TextureAtlasSprite` component and a `TextureAtlas` component instead of a `Handle<TextureAtlaslayout>`.

`DynamicTextureAtlasBuilder::add_texture` takes an additional `&Handle<Image>` parameter.

`TextureAtlasLayout::from_grid` no longer takes a `Handle<Image>` parameter.

`TextureAtlasBuilder::finish` now returns a `Result<(TextureAtlasLayout, Image), TextureAtlasBuilderError>`.

`UiTextureAtlasImage` was removed. The `AtlasImageBundle` is now identical to `ImageBundle` with an additional `TextureAtlas`.

- Sprites

```diff
Expand All @@ -894,12 +908,14 @@ fn my_system(
commands.spawn(SpriteSheetBundle {
- sprite: TextureAtlasSprite::new(0),
- texture_atlas: atlas_handle,
// the new sprite initialization is covered by the `..default()` expression; however, it is added to showcase migration
+ sprite: Sprite::default()
+ atlas: TextureAtlas {
+ layout: layout_handle,
+ index: 0
+ },
+ texture: texture_handle,
..Default::default()
..default()
});
}
```
Expand Down Expand Up @@ -933,11 +949,38 @@ fn my_system(
+ flip_x: false,
+ flip_y: false,
+ },
..Default::default()
..default()
});
}
```

- Queries (taken from the [sprite sheet example](https://bevyengine.org/examples/2D%20Rendering/sprite-sheet/))

```diff
fn animate_sprite(
time: Res<Time>,
mut query: Query<(
&AnimationIndices,
&mut AnimationTimer,
- &mut TextureAtlasSprite)>,
+ &mut TextureAtlas)>,
) {
- for (indices, mut timer, mut sprite) in &mut query {
+ for (indices, mut timer, mut atlas) in &mut query {
timer.tick(time.delta());
if timer.just_finished() {
- sprite.index = if sprite.index == indices.last {
+ atlas.index = if atlas.index == indices.last {
indices.first
} else {
- sprite.index + 1
+ atlas.index + 1
};
}
}
}
```

### [Exposure settings (adopted)](https://github.com/bevyengine/bevy/pull/11347)

<div class="migration-guide-area-tags">
Expand Down