我正在做一个项目,我需要一个节点图。在
这就是我目前为止所做的(一个屏幕和一个在鼠标点击位置绘制圆圈的函数),现在我被卡住了。在
如何在创建后选择一个圆来移动它?在
import pygame
WHITE = (255, 255, 255)
BLUE = ( 0, 0, 255)
GREEN = ( 0, 255, 0)
RED = (255, 0, 0)
TEXTCOLOR = ( 0, 0, 0)
(width, height) = (800, 600)
BASICFONTSIZE = 10
count = 0
running = True
def getPos():
pos = pygame.mouse.get_pos()
return (pos)
def drawCircle():
global count
pos = getPos()
radius = 20
pygame.draw.circle(screen, BLUE, pos, radius,7)
textSurf = BASICFONT.render(str(count), True, TEXTCOLOR)
textRect = textSurf.get_rect()
textRect.center = int(pos[0]),int(pos[1])
screen.blit(textSurf, textRect)
count += 1
def main():
global running, screen, BASICFONT
pygame.init()
BASICFONT = pygame.font.Font('freesansbold.ttf', BASICFONTSIZE)
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("TUFF")
screen.fill(WHITE)
pygame.display.update()
while running:
ev = pygame.event.get()
for event in ev:
if event.type == pygame.MOUSEBUTTONUP:
drawCircle()
pygame.display.update()
if event.type == pygame.QUIT:
running = False
if __name__ == '__main__':
main()
相关问题 更多 >
编程相关推荐