Pygame和spri的旋转

2024-04-19 09:01:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经用函数pygame.transform.rotate()_get_rect()_get_rect().center_get_size()玩了一段时间了。

我有一个箭头的图像,我想旋转,我有困难,以了解发生了什么。

我的问题是从哪个点开始旋转?

在我的例子中,我有一个28x182大小的图像,我用screen.blit()将其放在200100。


Tags: 函数rect图像sizegettransform箭头screen
2条回答

原始文档似乎没有指定问题的答案。

pygame.transform.rotate()

未经过滤的逆时针旋转。角度参数表示度数,可以是任何浮点值。负角度量将顺时针旋转。

除非以90度增量旋转,否则图像将被填充得更大以保持新的大小。如果图像有像素字母,填充区域将是透明的。否则pygame将选择与Surface colorkey或左上角像素值匹配的颜色。

可以使用示例here旋转,同时保持图像的中心:

def rot_center(image, rect, angle):
    """rotate an image while keeping its center"""
    rot_image = pygame.transform.rotate(image, angle)
    rot_rect = rot_image.get_rect(center=rect.center)
    return rot_image,rot_rect

我似乎找不到旋转中心pygame实际使用的是,bar a referencehere

it doesn't rotate about the origin, or any particular point for that matter: the fixed point of rotation depends on the surface dimensions and the rotation angle

相关问题 更多 >