python-pygame之旋转图像

  • 利用pygame.transform.ratate(Surface, angle)

  • angle为正,逆时针旋转;为负,顺时针旋转
    方法一:
    (用库函数写一个自定义函数)

     The below example is a bit redundant (and forgets that pygame.transform.rotate returns the rotated surface, it doesn't transform in place)
          
          You can simply write it thusly:
          
          def __init__(self, image, startangle):
              ...
              self.original = image
              self.rotate(startangle)
          def rotate(self, angle):
              self.image = pygame.transform.rotate(self.original, angle)
    

方法二:
(直接用,但是需要赋值更新)

A good idea in rotating in small angles is to restore the image or sprite to its
original picture for example:

def __init__(self)
    ...
    self.original=self.image
    self.image=pygame.transform.rotate(self.image,self.angle)
def rotate(self,angle)
    self.image=self.original
    pygame.transform.rotate(self.image,angle)

but in exchange it will eat more pc usage and memory usage but youll have 
almost 90% better than rotating the image again and again so you have to choose
whether speed or quality