使用的是cocos2dx 2.2.4
因为Armature创建很慢,我做了一个cache进行动画的预加载以及重复使用;
var ArmatureCache = cc.Class.extend({
_callExit:function(){
if(!this._beCached){
this._beCached=true;
ccs.Armature.prototype.onExit.call(this);
g_sharedArmatureCache.push(this);
}else{
cc.log(“recache:”+this.getName());
}
},
newArmature:function(name){
var armature = ccs.Armature.create(name);
armature.retain();
armature.onExit=this._callExit;
this.retainList.push(armature);
return armature;
},
pop:function(name){
var list = this.cacheList;
if(!list || list.length<1){
var armature = this.newArmature(name);
cc.log(“new:”+name);
}else{
var armature = list.pop();
armature.setOpacity(255);
armature.setScale(1);
armature._beCached=false;
cc.log(“pop:”+name+","+list.length);
}
armature.setVisible(true);
return armature;
},
push:function(armature){
var name = armature.getName();
var list = this.cacheList;
if(!list){
list = ];
this.cacheList = list;
}
list.push(armature);
cc.log(“push:”+name+","+list.length);
},
}
游戏进行过程就会出现如下错误:
不使用cache就不会出现问题…


