我一直在谷歌上搜索答案,但我不确定如何用关键词来表达我想要的东西。我想要做的是为pygame圈设置动画。不只是在x或y方向上移动它,而是为它绘制动画,就像我在追踪它一样。它就像this gif,如果你看到的只是画面上的红色部分,红色部分的形状是一个圆圈。圆圈将不得不多次执行此动画(它表示重新加载枪支),因此只要用户按下“r”,它就必须重置自己并重绘动画。圆圈在一个固定的位置。有什么想法吗?
答案 0 :(得分:4)
你可以使用一个精灵动画或者可以一个接一个地将几个图像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
答案 1 :(得分:1)
绘制arc,设置开始/停止角度的动画(例如,将起始角度设置为 0 ,并将停止角度从 0 设置为 2π)。
绘制椭圆的局部剖面
arc(Surface, color, Rect, start_angle, stop_angle, width=1) -> Rect
在Surface上绘制一个椭圆弧。 rect参数是椭圆将填充的区域。两个角度参数是以弧度表示的初始和最终角度,右侧为零。 width参数是绘制外边缘的厚度。