Can you use Gif's in a game?

Started by
7 comments, last by whitde 18 years, 10 months ago
I never really thought about it until I downloaded some free sprites that were gif's. If I read in a gif and display it in my game, will it automatically do the animation (for example, have my character walking)? or is there someway you can make a gif do this? I think it would just be nice to pre-build your animation sequences in a nice GUI gif maker, then just load the gif directly into the game and have it animate itself, although you would still have to have a separate animation sequence for each direction the character faces and whatnot. I've never heard this mentioned before anywhere, so I'm just wondering if it can be done (ie, DirectX/OpenGL/whatever supports it).
-Dan- Can't never could do anything | DansKingdom.com | Dynamic Particle System Framework for XNA
Advertisement
Yes, you can do that. But it won't be automatic. Once this data is in your game, your job as programmer won't be any easier than normal sprite animation. It may be easier on the artist, though, if it's easier to manage the images.

You'll probably have to do a search for the gif file format, if you want to use a graphics API to do this. I can't tell you for sure, but I doubt OpenGL or DirectX will load in an animated gif the way you need it loaded. You might also find a gif library, but you would only need it to transfer the data to the API.

Oh, and one other thing. I believe gif animation has a restriction of using a constant frame rate. I think only one timing value is stored in the file. That means you can't show one frame longer than another. It might not be a problem if you use really fluid, constant moving animations.
GIFs can have different delay values per frame, but neither DirectX nor OpenGL support an animated texture in this way. Also, they restrict you pretty much to 256 colors. There're ways to hack around this, but they're buttfugly.

If you want to use the GIF animation from the file you have to write

A) an importer to read the file contents (quite a hassle, but possible)
B) an animation handler, since YOU have to do the animation yourself, no built in help for those

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Quote:Original post by Endurion
GIFs can have different delay values per frame

Sorry for the goof up.

Also, you might want to think about texture sizes. Some video cards may do strange things to your textures if they are non power of 2 or not square. If most of your sprites are close to square size, you can probably do a lot of optimizing by throwing them onto a big texture to draw from.

Of course this has nothing to do with the gif format. Just considering the idea that each frame in a gif is a seperate image of equal size. It means you're forced to organize them in the engine rather than have the artist do it for you.
I have a program called Sprite Slicer (www.hoek.inkblue.net) that has the ability to unroll any animated GIF into separate cells within a texture.

A texture could actually be made up of several aninated GIF's if they fit.

The program allows you to then export a created 32 bit PNG and a file that has all the texture coordinates.

It also has Font Mechanic that makes bitmap fonts from any Windows True Type font.

For me I can from animated GIF to an animation in my program within a few minutes. Couldn't be easier.

(actually...reminds me that part of the program is a little busted and I will release a fix hopefully before anyone tries it).



Cool, thanks everyone. I wasn't planning on doing it at the moment, I was just wondering if it could be done. But at least now if I want to I know how to go about it -- although I've already written my own animation class so I'll probably stick with it for now.
-Dan- Can't never could do anything | DansKingdom.com | Dynamic Particle System Framework for XNA
Isn't there a copyright issue here? Like, compuserve or somebody has a patent on the format and you have to pay to use it?
The patent's expired I think in 2003, so you should be clear there. It was a patent on LZW compression filed by (and *granted to* :S) 2 different companies in the same year.
Also...if you convert the original GIF format to a series of images on a texture...it's not really a GIF. Also the patent relates to a program that actually creates the GIF and uses (or used) the LWZ compression.

If you created a program that produced a GIF with their patented compression they wanted big bucks for the doing so.

Funny how they only went cashing in on their patent AFTER the format got popular as if they charged from day 1 they would have got SFA.

This topic is closed to new replies.

Advertisement