본문 바로가기
파이썬/파이게임(Pygame)

[파이게임.007] 게임화면에 글자출력하기

by 긱펀 2022. 6. 14.
반응형

 

🚩 게임화면에 글자 출력하기

[1] 미리보기

게임화면에 글자 출력하기

 

[2] 코드

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
from turtle import back
import pygame
 
pygame.init()
 
background = pygame.display.set_mode((480,360))
pygame.display.set_caption("text")
 
# 글자체(text font) 지정하기
myFont = pygame.font.SysFont(None50#(글자체, 글자크기) None=기본글자체
 
# 변수
x_pos = 0
y_pos = 0
 
play = True
while play:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            play = False
    #end of for
 
    background.fill((255,255,0)) # 배경 노란색
    x_pos, y_pos = pygame.mouse.get_pos() # 마우스 x,y좌표값 저장
    # render함수로 글자출력(문자열이 아니면 str로 변환해야함)
    myText = myFont.render("Hello World " + str(x_pos), True, (0,0,255)) #(Text,anti-alias, color)
    background.blit(myText, (100,100)) #(글자변수, 위치)
    pygame.display.update()
 
 
pygame.quit()
cs
728x90
반응형

댓글