在pygame中制作游戏时,我想为滚动球制作动画。以下是I have和I want it to look like。
的示例以下是我的解决方案':
def update_sprite(self):
sprite_size = np.repeat([self.radius*2],2)
new_sprite = pygame.Surface(sprite_size)
new_sprite.fill((200, 200, 200))
new_sprite.set_colorkey((200, 200, 200))
#this is the actual ball part of the circle
pygame.draw.circle(new_sprite, self.color, sprite_size/2, self.radius)
if self.sprite_visible:
#sprite offset is an np array, with two coordinates,
#which contains the diplacement of the small circle from centre of the circle
pygame.draw.circle(new_sprite, (255, 255, 255), self.sprite_offset.astype(int)+[self.radius, self.radius], self.sprite_size)
if self.number!=0:
new_sprite.blit(self.text, (self.radius - self.text_length / 2)+self.sprite_offset.astype(int))
# used to remove part of the sprite which is outside the ball
triag1 = np.array(([0, 0], [self.radius / 2, 0], [0, self.radius / 2]))
triag2 = np.array(([0, 2*self.radius], [self.radius / 2, 2*self.radius], [0, 3*self.radius / 2]))
triag3 = np.array(([2*self.radius, 0], [2*self.radius, self.radius / 2], [3*self.radius / 2,0]))
triag4 = np.array(([2*self.radius, 2*self.radius], [3*self.radius / 2, 2*self.radius], [2*self.radius, 3*self.radius / 2]))
pygame.draw.polygon(new_sprite,(200,200,200),triag1)
pygame.draw.polygon(new_sprite, (200, 200, 200), triag2)
pygame.draw.polygon(new_sprite, (200, 200, 200), triag3)
pygame.draw.polygon(new_sprite, (200, 200, 200), triag4)
pygame.draw.circle(new_sprite, (200,200,200), sprite_size/2, self.radius+6,6)
self.image = new_sprite
self.rect = self.image.get_rect()
self.top_left = self.pos - self.radius
该行
pygame.draw.circle(new_sprite, (255, 255, 255), self.sprite_offset.astype(int)+[self.radius, self.radius], self.sprite_size)
绘制小圆圈,然后绘制数字后的第二行,但是,如果我将它留下this would happen。后来我在球上画了一个更大的圆圈,没有中间部分。但是,这会在圆圈周围留下小线条(您可以看到它here)。这就是为什么我需要在圆圈周围绘制4个三角形来删除它们。
现在,请告诉我,还有其他办法吗?