瓦片地图坐标与触摸坐标的转换

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);
}

已验证

posted @ 2014-10-14 00:17  百里抱木  阅读(612)  评论(0编辑  收藏  举报