代码:
onLoad: function () {
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP, this.onKeyUp, this);
cc.find("Canvas/background").on(cc.Node.EventType.MOUSE_MOVE, this.onMouseMove, this);
cc.find("Canvas").on(cc.Node.EventType.MOUSE_UP, this.onMouseUp, this);
cc.find("Canvas").on(cc.Node.EventType.MOUSE_DOWN, this.onMouseDown, this);
},
onDestroy () {
cc.systemEvent.off(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
cc.systemEvent.off(cc.SystemEvent.EventType.KEY_UP, this.onKeyUp, this);
//下面三个是错误的,会报错。
cc.find("Canvas/background").off(cc.Node.EventType.MOUSE_MOVE, this.onMouseMove, this);
cc.find("Canvas").off(cc.Node.EventType.MOUSE_UP, this.onMouseUp, this);
cc.find("Canvas").off(cc.Node.EventType.MOUSE_DOWN, this.onMouseDown, this);
},
报这些错误:
TypeError: cc.find(…) is null
object already destroyed
object already destroyed