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中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 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处理有问题.请官方提供个解决方案.