0
\$\begingroup\$

I am currently programming a 2d platformer and this is the first time I am coding a video game. Now I've downloaded the 'platformer art deluxe' package. In the tiles folder there are single tiles and a spritesheet with every tile on it.
Should I use the spritesheet or the single tile sprites?

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

If you should use them or not is up to you. You can learn more about why people use sprite sheets, and decide if it's worth implementing for your game. The logic is not too difficult too difficult for fixed grid sprite sheets. It's just a matter of calculating the offsets and sizes for each texture and converting those into UV coordinates:

//create UV arrays for each texture in the sheet, store look up by index
public TextureSheet(int width, int height) {
    for(int i = 0; i < width * height; i++) {
        textureMap.put(i, calculateUVMapping(i, width, height));
    }
}

private Vector2f[] calculateUVMapping(int texture, int sheetWidth, int sheetHeight) {
    int textureIndex = texture;
    int u = textureIndex % sheetWidth;
    int v = textureIndex / sheetHeight;

    float xOffset = 1f / sheetWidth;
    float yOffset = 1f / sheetHeight;
    float uOffset = (u * xOffset);
    float vOffset = (v * yOffset);

    Vector2f[] UVList = new Vector2f[6];

            //create the coordinates required for making a quad with the texture
    UVList[0] = new Vector2f(uOffset, vOffset); // 0,0
    UVList[1] = new Vector2f(uOffset, vOffset + yOffset); // 0,1
    UVList[2] = new Vector2f(uOffset + xOffset, vOffset); // 1,0
    UVList[3] = new Vector2f(uOffset + xOffset, vOffset + yOffset); // 1,1
    UVList[4] = new Vector2f(uOffset, vOffset + yOffset); // 0,1
    UVList[5] = new Vector2f(uOffset + xOffset, vOffset); // 1,0

    return UVList;
}

public Vector2f[] getTextureMap(int textureIndex) {
    return textureMap.get(textureIndex);
}
\$\endgroup\$
0
\$\begingroup\$

If its a small project then it shouldn't matter.

Binding a texture is expensive. So spritesheets can be bound once, and then instead of drawing the entire sprite, you draw just a section of the sheet. This is can be an performance increase, but really not the big of a deal on smaller projects. Also sprite sheets have a certain amount of optimization that can be placed into them (such as dithering, colors, compression, etc).

This tutorial is about spritesheets in CC2D, but has some good points about using spritesheets in general:

http://www.raywenderlich.com/32049/texture-packer-tutorial-how-to-create-and-optimize-sprite-sheets-in-cocos2d

But unless you are using a library or this is a serious game, writing your own spritesheet functionality is going to be a pain.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .