[英]python and pygame font centering is working but I don't know why
My code is working perfectly although I'm completely in the dark as to why. 尽管我完全不知道为什么,但我的代码运行良好。
my code is: 我的代码是:
def textobjects(message, font,color):
Textsurface = font.render(message, True, color)
return Textsurface, Textsurface.get_rect()
def Display_text(message,color):
Heading = pygame.font.SysFont("Arial",70)
TextShown, Textrect = textobjects(message, Heading,color)
Textrect.center = ((displaywidth/2),0)
gameWindow.blit(TextShown,Textrect)
pygame.display.update()
time.sleep(2)
game_loop()
def border():
Display_text("You hit the border",wine)
and I don't know why I was able to do: 而且我不知道为什么能做到:
Textrect.center = ((displaywidth/2),0)
without having to define ".center". 无需定义“ .center”。 Is .center a pygame/python predefined module?
.center是pygame / python预定义模块吗?
.center is a part of a rect object that you can both get and set .center是您可以获取和设置的rect对象的一部分
You can also do 你也可以
Rect.left
Rect.top
Rect.right
Rect.bottom
Rect.topleft
Rect.bottomleft
Rect.topright
Rect.bottomright
Rect.centerx
Rect.centery
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.