首页 > 代码库 > tilemap坐标转换
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;
}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。