0
\$\begingroup\$

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

\$\endgroup\$
0

1 Answer 1

1
\$\begingroup\$

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) 
\$\endgroup\$
2
  • \$\begingroup\$ Please explain the variable "N" denotes what..?? "N" is coordinates of tile or number of tile..?? Thanks \$\endgroup\$ Commented Jan 4, 2012 at 16:16
  • \$\begingroup\$ Number of tile, in the order specified on the "diagrams". \$\endgroup\$ Commented Jan 4, 2012 at 16:29

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.