Sie sind auf Seite 1von 3

Animated GIF's with XNA nooblet Member since: 3/18/2006 From: Tallahassee, FL, United States Posted - 4/23/2009

6:04:04 PM 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?

User Rating: 922 | Rate This User

Report this Post to a Moderator | Link

benryves GDNet+ Member since: 9/4/2003 From: Purley, United Kingdom Posted - 4/23/2009 9:17:52 PM 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!
.................................................................................................................................................................

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

User Rating: 1950 | Rate This User

Report this Post to a Moderator | Link

nooblet Member since: 3/18/2006 From: Tallahassee, FL, United States Posted - 4/23/2009 11:03:17 PM 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 :-).

User Rating: 922 | Rate This User

Report this Post to a Moderator | Link

benryves GDNet+ Member since: 9/4/2003 From: Purley, United Kingdom Posted - 4/24/2009 7:11:14 AM 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 */ }

.................................................................................................................................................................

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

User Rating: 1950 | Rate This User

Report this Post to a Moderator | Link

nooblet Member since: 3/18/2006 From: Tallahassee, FL, United States Posted - 4/24/2009 8:48:43 PM Extremely awesome, and I only have one last question... is it portable over to the xbox360 or not?

User Rating: 922 | Rate This User

Report this Post to a Moderator | Link

benryves GDNet+ Member since: 9/4/2003 From: Purley, United Kingdom Posted - 4/25/2009 10:54:01 AM 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.

Das könnte Ihnen auch gefallen