// 世界场景的一些数据管理,如提供坐标转换之类的接口
var WorldMapManager = function () {
this.mapSize = null; // 地图大小,像素
this.curViewPos = null; // 当前大地图视野坐标
// 初始化世界地图的数据
this.init = function (mapSize, tileSize) {
this.mapSize = {
width : globalConsts.WorldMapSize.width * globalConsts.TileSize.width + globalConsts.TileSize.width / 2,
height : globalConsts.WorldMapSize.height * ((globalConsts.TileSize.height - globalConsts.TileSize.hex) / 2 + globalConsts.TileSize.hex) +
(globalConsts.TileSize.height - globalConsts.TileSize.hex) / 2
};
this.tileSize = globalConsts.TileSize;
};
// 大地图坐标转成蜂窝cell
this.mapPosToTile = function (pos) {
// 算出缩放成正六边形后边长 a 的值
var a = this.tileSize.width / Math.sqrt(3);
var x = pos.x, y = (this.mapSize.height - pos.y) / this.tileSize.height * a * 2 + a / 2; // 加 a / 2 是因为矩形网格计算时会在底部增加 a / 2
//位于矩形网格边线上的三个CELL中心点
var points = new Array(cc.p(0, 0), cc.p(0, 0), cc.p(0, 0));
//当前距离的平方
var dist;
// index:被捕获的索引
var i, index;
//二分之根号3 边长的平方,如果距离比它还小,就必然捕获
var g_MinDistance2 = Math.pow(a * Math.sqrt(3) / 2, 2);
// 网格宽、高
var g_unitx = a * Math.sqrt(3); //sqrt(3) * a
va
六边形格子地图坐标计算与转换
最新推荐文章于 2024-06-10 10:27:32 发布
// 世界场景的一些数据管理,如提供坐标转换之类的接口var WorldMapManager = function () { this.mapSize = null; // 地图大小,像素 this.curViewPos = null; // 当前大地图视野坐标 // 初始化世界地图的数据 this.init = function (mapSize,
摘要由CSDN通过智能技术生成