Skip to content

Commit a5fa32e

Browse files
authored
Normalization anchor for sprite slice in dimensions of this slice (#12769)
# Objective Fixes #12408 . Fixes #12680. ## Solution - Recaclulated anchor from dimensions of sprite to dimension of each part of it (each part contains its own anchor)
1 parent 6b0e3fa commit a5fa32e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

crates/bevy_sprite/src/texture_slice/computed_slices.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,21 @@ impl ComputedTextureSlices {
5353
flip_x,
5454
flip_y,
5555
image_handle_id: handle.id(),
56-
anchor: sprite.anchor.as_vec(),
56+
anchor: Self::redepend_anchor_from_sprite_to_slice(sprite, slice),
5757
}
5858
})
5959
}
60+
61+
fn redepend_anchor_from_sprite_to_slice(sprite: &Sprite, slice: &TextureSlice) -> Vec2 {
62+
let sprite_size = sprite
63+
.custom_size
64+
.unwrap_or(sprite.rect.unwrap_or_default().size());
65+
if sprite_size == Vec2::ZERO {
66+
sprite.anchor.as_vec()
67+
} else {
68+
sprite.anchor.as_vec() * sprite_size / slice.draw_size
69+
}
70+
}
6071
}
6172

6273
/// Generates sprite slices for a `sprite` given a `scale_mode`. The slices

0 commit comments

Comments
 (0)