无限tilemap实现基于ccc
源码版本是2.09r5
我这边 主要是实际需要 实现 先 cok一样的无限大地图, 方法很简单
comp.testArray – (这个是我自己项目需要的一个列表 里面 放了 我需要显示的tile节点)
关键在于边界的处理 比如你的地图是 30x30 那么 超过 30或者 低于 0 怎么显示 很简单,比如 (0,31)就是把(0,0)移动到0,31的位置就行了,所以我们地图设计 师需要 收尾可以无缝结合的, comp.testArray 这个列表的选择可以比屏幕大一些,具体需要什么 自己结合游戏逻辑
if(comp.testArray){
for (const key in comp.testArray) {
let col = key%10000;
let row = Math.floor(key/10000);
let index = row*cols + col;
//let index = colOffset + col;
let flippedX = false, flippedY = false;
let tiledTile = tiledTiles[index];
if (tiledTile) {
gid = tiledTile.gid;
}
else {
gid = comp._tiles[index];
}
grid = grids[(gid & FLIPPED_MASK) >>> 0];
let isok = true;
if (!grid) {
isok = false;
return;
}
if(isok){
switch (layerOrientation) {
case Orientation.ORTHO:
left = col * maptw;
bottom = (rows - row - 1) * mapth;
break;
case Orientation.ISO:
let tcol = col;
let trow = row;
// 这里是我的一个设定 row存放的时候 *10000其实 你用字符串就行了
if(comp.testArray){
let pos = comp.testArray[col + row * 10000];
//这里就是实际的tile位置 你们 可以对比下源码 改动很小
if(pos){
tcol = pos.x;
trow = pos.y;
}
}
left = maptw / 2 * ( cols + tcol - trow - 1);
bottom = mapth / 2 * ( rows * 2 - tcol - trow - 2);