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) {

    },
});

 

posted @ 2018-09-21 21:38  icon_sunny  阅读(1296)  评论(0编辑  收藏  举报