I\'ve recently recreated a version of Lunar Lander (you know, the old retro game) in Python 3 and Pygame: my lander moves (̀̀̀rect.move
) each frame along the y
Since pygame.Rect is supposed to represent an area on the screen, a pygame.Rect
object can only store integral data:
The coordinates for Rect objects are all integers. [...]
If you want to store object positions with floating point accuracy, you have to store the location of the object in separate variables respectively attributes and to synchronize the pygame.Rect
object. round the coordinates and assign it to the location (e.g. .topleft
) of the rectangle:
x, y = # floating point coordinates
rect.topleft = round(x), round(y)
I haven't tested it myself so I am sorry if this does not work but I think python is taking the number as a string so instead of
int(variable)
You should do float(variable)