簡體   English   中英

pygame中文本的上半部分沒有顯示

[英]Top half of text in pygame is not being displayed

我從網站上導入了一種自定義字體“ Celtic-Bit Thin”,以用於項目中。 該文件具有pygame可以導入的正確擴展名(.ttf),但在使用時,僅顯示顯示的文本字符串的下半部分(您只能看到顯示在文本字符串中的每個字母的下半部分)。我選擇的字體)。 我不確定字體或實現方式是否有問題。 我試過了:

gameFont = pygame.font.Sysfont("Celtic-Bit Thin", 24)
font.render("Hello world!", False, (0,0,0))

我也嘗試使用pygame.font.Font()執行此操作,但是它也不起作用。 字體是否僅僅是與pygame不兼容,還是導入字體還有其他要求?

編輯:這是一個最小的可運行示例:

import pygame

pygame.init()
pygame.font.init()

screen = pygame.display.set_mode((800,600))

gameFont = pygame.font.SysFont("Celtic-Bit Thin", 36)

running =  True

while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            runnung = False

    screen.fill((255,255,255))
    screen.blit(gameFont.render("Hello World!",False,(0,0,0)), (300, 300))
    pygame.display.flip()
pygame.quit()

是我下載字體的地方

我不知道為什么字體會被截斷,但是我嘗試使用pygame.freetype模塊而不是pygame.font渲染它,並且效果很好。

import pygame
import pygame.freetype  # Import the freetype module.


pygame.init()
screen = pygame.display.set_mode((800,600))
gameFont = pygame.freetype.SysFont("Celtic-Bit Thin", 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` ...
    text_surface, rect = gameFont.render("Hello World!", (0,0,0))
    screen.blit(text_surface, (40, 250))
    # or `render_to`.
    gameFont.render_to(screen, (40, 350), "Hello World!", (0,0,0))

    pygame.display.flip()

pygame.quit()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM