简体   繁体   English

Pygame:我将如何设置文本对象,但文本是否会不断变化?

[英]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. 我正在创建游戏Pig的副本。 I have got a text based version of the game working. 我有一个基于文本的游戏版本。 I am just updating it to pygame, adding graphics and sounds. 我只是将它更新为pygame,添加图形和声音。

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. 我显示了'player1得分','得分2'得分。 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 同样适用于player2

I am assuming maybe that the first parameter -->'player1 score' I can pass a variable and if I update the variable. 我假设可能是第一个参数 - >'player1得分'我可以传递一个变量,如果我更新变量。 When i call pygame.update() it should work as I think it should. 当我调用pygame.update()它应该像我认为的那样工作。

Just want some conformation or a tip on actually doing it. 只是想要一些确实或实际做的提示。

Pygame Font objects are not meant to be updated and changed constantly. Pygame Font对象不打算不断更新和更改。 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. Render()将返回一个新曲面,因此您需要将其blit到屏幕上才能进行更改。

You're on the right track! 你走在正确的轨道上!

Use a variable. 使用变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM