참조1 
CCPoint tilePosFromLocation(CCPoint location, CCTMXTiledMap* tileMap)
{
// Tilemap position must be subtracted, in case the tilemap position is scrolling
CCPoint pos = ccpSub(location, tileMap->getPosition());
float halfMapWidth = tileMap->getMapSize().width * 0.5f;
float mapHeight = tileMap->getMapSize().height;
float tileWidth = tileMap->getTileSize().width;
float tileHeight = tileMap->getTileSize().height;
CCPoint tilePosDiv = CCPointMake(pos.x / tileWidth, pos.y / tileHeight);
float inverseTileY = mapHeight - tilePosDiv.y;
// Cast to int makes sure that result is in whole numbers
float posX = (int)(inverseTileY + tilePosDiv.x - halfMapWidth);
float posY = (int)(inverseTileY - tilePosDiv.x + halfMapWidth);
// make sure coordinates are within isomap bounds
posX = MAX(0, posX);
posX = MIN(tileMap->getMapSize().width - 1, posX);
posY = MAX(0, posY);
posY = MIN(tileMap->getMapSize().height - 1, posY);
return CCPointMake(posX, posY);
}


참조2 
-(CGPoint)touchToXY:(CGPoint)touch map:(CCTMXTiledMap *)_map mapsize:(int)_mapsize
{
touch = [[CCDirector sharedDirector] convertToGL:touch];
touch = [_map convertToNodeSpace:touch];
CGSize ts = [_map tileSize];
int isoy = (((touch.y/ ts.height) + (touch.x - (_mapsize * ts.width/2)) / ts.width) - _mapsize) *-1;
int isox = (((touch.y/ ts.height) - (touch.x - (_mapsize * ts.width/2)) / ts.width) -_mapsize) *-1;
return ccp(isox,isoy);
}

+ Recent posts