InfernoKay
InfernoKay

Reputation: 43

Pygame Font text not displaying correct number

So, for the game I am working on I have found an error which I haven't been able to find an answer anywhere.

Here is a snippet of my code from my UI

if not self.game.rot_lim == 0:
    pg.draw.rect(self.ui, (255,255,255), (730,16,32,32))
    rotators = str(self.game.rot_rem)
    self.draw_text("Prisms Remaining: " + rotators, 770)

rot_lim is an Integer which stores the value of how many total rotators the user can place for that level. Similarly, rot_rem is the amount remaining that can be placed.

My draw text function goes as follows:

def draw_text(self, text, x, y = 20):
    # Renders text
    draw = self.game.text.render(text, False, (0,0,0), (170, 170, 170))
    # Draws on UI
    self.ui.blit(draw, (x,y))

Now my issue comes with displaying this with 10 or more in total. When I go below 10, it displays with an extra 0 at the end (e.g. If I place 1 it goes to 90). For every one I place after it ignores the last 0, and it does not exist within the code (tested with print statements) so it only exists in the rendering side of it.

Before Placing

After Placing

Thanks a lot!

Upvotes: 0

Views: 130

Answers (1)

The4thIceman
The4thIceman

Reputation: 3889

Alright, I managed to recreate the issue and it has to do with re-drawing the screen (not with the code you posted). Since we can only see a portion of your code, I can't be exactly sure if my recreation matches your issue.

Make sure you are doing one of two things:

1) clearing the who screen by refilling the background color screen.fill((255, 255, 200))

2) clearing the portion where the text is by refilling it (maybe it is within a rectangle that needs to be redrawn)

This should happen in each pass of the game while loop. Basically, make sure you are refreshing the screen each time, because currently it is just drawing over

Upvotes: 1

Related Questions