Python 如何在 pygame 中加载动画 GIF
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23031102/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How load an animated GIF in pygame
提问by random soup dog
I'm trying to open and run an animated gif on my pygame display. i have spent quite a few hours searching for an solution for this but i have not came across one yet.
我正在尝试在我的 pygame 显示器上打开并运行动画 gif。我花了好几个小时来寻找解决方案,但我还没有遇到过。
thank you in advanced for you help!
感谢您的帮助!
采纳答案by mehmetminanc
Documentationclearly states that GIF's wont be animated. However, you could dissect the GIF into frames, or sprites or still images in that matter, and animate them yourself. You can find free tools that can generate those frames.
文档明确指出 GIF 不会被动画化。但是,您可以将 GIF 分解为帧、精灵或静止图像,然后自己制作动画。您可以找到可以生成这些帧的免费工具。
回答by mehmetminanc
Pygame doesn't support animated GIFs natively, and you'd need GIFImagefor that. But probably the author deleted it.
Pygame 本身不支持动画 GIF,为此您需要GIFImage。但可能作者删除了它。
You could use a spritesheet or separate images for your sprite frames. Herea tutorial for Sprites.
您可以为精灵帧使用精灵表或单独的图像。这里有一个精灵教程。
You could fix that problem simply, to get animation you have to do break up your images after then load them using by pygame.image.load()and in your main game logic, run that pictures. It will be an animation as a GIF image, except it's a little bit long process because you have to seperate frames. Also don't forget to use Sprites.
你可以简单地解决这个问题,为了获得动画,你必须在使用pygame.image.load()加载它们之后分解你的图像,并在你的主要游戏逻辑中运行这些图片。它将是一个 GIF 图像的动画,只是它的过程有点长,因为您必须分离帧。也不要忘记使用精灵。
For seperate images: GIMPAmazingly simple to use it.
对于单独的图像:GIMP使用起来非常简单。