2014-12-29 2 views
0

cocos2d-js 게임용 chipmunk physics 엔진을 구현하려고합니다. 내가 실행할 때 다음과 같은 오류가 발생합니다. 여기 cocos2d-js : 오류 : setPhysicsBody를 사용한 잘못된 네이티브 오브젝트



jsb: ERROR: File Y:\Documents\cocos\PrebuiltRuntimeJs\frameworks\js-bindings\bindings\auto\jsb_cocos2dx_auto.cpp: Line: 2143, Function: js_cocos2dx_Node_setPhysicsBody 
Invalid Native Object 
JS: D:/PROJECTS/cocos/Sliderule/runtime/win32/../../src/app.js:32:Error: Invalid Native Object

은 스프라이트에 몸을 설정할 때 내가 문제를 얻을 내가

`init:function() { 
     this._super(); 
     var size = cc.winSize; 
     this.rect1 = new cc.Sprite(res.null_png,cc.rect(0,0, 200, 25)); 
     this.rect1.setColor(cc.color(255,50,50,1)); 
     this.rect1.setPosition(size.width/2, size.height-12.5); 
     this.rect1._setAnchorX(0.5); 
     this.rect1._setAnchorY(0.5); 

     this.rectbody1 = new cp.Body(1,cp.momentForBox(1,this.rect1.getContentSize().width, this.rect1.getContentSize().height)); 
     this.rectbody1.p = cc.p(size.width/2, size.height-12.5);   
     this.space.addBody(this.rectbody1); 
     this.rectshape1 = new cp.BoxShape(this.rectbody1, this.rect1.getContentSize().width - 14, this.rect1.getContentSize().height); 
     this.space.addShape(this.rectshape1); 
     this.rect1.setPhysicsBody(this.rectbody1); 
     this.addChild(this.rect1,1); 
` 

함께 일하고 있어요 코드입니다. 미리 감사드립니다.

답변

2

이 오류 메시지는 일반적으로 retain()이 없어서 나타납니다. 네이티브 시스템 (Android, iOS)이 보관할 스프라이트를 명시 적으로 설정해야합니다. 그렇지 않으면 일정 시간이 지나면 유효하지 않습니다. 그리고 더 이상 필요가 없다면 그것을 놓으십시오.

보십시오 : 당신이 스프라이트를 만든 후

this.rect1.retain() 

. 그런 다음 더 이상 필요하지 않은 경우

this.rect1.release() 

을 입력하십시오.

관련 문제