【发布时间】:2021-05-06 20:42:48
【问题描述】:
所以,我正在制作一款我遇到多个问题的游戏,因为这是我的第一个游戏。问题之一是,每当我打开它时,只会弹出一个-5,然后程序开始工作。我认为这是因为以下具体警告:
Warning (from warnings module):
File "C:/Users/LENOVO/Desktop/Everything Here!!/MoreCollision.py", line 57
win.blit(text, (250 -(text.get_width()/2), 200))
DeprecationWarning: an integer is required (got type float). Implicit conversion to integers using __int__ is deprecated, and may be removed in a future version of Python.
而属于它的代码是:
def hit(self):
self.x = 60
self.y = 410
self.walkCount = 0
font1 = pygame.font.SysFont('comicsans', 100)
text = font1.render('-5', 1, (255,0,0))
win.blit(text, (250 -(text.get_width()/2), 200))
pygame.display.update()
i = 0
while i < 300:
pygame.time.delay(10)
i += 1
for event in pygame.event.get():
if event.type == pygame.QUIT:
i = 301
pygame.quit()
所以,我真的不知道如何解决它。如果有人可以,请提供帮助。
【问题讨论】:
-
您应该将该行更改为
win.blit(text, (250 -int(text.get_width()/2), 200))。但是,这可能不是您的问题的原因。负5在哪里弹出?在终端,pygame 窗口,还是其他地方? -
@Seth 负数 5 在屏幕中间弹出,整个背景变黑,但它不应该这样做。当我在游戏中的角色与敌人发生碰撞时,一切正常,直到它再次开始,角色在 pygame 窗口中真正下降。要我上传整个代码吗?
-
你的代码是
text = font1.render('-5', 1, (255,0,0)),所以当blitted时会在屏幕上显示-5。你期待什么? -
@Seth 我应该如何解决它?对不起,我是一个初学者
-
删除将-5写入屏幕的部分代码...