How to fix this DeprecationWarning

前端 未结 2 1208
挽巷
挽巷 2020-12-21 11:19

DeprecationWarning: an integer is required (got type float). Implicit conversion to integers using int is deprecated, and may be removed in a fut

相关标签:
2条回答
  • 2020-12-21 11:42

    The warning is related to the coordinate parameter of blit(). Floating point coordinates, would mean that the origin of the Surface is somewhere in between to pixels in the window. That doesn't make much sense. The coordinates are automatically, implicitly truncated and that is indicated by the warning.
    Use either int or round to convert the floating point coordinates to integral numbers:

    win.blit(playerStand, (round(x), round(y)))
    
    0 讨论(0)
  • 2020-12-21 11:59

    The message appears also with explicit conversions so, to be safe do:

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

    W1JGH

    0 讨论(0)
提交回复
热议问题