操作系统:macOS 10.13.3
极限跳跃小游戏原版链接:https://www.byjth.com/CocosCreator/66.html
替换掉cc.eventManager.addListener的一种方法:
监听:
this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
this.node.on(cc.Node.EventType.TOUCH_MOVE, function (event) {}, this);
this.node.on(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this);
在onTouchStart和onTouchEnd方法中通过event.getTouches()[0]来获取touch事件
关闭监听:
this.node.off(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
this.node.off(cc.Node.EventType.TOUCH_MOVE, function (event) {}, this);
this.node.off(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this);
其它js文件中获取GAME节点的一种方法:
var game2 = require("GAME"); //类外
var _game = cc.find("Canvas").getComponent(game2);//类的方法中
友情提示:
试了用cc.systemEvent来调用on、off方法,但没有效果。(可能是我的使用方法不正确)