我在Android中遇到了一些“无效的本机对象”错误(Nexus 5,Android 4.4.4)。在浏览器版本中没有错误。
我将应用程序的代码部分放入一个全新的helloworld应用程序中。出现错误的第59行标记如下。 这是来自亚行的logcat消息:
D / cocos2d-x调试信息(32165):jsb:错误:文件/Applications/MAMP/htdocs/test_actions/frameworks/runtime-src/proj.android/../../js-bindings/bindings/ auto / jsb_cocos2dx_auto.cpp:行:3955,功能:js_cocos2dx_Node_runAction D / cocos2d-x调试信息(32165):无效的本机对象 D / cocos2d-x调试信息(32165):JS:assets / src / app.js:59:错误:无效的本机对象 D / cocos2d-x调试信息(32165):
这是代码。
var HelloWorldLayer = cc.Layer.extend({ 精灵:空, ctor:function(){
var self = this; ////////////////////////////// // 1. super init first this._super(); ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program // you may modify it. // ask director the window size var size = cc.director.getWinSize(); // Load sprite frames to frame cache, add texture node cc.spriteFrameCache.addSpriteFrames(res.murbiks_plist); var murbiksImages = cc.SpriteBatchNode.create(cc.textureCache.addImage(res.murbiks_png)); self.addChild(murbiksImages); var anims = {}; var loadFrames = function(name,cnt) { var frames = []; for (var i = 1; i <= cnt; i++) { str = name + (i < 10 ? ("0" + i) : i); frames.push(cc.spriteFrameCache.getSpriteFrame(str)); } var anim = cc.Animation.create(frames, 0.06); anim.retain(); anims[name] = cc.animate(anim); } loadFrames("mostafa_fly",9); loadFrames("mostafa_land",7); var mostafa = cc.Sprite.create(res.murbiks_single_png); mostafa.attr({ x: 0, y: 0, scale: 1.9, rotation: 0 }); mostafa.retain(); self.addChild(mostafa, 5); var animAction = mostafa.runAction(cc.repeatForever(anims.mostafa_fly)), bezierMostafa = [ cc.p(0,0), cc.p(200,520), cc.p(500,220) ]; var mostafaAction = mostafa.runAction( cc.sequence( cc.bezierTo(2.5, bezierMostafa), cc.callFunc(function() { self.stopAction(animAction); animAction = mostafa.runAction(anims.mostafa_land); // LINE 59, INVALID NATIVE OBJECT }) ) ); return true;
} });
那可能是什么?
答案 0 :(得分:3)
murbiksImages也应该调用retain()
一般来说,&#34;无效的原生对象&#34;表示某些对象在本机代码中被删除,这通常发生在对象没有调用retain
时并且,在cocos2d-x3.0中不推荐使用SpriteBatchNode
你最好不要使用它,它也会在cocos2d-js中弃用