Skip to content

Commit c872148

Browse files
committed
Fixed issue with sprites
1 parent 3476f43 commit c872148

File tree

1 file changed

+13
-6
lines changed
  • crates/bevy_sprite/src/render

1 file changed

+13
-6
lines changed

crates/bevy_sprite/src/render/mod.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -373,28 +373,25 @@ pub fn prepare_sprites(
373373
// Impossible starting values that will be replaced on the first iteration
374374
let mut current_batch_handle = HandleId::Id(Uuid::nil(), u64::MAX);
375375
let mut current_image_size = Vec2::ZERO;
376-
let mut current_z_order = 0.0;
376+
let mut z_order = 0.0;
377377

378378
// Vertex buffer indices
379379
let mut index_start = 0;
380380
let mut index_end = 0;
381381

382382
for extracted_sprite in sprites {
383-
if extracted_sprite.image_handle_id != current_batch_handle
384-
|| extracted_sprite.transform.translation.z != current_z_order
385-
{
383+
if extracted_sprite.image_handle_id != current_batch_handle {
386384
if let Some(gpu_image) =
387385
gpu_images.get(&Handle::weak(extracted_sprite.image_handle_id))
388386
{
389387
current_image_size = gpu_image.size;
390388
current_batch_handle = extracted_sprite.image_handle_id;
391-
current_z_order = extracted_sprite.transform.translation.z;
392389
if index_start != index_end {
393390
commands.spawn().insert(SpriteBatch {
394391
range: index_start..index_end,
395392
image_handle_id: current_batch_handle,
396393
colored,
397-
z_order: current_z_order,
394+
z_order,
398395
});
399396
index_start = index_end;
400397
}
@@ -454,6 +451,16 @@ pub fn prepare_sprites(
454451
}
455452
}
456453
index_end += QUAD_INDICES.len() as u32;
454+
z_order = extracted_sprite.transform.translation.z;
455+
}
456+
// if start != end, there is one last batch to process
457+
if index_start != index_end {
458+
commands.spawn().insert(SpriteBatch {
459+
range: index_start..index_end,
460+
image_handle_id: current_batch_handle,
461+
colored,
462+
z_order,
463+
});
457464
}
458465
}
459466
sprite_meta

0 commit comments

Comments
 (0)