Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to make my player animate via a sprite sheet.

I looked online and there are many different ways; I want to know what is the best way. Which method will allow me greater flexibility when working with sprite sheets, including, for instance, changing the speed of animation, slowing down the animation, playing a punching animation when the space bar is hit, shooting, etc.?

Is there a better way to do animation than this:

public class SpriteSheet
    public BufferedImage spriteSheet;

    public SpriteSheet(BufferedImage ss)
        this.spriteSheet = ss;

    public BufferedImage grabSprite(int x, int y, int width, int height)
        BufferedImage sprite = spriteSheet.getSubimage(x,y,width,height);
        return sprite;

public class BufferedImageLoad
    public BufferedImage loadImage(String path) throws IOExceiption
        URL url = this.getClass().getResource(path);
        BufferedImage img =;
        return img;

public class main
    public void init()
        BufferedImageLoad loader = new BufferedImageLoad();
        BufferedImage spriteSheet = null;
        try {
            spriteSheet = loader.loadImage("spritesheet.png");
        catch(IOException ex) { 

        SpriteSheet ss = new SpriteSheet(spriteSheet);
        sprite = ss.grabSprite(0,0,20,20);
    g.drawImage(sprite, 100,100,10,10,null);
share|improve this question

closed as too localized by Sean Middleditch, Trevor Powell, bummzack, Byte56, Josh Petrie Mar 27 '13 at 13:59

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

If it works, then it's a good way. If it works for you, it's probably the best way. – user1306322 Mar 23 '13 at 5:22
This android or jogl or what? – Technik Empire Mar 24 '13 at 3:19

I can't see any tags I'm on mobile... looks like Java but no idea what framework or anything. When I wrote my engine the best way I figured was to create texture mappings for each part of the sprite sheet and push them all to a single VBO. This way you can just store the indices of the different mappings and have the texture maps permanently stored on the GPU and not have to rebind to different vbos. To my knowledge this is where you're going to get optimal performance since there's no vertex buffer rebinding during draw calls, no processor overhead of redrawing bitmap pixel etc. Basically your animations and static images are all cached on the gpu so I don't think it gets much better than that for performance.

Again this depends on if you have direct access to GL draw calls etc and as others have pointed out, if it works well just leave it.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.