Blog

Fluent Animation & Effects for your next Slick Game.

13 February 2009
Alex at Another Early Morning has written an animation and effects library with the aims of providing rich and concise animations and effects to games without the need to restructure the game architecture.
It will run on Java 1.5+ and has no depencencies, and can be used (if not preferred) with Slick.

It is surprisingly easy to use. Here is a simple usage (using Slick):

public class FluentFXTest extends BasicGameState
{
	public Image logo;
	public Timeline fx;
	public FluentConfig;

	@Override
	public void init(GameContainer container, StateBasedGame game) 
							throws SlickException
	{
		logo = new Image("image.png");
	
		config = new FluentConfig();
		config.add("setRotation", 0, 360, 1000);

		fx = new Timeline(logo, config);
		fx.forwards().loop();
		fx.start();
	}

	@Override
	public void update(GameContainer container, StateBasedGame game, int delta) 
							throws SlickException 
	{
		fx.step(delta);
	}

	@Override
	public void render(GameContainer container StateBasedGame game, Graphics g) 
							throws SlickException 
	{
		logo.draw();
	}

	@Override
	public int getID() 
	{
		return 0;
	}
}
What does this do exactly? Assuming you know the Slick2D library, I'll explain.

In the init() method, the statement config.add(\"setRotation\", 0, 360, 1000); will configure the Timeline. The first parameter specifies which method to call, in this case it is setRotation(angle). The second and third parameters set the values to go from and to, such as from setRotation(0) to setRotation(360). The final parameter specifies the amount of time to take performing this action, this is measured in milliseconds.

Also in the init() method, the statement fx.forwards().loop(); configures the Timeline. This statement tells the Timeline to go forwards until the end of the timeline, and then loop again from the beginning. The following line fx.start(); tells the Timeline to start. The timeline however wont do anything unless fx.step(delta) is called with delta being the number of milliseconds since the last call to update().

In a nutshell, this will rotate the image 360 degrees over one second, and repeat doing so infinitely.

Also, the object you pass into the Timeline doesn't have to be an Image; you can pass in any object that you like.

I will be using this library in creating Damon the Dinosaur.

To see the original article, see here.
Share:
Share on Facebook
Tags: