2013年8月21日星期三

As strong as a crusher,python game tutorial(3)

In this tutorial,we will use a font type to show your text:


import pygame,sys
from pygame.locals import *

pygame.init()

DISPLAYSURF = pygame.display.set_mode((400,300))
pygame.display.set_caption('Hello crusher')

WHITE = (255,255,255)
GREEN = (0,255,0)
BLUE = (0,0,128)

# use the font type in the current dir
fontObj = pygame.font.Font('arial.ttf',32)

# re-load the font and set color
textObj = fontObj.render('Hello crusher', True,GREEN,BLUE)
# make a margin for text
textRectObj = textObj.get_rect()

textRectObj.center = (200,150)

while 1:
    DISPLAYSURF.fill(WHITE)

    DISPLAYSURF.blit(textObj, textRectObj)
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
    pygame.display.update()

没有评论:

发表评论