cocos2dx tiledmap 45度地图 世界坐标转换 格子坐标

前端之家收集整理的这篇文章主要介绍了cocos2dx tiledmap 45度地图 世界坐标转换 格子坐标前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Size mapSize = m_map->getMapSize(); Size tileSize = m_map->getTileSize(); Vec2 pos = position; float halfMapWidth = mapSize.width * 0.5f; float mapHeight = mapSize.height; float tileWidth = tileSize.width; float tileHeight = tileSize.height; Vec2 tilePosDiv = CCPointMake(pos.x / tileWidth,pos.y / tileHeight); float inverseTileY = mapHeight - tilePosDiv.y; // Cast to int makes sure that result is in whole numbers,tile coordinates will be used as array indices 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(mapSize.width - 1,posX); posY = MAX(0,posY); posY = MIN(mapSize.height - 1,posY); pos = CCPointMake(posX,posY); 原文链接:https://www.f2er.com/cocos2dx/338311.html

猜你在找的Cocos2d-x相关文章