优化Animation 性能
This commit is contained in:
parent
7b53180344
commit
3c73480642
|
|
@ -11,10 +11,14 @@ class Animation extends Actor {
|
||||||
|
|
||||||
//当前帧数
|
//当前帧数
|
||||||
CurrentFrameIndex = 0;
|
CurrentFrameIndex = 0;
|
||||||
|
//总帧数
|
||||||
|
TotalFrameIndex = 0;
|
||||||
//当前帧时间
|
//当前帧时间
|
||||||
CurrentIndexT = 0;
|
CurrentIndexT = 0;
|
||||||
//当前帧
|
//当前帧
|
||||||
CurrentFrame = null;
|
CurrentFrame = null;
|
||||||
|
//下帧延迟
|
||||||
|
NextFrameDelay = 9999999;
|
||||||
//状态机对象(只有存在时才有KeyFlag)
|
//状态机对象(只有存在时才有KeyFlag)
|
||||||
StateMachine = null;
|
StateMachine = null;
|
||||||
|
|
||||||
|
|
@ -118,7 +122,6 @@ class Animation extends Actor {
|
||||||
Spritebuf.SetPosition(FrameObj.Pos);
|
Spritebuf.SetPosition(FrameObj.Pos);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SpriteArr.append(Spritebuf);
|
SpriteArr.append(Spritebuf);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -127,6 +130,8 @@ class Animation extends Actor {
|
||||||
|
|
||||||
//初始化完毕 如果是第一次初始化 而非重新构造 设置大小为第0帧大小否则天空 地板等依靠大小的初始化会有问题
|
//初始化完毕 如果是第一次初始化 而非重新构造 设置大小为第0帧大小否则天空 地板等依靠大小的初始化会有问题
|
||||||
if (CurrentIndexT == 0) SetSize(SpriteArr[0].GetSize());
|
if (CurrentIndexT == 0) SetSize(SpriteArr[0].GetSize());
|
||||||
|
//记录总帧数
|
||||||
|
TotalFrameIndex = FrameArr.len();
|
||||||
}
|
}
|
||||||
|
|
||||||
//被添加时 要刷新一下当前帧
|
//被添加时 要刷新一下当前帧
|
||||||
|
|
@ -159,7 +164,9 @@ class Animation extends Actor {
|
||||||
CurrentFrame = SpriteArr[CurrentFrameIndex];
|
CurrentFrame = SpriteArr[CurrentFrameIndex];
|
||||||
Addchild(SpriteArr[CurrentFrameIndex]);
|
Addchild(SpriteArr[CurrentFrameIndex]);
|
||||||
|
|
||||||
local FlagBuf = FrameArr[CurrentFrameIndex].Flag;
|
local FrameInfo = FrameArr[CurrentFrameIndex];
|
||||||
|
local FlagBuf = FrameInfo.Flag;
|
||||||
|
NextFrameDelay = FrameInfo.Delay;
|
||||||
//关键帧
|
//关键帧
|
||||||
if ("SET_FLAG" in FlagBuf) {
|
if ("SET_FLAG" in FlagBuf) {
|
||||||
if (StateMachine && StateMachine.State != -1) StateMachine.ChangeAniKeyFlag(FlagBuf.SET_FLAG);
|
if (StateMachine && StateMachine.State != -1) StateMachine.ChangeAniKeyFlag(FlagBuf.SET_FLAG);
|
||||||
|
|
@ -179,17 +186,16 @@ class Animation extends Actor {
|
||||||
|
|
||||||
//override
|
//override
|
||||||
function OnUpdate(dt) {
|
function OnUpdate(dt) {
|
||||||
|
|
||||||
//可用性检查
|
//可用性检查
|
||||||
if (IsUsability) {
|
if (IsUsability) {
|
||||||
//累加当前帧时间
|
//累加当前帧时间
|
||||||
CurrentIndexT += dt;
|
CurrentIndexT += dt;
|
||||||
|
|
||||||
//当前帧时间 超过 当前帧延迟就需要切换帧了
|
//当前帧时间 超过 当前帧延迟就需要切换帧了
|
||||||
if (CurrentIndexT >= FrameArr[CurrentFrameIndex].Delay) {
|
if (CurrentIndexT >= NextFrameDelay) {
|
||||||
CurrentIndexT = 0;
|
CurrentIndexT = 0;
|
||||||
//如果当前帧小于总帧数就切换
|
//如果当前帧小于总帧数就切换
|
||||||
if (CurrentFrameIndex<(FrameArr.len() - 1)) {
|
if (CurrentFrameIndex<(TotalFrameIndex - 1)) {
|
||||||
FlushFrame(CurrentFrameIndex + 1);
|
FlushFrame(CurrentFrameIndex + 1);
|
||||||
}
|
}
|
||||||
//说明播放完毕了
|
//说明播放完毕了
|
||||||
|
|
@ -206,10 +212,8 @@ class Animation extends Actor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//Animation类下只会有精灵 因此不需要对子对象进行更新
|
||||||
base.OnUpdate(dt);
|
// base.OnUpdate(dt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue