我在pygame上遇到了麻烦…又一次…总有一天我发誓我会很好的,不必为了简单的答案而来这里。。。在
不管怎样,这次的问题是我试图在屏幕上打印带有变量的文本。在
wordfont = pygame.font.SysFont("sans",12)
class Status:
def __init__(self):
self.a=30
def showme(self):
health = wordfont.render(("Your health: ", self.a,), 1, (255, 9, 12))
screen.blit(health, (150, 150))
它说它必须是一个字符串或unicode…但也许有什么办法?我再次提醒大家不要纠正我没有问到的任何事情。我知道也许有更简单的方法来做这些事情。。。在
您将
tuple
("Your health: ", self.a,)
作为render
的第一个参数。我想应该用一根绳子代替。在有几种方法to format a string with a variable,其中一种方法是:
应该是
^{pr2}$或者
("Your health: ", self.a,)
是一个元组。通过传递字符串,您可以解决您的问题。在请看here了解我所做的。。。在
要发送字符串而不是元组作为第一个参数呈现:
相关问题 更多 >
编程相关推荐