From 8a460cecad1f73c30f21555fec92a9a5032727a6 Mon Sep 17 00:00:00 2001 From: M Date: Fri, 11 Sep 2020 17:11:22 -0400 Subject: [PATCH] Apply recommended changes. --- crates/bevy_sprite/src/texture_atlas.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/crates/bevy_sprite/src/texture_atlas.rs b/crates/bevy_sprite/src/texture_atlas.rs index 63252c1d8bb36..6bdb6ffc4e72e 100644 --- a/crates/bevy_sprite/src/texture_atlas.rs +++ b/crates/bevy_sprite/src/texture_atlas.rs @@ -63,28 +63,26 @@ impl TextureAtlas { } /// Generate a `TextureAtlas` by splitting a texture into a grid where each - /// cell of the grid is one of the textures in the atlas + /// cell of the grid of `tile_size` is one of the textures in the atlas pub fn from_grid( texture: Handle, - size: Vec2, + tile_size: Vec2, columns: usize, rows: usize, ) -> TextureAtlas { - Self::from_grid_with_padding(texture, size, columns, rows, Vec2::new(0f32, 0f32)) + Self::from_grid_with_padding(texture, tile_size, columns, rows, Vec2::new(0f32, 0f32)) } /// Generate a `TextureAtlas` by splitting a texture into a grid where each - /// cell of the grid is one of the textures in the atlas and is separated by + /// cell of the grid of `tile_size` is one of the textures in the atlas and is separated by /// some `padding` in the texture pub fn from_grid_with_padding( texture: Handle, - size: Vec2, + tile_size: Vec2, columns: usize, rows: usize, padding: Vec2, ) -> TextureAtlas { - let texture_width = size.x() / columns as f32; - let texture_height = size.y() / rows as f32; let mut sprites = Vec::new(); let mut x_padding = 0.0; let mut y_padding = 0.0; @@ -100,18 +98,18 @@ impl TextureAtlas { sprites.push(Rect { min: Vec2::new( - (x as f32 * texture_width) + x_padding, - (y as f32 * texture_height) + y_padding, + tile_size.x() + x_padding, + tile_size.y() + y_padding, ), max: Vec2::new( - (x + 1) as f32 * texture_width, - (y + 1) as f32 * texture_height, + (x + 1) as f32 * tile_size.x(), + (y + 1) as f32 * tile_size.y(), ), }) } } TextureAtlas { - size, + size: Vec2::new(tile_size.x() * columns, tile_size.y() * rows), textures: sprites, texture, texture_handles: None,