Pygame,font.render 错误
Pygame, font.render error
我正在用 pygame 制作游戏并尝试打印变量 "money" 但每当我尝试游戏时都会给我这个错误:
Traceback (most recent call last):
File "C:\Users\camil\Desktop\final\New.py", line 201, in <module>
scoretext=font.render( money, 'coins', 1,(0,0,1))
TypeError: an integer is required
这是我的代码,我不知道问题出在哪里,非常感谢您的帮助:
while True:
global money
plot = plot+1
setDisplay.fill((255,255,255))
font=pygame.font.Font(None,20)
scoretext=font.render( money, 'coins', 1,(0,0,0))
setDisplay.blit(scoretext, (1130, 5))
我假设您正在尝试呈现某人拥有的硬币数量 - 例如“10 个硬币”?
在这种情况下,您将“10”和 "coins" 作为单独的变量传递,并且需要在将它们传递给函数之前将它们组合成一个对象:
font.render('%d coins' % (money,), 1,(0,0,0))
请务必仔细查看文档中所需的参数:
http://www.pygame.org/docs/ref/font.html#pygame.font.Font.render
Font.render() 的函数原型如下所示
Font.render(text, antialias, color, background=None): return Surface
您没有将正确的参数传递给函数,这是错误消息告诉您的(需要整数)。我假设你想显示 'XXX coins',试试这个:
Font.render(money + ' coins', 0, 1, (0,0,0))
我正在用 pygame 制作游戏并尝试打印变量 "money" 但每当我尝试游戏时都会给我这个错误:
Traceback (most recent call last):
File "C:\Users\camil\Desktop\final\New.py", line 201, in <module>
scoretext=font.render( money, 'coins', 1,(0,0,1))
TypeError: an integer is required
这是我的代码,我不知道问题出在哪里,非常感谢您的帮助:
while True:
global money
plot = plot+1
setDisplay.fill((255,255,255))
font=pygame.font.Font(None,20)
scoretext=font.render( money, 'coins', 1,(0,0,0))
setDisplay.blit(scoretext, (1130, 5))
我假设您正在尝试呈现某人拥有的硬币数量 - 例如“10 个硬币”?
在这种情况下,您将“10”和 "coins" 作为单独的变量传递,并且需要在将它们传递给函数之前将它们组合成一个对象:
font.render('%d coins' % (money,), 1,(0,0,0))
请务必仔细查看文档中所需的参数:
http://www.pygame.org/docs/ref/font.html#pygame.font.Font.render
Font.render() 的函数原型如下所示
Font.render(text, antialias, color, background=None): return Surface
您没有将正确的参数传递给函数,这是错误消息告诉您的(需要整数)。我假设你想显示 'XXX coins',试试这个:
Font.render(money + ' coins', 0, 1, (0,0,0))