2025-11-08 12:21:06 +08:00
|
|
|
/*
|
2026-01-14 20:28:24 +08:00
|
|
|
文件名:CustomAnimation_Class.nut
|
|
|
|
|
路径:Base/_Tool/CustomAnimation_Class.nut
|
|
|
|
|
创建日期:2026-01-13 19:54
|
|
|
|
|
文件用途:
|
2025-11-08 12:21:06 +08:00
|
|
|
*/
|
2026-01-14 20:28:24 +08:00
|
|
|
class Rindro_CustomAnimation {
|
2025-11-08 12:21:06 +08:00
|
|
|
|
2026-01-14 20:28:24 +08:00
|
|
|
//Img路径
|
2025-11-08 12:21:06 +08:00
|
|
|
ImgPath = null;
|
2026-01-14 20:28:24 +08:00
|
|
|
//Img对象
|
|
|
|
|
Img = null;
|
|
|
|
|
//帧信息
|
2025-11-08 12:21:06 +08:00
|
|
|
ImgFrame = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//播放状态
|
|
|
|
|
State = 0;
|
|
|
|
|
//循环
|
|
|
|
|
LoopFlag = true;
|
|
|
|
|
|
|
|
|
|
//当前帧数
|
|
|
|
|
CurFrame = 0;
|
|
|
|
|
//初始化时间
|
|
|
|
|
InitTime = 0;
|
|
|
|
|
//Ani当前帧播放时间
|
|
|
|
|
PlayCurTime = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//img 路径 调用帧数组
|
2026-01-14 20:28:24 +08:00
|
|
|
constructor(path, frame) {
|
|
|
|
|
ImgPath = path.tolower();
|
|
|
|
|
Img = Rindro_Image(ImgPath);
|
2025-11-08 12:21:06 +08:00
|
|
|
ImgFrame = frame;
|
|
|
|
|
InitTime = Clock();
|
|
|
|
|
State = 1;
|
2026-01-14 20:28:24 +08:00
|
|
|
|
|
|
|
|
//预载入img
|
|
|
|
|
foreach(FrameObj in ImgFrame) {
|
|
|
|
|
Img.DrawPng(FrameObj.ImgIndex, -999, 999);
|
|
|
|
|
}
|
2025-11-08 12:21:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2026-01-14 20:28:24 +08:00
|
|
|
function Show(dt, X, Y) {
|
2025-11-08 12:21:06 +08:00
|
|
|
if (State == 1) {
|
|
|
|
|
if (ImgFrame) {
|
|
|
|
|
local NowFrameObj = ImgFrame[CurFrame];
|
|
|
|
|
PlayCurTime += dt;
|
2026-01-14 20:28:24 +08:00
|
|
|
Img.DrawPng(NowFrameObj.ImgIndex, NowFrameObj.Pos[0] + X, NowFrameObj.Pos[1] + Y);
|
|
|
|
|
|
2025-11-08 12:21:06 +08:00
|
|
|
if (PlayCurTime >= NowFrameObj.Delay) {
|
|
|
|
|
CurFrame++;
|
|
|
|
|
//播放完成
|
|
|
|
|
if (CurFrame >= ImgFrame.len()) {
|
|
|
|
|
if (LoopFlag) CurFrame = 0;
|
|
|
|
|
else State = 0;
|
|
|
|
|
}
|
|
|
|
|
InitTime = Clock();
|
|
|
|
|
PlayCurTime = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-14 20:28:24 +08:00
|
|
|
function ShowEx(dt, X, Y, gRgba, rate_x, rate_y) {
|
2025-11-08 12:21:06 +08:00
|
|
|
if (State == 1) {
|
|
|
|
|
if (ImgFrame) {
|
|
|
|
|
local NowFrameObj = ImgFrame[CurFrame];
|
|
|
|
|
PlayCurTime += dt;
|
2026-01-14 20:28:24 +08:00
|
|
|
Img.DrawExPng(NowFrameObj.ImgIndex, NowFrameObj.Pos[0] + X, NowFrameObj.Pos[1] + Y, 0, gRgba, rate_x, rate_y);
|
2025-11-08 12:21:06 +08:00
|
|
|
if (PlayCurTime >= NowFrameObj.Delay) {
|
|
|
|
|
CurFrame++;
|
|
|
|
|
//播放完成
|
|
|
|
|
if (CurFrame >= ImgFrame.len()) {
|
|
|
|
|
if (LoopFlag) CurFrame = 0;
|
|
|
|
|
else State = 0;
|
|
|
|
|
}
|
|
|
|
|
InitTime = Clock();
|
|
|
|
|
PlayCurTime = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-14 20:28:24 +08:00
|
|
|
function Reset() {
|
2025-11-08 12:21:06 +08:00
|
|
|
CurFrame = 0;
|
|
|
|
|
State = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|