【发布时间】:2022-08-07 16:41:19
【问题描述】:
嗨,我在旋转蒙版的对象时遇到问题,旋转蒙版仍与原始图像处于相同位置。关键是在赛道上移动掩码形式的碰撞。
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)
我试图从表面制作新面具,但它不起作用 正如您在图像上看到的那样,当汽车转弯时,它们不应该堆积在角落里 enter image description here