下面这行代码,我已经借用作为一个例子来使用。它所做的是获取一个字符串,并在pygame中将其打印出来,然后这行将跟随鼠标移动到哪里。我只是想知道如何更改draw.circle的字符串行,我总是得到一个错误。干杯!在下面的代码中,有问题的字符串是“最后按下的按钮是”。
from pygame import *
init()
size = width, height = 800, 600
screen = display.set_mode(size)
button = 0
BLACK = (0, 0, 0)
RED = (255, 255, 255)
font = font.SysFont("Times New Roman",30)
def drawScene(screen, mx, my, button):
draw.rect(screen, BLACK, (0, 0, width, height))
# Draw circle if the left mouse button is down.
string = "The last button pressed is " + str(button) + "."
text = font.render(string, 1, RED)
size = font.size(string)
screen.blit(text, Rect(mx, my, size[0], size[1]))
display.flip()
running = True
myClock = time.Clock()
mx = my = 0
# Game Loop
while running:
for evnt in event.get(): # checks all events that happen
if evnt.type == QUIT:
running = False
if evnt.type == MOUSEBUTTONDOWN:
mx, my = evnt.pos
button = evnt.button
if evnt.type == MOUSEMOTION:
mx, my = evnt.pos
drawScene(screen, mx, my, button)
myClock.tick(60) # waits long enough to have 60 fps
quit()发布于 2016-05-09 05:45:26
这将在mx,my:处绘制一个5像素半径的圆:
pygame.draw.circle(screen, BLACK, (mx, my), 5)https://stackoverflow.com/questions/37102305
复制相似问题