Skip to content

Commit 9f35a49

Browse files
committed
font-test
1 parent 1c31a1f commit 9f35a49

6 files changed

Lines changed: 51 additions & 0 deletions

File tree

Binary file not shown.

python_game/4.font/1.1.jpg

112 KB
Loading

python_game/4.font/my_font.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#coding:utf-8
2+
import pygame
3+
from pygame.locals import *
4+
5+
my_name = "你好世界"
6+
7+
pygame.init()
8+
my_font = pygame.font.SysFont("宋体" ,64)
9+
name_surface = my_font.render(my_name,True,(0,0,0),(255,255,255))
10+
11+
pygame.image.save(name_surface,"name.png")
12+
13+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# -*- coding: utf-8 -*-
2+
# 记住上面这行是必须的,而且保存文件的编码要一致!
3+
import pygame
4+
from pygame.locals import *
5+
from sys import exit
6+
7+
pygame.init()
8+
screen = pygame.display.set_mode((1280, 800), 0, 32)
9+
10+
#font = pygame.font.SysFont("仿宋_GB2312", 40)
11+
#上句在Linux可行,在我的Windows 7 64bit上不行,XP不知道行不行
12+
#font = pygame.font.SysFont("simsunnsimsun", 40)
13+
#用get_fonts()查看后看到了这个字体名,在我的机器上可以正常显示了
14+
font = pygame.font.Font("仿宋_GB2312.ttf", 40)
15+
#这句话总是可以的,所以还是TTF文件保险啊
16+
text_surface = font.render(u"你好", True, (0, 0, 255))
17+
18+
x = 0
19+
y = (800 - text_surface.get_height())/2
20+
21+
background = pygame.image.load("1.1.jpg").convert()
22+
23+
while True:
24+
for event in pygame.event.get():
25+
if event.type == QUIT:
26+
exit()
27+
28+
screen.blit(background, (0, 0))
29+
30+
x -= 2 # 文字滚动太快的话,改改这个数字
31+
if x :
32+
x -= text_surface.get_width()
33+
else:
34+
x = 1280 - text_surface.get_width()
35+
36+
screen.blit(text_surface, (x, y))
37+
38+
pygame.display.update()

python_game/4.font/name.png

567 Bytes
Loading
3.81 MB
Binary file not shown.

0 commit comments

Comments
 (0)