我一直在谷歌上搜索这个问题的答案,但我不确定如何用关键字来表达我正在寻找的内容。我想要做的是制作一个 pygame 圈子的动画。不仅仅是在 x 或 y 方向上移动它,而是为它的绘图制作动画,就像我正在追踪它一样。这很像 this gif ,如果你看到的只是屏幕上正在绘制的红色部分,并且红色部分的形状是一个圆圈。圆圈将不得不多次执行此动画(它表示枪正在重新装弹)因此它必须自行重置并在用户按下“r”时重新绘制动画。圆在一个静止的地方。有什么想法吗?
最佳答案
你可以使用一个 Sprite 动画或者一个接一个地 blit 几个图像来创建一个小动画
试试这个:
https://github.com/ankur0890/Pygame-Examples-For-Learning/blob/master/fireSprite.png?raw=true
如果您拍摄该图像并运行此代码:
import pygame
from pygame.locals import *
from sys import exit
counter=0
def Update():
global counter
counter=(counter+1)%7
def sprite(w, h):
a=[]
clock=pygame.time.Clock()
screen=pygame.display.set_mode((200,200),0,24)
image = pygame.image.load("fireSprite.png").convert_alpha()
width,height=image.get_size()
for i in xrange(int(width/w)):
a.append(image.subsurface((i*w,0,w,h)))
while True:
for i in pygame.event.get():
if i.type==QUIT:
exit()
screen.fill((0,0,0))
screen.blit(a[counter],(100,100))
Update()
pygame.display.update()
clock.tick(5)
sprite(20,20)
此代码将播放我在动画中链接的图像
这是图片 fireSprite.png
关于python - 描绘一个 pygame 圆圈动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17181821/