Change the position of the origin in PyGame coordinate system

前端 未结 2 555
无人及你
无人及你 2020-12-18 06:54

I am doing some operations with vectors and physics in PyGame and the default coordinate system is inconvenient for me. Normally the (0, 0) point is at the top-

2条回答
  •  北海茫月
    2020-12-18 07:41

    If the objects you're trying to render are vertically symmetrical (like rectangles), you can just flip the screen to get the coordinate system to be the bottom-left, like this:

    display_surface = pygame.display.get_surface()
    display_surface.blit(pygame.transform.flip(display_surface, False, True), dest=(0, 0))
    

    You can do the same thing horizontally top/bottom-right. The important methods are documented here:

    • pygame.display.get_surface()
    • pygame.transform.flip(Surface, xbool, ybool)
    • Surface.blit(Surface, dest)

提交回复
热议问题