Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

share|improve this question
1  
How did you create that sprite-sheet? Did you use a tool that generates it for you? Btw. You should really accept some of the answers to your previous questions as you have a 0% accept rate. –  bummzack Jan 3 '12 at 8:14
add comment

1 Answer

up vote 1 down vote accepted

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

Horizontal Strip, Evenly Spaced

[0][1][2][3][4][5][6][7][8]

Coordinates for tile corresponding to position N:

X = N * TileWidth
Y = 0

Grid, Evenly Spaced, Single Index

[0][1][2]
[3][4][5]
[6][7][8]

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

[0,0][1,0][2,0]
[0,1][1,1][2,1]
[0,2][1,2][2,2]

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)
share|improve this answer
    
Please explain the variable "N" denotes what..?? "N" is coordinates of tile or number of tile..?? Thanks –  jubin Jan 4 '12 at 16:16
    
Number of tile, in the order specified on the "diagrams". –  David Gouveia Jan 4 '12 at 16:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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