Feb-16-2021, 04:27 PM
(Feb-16-2021, 03:38 AM)michael1789 Wrote: That effect is more that just a circle, there is a drawing effect applied when it is blit, and or the images are translucent. The color stacks up with overlapping circles, and they fade as they expand.
ripple_list = [] class Ripple: def __init__(self, pos): self.pos = pos self.radius = 0 self.max_radius = 50 self.surf = pygame.Surface((self.max_radius*2, self.max_radius*2) self.rect = self.surf.get_rect() self.surf.fill((0,0,0)) self.surface.set_colorkey((0,0,0)) self.alpha = 255 self.surf.set_alpha(self.alpha) self.color = (0, 0, 255) self.fade = 2 self.growth_speed = 2 self.rect.center = self.pos def update(self): if self.radius < self.max_radius: self.surf.fill((0,0,0)) pg.draw.circle(self.surf, self.color, (self.max_radius, self.max_radius), self.radius) self.alpha -= self.fade self.radius += self.growth_rate else: ripple_list.remove(self)When you click, spawn a ripple withripple_list.append(Ripple(Your_mouse_pos))
. And each frame:
for r in ripple_list: r.update() for r in ripple_list: your_game_window.blit(r.image, r.rect)That will get you started.
instead of using ripple_list as a global variable I think something like this would be better:
def update(self): if self.radius < self.max_radius: self.surf.fill((0,0,0)) pg.draw.circle(self.surf, self.color, (self.max_radius, self.max_radius), self.radius) self.alpha -= self.fade self.radius += self.growth_rate return False else: return True
for r in ripple_list: if r.update(): ripple_list.remove(r) for r in ripple_list: your_game_window.blit(r.image, r.rect)