Skip to content

Conversation

quantumpotato
Copy link

@quantumpotato quantumpotato commented May 24, 2025

Hello, thanks for providing this script.

I had to make a couple changes to get this working for me. Maybe something about your spritesheet is arranged differently. The issues I had:

  • code tried to multiply a usize by float
  • extension pushed down from top and left, but not bottom

I needed to update 16x16 tile sprites in a 128xn spritesheet. With a sprite that touches top and bottom, expanding from just 1 side does not solve the bleed issue. I updated the code so the padding you supply gets divided by 2 and added on both ends - by just moving the sprite up and left that much space.

This fixed my issue with the bevy sprite.
I see you already have examples in your readme so I recommend you test what my code does and compare it to your results and see if it's what you want.

Thanks for the project, it got me 99% of the way there.

The input file and outputs are added to the docs for your review:

./target/release/re-tile ./example1.png 16 0 0 ./out-example-4padding.png 4 4
./target/release/re-tile ./example1.png 16 0 0 ./out-example-8padding.png 8 8

You can see how padding is applied evenly top and bottom. Left and right.

Copy link

@BenjaminBrienen BenjaminBrienen left a comment

Choose a reason for hiding this comment

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

You have 2 main functions now

@tatref
Copy link
Owner

tatref commented Jun 14, 2025

Sorry for the delay

First off, thanks for the PR!

Usually you should just replace the code, instead of adding a duplicate function, it makes it easier to diff the code

I don't know what I did with the usize/float mismatch, obviously you're correct. I must have commited a wrong version...

I'm not sure I understand the changes you've made to the padding. The width and height formulas are not symmetrical, as it should be, because the tiles are squares

let dst_w = (dst_offset * 2 + columns * tile_size + (columns - 1) * dst_padding) - dst_padding;
let dst_h = (dst_offset * 2 + rows * tile_size + (rows - 1) * dst_padding) + dst_padding;

Here is a simple example with only horizontal orientation
image

padding is green
offset is red

We have 2 * offset (left and right), regardless of the number of columns
Here we have 3 columns, but only 2 padding (in between the columns), so padding * (cols - 1)
Then we account for the tiles themselves : cols * tile_size

Also here:

        let dst_x = dst_offset + column * (dst_padding + tile_size) - (dst_padding / 2);
        let dst_y = dst_offset + row * (dst_padding + tile_size) - (dst_padding / 2);

You divide padding by 2, but what happens if I set padding = 1?

I fix the u32/float issue on master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants