Skip to content

Commit

Permalink
Apply recommended changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
test90 committed Oct 3, 2020
1 parent f4af401 commit 8a460ce
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions crates/bevy_sprite/src/texture_atlas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Texture>,
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<Texture>,
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;
Expand All @@ -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,
Expand Down

0 comments on commit 8a460ce

Please sign in to comment.