Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon

9. December 2013


Back in Tutorial 3 I created a simple animation using a Timer and setting the frame manually from a TextureAtlas.  This is not the ideal way to perform animation using LibGDX and was done to illustrate how to use a TextureAtlas, not how to perform animation.  Instead the better way to perform animations is using the Animation class.  Here is an example using the same spritesheet from tutorial 3, remember you need to add it to the Android project assets folder.


package com.gamefromscratch;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;

public class AnimationDemo implements ApplicationListener {
    private SpriteBatch batch;
    private TextureAtlas textureAtlas;
    private Animation animation;
    private float elapsedTime = 0;
    public void create() {        
        batch = new SpriteBatch();
        textureAtlas = new TextureAtlas(Gdx.files.internal("data/spritesheet.atlas"));
        animation = new Animation(1/15f, textureAtlas.getRegions());

    public void dispose() {

    public void render() {       , 0, 0, 1);;
        elapsedTime +=;
        batch.draw(animation.getKeyFrame(elapsedTime, true), 0, 0);

    public void resize(int width, int height) {

    public void pause() {

    public void resume() {

When you run it, you should see:



The key here is the Animation, created here:

animation = new Animation(1/15f, textureAtlas.getRegions());

When creating an animation you pass in the amount of time per frame ( 15 frames per second in this case ) and an array of TextureRegions.  These represent the individual frames of animation within the TextureAtlas.  In this particular example we are simply using all of the frames available within the Atlas as a single animation.  The next key change is:

elapsedTime +=;

batch.draw(animation.getKeyFrame(elapsedTime, true), 0, 0);

Here we are simply drawing the current frame from the animation to the screen.  We pass in the amount of time that has elapsed so the animation knows where it is in the sequence.  The true parameter is telling it to loop the animation.


Of course, you can have multiple animations from a single texture Atlas.  Consider the spritesheet we are currently working with.  If you take a look at the .atlas file, you will see each individual frame is named:



Looking at the spritesheet, you will see the animations are organized like such:



What we want to do is treat this as two sepeate animations.  Frames 1 through 10 represent an upward roll, while 11-20 are a downward roll.  Let’s take a look at how we do that:

public void create() {        
    batch = new SpriteBatch();
    textureAtlas = new TextureAtlas(Gdx.files.internal("data/spritesheet.atlas"));
    TextureRegion[] rotateUpFrames = new TextureRegion[10];
    // Rotate Up Animation
    // Create an array of TextureRegions
    rotateUpFrames[0] = (textureAtlas.findRegion("0001"));
    rotateUpFrames[1] = (textureAtlas.findRegion("0002"));
    rotateUpFrames[2] = (textureAtlas.findRegion("0003"));
    rotateUpFrames[3] = (textureAtlas.findRegion("0004"));
    rotateUpFrames[4] = (textureAtlas.findRegion("0005"));
    rotateUpFrames[5] = (textureAtlas.findRegion("0006"));
    rotateUpFrames[6] = (textureAtlas.findRegion("0007"));
    rotateUpFrames[7] = (textureAtlas.findRegion("0008"));
    rotateUpFrames[8] = (textureAtlas.findRegion("0009"));
    rotateUpFrames[9] = (textureAtlas.findRegion("0010"));

    rotateUpAnimation = new Animation(0.1f,rotateUpFrames);
    // Rotate Down Animation
    // Or you can just pass in all of the regions to the Animation constructor
    rotateDownAnimation = new Animation(0.1f,



As you can see, it’s easy to create multiple animations from a single TextureAtlas.  Keep in mind, when creating a TextureAtlas using TexturePacker, it was the filename that you passed in that created the region names.  So what you would generally do is name your separate animations accordingly, such as WalkLeft, WalkRight, etc. 

Programming , ,

blog comments powered by Disqus

Month List

Popular Comments

Autodesk announced 2015 versions of products and silently kill off Softimage
Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon

Home > News >

18. March 2014


With GDC going on it’s no surprise to hear a number of product announcement.  Today Autodesk announced the annual refresh of almost all of their game related technologies including Maya and Maya LT, Max, MotionBuilder, Mudbox and Softimage. 


From the official press release here are the major new features for each product:

Autodesk Maya 2015 software adds new capabilities to the toolset such as the new Bifrost
procedural effects platform which provides an extensible, artist-friendly workflow for complex
simulation and rendering tasks, initially applied to near photorealistic liquids; XGen Arbitrary
Primitive Generator for the easy creation of richly detailed geometry such as hair, fur, and foliage; 
Geodesic Voxel Binding method for skinning characters; ShaderFX, a new node-based visual
interface for shader programing; support for Pixar’s OpenSubdiv libraries; enhanced polygon
modeling tools; and expanded UV options;

Autodesk 3ds Max 2015 software has been extended and redesigned to help improve
performance, ease-of-use and management of complex scenes. New in 2015 is ShaderFX, a new
node-based visual interface that allows game artists and programmers to more easily create
advanced HLSL viewport shaders; point cloud dataset support for reality capture workflows; new
viewport performance optimizations; a redesigned scene explorer to make it easier for artists to
manage large scenes; ActiveShade support for the NVIDIA mental ray renderer; and new Python
scripting support – a highly requested user feature for pipeline integration; 

Autodesk MotionBuilder 2015 provides several features that advance motion capture workflow
accessibility such as: a new plug-in for Microsoft Kinect to help capture body movements for use
in MotionBuilder, Animatable Depth of Field and Follow Focus camera options to recreate
elements of real-world cinematography, a robust content library with 100 commonly required
character animations in the Autodesk FBX®
format and flexible marker assignment to adjust
character positions;

Autodesk Mudbox 2015 software boasts streamlined mesh refinement for retopologizing and new
Sculpt Layer and Paint Layer groups for organizing and identifying particular layers in complex
scenes. The release also has advanced interoperability with Maya 2015, an enhanced texture
export and updating workflow, new caliper tool and support for Intel HD graphics 4000 on
compatible Windows 8 operating system hybrid tablet/PCs;

Autodesk Softimage 2015* software helps streamline 3D asset creation and management with
Alembic caching, enhancements to the ICE platform and animatable weight maps in Syflex cloth.

Autodesk Maya LT 2015 Software  Streamlines Indie Game Development

Maya LT 2015, the latest iteration of Autodesk’s cost-effective 3D animation and modeling software for
professional indie game makers, introduces a series of rich new features and integrations that help
advance the 3D content creation process for indie game development.

The updated application has:

  • Cloud integration allows artists to browse, open, modify and save Dropbox or Autodesk 360 files to the cloud directly through the Maya LT interface. Leverage 123D Catch or 123D Creature files saved in Autodesk’s 123D cloud storage as a reference for creating game assets in Maya LT;
  • Unfold 3D helps facilitate the seamless creation of UV maps from 3D models;
  • Substance Material Integration allows users to apply materials created in the Allegorithmic Substance Designer procedural texture creation tool to 3D models

In addition to the new features, Maya LT 2015 also has the extension releases of Maya LT 2014, such as:
support for MEL scripting, a send-to-Unity workflow, uncapped polygon export to Unity, the ability to
export models or scenes up to 65,000 polygons in the FBX or OBJ formats, Human IK and IK Handle
Animation, and Boolean operations on polygon geometry.


Notice the little asterisk beside Softimage 2015?  Well, here is the fine print.

* Editor’s Note: Softimage 2015 will be the final new release of this product.


So there you have it, Autodesk finally killed it off.  I think the writing has been on the wall for a long time, but it still sad to see an old friend go.

News ,

blog comments powered by Disqus

Month List

Popular Comments