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

cocos2dx tiledmap 45度地图 世界坐标转换 格子坐标,第1张

概述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.w 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); 总结

以上是内存溢出为你收集整理的cocos2dx tiledmap 45度地图 世界坐标转换 格子坐标全部内容,希望文章能够帮你解决cocos2dx tiledmap 45度地图 世界坐标转换 格子坐标所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1085155.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存