当前位置 : 主页 > 手机开发 > 其它 >

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

来源:互联网 收集:自由互联 发布时间:2021-06-13
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;
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);
网友评论