Help with migration with the Texture Atlas rework on main branch #11488
-
Wanted to give my question a little more visibility: I'm a bit confused on the migration guide Here is an example of code I'll need to migrate: pub fn spawn(
texture: &Handle<TextureAtlas>,
builder: &mut ChildBuilder,
color: Color,
) {
builder.spawn((
SpriteSheetBundle {
texture_atlas: texture.clone(),
sprite: TextureAtlasSprite {
color,
index: 1,
..Default::default()
},
..Default::default()
},
));
} The diff in the migration guide shows: fn my_system(
mut images: ResMut<Assets<Image>>,
- mut atlases: ResMut<Assets<TextureAtlas>>,
+ mut atlases: ResMut<Assets<TextureAtlasLayout>>,
asset_server: Res<AssetServer>
) {
let texture_handle: asset_server.load("my_texture.png");
- let layout = TextureAtlas::from_grid(texture_handle, Vec2::new(25.0, 25.0), 5, 5, None, None);
+ let layout = TextureAtlasLayout::from_grid(Vec2::new(25.0, 25.0), 5, 5, None, None);
let layout_handle = atlases.add(layout);
commands.spawn(SpriteSheetBundle {
- sprite: TextureAtlasSprite::new(0),
- texture_atlas: atlas_handle,
+ atlas: TextureAtlas {
+ layout: layout_handle,
+ index: 0
+ },
+ texture: texture_handle,
..Default::default()
});
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The new That component stores both the texture layout handle, and the section index. In your example you need an extra argument because the pub fn spawn(
+ image: &Handle<Image>,
texture: &Handle<TextureAtlasLayout>,
builder: &mut ChildBuilder,
color: Color,
) {
builder.spawn((
SpriteSheetBundle {
texture_atlas: TextureAtlas {
layout: texture.clone(),
index: 1
},
sprite: Sprite {
color,
..Default::default()
},
+ texture: image.clone(),
..Default::default()
},
));
} |
Beta Was this translation helpful? Give feedback.
The new
SpriteSheetBundle
is now aSpriteBundle
with one additional component:TextureAtlas
That component stores both the texture layout handle, and the section index.
In your example you need an extra argument because the
TextureLayoutHandle
no longer stores theHandle<Image>