zhuguoqing ff550d5d6a init
2022-05-22 10:32:02 +08:00

135 lines
3.0 KiB
JavaScript

var Util;
var myAni = function(target,nootloop){
this.aniclip={
}
this.isOne = false
this.target = target;
if(Util==null){
Util = require("Utils");
}
if(nootloop){
this.selfupdate = true
this.step = 0
this.clip = null
this.isloop = false
}
this.ispause = false
}
myAni.prototype.addClip = function(name,arr) {
this.aniclip[name] = arr;
};
myAni.prototype.cleanAni = function(name) {
this.aniclip={}
};
myAni.prototype.setAtlas = function(atlas) {
this.atlas=atlas
};
myAni.prototype.Aniloop = function(name) {
if(this.ispause){
return false
}
if(this.isOne){
return false
}
if(!this.clip){
return false
}
if(this.isloop == false&&this.step==this.clip.length){
this.target.getComponent(cc.Sprite).spriteFrame=null
return false
}
if(this.atlas){
this.target.getComponent(cc.Sprite).spriteFrame = this.atlas.getSpriteFrame(this.clip[this.step])
}else{
Util.loadSprite(this.clip[this.step],this.target);
}
this.step++;
// if(this.isloop == false&&this.step==this.clip.length){
// //this.target.getComponent(cc.Sprite).spriteFrame=null
// //this.stopnCb && this.stopnCb()
// return false
// }
if(this.isloop){
this.step%= this.clip.length;
}
return true
};
myAni.prototype.play = function(name,isloop,time) {
this.target.active = true
time = time || 0.5;
if(isloop==null)
isloop = true;
var clip = this.aniclip[name];
this.isloop = isloop
if(clip==null){
return;
}
this.target.stopAllActions();
var isone = clip.length == 1;
var self = this;
if(isone){
this.isOne = true
if(this.atlas){
this.target.getComponent(cc.Sprite).spriteFrame = this.atlas.getSpriteFrame(clip[0])
}else{
Util.loadSprite(clip[0],this.target);
}
return;
}
var step = 0;
if(this.selfupdate){
this.step=0
this.clip = clip
// this.Aniloop()
this.isOne = false
return
}
var cb = cc.callFunc(function () {
if(self.atlas){
self.target.getComponent(cc.Sprite).spriteFrame = self.atlas.getSpriteFrame(clip[step])
}else{
Util.loadSprite(clip[step],self.target);
}
step++;
if(isloop == false&&step==clip.length){
self.target.stopAllActions();
step%= clip.length;
self.stopnCb && self.stopnCb()
self.target.active = false
return;
}
step%= clip.length;
});
var seq = cc.repeatForever(cc.sequence(cb,cc.delayTime(time)));
this.target.runAction(seq);
};
myAni.prototype.stop = function(name) {
this.target.getComponent(cc.Sprite).spriteFrame=null
this.target.stopAllActions();
};
myAni.prototype.pause = function(name) {
this.ispause = true
};
myAni.prototype.resume = function(name) {
this.ispause = false
};
module.exports = myAni;