###질문###
파이게임에서 텍스트를 디스플레이 하는 법을 잘 모르겠습니다.
IDLE 에서 print 하는 방식으로는 할수 없다는걸 잘 알고 있습니다.
import pygame, sys
from pygame.locals import *
BLACK = ( 0, 0, 0)
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
RED = ( 255, 0, 0)
pygame.init()
size = (700, 500)
screen = pygame.display.set_mode(size)
DISPLAYSURF = pygame.display.set_mode((400, 300))
pygame.display.set_caption('P.Earth')
while 1: # main game loop
for event in pygame.event.get():
if event.type == QUIT:
pygame.display.update()
import time
direction = ''
print('Welcome to Earth')
pygame.draw.rect(screen, RED, [55,500,10,5], 0)
time.sleep(1)
위의 코드는 제 프로그램의 초반 도입 부분 입니다.
텍스트를 표시 하는 법을 알려 주세요~
###답변###
pygame.font.init() # you have to call this at the start,
# if you want to use this module.
myfont = pygame.font.SysFont('Comic Sans MS', 30)
textsurface = myfont.render('Some Text', False, (0, 0, 0))
screen.blit(textsurface,(0,0))
###답변###
import pygame
import pygame.freetype # Import the freetype module.
pygame.init()
screen = pygame.display.set_mode((800, 600))
GAME_FONT = pygame.freetype.Font("your_font.ttf", 24)
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
screen.fill((255,255,255))
# You can use `render` and then blit the text surface ...
text_surface, rect = GAME_FONT.render("Hello World!", (0, 0, 0))
screen.blit(text_surface, (40, 250))
# or just `render_to` the target surface.
GAME_FONT.render_to(screen, (40, 350), "Hello World!", (0, 0, 0))
pygame.display.flip()
pygame.quit()
#출처 : https://stackoverflow.com/questions/20842801/how-to-display-text-in-pygame
| Pygame, sounds don't play 파이게임에서 소리 재생이 안됩니다. (0) | 2021.10.15 |
|---|---|
| Pygame error: 'pygame' has no attribute 'init' (0) | 2021.10.15 |
| dll load failed 1은(는) 올바른 win32 응용 프로그램이 아닙니다 (0) | 2021.10.14 |
| ImportError: No module named 'pygame' (0) | 2021.10.14 |
| pygqme을 설치할수 없습니다 (0) | 2021.10.14 |