Reputation:
I have written a pygame script that renders a horizontally moving text across the screen. It works, but when I change the string to a non-latin string (Persian), it does not work completely. I mean it does everything (animation, rendering ...) but the characters are depareted from each, though they are shown healthy, but are not in the expected order. I mean each letter is shown well, but a word is not rendered, a sequence of characters are rendered.
the string should beسلام
but it is rendered م ا ل س
Here is the full code:
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
Upvotes: 0
Views: 268
Reputation: 122090
This is a known bug in pygame
and is currently classified as "won't fix", because:
To support all languages, we'd need to include a much larger font file, and changing files would break existing games.
One user in the thread suggests that python-fribidi
can be used to get the correct behaviour.
Upvotes: 1