Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix spacing being added to atlas size #301

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/render/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,8 @@ impl ExtractedTilemapTexture {
it is being extracted as a texture!",
);
let texture_size: TilemapTextureSize = image.size().into();
let tile_count_x =
(texture_size.x + tile_spacing.x) / (tile_size.x + tile_spacing.x);
let tile_count_y =
(texture_size.y + tile_spacing.y) / (tile_size.y + tile_spacing.y);
let tile_count_x = (texture_size.x) / (tile_size.x + tile_spacing.x);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this making the assumption that every tile, including the last one in the atlas will have padding? Is that the right assumption here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is indeed the assumption.

If we wanted to get rid of this assumption, I propose that we take inspiration from bevy's own bevy_sprite from_grid_with_padding.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@antoinePaulinB7 I have been thinking about it, and I think it's a fine assumption, because it provides a lot of regularity and eliminates special cases. Perhaps it is something we can document, so users know that this is what we expect. I will create a separate issue for it if this PR gets merged, to work on documenting that.

let tile_count_y = (texture_size.y) / (tile_size.y + tile_spacing.y);
((tile_count_x * tile_count_y) as u32, texture_size)
}
#[cfg(not(feature = "atlas"))]
Expand Down
20 changes: 10 additions & 10 deletions src/render/texture_array_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,8 @@ impl TextureArrayCache {
it is being extracted as a texture!",
);
let texture_size: TilemapTextureSize = image.size().into();
let tile_count_x =
(texture_size.x + tile_spacing.x) / (tile_size.x + tile_spacing.x);
let tile_count_y =
(texture_size.y + tile_spacing.y) / (tile_size.y + tile_spacing.y);
let tile_count_x = (texture_size.x) / (tile_size.x + tile_spacing.x);
let tile_count_y = (texture_size.y) / (tile_size.y + tile_spacing.y);
((tile_count_x * tile_count_y) as u32, texture_size)
}
TilemapTexture::Vector(handles) => {
Expand Down Expand Up @@ -206,12 +204,14 @@ impl TextureArrayCache {
});

for i in 0..count {
let columns = (texture_size.x as f32 + spacing.x as f32)
/ (tile_size.x as f32 + spacing.x as f32);
let sprite_sheet_x: f32 =
(i as f32 % columns).floor() * (tile_size.x + spacing.x) as f32;
let sprite_sheet_y: f32 =
(i as f32 / columns).floor() * (tile_size.y + spacing.y) as f32;
let columns =
(texture_size.x as f32) / (tile_size.x as f32 + spacing.x as f32);
let sprite_sheet_x: f32 = (i as f32 % columns).floor()
* (tile_size.x + spacing.x) as f32
+ spacing.x / 2.0;
let sprite_sheet_y: f32 = (i as f32 / columns).floor()
* (tile_size.y + spacing.y) as f32
+ spacing.y / 2.0;

command_encoder.copy_texture_to_texture(
ImageCopyTexture {
Expand Down