我正在尝试使用 pygame.draw.arc() 作为精灵,但它没有显示在屏幕上。我可以通过在主循环中编写相同的代码来实现相同的效果,但是一旦我尝试创建一个精灵,效果就不会显示出来。
(主循环中的一部分可以取消注释以查看所需的效果。)
任何指针都会有很大帮助。
import pygame
import random
import math
BLACK = ( 0, 0, 0)
WHITE = ( 255, 255, 255)
RED = ( 255, 0, 0)
SCREEN_WIDTH = 513
SCREEN_HEIGHT = 513
class Block(pygame.sprite.Sprite):
def __init__(self, color, width, height):
pygame.sprite.Sprite.__init__(self)
self.color = color
self.image = pygame.Surface([width, height])
self.image.fill(WHITE)
self.image.set_colorkey(WHITE)
self.center_x = SCREEN_WIDTH/2-15
self.center_y = SCREEN_HEIGHT/2-15
# Draw the ellipse, THIS WORKS PERFECTLY
#pygame.draw.ellipse(self.image, color, [0, 0, width, height])
self.i=0
#THIS DOESN'T WORK FOR SOME REASON
pygame.draw.arc(self.image, (0,255,255),(25,25,450,450),0+(self.i*math.pi)/180,math.pi/6 +(self.i*math.pi)/180,10)
self.rect = self.image.get_rect()
self.angle = 0
self.radius = 210
self.speed = 0.05
def update(self):
self.i += self.speed
pygame.init()
screen = pygame.display.set_mode([SCREEN_WIDTH, SCREEN_HEIGHT])
all_sprites_list = pygame.sprite.Group()
block = Block(BLACK, 20, 15)
all_sprites_list.add(block)
done = False
clock = pygame.time.Clock()
i=0
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT: #
done = True
screen.fill(WHITE)
all_sprites_list.update()
all_sprites_list.draw(screen)
#UNCOMMENT TO SEE THE DESIRED EFFECT
#i= i+1
#pygame.draw.arc(screen, (0,255,255),(25,25,450,450),0+(i*math.pi)/180,math.pi/6 +(i*math.pi)/180,10)
pygame.display.flip()
clock.tick(60)
pygame.quit()