2017-01-08 3 views
1

私はPygameのPokémonスタイルのダイアログボックスで作業しています。私はPokemon GBフォントを使用していますが、何らかの理由でテキストが一番上に切り取られています。 pygame.font.Font.sizeは、テキストをレンダリングするのに必要なサイズが正しく計算されていないようです(Surface)。 テキストはPygameの特定のフォントで一番上に切り取られます

This screenshotは、どのように見えるのかを示します。

import pygame 

pygame.init() 

window = pygame.display.set_mode((640, 192)) 
window.fill((255, 255, 255)) 

POKEFONT = pygame.font.Font("Pokemon GB.ttf", 32) 
positions = [[32, 64], [36, 128]] 
lines = ["Hello there!", "Welcome to the"] 

for line, pos in zip(lines, positions): 
    text = POKEFONT.render(line, True, (0, 0, 0)) 
    rect = text.get_rect() 
    rect.topleft = pos 
    window.blit(text, rect) 

while True: 

    for event in pygame.event.get(): 
     if event.type == pygame.QUIT: 
      pygame.quit() 
      exit() 

    pygame.display.update() 

PKMN RBYGSCフォントがほとんど同じに見えますが、正しくレンダリングされます。どうしたの?

答えて

2

解決策は、Pygame 1.9.2で利用可能なpygame.freetypeを使用することです。

PKMN RBYGSCは右に左とポケモンGBです。感嘆符は、ポケモンGB(用語についてはthis pageを参照)の最大上昇線とベースラインの両方を横切っています。 pygame.fontはこれらの行の外側にあるものはすべて無視しますが、pygame.freetypeはそうではありません。

import pygame.freetype 

pygame.init() 

window = pygame.display.set_mode((640, 192)) 
window.fill((255, 255, 255)) 

POKEFONT = pygame.freetype.Font("Pokemon GB.ttf", 32) 
positions = [[32, 64], [36, 128]] 
lines = ["Hello there!", "Welcome to the"] 

for line, pos in zip(lines, positions): 
    text, rect = POKEFONT.render(line, (0, 0, 0)) 
    rect.topleft = pos 
    window.blit(text, rect) 

while True: 

    for event in pygame.event.get(): 
     if event.type == pygame.QUIT: 
      pygame.quit() 
      exit() 

    pygame.display.update() 

コードのこの修正版は正しい結果を与えます

関連する問題