I am building a game using libgdx a 2048 like game and I draw the tiles of the board using textures (each texture represents a tile with the number 2 or 4 etc.)

I would like tohave a small space around the square textures. How can I do this ?

Thanks.

I'd suggest you give your actor (I suppose you use Scene2D) a bigger size, than your Image.

If you dont use Scene2D I recommend that you watch into it, because that would is the best way I can imagine to do such a game.

But as a final answer on your question: add transparency to your Image at the border. (which would go quite easy for once, but changing it would be a hell.

Or you try to use a Container. As example use Stack from Scene2D. You can place a bigger Image, which is transparent and on top of this Image a smaller one. Now you can scale your padding, or your Image, as you want.

https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/Stack.html

Why don't you simply offset the texture's position by some amount? If you want a 5px border around your images simply offset the position by 5 and the images will have a 5px gap between them. Assuming an array of the textures you want to draw you could do something like this:

float prevPos = 0;
for (Texture tex : texturesToDraw) {
    // 5px to the right of the previous textures position
    float texturePos = prevPos + 5;
    float textureWidth = tex.getWidth();
    prevPos = texturePos + textureWidth;

    batch.draw(tex, texturePos, 0);
}

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.