What are the recommended values for margin and spacing when creating a tilesource? I currently use 4 pixels for spacing and 2 pixels for margin, but my tiles still get smudged with neighbor data around the edges when I run the program.
Hi Karl! It should be enough to set extrude borders to 1 and leave margin and inner padding to 0. Our own documentation mentions this for Extrude Borders:
“A good measure is to specify a number that corresponds to how much you scale the textures when viewed in game. If you display the game world at half scale (you can see 2 times as much) then set Extrude Borders to 2. When the texture is used scaled down to half the size, a mipmap is used for rendering. That mipmap is half the width and height of the original image.”
To be honest, I was actually a bit uncertain about the use of inner padding and margin, but since I assume these values have the same purpose and meaning as in TexturePacker I took a look at the documentation there:
Inner Padding
Adds transparent pixels to the inside of the sprite, growing it.
There are two uses for this:
- It can help in preventing cut-off artifacts near the edges of scaled sprites. E.g. if your sprite has a few pixels along its own boundaries, scaling the sprite up or down won’t let these pixels appear as gaps or cuts.
- It considerably reduces aliasing along the polygon edges when rotating trimmed or cropped sprites. E.g. if your sprite has many pixels along its own boundaries, it will be drawn more smoothly when rotating it.
Margins
Note: I’m assuming Margin is the same as TexturePackers shape padding setting:
Shape padding is the space between sprites. Value adds transparent pixels between sprites to avoid artifacts from neighbor sprites. The transparent pixels are not added to the sprites. Default is 2.
Use a value of at least 2 to avoid dragging in pixels from neighbor sprites when using OpenGL rendering.
@sicher: We should clarify the use of Margins and Inner Padding in our documentation
Inner padding reduces edge aliasing when image graphic makes contact with edge of image container
A really good tip. Especially if you are making a card game with rotated card layouts.
Thanks for clearing that up. I should have read the documentation more closely.
But I’m still confused about one detail. From this explanation it seems that the margin and spacing values are only used for interpreting the input image for a tile source (to get the coordinates of each tile), whereas for a sprite atlas they become part of the output image. Is this correct?
I agree with you Karl, from the documentation it seems as though there is a difference in how to interpret spacing and margin in a tile source and an atlas.
@Ragnar_Svensson: Is Karl correct in his assumption?
@sicher: The documentation could really use some clarification here.
Yup, I’m taking notes. DEF-1931
Yes, and I agree that is incredibly confusing! I’ll try to fix it by improving the previewing in Editor2 so you can see what happens with the resulting texture in each case.