在我的代码中,我正在尝试在特定位置放置一个文本框。
screen = pygame.display.set_mode((1000, 600), 0, 32) #Set the window to 1000x600
WHITE = (255, 255, 255)
BLUE = (0, 0, 255)
text = font.render('Start', True, BLACK)
textRect = text.get_rect()
最后一行是做什么的,如何修改此代码以便将文本放在特定的(x,y)坐标上?
答案 0 :(得分:0)
它获得与渲染表面相关的矩形,改变位置如下:
textRect.center = (center_x, center_y) # set center to (x, y) coordinates
此外,请确保您正在更新屏幕并在游戏循环中绘制表面:
while True:
pygame.display.flip()
screen.blit(text, textRect)
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()