您的位置:首页 > 游戏 > 游戏 > 【cocos creator】2.x,伪3d拖拽,60度视角,房屋装扮

【cocos creator】2.x,伪3d拖拽,60度视角,房屋装扮

2024/11/19 16:22:34 来源:https://blog.csdn.net/K86338236/article/details/140332235  浏览:    关键词:【cocos creator】2.x,伪3d拖拽,60度视角,房屋装扮

房屋装扮
伪3d拖拽,60度视角
工程下载:(待审核)
https://download.csdn.net/download/K86338236/89530812

dragItem.t s

import dragItem from "./dragItem";const { ccclass, property } = cc._decorator;@ccclass
export default class mapCreat extends cc.Component {//可修改mapH = 10;     // 地图纵向格子数量mapW = 10;     // 地图横向格子数量_layerH = 64.3;     // 地图单元格子高度,根据ui素材调整_gridW = 64.3;   // 地图单元格子长度,根据ui素材调整_gridH = 19;   // 地图单元格子宽度,根据ui素材调整boxAngel = 52;//地图伪3d角度,根据ui素材调整@property(cc.Graphics)map: cc.Graphics = null;@property(cc.Node)boxRoot: cc.Node = null;@property(cc.Node)boxNode: cc.Node = null;maxLayer = 0;   //最大高度gridsList = nullonLoad() {this.gridsList = null;this.maxLayer = 0;this.initMap();}protected start(): void {let boxArr = ["1,1|1,2|1,3|2,1|2,2|3,1", "1,1|1,2|2,1", "1,1"]//行列不超过mapW,mapHthis.init(boxArr)}init(boxArr) {this.creatSceneBox(boxArr)}/*** 初始化格子二维数组*/initMap() {this.gridsList = new Array(this.mapW);for (let col = 0; col < this.gridsList.length; col++) {this.gridsList[col] = new Array(this.mapH);}this.map.clear();for (let col = 0; col < this.mapW; col++) {for (let row = 0; row < this.mapH; row++) {this.addGrid(col, row, 0);}}this.drawBlock()}addGrid(x, y, topLayer) {let grid = {x: 0,y: 0,zArr: [0],topLayer: 0}grid.x = x;grid.y = y;grid.topLayer = topLayer;this.gridsList[x][y] = grid;}/*** 绘制底部地图线*/drawBlock() {for (let col = 0; col <= this.mapW; col++) {this.drawLine(cc.v2(col - 0.5, -0.5), cc.v2(col - 0.5, this.mapH - 0.5));}for (let row = 0; row <= this.mapH; row++) {this.drawLine(cc.v2(0 - 0.5, row - 0.5), cc.v2(this.mapW - 0.5, row - 0.5));}}creatSceneBox(boxArr = []) {let maxData = this.getMaxWidth(boxArr)this.boxRoot.children.forEach((value) => { value.active = false })let index = 0;for (let i = 0; i < boxArr.length; i++) {const element = boxArr[i];index = this.creatBox(element, this.boxRoot, i, index, maxData);}}/*** 获取方块位置范围* @param boxArr * @returns */getMaxWidth(boxArr) {let minX = 999let maxX = -999let minZ = 999let maxZ = -999for (let i = 0; i < boxArr.length; i++) {const element1 = boxArr[i];const element = element1.split("|")for (let j = 0; j < element.length; j++) {const element2 = element[j];let pos = element2.split(",")let x = (Number(pos[0]) - 1) || 0let z = (Number(pos[1]) - 1) || 0if (x < minX) minX = xif (x > maxX) maxX = xif (z < minZ) minZ = zif (z > maxZ) maxZ = z}}let middleX = Math.floor((maxX - minX) / 2);let middleY = Math.floor((maxX - minX) / 2);let maxData = { minX, maxX, minZ, maxZ, middleX, middleY }return maxData;}/*** 创建方块初始位置* @param boxString * @param parent * @param layer * @param index * @param maxData * @returns */creatBox(boxString = "", parent: cc.Node, layer, index, maxData) {let boxArr = boxString.split("|")for (let i = 0; i < boxArr.length; i++) {const element = boxArr[i];let colRowPos = element.split(",")let x = Number(colRowPos[0]) - 1 + Math.floor(this.mapW / 2) - maxData.middleXlet y = this.mapH - (Number(colRowPos[1]) 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com