It’s me again (2 messages in the same day…). I’m currently trying to correct some bug in my game and this one drive me crazy!
Each time a collision is detected from a weapon to a enemy, an explosion is trigered. This is working. The problem is that all the explosion STAY in the scene graph after the animation is finished.
Each time this method is called, all of this is called. This is working but I’m sure I will get trouble soon or later with memory. Also, I can see the explosion last frame when I go back where it happened.
Thanks for the answer. I tried something like that but there was another problem involved I don’t remember what.
But today I got a flash and I will change the way I manage my explosion. I will have an ExplosionManager that will contain a list of current explosion. Each explosion will have a time to live and will be deleted right after. It maybe not the best way to do it but it’s working with my weapon class.
Just 2 questions to check if this method is good:
-Is there a way in Python to display all class that are currently instantiated. (My node will be deleted but it’s not bether if I have like 4000 object “Explosion” created, I want to check that)
-Is there a way to clearly kill an object and that way the garbage collector will free the memory?
Python’s “gc” module can do this sort of thing for you. You’ll have to look into how it is used.
Simply removing all references to the object is the way you kill something in Python. You’re not supposed to even have to worry about questions like this; it’s just supposed to happen automatically.