问题
I want to change pygame coordinate system so that the center of the window is (0,0) and has negative values as in the image. Is there a possible way to convert the coordinates?
https://i.stack.imgur.com/sGPFt.gif
回答1:
PyGame uses a coordinate system where the top left corner is (0,0). That cannot be changed.
If you want to move the origin of the coordinate system to the center of the screen, then you have to translate the coordinates by yourself. For instance write a function that translates the coordinates:
def center_origin(surf, p):
return (p[0] + surf.get_width() // 2, p[1] + surf.get_height() // 2)
screen.blit(my_image, center_origin(screen, (x, y)))
Or use a lambda expression:
center_origin = lambda p: (p[0] + screen.get_width() // 2, p[1] + screen.get_height() // 2)
screen.blit(my_image, center_origin((x, y))
来源:https://stackoverflow.com/questions/61514113/how-do-i-change-the-pygame-coordinate-system-so-that-the-center-of-the-window-is