Drawing on a sprite surface in pygame

I have several different classes that extend the Sprite pygame class, and initially I just created a Surge object for pygame using an external image and painted this image on my screen. I have large groups of these sprites, so I include them in the RenderClear group, and then just clear and draw the group for simplicity. This worked until I decided to draw my own graphics with pygame.

Instead of an external image, I create a Surface image and draw a circle on it:

pygame.draw.circle(self.image, self.color, (int(self.x), int(self.y)), self.radius, 0) 

However, the circle does not appear when I draw it on the screen. Nothing is visible, it's just a transparent surface.

I also tested drawing a circle right on the screen with the same parameters, and it works, but if I draw a sprite image, nothing. Any ideas?

+4
source share
1 answer

You need to make the update method inside the classes, and then draw circles and stuff on the surface of the window inside the method. Then every time you draw a RenderClear group, call RenderClear.update () and it will draw whatever you want.

+1
source

All Articles