1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

Smooth Motion: Tweening in Gosu with Ruby

By

3 of 4

Run the Demo
Smooth Motion: Tweening in Gosu with Ruby

The demo can be found in your gem's directory in $GEM_HOME. If you can't find it there, you can download it from here. To run it, simply run demo.rb. Click anywhere in the window the the sprite will move. Use the left and right keys to change the easer.

In the background, you'll see a graph displayed. This is a graph of time and position relative to the starting location. The linear graph is straight, but the other easers have more interesting graphs.

When you start the demo, the Tween::Linear easer will be selected. This is the simplest easer, it'll provide evenly spaced intermediate points from point A to point B. It provides rather stiff animation, but that's what we're trying to avoid. Try some easings such as Tween::Cubic::Out and Tween::Quart::InOut for some examples of more fluid animation.

There are also some more interesting easings that do a bit more than get the sprite from point A to point B. For example, Tween::Bounce::Out makes it look like the sprite bounces off of point B and eventually comes to rest. Tween::Elastic::Out makes it look like the sprite is being held to point B with an elastic band. And Tween::Back::Out makes it look like the sprite overshot point B and had to back up. These can provide for some interesting effects in games.

©2014 About.com. All rights reserved.