我一直试图在使用中围绕其中心旋转图像,pygame.transform.rotate()但它不起作用.特别是挂起的部分是rot_image = rot_image.subsurface(rot_rect).copy().我得到了例外:
ValueError: subsurface rectangle outside surface area
以下是用于旋转图像的代码:
def rot_center(image, angle):
"""rotate an image while keeping its center and size"""
orig_rect = image.get_rect()
rot_image = pygame.transform.rotate(image, angle)
rot_rect = orig_rect.copy()
rot_rect.center = rot_image.get_rect().center
rot_image = rot_image.subsurface(rot_rect).copy()
return rot_image
Run Code Online (Sandbox Code Playgroud) 我想围绕一个支点,这是不是在中心旋转图像表面的pygame的。
枢轴是图像中的绿色十字:
我知道游戏窗口中枢轴的位置。我如何在此时跟踪图像并同时围绕该点旋转它。
image = pygame.image.load("boomerang64.png")
pos = (200, 200)
angle = 0
while True:
# [...]
rotate_rect, rotate_image = ???? # rotate around green cross by angle
surf.blit(rotated_image, rotate_rect)
angle += 1
# [...]
Run Code Online (Sandbox Code Playgroud)