cocos2d / cocos2d-js

cocos2d-x for JS
http://www.cocos2d-x.org
MIT License
1.86k stars 489 forks source link

jsb中js继承c++对象有bug #1800

Open Jamy325 opened 9 years ago

Jamy325 commented 9 years ago

jsb中js继承c++对象有bug, bug代码如下

var HitZoneAnimation = sp.SkeletonAnimation.extend({ ctor:function(skeletonDataFile, atlasFile/* or atlas*/, scale){
var r = this._super(); this.initWithFile(skeletonDataFile, atlasFile, scale); this.initialize();
} });

var HelloWorldLayer = cc.Layer.extend({ sprite:null, ctor:function () { ////////////////////////////// // 1. super init first this._super();

    var self = this;
    var s1 =  new HitZoneAnimation("res/animation/yecha_da.json", "res/animation/yecha_da.atlas", 1);
    self.addChild(s1);
    s1.setPosition(cc.p(500,200));

    return true;
}

});

var HelloWorldScene = cc.Scene.extend({ onEnter:function () { this._super(); var layer = new HelloWorldLayer(); this.addChild(layer); } });

这段代码会报错: jsb: ERROR: File jsb_cocos2dx_spine_auto.cpp: Line: 370, Function: js_cocos2dx_spine_SkeletonRenderer_initWithFile js_cocos2dx_spine_SkeletonRenderer_initWithFile : Invalid Native Object JS:app.js:5:Error: js_cocos2dx_spine_SkeletonRenderer_initWithFile : Invalid Native Object 跟踪了下跟踪一下发现是jsb里对js的this处理有问题.请官方提供个解决方案.