I am new to Android COCOS2D and developing a simple game to start with. I am developing a game for kids in which the kids shall spell out the names of the fruits they select. I have developed the sprite sheet consisting of pictures of several fruits. Kindly tell me how will the fruit on which the kid taps will get selected. How are the x and y co-ordinates in the sprite sheet determined??

I shall be thankful in case anyone can help me out with this. Thanks in advance


Depends on your spritesheet and how you'd like to refer to each sprite.

Horizontal Strip, Evenly Spaced


Coordinates for tile corresponding to position N:

X = N * TileWidth
Y = 0

Grid, Evenly Spaced, Single Index


Coordinates for tile corresponding to position N:

X = (N % Cols) * TileWidth
Y = floor(N / Cols) * TileHeight

In this example Cols equals 3.

Grid, Evenly Spaced, Double Index


Coordinates for tile corresponding to position NX and NY:

X = NX * TileWidth
Y = NY * TileHeight

Irregular Sprite Sheet

Store rectangle regions of each sprite in a seperate file. E.g.

0 0 30 60      // First sprite at (0,0) with size (30,60)
30 0 100 60    // Second sprite at (30,0) with size (100,60)
0 60 130 60    // Third sprite at (0,60) with size (130,60)
| improve this answer | |
  • \$\begingroup\$ Please explain the variable "N" denotes what..?? "N" is coordinates of tile or number of tile..?? Thanks \$\endgroup\$ – jubin Jan 4 '12 at 16:16
  • \$\begingroup\$ Number of tile, in the order specified on the "diagrams". \$\endgroup\$ – David Gouveia Jan 4 '12 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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