您的位置:首页 > 编程语言 > Python开发

用Python和Pygame写游戏-从入门到精通(4)字体

2017-08-30 13:47 671 查看
1、字体

import pygame
from pygame.locals import *
from sys import exit

close = False

pygame.init()
screen = pygame.display.set_mode((640, 480), 0, 32)

font = pygame.font.Font("simsun.ttc", 40)

text_surface = font.render(u"你好", True, (0, 0, 255))

x = 0
y = (480 - text_surface.get_height())/2

background = pygame.image.load("sushiplate.jpg").convert()

while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit
close = True

if close == True:
break

screen.blit(background, (0, 0))

x -= 0.1

if x < -text_surface.get_width():
x = 640 - text_surface.get_width()

screen.blit(text_surface, (x, y))
pygame.display.update()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: