Sign in to follow this  
deadlydog

Can you use Gif's in a game?

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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).



Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this