tilemap坐标转换

像素点跟tile的索引之间的转换
//从cocos2d-x坐标转换为Tilemap坐标
CCPoint GameMap::tileCoordForPosition(CCPoint position)
{
int x = position.x / this->getTileSize().width;
int y = (((this->getMapSize().height) * this->getTileSize().height) - position.y) / this->getTileSize().height;
return ccp(x, y);
}

//从Tilemap坐标转换为cocos2d-x坐标
CCPoint GameMap::positionForTileCoord(CCPoint tileCoord)
{
CCPoint pos = ccp((tileCoord.x * this->getTileSize().width),
((this->getMapSize().height - tileCoord.y) * this->getTileSize().height));
return pos;
}

posted @ 2014-07-25 13:23  rexzhao  阅读(1135)  评论(0编辑  收藏  举报