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); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- 去掉tppabs冗余代码和注释
- ruby-on-rails – Rails 4.将表格ID移动到UUID
- ruby-on-rails – Rails:rake db:test:准备Vs
- 两种处理XML方式的比较---DOM and SAX
- JSON.parse()和JSON.stringify() 和 json.js+ jq
- oracle 9i/10g/11g(11.2.0.3)安装包和PATCH下载地
- ios – Xcode 8.2使用Legacy Swift问题
- React实战 -- todoList
- 【推荐】手Q开源Hybrid框架VasSonic介绍,极致的
- react-native试玩(29)-React Native Playground
热点阅读