首页 > 解决方案 > pygame 中不断弹出弃用警告

问题描述

所以,我正在制作一款我遇到多个问题的游戏,因为这是我的第一个游戏。问题之一是,每当我打开它时,只会弹出一个-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()

所以,我真的不知道如何解决它。如果有人可以,请提供帮助。

标签: pythonpygamewarnings

解决方案


删除写入屏幕的代码-5以阻止其写入屏幕。这也解决了DeprecationWarning因为它是由写入-5屏幕的代码引起的!


推荐阅读