Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

If I have a 200x200 pixel sprite, and I want to create an animation for it with 30 different frames, how can I accomplish that? I can't put them on one texture/spritesheet.

share|improve this question

3 Answers 3

up vote 3 down vote accepted

You just need to abstract your animation system enough that it doesn't care (read: know) where each frame of the animation is coming from. I have built one such system myself where each animation sequence is built up using a list of frames, where each frame is merely a rectangular section of some image. Using that set of definitions, the animation sequence does not know that each frame is on a different texture.

Assuming you're restricted to something larger than 256x256, you can still pack multiple frames into each texture. I would recommend doing this for a number of reasons that I'll let someone else explain.

share|improve this answer
    
+1 - This is what I do and it works very well. –  Cypher Sep 14 '12 at 23:32

This is an extension of @John McDonald's answer.

Here's a stripped-down example of how to abstract your code-base so other systems of your library/application won't care about individual files. (Example is in C#):

public static class TextureStorage {
    public List<TextureObject> Textures;  // list of all textures used in the game
}

public class AbstractTexture {
    public int TextureId;         // the index of the texture
    public Rectangle SourceRect;  // the source rect describing where in the texture
                                  // to get the image from

    public TextureObject GetTextureObject() {
        return TextureStorage.Textures[ this.TextureId ];
    }
}

Now everything can reference your AbstractTexture and not care what file it came from.

When your rendering system goes to draw a frame, you'll have all the information handy:

public void Draw() {
    ...
    someBlitFunction(
        someObject.AbstractTexture.GetTexture(), // the texture to render
        someObject.AbstractTexture.SourceRect,   // the source rect
        someObject.Position,                     // the dest rect
        ... );
    ...
}
share|improve this answer

You can convert the size of your image a little bigger or smaller according to the appropriate size. I had used this link - http://www.garyshood.com/imageconvert/ You can use a size that would be completely divisible by 2. For example, if your image size is 200, then 200/2=100;100/2=50;50/2=25, so here 25 is not divisible by 2. Therefore, 200 is not an appropriate size. You can use 1024, 512, 256, 128 and so on..

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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