chris
chris

Reputation: 15

Pygame: How would I go about setting a text object, BUT the text is meant to keep changing?

I am creating a copy of the game Pig. I have got a text based version of the game working. I am just updating it to pygame, adding graphics and sounds.

I will eventually add in mouse toggles, but for now I am trying to update a score.

I have display a 'player1 score', 'player2 score' out. I am trying to see how will it work to display text that is not constant.

i got

player1_text = font.render('player1 score', True,(0,0,0))

same for player2

I am assuming maybe that the first parameter -->'player1 score' I can pass a variable and if I update the variable. When i call pygame.update() it should work as I think it should.

Just want some conformation or a tip on actually doing it.

Upvotes: 0

Views: 1034

Answers (2)

Leif Theden
Leif Theden

Reputation: 85

Pygame Font objects are not meant to be updated and changed constantly. You will need to call render(text) each time your text changes. Render() will return a new surface, so you will need to blit that to your screen to make the change.

Upvotes: 2

jgritty
jgritty

Reputation: 11935

You're on the right track!

Use a variable.

Upvotes: 0

Related Questions