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