-
efaresLikes 0Problem Description
I'm having an issue with a collision handler I made:
var PlayScene = cc.Scene.extend({ // Some variables initPhysics: function () { this.space = new cp.Space(); this.space.addCollisionHandler(spriteTag.player, spriteTag.rocketSprite, this.onCollisionRocketPickup.bind(this), null, null, null); }, ... onCollisionRocketPickup: function (arbiter, space) { // Call methods from other layers this.getChildByTag(tagOfLayer.animation).addRocketPickedUp(); this.getChildByTag(tagOfLayer.topLayer).addShootButtonRocket(); }, ... });
When the player hits a rocketSprite (physicsSprite) it creates/logs this error and the methods from other layers are not run:
jsb: ERROR: File /Users/jenkins/Work/CocosPackageAuto/CocosFramework/cocos2d-x/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp: Line: 1479, Function: js_cocos2dx_Node_addChild Invalid Native Object jsb: ERROR: File /Users/jenkins/Work/CocosPackageAuto/CocosFramework/cocos2d-x/cocos/scripting/js-bindings/manual/chipmunk/js_bindings_chipmunk_manual.cpp: Line: 815, Function: myCollisionBegin Error calling collision callback: begin
I am using Cocos2d-x v3.7 (JavaScript) on a Mac running on Xcode.
Any help would be much appreciated.
-
Sonar Systems adminLikes 0
-
efaresLikes 0
Hi,
It was a matter of retaining the sprite that was being called in the function. I used a retain() on the sprite/object and it worked as expected now. I also included a release() onExit.
Thanks!
-
Sonar Systems adminLikes 0
Great to hear you have resolved it.
Login to reply