Skip to content

Commit

Permalink
Update example and fix tile size calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
test90 committed Oct 3, 2020
1 parent c42c449 commit 6f423fe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
18 changes: 12 additions & 6 deletions crates/bevy_sprite/src/texture_atlas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,23 @@ impl TextureAtlas {
x_padding = padding.x();
}

let rect_min = Vec2::new(
(tile_size.x() + x_padding) * x as f32,
(tile_size.y() + y_padding) * y as f32,
);

sprites.push(Rect {
min: Vec2::new(tile_size.x() + x_padding, tile_size.y() + y_padding),
max: Vec2::new(
(x + 1) as f32 * tile_size.x(),
(y + 1) as f32 * tile_size.y(),
),
min: rect_min,
max: Vec2::new(rect_min.x() + tile_size.x(), rect_min.y() + tile_size.y()),
})
}
}

TextureAtlas {
size: Vec2::new(tile_size.x() * columns as f32, tile_size.y() * rows as f32),
size: Vec2::new(
((tile_size.x() + x_padding) * columns as f32) - x_padding,
((tile_size.y() + y_padding) * rows as f32) - y_padding,
),
textures: sprites,
texture,
texture_handles: None,
Expand Down
4 changes: 3 additions & 1 deletion examples/2d/sprite_sheet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ fn setup(
)
.unwrap();
let texture = textures.get(&texture_handle).unwrap();
let texture_atlas = TextureAtlas::from_grid(texture_handle, texture.size, 7, 1);
// let texture_atlas = TextureAtlas::from_grid(texture_handle, texture.size, 7, 1);

let texture_atlas = TextureAtlas::from_grid(texture_handle, Vec2::new(24.0, 24.0), 7, 1);
let texture_atlas_handle = texture_atlases.add(texture_atlas);
commands
.spawn(Camera2dComponents::default())
Expand Down

0 comments on commit 6f423fe

Please sign in to comment.