Game Development Reference
In-Depth Information
With the scrolling offset taken into account, you can get the tile coordinates for the tile
at this location into the tilemap. At this point, you have to consider that the tile co-
ordinates' 0,0 tile is at the top left-hand corner of the tilemap. Contrary to screen co-
ordinates, where the 0,0 point (point of origin) is at the lower left-hand corner, the
tilemap coordinates start at the upper left-hand corner. Figure 10-11 shows the x,y co-
ordinates of a series of tiles. The screenshot was made with the Tiled Java version by
enabling View
Show Coordinates, which is a feature that isn't available yet in the
Tiled Qt version.
Figure 10-11 . The coordinate system of an orthogonal tilemap
So you're not confused, here's the code that calculates the tile coordinate's x position:
float pointWidth = tileMap.tileSize.width / CC_CONTENT_SCALE_FACTOR();
pos.x = (int)(pos.x / pointWidth);
The tileMap.tileSize property is the size of the tiles in the tileset, which in this
case is 32Ă—32 (see also Figure 10-6 ). By dividing the tilemap's tilesize with the
CC_CONTENT_SCALE_FACTOR() , the width (and height) are converted to point co-
ordinates. Internally, cocos2d handles tilemap sizes as pixel coordinates—this is one of
 
 
Search Nedrilad ::




Custom Search