2012-03-13 2 views
2

ねえ、私はそれを作るようにしましたが、私はそれでいくつかの奇妙なバグがあり、何が間違っているか把握できません。ここに私のコードはありますか?テキストを表示するには?

def write(text): 
     for j in range(h): 

      for j in range(w): 

       for char in text: 

        if char.lower() == "a": 

         screen.blit(a, (k, l)) 
        self.k += 10 

       self.l += 11 
    write("aaaaaaaa") 

私の間違いを指摘したり、適切なやり方を提案していただければ幸いです。

+2

あなたは使い捨ての変数として 'j'を使用しているように見えます。 Pythonの規約では、使い捨ての名前に '_'を使用しています。さらに、実際にいくつかの変数をインクリメントしているので、 'step'パラメータを利用しないのはなぜですか? 'self.k'と' self.l'は範囲(0、h、10): '内のself.k:'と '(0、w、11)'内のself.l 'として開始します。 – Darthfett

答えて

2

は一つの方法です:

import pygame, pygame.font, pygame.event, pygame.draw, string 
from pygame.locals import * 

def display_box(screen, message): 
    fontobject=pygame.font.SysFont('Arial', 18) 
    if len(message) != 0: 
     screen.blit(fontobject.render(message, 1, (255, 255, 255)), 
       ((screen.get_width()/2) - 100, (screen.get_height()/2) - 10)) 
    pygame.display.flip() 

def get_key(): 
    while True: 
     event = pygame.event.poll() 
     if event.type == KEYDOWN: 
      return event.key 

if __name__ == "__main__": 
    # Graphics initialization 
    full_screen = False  
    window_size = (1024, 768) 
    pygame.init()  
    if full_screen: 
     surf = pygame.display.set_mode(window_size, HWSURFACE | FULLSCREEN | DOUBLEBUF) 
    else: 
     surf = pygame.display.set_mode(window_size) 

    # Create a display box 
    while True: 
     display_box(surf, "hello world") 
     inkey = get_key() 
     if inkey == K_RETURN or inkey == K_KP_ENTER: 
      break 
     pygame.display.flip() 
+0

ありがとうございました。 – Gustavo

1

Very simple Pong gameで、このサンプルに見てください:ここで

font = pygame.font.SysFont("calibri",40) 
... 
score1 = font.render(str(bar1_score), True,(255,255,255)) 
... 
screen.blit(score1,(250.,210.)) 
関連する問題