Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (581)
Games in Android Showcase (162)
games submitted by our members
Games in WIP (632)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  LWJGL Best way to handle 2D Sprite Animations?  (Read 1808 times)
0 Members and 1 Guest are viewing this topic.
Offline Clepto

Senior Newbie

Exp: 3 years

« Posted 2014-05-11 20:04:46 »

Hi, I'm wondering if there is a "recommended" way or something that would be better than what I'm currently doing.

My game currently has animations that are hundreds of frames, and there are hundreds of animations. I'm wondering if loading each of those frames as a separate image and then running those through a loop of some sort is the best way to do it.

Currently there is a spritesheet for each animation, that image is loaded as a BufferedImage, then the code splits it into individual BufferedImages for each frame, and adds them to the animation. It just seems like there is a much more efficient way to do this, perhaps some external library exists that makes animations easier.

I've entertained the idea of defining animations with XML or something like that, and loading the different limbs and bone structures of say a player, and having the code itself run through the animation rather than running through frames.

I'm not really seeing any performance issues doing this way, but it seems like there should be a better way.

Please don't say use LibGDX, I'm making it from straight LWJGL as I'm more interested in learning the core stuff than finishing a complete game.
Offline Bearded Cow

Senior Devvie

Medals: 2
Projects: 1
Exp: 1 year


« Reply #1 - Posted 2014-05-11 20:07:29 »

If you don't want to go fully with LibGDX I would recommend Slick2D. It is very useful.
Offline Clepto

Senior Newbie

Exp: 3 years

« Reply #2 - Posted 2014-05-11 20:09:48 »

If you don't want to go fully with LibGDX I would recommend Slick2D. It is very useful.

I have used Slick2D before, and I probably will for actually loading the images at some point, but right now I'm just wondering if there is a better way that anyone knows of to handle the actual animation other than just loading each frame as a separate image.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Drenius
« Reply #3 - Posted 2014-05-11 20:33:35 »

Look into skeletal animation.
Spine is a (probably) good tool for this, but looking at it at is least helpful to understand the concept.
Offline Clepto

Senior Newbie

Exp: 3 years

« Reply #4 - Posted 2014-05-11 20:58:00 »

Look into skeletal animation.
Spine is a (probably) good tool for this, but looking at it at is least helpful to understand the concept.

Would this be able to work well with a physics library? I can't think of a specific one I would use yet, but in theory would it be compatible with it(E.g. character get's blown up and falls around places with limbs freely flailing), is that how that is commonly done?
Offline Cero
« Reply #5 - Posted 2014-05-11 23:08:29 »

Spine is a different concept, its for ragdoll animations n stuff - of course you can also use it to render those frame to images

@question: usually you use a spritesheet aka textureAtlas

like so:

Click to Play

Offline Nate

« JGO Bitwise Duke »

Medals: 164
Projects: 4
Exp: 14 years

Esoteric Software

« Reply #6 - Posted 2014-05-12 10:17:57 »

Spine would reduce your need to have so many images, as well as allow you to have many more animations, including procedural animation (eg looking at the mouse).

Offline cylab

JGO Ninja

Medals: 79

« Reply #7 - Posted 2014-05-12 10:37:13 »

The OP already stated that he has a spritesheet, but splits it into multiple separate images on the "java-side".

This is not the right way to do it. Just load your complete spritesheet as one texture and change the texture coordinates of your Quad (or whatever you are using) to only contain the sprite frame you want to draw.

Take a look here: for inspiration

Mathias - I Know What [you] Did Last Summer!
Offline Clepto

Senior Newbie

Exp: 3 years

« Reply #8 - Posted 2014-05-13 23:47:54 »

Thanks for the help guys. I think I may end up switching to LibGDX and using Spine. I currently will have over 10,000 animations if I keep doing it this way, and most likely many more than that. I think from what I've been Spine will be exactly what I need. Thanks for the advice.
Offline GNecro1
« Reply #9 - Posted 2014-07-14 21:35:09 »

This is how i do it, no LWJGL!

import java.awt.image.BufferedImage;

public class Animation {

   private BufferedImage[] animImages = {};
   private boolean animate = false;
   private int index = 0;
   private long miliSeconds, targetTime, now;

   public Animation(int mili,BufferedImage[] images) {
      this.miliSeconds = mili;
      animImages = images;
      now = System.currentTimeMillis();
      targetTime = now + miliSeconds;
   public void stopAnimation(){
      animate = false;
   public void startAnimation(){
      animate = true;
   public BufferedImage getCurrentImage(){
      if(index < 0 || index > animImages.length){
         new Exception();
      return animImages[index];
   public void disposeAnimation(){
   public void setIndex(int i){
      index = i;
   public void tick(){
      if (System.currentTimeMillis() >= targetTime && animate) {
         now = System.currentTimeMillis();
         targetTime = now + miliSeconds;
            index = 0;


Java freak! Cheesy
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

MrMapcom (15 views)
2015-05-23 20:26:16

MrMapcom (22 views)
2015-05-23 20:23:34

Waterwolf (29 views)
2015-05-20 15:01:45

chrislo27 (35 views)
2015-05-20 03:42:21

BurntPizza (70 views)
2015-05-10 15:53:18

FrozenShade (56 views)
2015-05-07 09:11:21

TheLopais (218 views)
2015-05-06 13:36:48

TheLopais (202 views)
2015-05-06 13:35:14

TheLopais (207 views)
2015-05-06 13:33:39

TheLopais (226 views)
2015-05-06 13:32:48
List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!