关闭监听失败

代码如下:

    var canvas = cc.director.getScene().getChildByName('Canvas');

    var self = this;

    if (!this.cursor) {
        cc.loader.loadRes(resList.diamondPrefab, function (err, prefab) {
            self.cursor = cc.instantiate(prefab);

            var startLoc = canvas.convertToNodeSpaceAR(self.node.getPosition());

            self.cursor.setPosition(startLoc);
            canvas.addChild(self.cursor);

        });

        //注册鼠标移动的监听
        canvas.on(cc.Node.EventType.MOUSE_MOVE, function (touch) {
            cc.log('监听中');
            if (self.cursor) {
                var touchLoc = touch.getLocation();

                touchLoc = canvas.convertToNodeSpaceAR(touchLoc);

                self.cursor.setPosition(touchLoc);
            }
        }, this);
    } else {
        this.cursor.removeFromParent();
        this.cursor = null;

        cc.log('移除监听');

        //注销鼠标移动的监听
        canvas.off(cc.Node.EventType.MOUSE_MOVE, function (touch){
            cc.log('移除监听');
        }, this);
    }

注销监听调用成功,但鼠标移动的监听仍在,求大神指点

你应该需要

canvas.on(cc.Node.EventType.MOUSE_MOVE, this._mouseMoveCallBack, this);
canvas.off(cc.Node.EventType.MOUSE_MOVE, this._mouseMoveCallBack, this);

而不是

canvas.on(cc.Node.EventType.MOUSE_MOVE, function () {}, this);
canvas.off(cc.Node.EventType.MOUSE_MOVE, function () {}, this);

1赞

十分感谢,当时虽然在文档中看到了但是没意识到~