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);
}
});
```
这段代码会报错:
JS: sp.SkeletonAnimation.prototype._ctor,undefined,undefined,undefined, {}
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处理有问题.请官方提供个解决方案.
JS: sp.SkeletonAnimation.prototype._ctor,undefined,undefined,undefined, {} 这句话是我特意加打印的日志.
sp.SkeletonAnimation.prototype._ctor = function(skeletonDataFile, atlasFile, scale) {
cc.log("sp.SkeletonAnimation.prototype._ctor,%s,%s,%s, %s", skeletonDataFile, atlasFile, scale, JSON.stringify(this));
this.retain();
if(atlasFile) {
if (isNaN(scale)) {
scale = 1;
}
//sp.SkeletonAnimation.prototype.init.call(this);
sp.SkeletonAnimation.prototype.initWithFile.call(this, skeletonDataFile, atlasFile, scale);
sp.SkeletonAnimation.prototype.initialize.call(this);
this._target = null;
this._callback = null;
cc.log("sp.SkeletonAnimation.prototype._ctor finish");
}
};
```