How Do I Change The Pygame Coordinate System So That The Center Of The Window Is (0,0)?
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? ht
Solution 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:
defcenter_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))
Post a Comment for "How Do I Change The Pygame Coordinate System So That The Center Of The Window Is (0,0)?"