Image padding

Monkey Forums/Monkey Beginners/Image padding

Loofadawg(Posted 2013) [#1]
The whole image padding is new to me. I already have same sprite sheets created but they are not padded. Is there a program out there that after inputing the tile size it will produce a new file with the padding?

And for future reference:

Say I were to a new sprite/tile sheet for my next project and say the tiles are 64x64 pixels.
Do I leave at least a two pixel boundary around each image? And what's this with the power of 2 for images. Is that for the whole sprite sheet? It seems that would kill that whole thing.

Lastly, I understand you can pass the image two ways. One with "blank" pixels which seems good because the images will look just as they should as opposed to the second method where you pad the images with the copies of the actual pixels that make up the border for that images.

That would look odd when trying to edit the images in the first place.

Hope my confusion makes sense.


Example sprite sheet of both methods with code used on the images would be fantastic.

I am lying in bed sick as a dog typing this on my phone. So please forgive bad grammar and spelling. I didn't want to ask this but it has been bugging me and since I am confined to the bed for a bit I figured the new forum might help me while lay here feeling absolutely miserable.


Goodlookinguy(Posted 2013) [#2]
I'm a tad out of it (since my cat forced me to wake up), so I'm only going to address your first question. I think you might be confusing the padding flag on monkey for padding your image.

When you load an image you have these flag choices...
Image.MidHandle
Image.XPadding
Image.YPadding
Image.XYPadding

The ones with Padding will add a one pixel border to the edge of the image. This is useful since images are just sections of a texture. When a section is filtered bilinearly it can cause any colors from right next to it on the texture to bleed over.

So, if you plan to have smoothed graphics it would be handy to use those flags. If on the other hand you are aiming for retro, they're unnecessary.


marksibly(Posted 2013) [#3]
I don't know of any tools that do this, sorry.

You only need a 1 pixel border around each 'frame' though (although this means there will be a 2 pixel gap between 2 consecutive frames), and you should 'copy' the adjacent pixels to produce the border, not leave them blank. Padding image frames is really a way to emulate 'texture coordinate clamping' - ie: when texture coordinates fall outside a frame, ideally you want to be able to 'clamp' them to the frame rectangle. Duplicating the edges of frames to create a border achieves the same result without having to modify texture coordinates. If that makes any sense...!

But in practice, a transparent/blank border will often work (or work well enough) depending on your needs...

Images don't need to be power of 2. Some platforms require this, but mojo handles it internally.


Loofadawg(Posted 2013) [#4]
Okay, Thank you. That should have answered all my questions then.


Gerry Quinn(Posted 2013) [#5]
And when we talk about powers of two, we mean the actual images that are loaded. Some Android devices want them to be powers of two in size. Each image might easily have lots of sprites/sub-images that you are using.


darky000(Posted 2013) [#6]
I learned something on the padding today here. I got a similar problem with texture bleeding but didn't know what was causing it or how it came to be. Now I know. Thanks.


Supertino(Posted 2013) [#7]
Just to add my 2-cent I use Texture packer http://www.codeandweb.com/texturepacker to create my sprite sheets and this lets you set a spacing between images which I set to 2px, which means I can do away with the need to pad images for 90% of my graphics and only really pad images manually with animation strips.

At-least I have never noticed an texture bleed using this method.