如何旋转图像pygame的口罩
嗨,我在旋转旋转掩码的对象面罩上遇到麻烦,仍然与原始图像相同。关键是要在赛道上移动面膜形式碰撞。
def __init__(self, x, y , height , width):
self.x = x - width / 2
self.y = y - height / 2
self.height = height
self.width = width
self.car_img = pygame.image.load('img/auticko.png').convert_alpha()
self.car_rect = self.car_img.get_rect()
self.car_mask = pygame.mask.from_surface(self.car_img)
self.surface = pygame.Surface((height, width),pygame.SRCALPHA)
self.surface.blit(self.car_img, (0, 0))
self.angle = 0
self.speed = 2
def draw(self,screen): # 3
self.car_rect.topleft = (int(self.x), int(self.y))
rotated = pygame.transform.rotate(self.surface, self.angle)
#rotated.set_colorkey((0, 0, 0))
surface_rect = self.surface.get_rect(topleft=self.car_rect.topleft)
new_rect = rotated.get_rect(center=surface_rect.center)
screen.blit(rotated, new_rect.topleft)
我试图从表面制作新面具,但它不起作用 正如您在图像上看到的那样,转动汽车不应该是 在此处输入图像描述
Hi i have trouble with rotating mask of object that is rotating mask is still in the same position as original image. The point is to move mask form collision in race track.
def __init__(self, x, y , height , width):
self.x = x - width / 2
self.y = y - height / 2
self.height = height
self.width = width
self.car_img = pygame.image.load('img/auticko.png').convert_alpha()
self.car_rect = self.car_img.get_rect()
self.car_mask = pygame.mask.from_surface(self.car_img)
self.surface = pygame.Surface((height, width),pygame.SRCALPHA)
self.surface.blit(self.car_img, (0, 0))
self.angle = 0
self.speed = 2
def draw(self,screen): # 3
self.car_rect.topleft = (int(self.x), int(self.y))
rotated = pygame.transform.rotate(self.surface, self.angle)
#rotated.set_colorkey((0, 0, 0))
surface_rect = self.surface.get_rect(topleft=self.car_rect.topleft)
new_rect = rotated.get_rect(center=surface_rect.center)
screen.blit(rotated, new_rect.topleft)
i was trying to make new mask from surface but its not working
as you can see on image while turning cars got stacked corner when they should not be
enter image description here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

您无法旋转蒙版,但可以在旋转图像后创建新蒙版:
You can't rotate the mask, but you can create a new mask after rotating the image: