We now working on our first cocos2d-x JS project, got trouble running MAC project. For WEB it's working correctly.
We have created following eventListener:
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();
}
}
}
});
And there is code part where it is used in eventManager:
this.touchListener = MouseFetcher;
this.touchListener.initial();
cc.eventManager.addListener(this.touchListener, this);
When we running app we getting following error:
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
Can someone help solve that issue, what we doing wrong for MAC/IOS version? How eventListener should be initialized in that case and used.
"Invalid Native Object" error means that you are using a CCNode that has been released(maybe never added to scene graph and not calling retain(), or has been remove from parent).
In web version, nodes are retained/released automatically, you can still use it even nodes are not added to scene graph; however, in native version you must make sure nodes are still valid before operating it.
In your case, you should check whether the "this" node is valid in below code: