Pixel-Composer/scripts/animation_controller/animation_controller.gml

60 lines
1.2 KiB
Text
Raw Normal View History

2022-12-10 11:06:01 +07:00
#region anomation class
function AnimationManager() constructor {
2023-03-07 20:29:47 +07:00
frames_total = 30;
current_frame = 0;
real_frame = 0;
2023-01-01 08:06:02 +07:00
time_since_last_frame = 0;
2023-03-07 20:29:47 +07:00
framerate = 30;
is_playing = false;
frame_progress = false;
play_freeze = 0;
2022-12-10 11:06:01 +07:00
2022-12-23 10:45:52 +07:00
rendering = false;
2022-12-10 11:06:01 +07:00
playback = ANIMATOR_END.loop;
static setFrame = function(frame) {
2023-04-10 20:02:59 +02:00
//if(frame == 0) resetAnimation();
2022-12-12 15:08:03 +07:00
var _c = current_frame;
2023-02-14 08:51:14 +07:00
frame = clamp(frame, 0, frames_total);
2022-12-10 11:06:01 +07:00
real_frame = frame;
current_frame = round(frame);
2022-12-12 15:08:03 +07:00
2023-02-14 08:51:14 +07:00
if(current_frame == frames_total) {
if(playback == ANIMATOR_END.stop || rendering) {
is_playing = false;
rendering = false;
} else
setFrame(0);
}
if(_c != current_frame) {
2022-12-12 15:08:03 +07:00
frame_progress = true;
2023-02-14 08:51:14 +07:00
time_since_last_frame = 0;
2023-03-31 11:59:08 +07:00
UPDATE |= RENDER_TYPE.full;
2023-03-02 13:59:14 +07:00
} else
frame_progress = false;
2022-12-10 11:06:01 +07:00
}
2023-04-10 20:02:59 +02:00
static resetAnimation = function() {
var _key = ds_map_find_first(NODE_MAP);
var amo = ds_map_size(NODE_MAP);
repeat(amo) {
var _node = NODE_MAP[? _key];
_node.resetAnimation();
_key = ds_map_find_next(NODE_MAP, _key);
}
}
2022-12-10 11:06:01 +07:00
}
#endregion
#region object
2022-12-19 19:35:30 +07:00
enum ANIMATOR_END {
loop,
stop
}
2022-12-10 11:06:01 +07:00
globalvar ANIMATOR;
ANIMATOR = new AnimationManager();
#endregion