Jez Ross-Smith
Jez Ross-Smith

Reputation: 23

Unwanted symbol in text when using blit from pygame

When using the blit function to show text from a file (each line ends with a number - 1 in this case), it shows an unwanted box. This happens for all lines in the file. How do I get rid of it?

I know it would maybe work if a comma is put at the end of each line and then split up using the comma. However I would like to try to do it this way.

I can’t post pictures due to my reputation so here’s a link: https://i.sstatic.net/rsyg1.jpg

example output

Upvotes: 2

Views: 74

Answers (1)

Kingsley
Kingsley

Reputation: 14906

I can only guess because you have not included any code, but I suspect that is an end-of-line character or other non-printable character read from the input-file. Maybe also a tab, line-feed, NUL or suchlike.

However, converting the test up\n, results in this output:

bad-test-with-cr

You can test for yourself with the code:

font = pygame.font.Font( None,100 )
text_image = font.render( "whatever\n", True, (255,0,0) )  # <<-- HERE \n
screen.fill((255,255,255))
screen.blit( text_image, text_rect )
pygame.display.flip()

The difference in the "bad-character" graphic, I would put down to different font and/or operating system.

Perhaps use the python strip() function on the string before calling font.render().

Upvotes: 1

Related Questions