from pygame.locals import *
pygame.init()
DISPLAYSURF = pygame.display.set_mode((400,300))
pygame.display.set_caption('Hello World!')
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
BLUE = (0, 0, 128)
BLACK = (0, 0, 0)
fontObj = pygame.font.Font('font/nanum.ttf', 32)
textSurfaceObj = fontObj.render('Hello world!', True, BLACK, WHITE)
textRectObj = textSurfaceObj.get_rect()
textRectObj.center = (100, 16)
while True: # main game loop
DISPLAYSURF.fill(WHITE)
DISPLAYSURF.blit(textSurfaceObj, textRectObj)
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
---------
Anti-Aliasing == False
Anti-Aliasing == True
fontObj란 변수에 pygame.font.Font를 이용해 .ttf 형식 등의 폰트 파일을 불러와 저장합니다.
미리 폰트를 연결시킨 변수 fontObj를 이용해 render() 함수를 통해 글씨를 화면 상에 출력할 수 있습니다.
render(message, Anti-Aliasing, color, backgroundcolor)의 4개의 인자를 전달받으며,
Anti-Aliasing이 True일 경우 안티앨리어싱을 적용해 부드러운 글자를 출력하며, False를 전달할 경우 안티앨리어싱이 적용되지 않아 다소 딱딱한 글씨체를 화면 상에 출력합니다.
댓글 없음:
댓글 쓰기