GM Tween

Version 7.1.0
Written by Tyler Gill


Intro

As I worked with Game Maker, I realized that it was missing something very important - a simple animation tool. Then, as I began learning to work with Adobe Flash, I decided that the time was ripe for a Game Maker variation on tweening.

Functions

There are several functions that can be used with the GM Tween engine to initiate tweens. The follow basic functions exist to tween a color or number from an initial value to an ending value over a certain amount of time.

tween(id, variable, start, stop, time) This function begins a tween of instance id's variable (given as a string) from value start to value stop in time number of frames, without any more advanced options.
tween_color(id, variable, start, stop, time) This function begins a tween of of instance id's color variable (given as a string) from value start to value stop in time number of frames, without any more advanced options.

In addition to those more simple aimation effects, GM Tween can perform several more advanced functions, and include easing and looping. Easing is the process of having the tween change the speed at which it processes through the animation. For example, a car object might tween to a stop at a stop sign, and slow down as it moves. Here are some of the options for easing (sorry I can't remember how they all look/travel like):

TWEENEASE_REG The default easing, it just goes straight through.
TWEENEASE_SIN_UP Sin function on it's way up (starts fast, slows down).
TWEENEASE_COS_UP Sin manipulation (starts slow, speeds up).
TWEENEASE_LOG Logistic function. (Starts slow, speeds up, slows down)
TWEENEASE_LOG_INV
Inverse logistic function. (Starts fast, slows down, speeds up)

Here they all are as the function that is processed (x is the percent of time through the tween, and the result is the value the tween is placed at between start and stop):

TWEENEASE_REG "x"
TWEENEASE_SIN_UP "sin(x*(pi/2))"
TWEENEASE_SIN_DOWN "sin((x*(pi/2))+(pi/2))"
TWEENEASE_COS_UP "1-sin(x*(pi/2))"
TWEENEASE_COS_DOWN "1-sin((x*(pi/2))+(pi/2))"
TWEENEASE_LOG "1/(1+exp(-10*x+5))"
TWEENEASE_LOG_INV
"(ln((1/x)-1)-5)/-10"

Looping in GM Tween is defined in one of three ways:

TWEENREPEAT_NONE Animates the tween once.
TWEENREPEAT_LOOP Loops forwards, then backwards through the tween.
TWEENREPEAT_PULSE Pulsates through the animation by jumping back to the beginning when it's done.

In addition, the general tweening functions require a specification for the type of tween. Currently, only these are supported:

TWEENTYPE_REG Regular tweening (one number to the next)
TWEENTYPE_COLOR Color tweening

And without further ado, here is the final function:

tween_gen(id, variable, start, stop, time, [type, repeat, easing]) Tweens the variable variable of type type with repeat repeat and easing easing from start to stop in time frames. Note that the type, repeat, and easing will default to TWEENTYPE_REG, TWEENREPEAT_NONE, and TWEENEASE_REG if they are not specified (don't use -1!).