Drawing a circle to a surface in pygame

强颜欢笑 提交于 2020-03-22 09:42:53

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!