Ver Mensaje Individual
  #2 (permalink)  
Antiguo 13/03/2010, 16:50
Avatar de razpeitia
razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 1 mes
Puntos: 1360
Respuesta: Escribir texto en pygame

Un pequeño hola mundo con pygame.
Código:
import pygame
 
class Text:
    def __init__(self, FontName = None, FontSize = 30):
        pygame.font.init()
        self.font = pygame.font.Font(FontName, FontSize)
        self.size = FontSize
 
    def render(self, surface, text, color, pos):
        text = unicode(text, "UTF-8")
        x, y = pos
        for i in text.split("\r"):
            surface.blit(self.font.render(i, 1, color), (x, y))
            y += self.size   
 
pygame.init()
white = (255, 255, 255)
size = width, height = 640, 480
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Pygame Hello Word!")
color = (0, 0, 0)
text = Text()
 
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            exit()
        if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
            exit()
    screen.fill(color)
    text.render(screen, "Hello Word!", white, (0, 0))
    pygame.display.flip()

Última edición por razpeitia; 13/03/2010 a las 17:00