Jump to content
  • Advertisement
Sign in to follow this  
nooblet

Animated GIF's with XNA

This topic is 2994 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey everyone! So I was curious as to how to get animated GIF's to work with XNA. I downloaded the XNA GIF Animation Library, but I have absolutely no clue how to use it. The link is: http://www.codeplex.com/xnagif . I can't seem to find any tutorials for it, nor can I find any functions listed for it. Is it a dead project, or what?

Share this post


Link to post
Share on other sites
Advertisement
It works for me. I downloaded XNAGifAnimationLibrary [XNA 3.0 CTP][Source Code].zip, then copied the XNAGifAnimationLibrary and XNAGifAnimationLibrary.Pipeline folders into the directory of an XNA solution.

In Visual Studio, I then added the two project files (one in each of the two folders you just copied) to the XNA solution via the Solution Explorer (right click, Add, Existing Project).

Now, in the main XNA project I added references to both projects. First select the main References folder in your XNA project, right-click, Add Reference, Projects, XNAGifAnimationLibrary. Now select the References folder under the Content folder and right-click, Add Reference, Projects, XNAGifAnimationLibrary.Pipeline.

That's the hard bit done. Grab your animated GIF and add it to the Content folder normally. Open up your Game1 class (or whatever you renamed it to), add a using XNAGifAnimationLibrary to the top, and you can now render an animated GIF by adding the following lines (obviously heavily abridged!):

public class Game1 : Microsoft.Xna.Framework.Game {

GifAnimation animation;

protected override void LoadContent() {
/* snip */
this.animation = this.Content.Load<GifAnimation>("attackofthekittens"); // name of your GIF.
}

protected override void Update(GameTime gameTime) {
/* snip */
animation.Update(gameTime.ElapsedGameTime.Ticks);
/* snip */
}

protected override void Draw(GameTime gameTime) {
/* snip */
this.spriteBatch.Begin();
this.spriteBatch.Draw(this.animation.GetTexture(), new Vector2(0, 0), Color.White);
this.spriteBatch.End();
/* snip */
}
}

I know I've missed out a lot of steps but I don't know what exactly you're having trouble with. If you need more information (and you probably will), please ask!

Share this post


Link to post
Share on other sites
Actually, not that many questions at all :-). It worked great, but the only problem I have is this... I'm trying to create a fighting game and right now we have a GIF of a guy swinging his sword, well, if I make the image only update when he presses the space bar, then it will only do it frame by frame. Any solution to this? Thanks a bunch, and I'll +rep for that great guide :-).

Share this post


Link to post
Share on other sites
The GifAnimation class has some useful methods in it to control the animation. You could detect the space bar being pressed or released to play or stop the animation, for example:

KeyboardState lastKeyboardState = new KeyboardState();

protected override void Update(GameTime gameTime) {

/* snip */

KeyboardState currentKeyboardState = Keyboard.GetState();

if (currentKeyboardState.IsKeyDown(Keys.Space) && lastKeyboardState.IsKeyUp(Keys.Space)) {
animation.Play();
} else if (currentKeyboardState.IsKeyUp(Keys.Space) && lastKeyboardState.IsKeyDown(Keys.Space)) {
animation.Stop();
}

animation.Update(gameTime.ElapsedGameTime.Ticks);

lastKeyboardState = currentKeyboardState;

/* snip */
}

Share this post


Link to post
Share on other sites
No idea, I'm afraid. It looks like the GIF importer just splits the GIF into a sequence of textures so it should do, but I don't have a 360 to verify that myself.

Share this post


Link to post
Share on other sites
Hi!

The topic is almost 2 years old but this is the only place I can find the answer.

I have downloaded the latest version of Xna Gif Animation for XNA 4.0*. I did all the instructions that you put in here (I couldn't find any other) but still I can't find the Gif Importer in the list of Importers.

I don't know what to do.

Please, help!

*http://xnagif.codeplex.com/releases/view/14762

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!