Will pygame.draw shapes still remain within the game if size/radius is 0 and stopped pygame.draw or screen.blit (showing on screen)

Viewed 41

I have a question regarding FPS and memory, do any of you know if I use list and append pygame.squares/circles/other shapes, if radius or size minimized and became 0 and remove from the current list, stopped pygame.draw function after, but it will still stay in the game right??

So if I'm creating something like fire smoke effect (let's say create radius 12 pygame.draw.circles, append in a list, minimize, remove from list if radius <= 0 and stopped showing on screen), will the removed ones stored alot and slow down the whole speed and takes memory?? Do any of you know if theres any solution to this problem or minimize it?? Thank you, this will help me alot

def createparticle(self):
    # make particle settings - original and fade size and add inside a list
    self.mouseposition = pygame.mouse.get_pos()
    self.x = pygame.mouse.get_pos[0]
    self.y = pygame.mouse.get_pos[1]
    self.fade_x = 1
    self.fade_y = 1
    self.radius = 12
    self.ball = [[self.x, self.y], self.radius, [self.fade_x, self.fade_y]]
    self.particles.append(self.ball)
def emit(self):
    # run loop, blit and move particle
    for p in self.particles:
        p[0][1] += p[2][1]
        p[0][0] += p[2][0]
        p[1] -= 0.2
        pygame.draw.circle(self.screen, pygame.Color('orange'), p[0], int(p[1]))
def deleteparticle(self):
    # remove particle if size is smaller than 0
    self.particles_copy = [p for p in self.particles if p[1] > 0]
    self.particles = self.particles_copy
1 Answers

If they are removed from the list (and that is the only place references are stored of that object) they should get garbage collected and removed from the memory, draw doesn't create any game objects that stay in the game that way. It just simply changes some pixels on the screen and that is it (it does return pygame.Rect but that can be ignored or if you store those in a list removing them will free the memory), those functions don't create any objects that just stay in the game as some kind of special object, that would be pretty poor design.

Related