Skip to content

Instantly share code, notes, and snippets.

@chasepeck
Last active July 1, 2022 11:52
Show Gist options
  • Save chasepeck/64b6970133f9bcc7e9f3de3f41d8c84f to your computer and use it in GitHub Desktop.
Save chasepeck/64b6970133f9bcc7e9f3de3f41d8c84f to your computer and use it in GitHub Desktop.
AC system
function ac(_curve, _channel, _step, _backwards = false, _frame = 0, _disabled = false, _mn = 0, _mx = 1, _autoreset = true, _autodisable = true) constructor {
curve = _curve;
channel = _channel;
step = _step;
backwards = _backwards;
frame = _frame;
disabled = _disabled;
mn = _mn;
mx = _mx;
autoreset = _autoreset;
autodisable = _autodisable;
static update = function() {
if(!disabled) {
if(!backwards)
frame = clamp(frame + step, mn, mx);
else
frame = clamp(frame - step, mn, mx);
}
if(frame == 0) {
if(autoreset) backwards = false;
if(autodisable) disabled = true;
}
value = animcurve_channel_evaluate(animcurve_get_channel(curve, channel), frame);
}
static reset = function(maximum = false) {
if(!maximum) frame = mn;
else frame = mx;
}
}
function ac_updateall(arr) {
for(var i = 0; i < array_length(arr); i++){
arr[i].update();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment