M
M
michadimin2021-12-30 15:11:23
pygame
michadimin, 2021-12-30 15:11:23

How to clear the screen of ALL objects in PyGame + Pymunk?

I am making a program where the user has the ability to draw surfaces to interact with these surfaces of balls, which the user can also launch wherever and whenever he wants.

Periodically - the screen overflows, and performance drops due to the fact that there are too many objects to process.

Well and so... How to clear space of all created objects?

I don’t know the names of the objects, since I create them using a function (I tried to use classes, but for some reason it gave an error, apparently I did something wrong).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
michadimin, 2021-12-30
@michadimin

I found the answer myself.
For those who will suffer with the same question in the future and see this topic here - I will explain the solution:
You need to declare arrays (lists) for objects that are created in functions, and then add each new element to these arrays.
If you need to delete, you need to create a cycle (I think everyone has already understood which one, so I won’t explain), where you will delete each object by referring to its index in the array through the remove () method for your space in Pymunk.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question