TDD EASE SCRIPT

RPG Maker VX Ace

Implements selectable easing motion for use with Move Picture and Tint Picture event calls, as well as direct calls in scripts

Version: 1.0.1
Updated: 08/12/2013

Introduction
Have you tried using the Move Picture event command in Ace? You'll notice that, if you move the picture's position from one spot to another, the movement in between is linear - it moves from point A towards point B in X amount of frames in equal amounts each frame. A lot of the time this is fine, but what if you want to move the pictures quickly but with a little slowing down at the end, for example for a "pop up" effect? That's what easing can do. Easing is using math to apply a modified movement curve to an object's attributes over a given period of time. Math has a tendency to sound boring, doesn't it? Video time!



The video above shows how a Move Picture event and a Tint Picture event are changed based on the selected easing method; the duration and settings in the events are the same, only the applied easing algorithm changes, to often drastic effect. Here's a screenshot of how easy it is to set an easing method:



By setting the Game_Picture.easing value to Easing::BOUNCE_OUT, all subsequent calls to Move Picture and Tint Picture are affected. You can set different easing methods for tint and move by adding another script call in between them, and there is no limit to how many pictures you can animate like this at any time. The script hooks into the update loop and replaces the default animation methods with the new easing one; as far as I can tell, there is no performance hit whatsoever.



This second video shows the use of three new Move Route script calls you can call to use easing for moving events and characters:

* ease_moveto(x, y, duration, easing_method)
* ease_moveto_char(char_id, duration, easing_method)
* ease_opacity(opacity, easing_method)

Features
* Works on both Move Picture and Tint Picture
* Three available Move Route script calls for easing events and characters.
* 7 groups of easing methods, each with 3 variations: In, out and in-out. Also includes an improved (performance vise) version of the default Linear ease method.
* Fully documented script - makes it very easy for scripters to use the Ease module for their own animations
* Fully modular script setup - like the above, this will help other scripters (and myself!) extend the functionality of the Ease module with new Easing algorithms, and using the Ease module in other scripts
* Virtually no performance hit as far as I have been able to tell, due to using mathematical algorithms to affect only the attributes of objects and hooking into the default update loop

How to use
To install this script, open up your script editor and copy/paste this script to an open slot below Materials but above Main. Remember to save.

Using in event editor:
Before calling Move Picture and Tint Picture for a picture in the event editor, make a script call like this:
Game_Picture.easing = Easing::ELASTIC_OUT

This will set the easing method to the ELASTIC_OUT algorithm. When you erase any picture using Erase Picture, the easing method is reset to the set default (Easing::LINEAR by default)
You can provide different easing methods for different events as well, by setting Game_Picture.easing between each call. It is remembered for each individual event call.

If you wish to set the default easing, you use the following in a script call:
Game_Picture.easing_default = :elastic_out

# :elastic_out is shorthand for Easing::ELASTIC_OUT. You could also write "elastic_out"; it's up to you :)


You can look at the picture linked above in the introduction section for a visual demonstration of the script call.

Using in Move Routes:
There are 3 Move Route script calls you can use. Below are the script calls and an explanation of the parameters. You place these within an event's Move Route by using the Script button. Here is the documentation describing the different script calls and their parameters:

ease_moveto(x, y, duration, easing)

#--------------------------------------------------------------------------
# * Move To Position
# Params:
# =======
# - x (integer or "string")
# The x position to move to.
# if integer then absolute X position on map
# if string then relative to current position. Examples:
# "0" -> 0 from current x pos
# "-5" -> -5 from current x pos
# "5" or "+5" -> +5 from current x pos
# - y (integer or "string")
# The y position to move to. Same rules as x param
# - duration (integer)
# How many frames the easing should last for
# - easing (:symbol or "string")
# The easing method to apply. Default is :linear
#--------------------------------------------------------------------------

ease_moveto_char(char, duration, easing)
#--------------------------------------------------------------------------
# * Move Character To Other Character
# Params:
# =======
# - char (integer)
# An integer noting the character to move to.
# -1 -> player
# 0 -> the current object calling this method
# 1 and above -> event id on the current map
# - duration (integer)
# How many frames the easing should last for
# - easing (:symbol or "string")
# The easing method to apply. Default is :linear
#--------------------------------------------------------------------------

ease_opacity(opacity, duration, easing)
#--------------------------------------------------------------------------
# * Ease To Opacity
# Params:
# =======
# - opacity (integer or "string")
# Target opacity to ease to. If string, then relative to current opacity
# value. See ease_moveto's x param for more on how to use relative
# string values.
# - duration (integer)
# How many frames the easing should last for
# - easing (:symbol or "string")
# The easing method to apply. Default is :linear
#--------------------------------------------------------------------------

Here are two in-editor examples:

The above uses the relative position X and Y coordinates "0" and "+6" respectively, by setting them as strings. The duration is set as 90 frames, and the easing method is :bounce_out.

The above uses ease_moveto to move the entity to 11x, 0y, over 90 frames, using the easing method :circ_in. An opacity ease is chained in the same call (must be separated with ";") easing the opacity to 0 over 120 frames.

The following is a list of all available easing methods included by default:

LINEAR (default, and like the default in VXAce)
BACK_IN
BACK_IN_OUT
BACK_OUT
BOUNCE_IN
BOUNCE_IN_OUT
BOUNCE_OUT
CIRC_IN
CIRC_IN_OUT
CIRC_OUT
CUBIC_IN
CUBIC_IN_OUT
CUBIC_OUT
ELASTIC_IN
ELASTIC_IN_OUT
ELASTIC_OUT
EXPO_IN
EXPO_IN_OUT
EXPO_OUT
QUAD_IN
QUAD_IN_OUT
QUAD_OUT

Demo
This is a download for the demo shown in the video

Script
This is a direct link to a .rb file with the script
You can also copy-paste the script from the scriptcode area below, but the above link is guaranteed to be up-to-date :)

Credits and thanks
– Galenmereth / Tor Damian Design (that's me)
– Tsukihime (For the "Hime External Script Loader" script in the demo file)
https://github.com/ai/easings.net: For a few of the base algorithms. Free and open source.

License
Free for non-commercial and commercial use. Credit greatly appreciated but not required. Share script freely with everyone, but please retain this license unless you change the script completely. Thank you.

Author's notes
Currently planned future extensions:
* Rotate implementation (I can't extend the Rotate Picture event command due to its structure, so I will have to make a script call for this)

Feel free to request an extension or modification, and please give me your feedback; it's greatly appreciated.