2015-04-07 205 views
0

出於某種原因,我的代碼沒有工作。我相信這只是因爲我指定了字體爲「無」。我這樣做的唯一原因是因爲它似乎沒有其他字體被支持!甚至不是arial或等寬的。 下面是代碼(這在pygame的編碼):Pygame字體不受支持?

import pygame 
pygame.init() 
white = (34,34,34) 
black=(0,0,0) 
red=(255,0,0) 
led=45 
pik=105 
silver=(110,108,108) 
yellow=(193,206,104) 
yellow2=(213,230,100) 
display_height=600 
display_width=800 
gameDisplay = pygame.display.set_mode((display_width,display_height)) 
pygame.display.set_caption('Slither') 

def text_objects(text, font): 
    textSurface = font.render(text, True, black) 

def message_display(text): 
    largeText = pygame.font.Font(==>None<==,115) 
    TextSurf, TextRect = text_objects(text , largeText) 
    TextRect.center = (display_width/2),(display_height/2) 
    gameDisplay(TextSurf, TextRect) 

    time.sleep(2) 

    game_loop() 

gameExit=False 

myfont = pygame.font.SysFont("monospace", 15) 
lead_x = 300 
lead_y = 300 
ps=-43+300 
background_color=black 
while not gameExit: 
    for event in pygame.event.get(): 
     if event.type == pygame.QUIT: 
      gameExit = True 
     if event.type == pygame.KEYDOWN: 
      if event.key == pygame.K_LEFT: 
       lead_x -= 10 
       print("LEFT") 

      if event.key == pygame.K_RIGHT: 
       lead_x +=10 
       print("RIGHT") 
      if event.key == pygame.K_UP: 
       lead_y -=10 
       print("UP") 
      if event.key == pygame.K_DOWN: 
       lead_y +=10 
       print("DOWN") 
      if event.key == pygame.K_a: 
       gameDisplay.fill(red) 
       led +=10 
       ps -=5 
      if led == 95: 
       background_color=red 
       message_display('You found me') 


    gameDisplay.fill(background_color) 
    pygame.draw.ellipse(gameDisplay, black,[-295+300,-54+300,75,100]) 
    pygame.draw.ellipse(gameDisplay, red,[-285+300,-35+300,20,34]) 
    pygame.draw.ellipse(gameDisplay, red,[-255+300,-35+300,20,34]) 
    pygame.draw.circle(gameDisplay, yellow, (650, 300), 105, 45) 
    pygame.draw.rect(gameDisplay, silver,[470+lead_x,-35+lead_y,75,30]) 
    pygame.draw.ellipse(gameDisplay, yellow,[375+lead_x,ps,105,led]) 


    pygame.display.update() 

pygame.quit() 
quit() 
+0

李四它現在的工作? :) – elegent

+0

的確如此,謝謝你,Elegent,我很感謝幫助:) – DarkRunner

+0

好吧,我很高興我可以幫到你:)如果你想要你可以接受我的回答... – elegent

回答

0

的問題是,該功能text_objects(text, font)回報什麼,但你打電話

TextSurf, TextRect = text_objects(text , largeText) 

所以,你需要改變你的text_objects()功能實例

def text_objects(text, font): 
    textSurface = font.render(text, True, black) 
    return textSurface, textSurface.get_rect() 

希望這有助於:)