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

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

在这里插入图片描述

dragItem2.t s


import mapCreat2 from "./mapCreat2";


const {
    ccclass, property } = cc._decorator;
/**
 * 拖拽类,挂在要拖拽的节点上
 */
@ccclass
export default class dragItem2 extends cc.Component {
   

    @property(mapCreat2)
    mapCreat: mapCreat2 = null;

    private _originPos: cc.Vec2;
    private _startPos: any;
    oginPos: any;

    colRowPos = cc.v3(0, 0, 0)

    onLoad() {
   
        this.oginPos = this.node.position;
        this.regiestNodeEvent(this.node.children[0] || this.node);
    }

    init(pos) {
   
        this.colRowPos = pos;
    }

    /** 节点注册事件 */
    regiestNodeEvent(node: cc.Node) {
   
        if (!node) return;
        node.on(cc.Node.EventType.TOUCH_START, this.touchStartEvent, this);
        node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMoveEvent, this);
        node.on(cc.Node.EventType.TOUCH_END, this.touchEndEvent, this);
        node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchEndEvent, this);
    }

    touchStartEvent(event) {
   
        console.log('touch start--------')
        this._originPos = this.node.getPosition();
        this._startPos = event.getLocation();
        this.node.zIndex = 9999;
        this.mapCreat.removeBox(this.colRowPos)
    }

    touchMoveEvent(event) {
   
        let pos = event.getLocation();
        if (!this._startPos) {
   
            return;
        }
        let offset_x = pos.x - this._startPos.x;
        let offset_y = pos.y - this._startPos.y;

        this.node.x = this._originPos.x + offset_x;
        this.node.y = this._originPos.y + offset_y;
    }

    touchEndEvent(event) {
   
        this._startPos = null;
        this.setPos(false)
    }


    setPos(isInit?) {
   
        const {
    endPos, col, row, layer } = this.mapCreat.getPutPos(this.node, isInit, this.colRowPos)
        if (!endPos) return
        this.node.position = endPos;
        this.colRowPos = cc.v3(col, row, layer);
        this.mapCreat.addBox(cc.v3(col, row, layer))
        this.node.zIndex = -col * 10 - row * 10 + layer;
    }
}


mapCreat2.ts

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素材调整


    

相关推荐

  1. CocosCreator3.x相机实践

    2024-07-11 21:34:05       21 阅读
  2. 【国产开源可视化引擎Meta2d.js】

    2024-07-11 21:34:05       19 阅读
  3. Unity 鼠标3D物体跟随移动的方法

    2024-07-11 21:34:05       35 阅读
  4. 前端视角如何理解“时间复杂O(n)”

    2024-07-11 21:34:05       38 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-11 21:34:05       66 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-11 21:34:05       70 阅读
  3. 在Django里面运行非项目文件

    2024-07-11 21:34:05       57 阅读
  4. Python语言-面向对象

    2024-07-11 21:34:05       68 阅读

热门阅读

  1. k8s 容器环境下的镜像如何转换为docker 使用

    2024-07-11 21:34:05       26 阅读
  2. 使用Apache Beam进行统一批处理与流处理

    2024-07-11 21:34:05       23 阅读
  3. 【LinuxC语言】手撕Http之处理POST请求

    2024-07-11 21:34:05       21 阅读
  4. 常用的简单的ps快捷键

    2024-07-11 21:34:05       19 阅读
  5. Bug汇总

    2024-07-11 21:34:05       20 阅读
  6. LVS集群(二)

    2024-07-11 21:34:05       22 阅读
  7. vscode连接unbuntu失败,显示Downloading vs code server...

    2024-07-11 21:34:05       19 阅读
  8. Memcached介绍和详解

    2024-07-11 21:34:05       20 阅读
  9. Qt常用基础控件总结—表格控件(QTableWidget类)

    2024-07-11 21:34:05       22 阅读
  10. pudb: Python的图形化调试器

    2024-07-11 21:34:05       24 阅读
  11. 派森学长带你学python—字符串

    2024-07-11 21:34:05       20 阅读
  12. DP学习——设计模式怎么来的?

    2024-07-11 21:34:05       17 阅读
  13. 7.10飞书一面

    2024-07-11 21:34:05       17 阅读