问题
I'm writing a program in pygame in which I want to draw circles on several surfaces, so that when I erase a circle (redraw it with the transparent colorkey) I get the picture that was in the layer below back. However, I seem to be stuck at an early step and can't seem to draw a circle on a surface (as opposed to the background display). Here is a minimal example:
import pygame
pygame.init()
width = 400
height = 400
screen = pygame.display.set_mode((width, height))
surf1 = pygame.Surface((width,height))
surf1.fill((0,255,0))
pygame.draw.circle(surf1, (0,0,0), (200,2000), 5)
screen.blit(surf1, (0,0))
exit = False
while not exit:
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit = True
pygame.display.update()
pygame.quit()
I expected to get a green surface with a black circle in the middle, but I only get a green surface. What am I doing wrong? Thanks!
回答1:
You have a typo in the coordinates for the circle, it should be
pygame.draw.circle(surf1, (0,0,0), (200,200), 5)
i.e. a 200
instead of a 2000
.
来源:https://stackoverflow.com/questions/48500162/drawing-a-circle-to-a-surface-in-pygame