簡體   English   中英

python和pygame字體居中工作,但我不知道為什么

[英]python and pygame font centering is working but I don't know why

盡管我完全不知道為什么,但我的代碼運行良好。

我的代碼是:

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)

而且我不知道為什么能做到:

Textrect.center = ((displaywidth/2),0)

無需定義“ .center”。 .center是pygame / python預定義模塊嗎?

.center是您可以獲取和設置的rect對象的一部分

你也可以

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM