瓦片地图坐标与触摸坐标的转换
CCPoint HelloWorld::positionToTileCoord(CCPoint pos) { int x = pos.x / map->getTileSize().width; int y = ((map->getMapSize().height * map->getTileSize().height) - pos.y) / map->getTileSize().height; return ccp(x,y); } CCPoint HelloWorld::tilecoordToPosition(CCPoint tileCoord) { int x=tileCoord.x * map->getTileSize().width + map->getTileSize().width/2; int y=map->getMapSize().height * map->getTileSize().height - tileCoord.y * map->getTileSize().height - map->getTileSize().height/2; return ccp(x, y); }
已验证