加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 17:27:07 所属栏目:百科 来源:网络整理
导读: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);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读