[]分享:销毁龙骨动画!
package {
import laya.ani.bone.Skeleton;
import laya.ani.bone.Templet;
import laya.display.Sprite;
import laya.events.Event;
import laya.utils.Browser;
import laya.utils.Stat;
import laya.webgl.WebGL;
public class ASDemo {
private var mAniPath:String;
private var mFactory:Templet;
private var mCurrIndex:int = 0;
private var mArmature:Skeleton;
public function ASDemo() {
WebGL.enable();
Laya.init(Browser.width, Browser.height);
Laya.stage.bgColor = "#ffffff";
Stat.show();
var DesBtn:Sprite = createButton("销毁动画");
DesBtn.x = 50;
DesBtn.y = 50;
Laya.stage.addChild(DesBtn);
//创建一个Sprite充当音乐播放按钮
var addBtn:Sprite = createButton("添加动画");
addBtn.x = 250;
addBtn.y = 50;
Laya.stage.addChild(addBtn);
DesBtn.on(Event.CLICK, this, onDesBtn);
addBtn.on(Event.CLICK, this, onAddBtn);
}
private function onDesBtn():void
{
destroy();
}
private function onAddBtn():void
{
startFun();
}
public function startFun():void
{
mAniPath = "Dragon/Dragon.sk";
mFactory = new Templet();
mFactory.on(Event.COMPLETE, this, parseComplete);
mFactory.loadAni(mAniPath);
}
public function destroy():void
{
mArmature.stop();//停止龙骨动画播放
removeEvent();//移除事件
mArmature.removeSelf();//从显示列表移除龙骨动画本身
mArmature.removeChildren();//从显示列表移除龙骨动画子对象
mArmature.destroy(true);//从显存销毁龙骨动画及其子对象
mFactory.destroy();//释放动画模板类下的纹理数据
mFactory.releaseResource(true);//释放龙骨资源
}
public function removeEvent():void
{
mFactory.off(Event.COMPLETE, this, parseComplete);
mArmature.off(Event.STOPPED, this, completeHandler);
}
private function createButton(label:String):Sprite
{
var w:int = 110;
var h:int = 40;
var button:Sprite = new Sprite();
button.size(w, h);
button.graphics.drawRect(0, 0, w, h, "#FF7F50");
button.graphics.fillText(label, w / 2 , 8, "25px SimHei", "#FFFFFF", "center");
Laya.stage.addChild(button);
return button;
}
private function parseComplete(fac:Templet):void {
//创建模式为1,可以启用换装
mArmature = mFactory.buildArmature(0);
mArmature.x = 400;
mArmature.y = 500;
mArmature.scale(0.5, 0.5);
Laya.stage.addChild(mArmature);
mArmature.on(Event.STOPPED, this, completeHandler);
play();
}
private function completeHandler():void
{
play();
}
private function play():void
{
mCurrIndex++;
if (mCurrIndex >= mArmature.getAnimNum())
{
mCurrIndex = 0;
}
mArmature.play(mCurrIndex,false);
}
}
}
没有找到相关结果
已邀请:
要回复问题请先登录
3 个回复
Monica - 知识达人
赞同来自:
沧海一粟
赞同来自:
懒懒
赞同来自:
Skeleton的destroy已经包含了移除事件,移除自身及移除子项,Templet的destroy也已经包含了释放资源。