How to fix this DeprecationWarning

Blazing_Sun picture Blazing_Sun · Dec 14, 2019 · Viewed 12.1k times · Source

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.

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

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.

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

Answer

Rabbid76 picture Rabbid76 · Dec 14, 2019

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)))