2
\$\begingroup\$

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.

\$\endgroup\$
3
\$\begingroup\$

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.

\$\endgroup\$
0
1
\$\begingroup\$

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
        ... );
    ...
}
\$\endgroup\$
1
\$\begingroup\$

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..

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .