CocosCreator内置函数实现物体拖动

通过CocosCreator由内置的cc.Node.EventType.MOUSE_MOVE鼠标(触摸)事件实现,返回参数为鼠标的坐标值。

根据鼠标的x,y实现物体的移动,即将鼠标放置在该节点上,实现移动。脚本代码如下:

cc.Class({
    extends: cc.Component,

    properties: {

    },

    // use this for initialization
    onLoad: function () {

        this.node.on(cc.Node.EventType.TOUCH_MOVE, function (event) { 
            var delta = event.touch.getDelta();
            this.x += delta.x;
            this.y += delta.y;
        }, this.node);
    },

    // called every frame
    update: function (dt) {

    },
});
原文地址:https://www.cnblogs.com/allyh/p/9688571.html