반응형

텍스트(폰트)를 렌더링 해 보자.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import pygame
 
pygame.init()
pygame.display.set_caption("Super fun game development")
screen = pygame.display.set_mode((640480))
clock = pygame.time.Clock()
running = True
 
font = pygame.font.Font(None48)
text = font.render("Super fun game development"True, (128128128))
#text = font.render("Sean loves game", True, "gray")
# 폰트를 지정하고 텍스트를 렌더링 한다.
 
text_pos = text.get_rect()
text_pos.centerx = screen.get_width()/2
text_pos.centery = screen.get_height()/2
#text_pos = text.get_rect(center=(screen.get_width()/2, screen.get_height()/2))
# pygame.Surface.get_rect()에 인수를 주면 인수가 적용된 영역이 반환되어 간단히
# 위치가 지정된 영역을 얻을 수 있다.
 
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
            running = False
 
    screen.fill("black")
    screen.blit(text, text_pos)
 
    pygame.display.flip()
    clock.tick(60)
 
pygame.quit()
 

 

 

텍스트(폰트)가 렌더링 된다.

 

반응형
Posted by J-sean
: