我们现在正在处理我们的第一个 cocos2d-x JS 项目,在运行 MAC 项目时遇到了麻烦。对于 WEB 它工作正常。
我们创建了以下事件监听器:
var MouseFetcher;
MouseFetcher = cc.EventListener.create({
event: cc.EventListener.MOUSE,
TP: cc.Point,
initial:function(){
this.TP = new cc.p(cc.winSize.width/2, cc.winSize.height/2);
},
onMouseDown: function (event) {
this.TP = event.getLocation();
return true;
},
onMouseMove: function (event) {
},
onMouseUp:function(event){
this.TP = event.getLocation();
var i;
for(i = 0; i < clickables.length; i++){
if(clickables[i].containsPoint(this.TP)){
clickables[i].touchEvent();
}
}
}
});
并且有代码部分在 eventManager 中使用:
this.touchListener = MouseFetcher;
this.touchListener.initial();
cc.eventManager.addListener(this.touchListener, this);
当我们运行应用程序时,我们收到以下错误:
frameworks/cocos2d-x/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp: Line: 18190, Function: js_cocos2dx_EventDispatcher_addEventListenerWithSceneGraphPriority
Invalid Native Object
JS: /script/jsb_cocos2d.js:1643:Error: Invalid Native Object
有人可以帮助解决这个问题吗,我们在 MAC/IOS 版本上做错了什么?在这种情况下应该如何初始化 eventListener 并使用它。