In the main menu of my game I have several animations that pause in specific frames.

I made the sprite sheets for the different layers, but then I found out that the sprite sheet has to be smaller than 2048 pixels. My sprite sheet is 14400 pixels with 18 frames...

How can I play these large animations? I tried video playback but I couldn't find a way to do this...


Don't make a sprite sheet.

You are going to want to just create a


with each frame of animation inside. It will be much more efficient on video memory usage, as you are only passing each frame of animation when the video card needs it, instead of loading everything in at once when you at most will be displaying one frame at a time.

Save all the animation as a png sequence inside a folder of the same name. (bigBG/bigBG0001,bigBG/bigBG0002.....)

Create a method that all you have to pass is the name of the folder, and have it make a sprite and add it to a


for each file in the folder.

To get how many files are in the folder, use:

int count = Directory.GetFiles("Content/"+path,"*",SearchOption.TopDirectoryOnly).

That line references System.IO so on the top of the file in which you use this add

using System.IO;

Create a loop that goes through all the files with the count as the max.

You are going to need to make your method aware of how many spaces for the numbers there are and pass that and the increment number of the loop to a method like this.

internal static string fillZeroes(int num, int spaces)
        string str = num.ToString();
        for (int i = str.Count(); i < spaces; i++)
            str = "0" + str;
        return str;

Then you can use:

texture = rr.g.Content.Load<Texture2D>(path + name+ num);

Add it to your List and the loop restarts, after the loop is done, you are going to want to return the finished list.

You can can now draw any frame of the animation by using:

Texture2D texture = spriteListMenu[frameNumber];

and pass that texture to your spritebatch.draw

  • \$\begingroup\$ in "int count = Directory.GetFiles("Content/"+path,"*",SearchOption.TopDirectoryOnly)." the "SearchOption.TopDirectoryOnly)." doesnt work, it doesnt recognise "SerachOption" \$\endgroup\$ Mar 19 '11 at 19:39
  • \$\begingroup\$ Sorry about that. You need to use System.IO, I edited the question to include that information. \$\endgroup\$ Mar 19 '11 at 21:14

You could always put each frame on a separate texture, and change the texture on your sprite to animate it.

  • \$\begingroup\$ yeh but that would mean 18 different sprites... it could work but am trying to find the easiest way. Thanks though, this will be plan B. \$\endgroup\$ Mar 19 '11 at 18:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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