3

I'm working on a game with pygame (Tetris), and I have several texts displayed. They all use the same font, the same size and the same render parameters (except for the text to display). However, some texts appear normally like this : normal text , and some texts appear like that : pixelated text. But it seems to depend on the coordinates, because when I move it a bit (50 pixels left), it appears like this : semi-pixelated text.

The font is defined like this: font = pygame.font.SysFont("Times New Roman", 26). Then I create the surface : nextblock_text = font.render("Next block :", 1, (0, 0, 0)), and I blit the text using screen.blit(nextblock_text, (400, 0))

I first thought that this was due to drawing a surface onto another surface, but after creating a little script to test this hypothesis, I saw that it was not the case as I could draw a text on a square without the text being pixelated, so I don't really understand why the text is pixelated depending on the coordinates.

Has one of you ever experienced this problem? Do you have any idea on what could cause this?

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Reywaz
  • 45
  • 7
  • Is your display scaled? – Rabbid76 Mar 03 '23 at 15:02
  • @Rabbid76 If you're talking about my windows settings, the scaling is 100% (the recommended one is 150%). If you're talking about my code, the only mentions of 'display' that I have are : `pygame.display.set_mode(600, 760)` + a few other mentions to give it a title and update it, so I don't think it is scaled. – Reywaz Mar 03 '23 at 17:29
  • 3
    what is clearly visible in the images you posted is that the pixelated areas are "dropping" the alpha channel information - and using only full transparency/full opacity (which makes antialiasing worse than no aliasing). Is there some other thing drawn in in the places you are pasting text? – jsbueno Mar 03 '23 at 20:44
  • I agree with @jsbueno. There has to be some colliding/overlapping surfaces in that area. When you moved it 50 pixels to the left, we can see that the text begins to come out from the area. – ArjunSahlot Mar 04 '23 at 03:55
  • 1
    @jsbueno Thank you for your answer! My code is long and not optimized, so it's gonna take me a bit of time to find the surface that is colliding / overlapping my text. I'll let you know if I find something – Reywaz Mar 04 '23 at 09:42
  • if you are using version control, I ´d suggest creating a branch to investigate that, and just switch off "massive" parts of the code at a time, so you can nail down when the display deffect goes away. – jsbueno Mar 04 '23 at 12:26
  • @jsbueno I'm not sure what you mean by "version control", but all I use is vscode and I just have a simple .py file. I will try to remove some parts of the code to see where the problem is. Thanks for your advices! – Reywaz Mar 04 '23 at 15:03
  • Unfortunately, the problem is not reproducible, so the question cannot be answered. Please see [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) – Rabbid76 Mar 04 '23 at 15:05
  • 1
    by "version control" I mean "git" - and the capabilities of infinte undo-redo without needing to save a file with different names. VSCode has a nice integration to it - if you are not, it is _very_ well worth your time to see some tutorial on git, followed by some tutorial on git + vscode - it can help you a lot, even with this simple project. – jsbueno Mar 04 '23 at 15:47

0 Answers0