Javid Aliyev
Javid Aliyev

Reputation: 11

How to delete one object from a Surface instance?

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

Answers (1)

Rabbid76
Rabbid76

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:

Upvotes: 1

Related Questions