laya龙骨动画的几种使用方法

第一种直接加载显示:

var skeleton:Laya.Skeleton = new Laya.Skeleton();
//添加到舞台
this.addChild(skeleton);
skeleton.pos(300,350);
//通过加载直接创建动画
skeleton.load("res/skeletonEffect/win/xiaobingWIN.sk", new Laya.Handler(this, function(){
// console.log("!!!!!!!!!!!!!!!!!!!~~~~",skeleton.getAnimNum());
  skeleton.play(1,false);
 },null,true));
  skeleton.on(LayaEvent.STOPPED, this, function(){console.log("STOPPED!!!!")})
 skeleton.on(LayaEvent.PAUSED, this, function(){console.log("PAUSED!!!!")})
 skeleton.on(LayaEvent.LABEL, this, function(){console.log("LABEL!!!!")})
 skeleton.on(LayaEvent.PLAYED, this, function(){console.log("PLAYED!!!!")})


第二种预加载:

   var mFactory = new Laya.Templet();
   mFactory.on(LayaEvent.COMPLETE, this, function(){
    var mArmature = mFactory.buildArmature(0);
    mArmature.x = 300;
    mArmature.y = 300;
    this.addChild(mArmature);
    mArmature.play(1, true);
   });
   mFactory.loadAni("res/skeletonEffect/win/xiaobingWIN.sk");


第三种很多的时候一起打包预加载:

this.mTexturePath = "../../res/skeleton/" + this.fileName + "/" + this.fileName + ".png";
this.mAniPath = "../../res/skeleton/" + this.fileName + "/" + this.fileName + ".sk";
Laya.loader.load([{ url: this.mTexturePath, type: Loader.IMAGE }, { url: this.mAniPath, type: Loader.BUFFER }], Handler.create(this, this.onAssetsLoaded));
        
public onAssetsLoaded(): void {
       var tTexture: Texture = Loader.getRes(this.mTexturePath);
       var arraybuffer: ArrayBuffer = Loader.getRes(this.mAniPath);
       this.mFactory = new Templet();
       this.mFactory.on(Event.COMPLETE, this, this.parseComplete);
       this.mFactory.parseData(tTexture, arraybuffer, 10);
}
        
this.mArmature = this.mFactory.buildArmature();
       this.mArmature.x = this.xOff + j * this.mSpacingX;
       this.mArmature.y = this.yOff + i * this.mSpacingY;
       this.mArmature.play(0, true);
       this.mAnimationArray.push(this.mArmature);
       Laya.stage.addChild(this.mArmature);



暂无评论

发布评论

分享:

支付宝

微信