Skip to content

Commit

Permalink
Normalization anchor for sprite slice in dimensions of this slice (#1…
Browse files Browse the repository at this point in the history
…2769)

# 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)
  • Loading branch information
bugsweeper committed Apr 16, 2024
1 parent 6b0e3fa commit a5fa32e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion crates/bevy_sprite/src/texture_slice/computed_slices.rs
Expand Up @@ -53,10 +53,21 @@ impl ComputedTextureSlices {
flip_x,
flip_y,
image_handle_id: handle.id(),
anchor: sprite.anchor.as_vec(),
anchor: Self::redepend_anchor_from_sprite_to_slice(sprite, slice),
}
})
}

fn redepend_anchor_from_sprite_to_slice(sprite: &Sprite, slice: &TextureSlice) -> Vec2 {
let sprite_size = sprite
.custom_size
.unwrap_or(sprite.rect.unwrap_or_default().size());
if sprite_size == Vec2::ZERO {
sprite.anchor.as_vec()
} else {
sprite.anchor.as_vec() * sprite_size / slice.draw_size
}
}
}

/// Generates sprite slices for a `sprite` given a `scale_mode`. The slices
Expand Down

0 comments on commit a5fa32e

Please sign in to comment.