Ver Mensaje Individual
  #8 (permalink)  
Antiguo 15/06/2010, 21:17
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: Texto encima de una imagen

Prueba con esto:
Código Python:
Ver original
  1. import pygame, os
  2.  
  3. class Text:
  4.     def __init__(self, FontName = None, FontSize = 30):
  5.         pygame.font.init()
  6.         self.font = pygame.font.Font(FontName, FontSize)
  7.         self.size = FontSize
  8.  
  9.     def render(self, surface, text, color, pos):
  10.         text = unicode(text, "UTF-8")
  11.         x, y = pos
  12.         for i in text.split("\r"):
  13.             surface.blit(self.font.render(i, 1, color), (x, y))
  14.             y += self.size
  15.  
  16. def load_image(path, colorkey=False):
  17.     _image = pygame.image.load(path)
  18.     if colorkey:
  19.         if colorkey == -1:
  20.             colorkey = _image.get_at((0, 0))
  21.             _image.set_colorkey(colorkey)
  22.             image.set_colorkey(colorkey)
  23.             _image = _image.convert()
  24.     else:
  25.         _image = _image.convert_alpha()
  26.     return _image
  27.    
  28.  
  29. pygame.init()
  30. white = (255, 255, 255)
  31. size = width, height = 640, 480
  32. screen = pygame.display.set_mode(size)
  33. pygame.display.set_caption("Pygame Hello Word!")
  34. color = (0, 0, 0)
  35. text = Text()
  36.  
  37. background = load_image(os.path.join("data", "imagen1.jpg"))
  38.  
  39. while True:
  40.     for event in pygame.event.get():
  41.         if event.type == pygame.QUIT:
  42.             exit()
  43.         if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
  44.             exit()
  45.     screen.blit(background, background.get_rect())
  46.     text.render(screen, "Hello Word!", white, (0, 0))
  47.     pygame.display.flip()