1 回答
TA贡献1836条经验 获得超13个赞
当您从表面创建蒙版时,表面是空的,因为圆圈是在表面上绘制的draw:
class Gameobject:
"""
Interactive objects with the game
"""
def __init__(self, coordinates, velocity, angle, radius, objectColor):
# [...]
self.surface = pygame.Surface((self.radius*2, self.radius*2), pygame.SRCALPHA)
self.rectangle = self.surface.get_rect(center=[self.x, self.y])
self.mask = pygame.mask.from_surface(self.surface)
def draw(self):
pygame.draw.circle(self.surface, self.objectColor, [self.radius, self.radius], self.radius)
.surface在的上绘制圆圈后,您必须创建蒙版Gameobject:
class Gameobject:
# [...]
def draw(self):
# draw circle on surface
pygame.draw.circle(self.surface, self.objectColor, [self.radius, self.radius], self.radius)
# create mask from surface with circle
self.mask = pygame.mask.from_surface(self.surface)
添加回答
举报