相关疑难解决方法(0)

如何使用Pygame围绕其中心旋转图像?

我一直试图在使用中围绕其中心旋转图像,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)

python pygame rotation

13
推荐指数
4
解决办法
2万
查看次数

如何在 Pygame 中围绕偏离中心的支点旋转图像

我想围绕一个支点,这是不是在中心旋转图像表面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)

python pygame

4
推荐指数
1
解决办法
846
查看次数

标签 统计

pygame ×2

python ×2

rotation ×1