cocos2dx tiledmap 45度地图 世界坐标转换 格子坐标
2017-11-04 13:40
666 查看
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);
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度地图场景
- 游戏中45度地图的坐标转换
- 45度斜角地图菱形坐标转换
- 45度斜角地图菱形坐标转换
- 45度斜角地图菱形坐标转换
- cocos2dx使用TiledMap创建斜45度地图场景
- cocos2dx使用TiledMap创建斜45度地图场景
- iOS 地图坐标系之间的转换WGS-84世界标准坐标、GCJ-02中国国测局(火星坐标,高德地图)、BD-09百度坐标系转换
- cocos2dx学习之路----第七篇(坐标系统中本地坐标与世界坐标的转换详解)
- Unity3D世界的坐标与小地图UI上对应坐标之间的转换
- 45度斜角地图与鼠标坐标转换
- cocos2dx中。两个节点之间,世界坐标与本地坐标之间的转换
- cocos2dx 本地和世界坐标的转换
- 【cocos2dx】相对世界坐标与相对节点坐标的转换
- 45度斜角地图菱形坐标转换
- 如何通过界面屏幕的UI坐标,转换成45度叫的地图坐标?
- 45度斜角地图菱形坐标转换
- AS3-45度角地图坐标转换一(Diamond)
- AS3 RPG游戏引擎开发日志3:地图坐标转换