我想在pygame中打印到控制台,在这里:
def drawPressKeyMsg(self):
BASICFONT = pygame.font.Font("freesansbold.ttf", 18)
pressKeySurf = BASICFONT.render("Press a key to play.", True, DARK_GREY)
pressKeyRect = pressKeySurf.get_rect()
pressKeyRect.topleft = (WINDOW_WIDTH - 200, WINDOW_HEIGHT - 30)
DISPLAYSURF.blit(pressKeySurf, pressKeyRect)
我可以使用.topleft但稍后在代码中使用:
def showMenuScreen(self):
menuFont = pygame.font.Font("freesansbold.ttf", 100)
optionFont = pygame.font.Font("freesansbold.ttf", 50)
menuSurf = menuFont.render("PONG GAME", True, WHITE, TURQUOISE)
option1Surf = optionFont.render("Press 1 to play the game!", True, WHITE, TURQUOISE)
option2Surf = optionFont.render("Press 2 to exit!", True, WHITE, TURQUOISE)
menuRect = menuSurf.get_rect
option1Rect = option1Surf.get_rect
option2Rect = option2Surf.get_rect
menuRect.center = (WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2)
option1Rect.center = (WINDOW_WIDTH / 2, (WINDOW_HEIGHT / 2) - 25)
option2Rect.center = (WINDOW_WIDTH / 2, (WINDOW_HEIGHT / 2) - 50)
DISPLAYSURF.blit(menuSurf, menuRect)
DISPLAYSURF.blit(option1Surf, option1Rect)
DISPLAYSURF.blit(option2Surf, option2Rect)
<。> .center显示错误“AttributeError:'builtin_function_or_method'对象没有属性'center'”
答案 0 :(得分:0)
您忘记了所有()
中的get_rect()
,因此它不会返回Rect
center
,但会返回对方法get_rect
的引用并引用没有center