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



我已经编写了一个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

这是pygame中的一个已知错误,目前被归类为"不会修复",因为:

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

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

最新更新