layabox - 龍骨動畫

layabox 使用龍骨動畫的時候雜七雜八的事情很多

資源未加載完 崩潰

龍骨動畫添加幀動畫報錯等等
Failed to load resource: net::ERR_FILE_NOT_FOUND [file:///G:/program/20191112/bin/res/spine/undefined]

 

自己封裝了一個 要用的拿去

/**@author ccj

* 通用版本動畫組件

* date:2019.11.27

*/

export default class SpineMr extends fairygui.GComponent {

 

constructor(str: string) {

super()

this._url = str;

this.create()

}

 

public mFactory: Laya.Templet

public mArmature: Laya.Skeleton

public isComplete: boolean;

public _url: string


 

public rest() {

this.isComplete = false

this._url = ""

 

}

 

private create() {

 

this.mFactory = new Laya.Templet();

this.mFactory.on(Laya.Event.COMPLETE, this, this.parseComplete)//or 'complete'

this.mFactory.loadAni(this._url)

}

 

public parseComplete(): void {

 

this.mArmature = this.mFactory.buildArmature(1);

this._container.addChild(this.mArmature)

this.mArmature.play(0, true, false, 0, 5000, false, false)

this.isComplete = true

}


 

public playIndex(nameOrIndex: any, loop: boolean, force: boolean = true, start: number = 0, end: number = 5000, freshSkin: boolean = false, playAudio: boolean = false) {

if (!this.isComplete) {

return

}

this.mArmature.play(nameOrIndex, loop, force, start, end, freshSkin, playAudio)

}

 

public pos(x: number, y: number) {

this.x = x;

this.y = y;

}

 

public scale(x: number, y: number) {

this.scaleX = x;

this.scaleY = y;

}


 

}

例子:

this.effect = new SpineMr("res/spine/skill-effect-fire-2.sk")

this.view.addChild(this.effect)

this.effect.pos(500,400)

this.effect.scale(0.5,0.5)

發佈了12 篇原創文章 · 獲贊 2 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章