【问题标题】:How to fix this DeprecationWarning如何解决此弃用警告
【发布时间】:2020-04-07 18:05:10
【问题描述】:

DeprecationWarning:需要一个整数(类型为浮点数)。不推荐使用 int 隐式转换为整数,并且可能会在未来的 Python 版本中删除。

win.blit(playerStand, (x, y))

DeprecationWarning:需要一个整数(类型为浮点数)。不推荐使用 int 隐式转换为整数,并且可能会在 Python 的未来版本中删除。

win.blit(walkLeft[animCount // 5], (x, y))

【问题讨论】:

    标签: python python-3.x pygame pygame-surface pygame2


    【解决方案1】:

    警告与blit()的坐标参数有关。浮点坐标意味着Surface 的原点介于窗口中的像素之间。这没有多大意义。坐标会被自动、隐式截断,并由警告指示。
    使用intround 将浮点坐标转换为整数:

    win.blit(playerStand, (round(x), round(y)))
    

    【讨论】:

      【解决方案2】:

      该消息还带有显式转换,因此,为了安全起见:

      a = round(x)
      b = round(y)
      win.blit(playerStand, (a, b))
      

      W1JGH

      【讨论】:

        猜你喜欢
        • 2012-06-14
        • 2022-09-26
        • 1970-01-01
        • 2012-01-31
        • 2010-11-23
        • 1970-01-01
        • 2013-04-29
        • 1970-01-01
        相关资源
        最近更新 更多