Reputation: 11
There is an instance of the Surface class, and there are also several instances of the Rect class on it. Surface.fill([color])
will hide all elements that are on the Surface. But i need to hide only one Rect instance. How can I remove just one specific Rect element from Surface?
Upvotes: 1
Views: 508
Reputation: 210878
Surface.fill([color])
will hide all elements that are on the Surface [...]
No, it does not. A Surface
does not contain any object, a Surface
is just a bunch of pixel organized in rows and columns. fill
just changes the color of all pixels. You cannot "delete" an object from a surface. You can just paint on the Surface in a different color.
If you want to change the color of a rectangular region of a Surface
object, then you can paint a rectangle on the Surface
by pygame.draw.rect()
.
If you have a dynamic scene with dynamic objects, then common way is to redraw to entire scene in every frame. Implement and application loop. The application loop has to:
pygame.event.pump()
or pygame.event.get()
.blit
all the objects)pygame.display.update()
or pygame.display.flip()
Upvotes: 1