In my (OpenGL ES 2.0 Android) game, I use 2 types of Sprite Sheets. In one type all sprites/frames are of equal size and in the other they are all different shapes and sizes.

It is the latter one to which this question pertains. Basically, I've created a sprite sheet and I currently use Paint.net to find the coordinates a particular frame sits at. I then have to work out the texture coordinates by dividing the pixel by the width (for X) or height (for Y) so, if my image is 2048 x 2048 and a particular frame is at 300, 500, I work it out like so:

300/2048 = 0.146484375
500/2048 = 0.244140625

So, my X (or S) is 0.146484375 and my Y (or T) is 0.244140625.

I use the same method to work out the width and height.

I then code this using a method like so:

setTexCoords(0.146484375f, 0.244140625f, 0.048828125f, 0.048828125f);  //X, Y, Width, Height

When working with lots of sprites, this is a very tedious process.

The main problem however, is if I, at a later date, want to add sprites to the sheet and make it bigger to accommodate the extra sprites, I have to revisit every sprite and work out it's new texture coords based on the new bitmap size.

Is there any method I can use to make this process easier?

Even if it's just a program where I can hover the mouse over a bitmap and it tells me the texture coordinate (between 0-1). Even that would take a little of the work out of it.

Any suggestions welcomed.

I have read a similar question on here however, none of the answers really helped

  • 1
    \$\begingroup\$ At the very least use setTexCoords(300/2048f, 500/2048f, and so on) \$\endgroup\$ Sep 6, 2015 at 6:50

2 Answers 2


Here's a really simple improvement:

Define a method that sets the texture coordinates as pixels. Something like:

void setTexCoordsI(int x, int y, int w, int h) {
    float TEXTURE_SIZE = 2048.0f;

Then call:

setTexCoordsI(300, 500, 100, 100);

instead of:

setTexCoords(0.146484375f, 0.244140625f, 0.048828125f, 0.048828125f);
  • \$\begingroup\$ Thanks @Immibis I already started using 'pixel/size' a while back but for some reason I never thought to include the calculation in my set texture method! Thanks,- this will save me a lot of hassle. Have accepted your answer. \$\endgroup\$ Sep 6, 2015 at 10:53

Doing this manually is insane.

You need a tool that will take a folder full of images, pack them into atlases AND write a file containing all the coordinates. So then in your game you could address any image by its index or name or whatever and get its atlas coordinates (in pixels or UV).

  • \$\begingroup\$ @KromSterm, do you know of such a tool? Currently, I'm just creating my sprite sheets using Paint.Net. \$\endgroup\$ Apr 8, 2015 at 20:43
  • 2
    \$\begingroup\$ Sorry, this is not "software recommendations" site. You can program one yourself and learn something new from it quite easily. \$\endgroup\$
    – Kromster
    Apr 8, 2015 at 20:46

You must log in to answer this question.

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