Merge TextureAtlas::from_grid_with_padding into TextureAtlas::from_grid through option arguments (#6057)
This is an adoption of #3775 This merges `TextureAtlas` `from_grid_with_padding` into `from_grid` , adding optional padding and optional offset. Since the orignal PR, the offset had already been added to from_grid_with_padding through #4836 ## Changelog - Added `padding` and `offset` arguments to `TextureAtlas::from_grid` - Removed `TextureAtlas::from_grid_with_padding` ## Migration Guide `TextureAtlas::from_grid_with_padding` was merged into `from_grid` which takes two additional parameters for padding and an offset. ``` // 0.8 TextureAtlas::from_grid(texture_handle, Vec2::new(24.0, 24.0), 7, 1); // 0.9 TextureAtlas::from_grid(texture_handle, Vec2::new(24.0, 24.0), 7, 1, None, None) // 0.8 TextureAtlas::from_grid_with_padding(texture_handle, Vec2::new(24.0, 24.0), 7, 1, Vec2::new(4.0, 4.0)); // 0.9 TextureAtlas::from_grid(texture_handle, Vec2::new(24.0, 24.0), 7, 1, Some(Vec2::new(4.0, 4.0)), None) ``` Co-authored-by: olefish <88390729+oledfish@users.noreply.github.com>
This commit is contained in:
parent
c4d1ae0a47
commit
b91945b54d
@ -69,29 +69,19 @@ impl TextureAtlas {
|
|||||||
|
|
||||||
/// Generate a `TextureAtlas` by splitting a texture into a grid where each
|
/// Generate a `TextureAtlas` by splitting a texture into a grid where each
|
||||||
/// `tile_size` by `tile_size` grid-cell is one of the textures in the
|
/// `tile_size` by `tile_size` grid-cell is one of the textures in the
|
||||||
/// atlas. Resulting `TextureAtlas` is indexed left to right, top to bottom.
|
/// atlas. Grid cells are separated by some `padding`, and the grid starts
|
||||||
|
/// at `offset` pixels from the top left corner. Resulting `TextureAtlas` is
|
||||||
|
/// indexed left to right, top to bottom.
|
||||||
pub fn from_grid(
|
pub fn from_grid(
|
||||||
texture: Handle<Image>,
|
texture: Handle<Image>,
|
||||||
tile_size: Vec2,
|
tile_size: Vec2,
|
||||||
columns: usize,
|
columns: usize,
|
||||||
rows: usize,
|
rows: usize,
|
||||||
|
padding: Option<Vec2>,
|
||||||
|
offset: Option<Vec2>,
|
||||||
) -> TextureAtlas {
|
) -> TextureAtlas {
|
||||||
Self::from_grid_with_padding(texture, tile_size, columns, rows, Vec2::ZERO, Vec2::ZERO)
|
let padding = padding.unwrap_or_default();
|
||||||
}
|
let offset = offset.unwrap_or_default();
|
||||||
|
|
||||||
/// Generate a `TextureAtlas` by splitting a texture into a grid where each
|
|
||||||
/// `tile_size` by `tile_size` grid-cell is one of the textures in the
|
|
||||||
/// atlas. Grid cells are separated by some `padding`, and the grid starts
|
|
||||||
/// at `offset` pixels from the top left corner. Resulting `TextureAtlas` is
|
|
||||||
/// indexed left to right, top to bottom.
|
|
||||||
pub fn from_grid_with_padding(
|
|
||||||
texture: Handle<Image>,
|
|
||||||
tile_size: Vec2,
|
|
||||||
columns: usize,
|
|
||||||
rows: usize,
|
|
||||||
padding: Vec2,
|
|
||||||
offset: Vec2,
|
|
||||||
) -> TextureAtlas {
|
|
||||||
let mut sprites = Vec::new();
|
let mut sprites = Vec::new();
|
||||||
let mut current_padding = Vec2::ZERO;
|
let mut current_padding = Vec2::ZERO;
|
||||||
|
|
||||||
|
|||||||
@ -39,7 +39,8 @@ fn setup(
|
|||||||
mut texture_atlases: ResMut<Assets<TextureAtlas>>,
|
mut texture_atlases: ResMut<Assets<TextureAtlas>>,
|
||||||
) {
|
) {
|
||||||
let texture_handle = asset_server.load("textures/rpg/chars/gabe/gabe-idle-run.png");
|
let texture_handle = asset_server.load("textures/rpg/chars/gabe/gabe-idle-run.png");
|
||||||
let texture_atlas = TextureAtlas::from_grid(texture_handle, Vec2::new(24.0, 24.0), 7, 1);
|
let texture_atlas =
|
||||||
|
TextureAtlas::from_grid(texture_handle, Vec2::new(24.0, 24.0), 7, 1, None, None);
|
||||||
let texture_atlas_handle = texture_atlases.add(texture_atlas);
|
let texture_atlas_handle = texture_atlases.add(texture_atlas);
|
||||||
commands.spawn(Camera2dBundle::default());
|
commands.spawn(Camera2dBundle::default());
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
|
|||||||
@ -46,7 +46,8 @@ fn setup(
|
|||||||
let half_y = (map_size.y / 2.0) as i32;
|
let half_y = (map_size.y / 2.0) as i32;
|
||||||
|
|
||||||
let texture_handle = assets.load("textures/rpg/chars/gabe/gabe-idle-run.png");
|
let texture_handle = assets.load("textures/rpg/chars/gabe/gabe-idle-run.png");
|
||||||
let texture_atlas = TextureAtlas::from_grid(texture_handle, Vec2::new(24.0, 24.0), 7, 1);
|
let texture_atlas =
|
||||||
|
TextureAtlas::from_grid(texture_handle, Vec2::new(24.0, 24.0), 7, 1, None, None);
|
||||||
let texture_atlas_handle = texture_atlases.add(texture_atlas);
|
let texture_atlas_handle = texture_atlases.add(texture_atlas);
|
||||||
|
|
||||||
// Spawns the camera
|
// Spawns the camera
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user