blit函数在屏幕上呈现utf-8字符串

时间:2014-02-21 08:17:44

标签: python utf-8 pygame blit

我编写了一个pygame脚本,可以在屏幕上呈现水平移动的文本。它可以工作,但是当我将字符串更改为非拉丁字符串(波斯语)时,它不能完全正常工作。我的意思是它完成所有事情(动画,渲染......)但是每个角色都被删除了,尽管它们显示的是健康的,但不符合预期的顺序。我的意思是每个字母都显示得很好,但是没有渲染一个单词,会渲染一系列字符。

字符串应为سلام 但它呈现م ا ل س

以下是完整代码:

import sys, pygame; #importing the required modules

#initialize the game module
pygame.init();

#setting the display properties and put in a variable
width = 800; #px
height = 600; #px
display_info = (width, height);
screen = pygame.display.set_mode(display_info);

# adding contents
arial = pygame.font.SysFont("Tahoma", 21);
text = arial.render("سلام", 1, (233,114,93), (255,255,255));
clock = pygame.time.Clock();
x = 0;
#starting the game loop
while True :
    #it sets the timing of the loop-execution (40 fps)
    clock.tick(40);

    #getting the list of event on each game loop
    for event in pygame.event.get() :

        #if the event is QUIT (if the user has acted to close the application)
        if event.type == pygame.QUIT :
            pygame.quit(); #terminate python-side
            sys.exit(); #exits system-side

    #refreshing the screen with overall blackness
    screen.fill((0,0,0));

    #rendering the text. We do not move the text, we just increment the position on each loop
    screen.blit(text, (x, height/3));

    #incrementing the x-position
    x += 1;

    #updating the display to the latest changes
    pygame.display.update();
#end of the while loop

1 个答案:

答案 0 :(得分:1)

这是pygame中的known bug,目前归类为“无法修复”,因为:

  

为了支持所有语言,我们需要包含更大的字体文件,更改文件会破坏现有游戏。

线程中的一个用户建议可以使用python-fribidi来获取正确的行为。