Node.Remove_from_parent, not really gone?
Hi. So I have made some progress in my space game.
I now have enemy ships that appears and moves, and I can shoot them down. However. If my ship moves to where they got hit, my ship will die it as if they are still there
I have used
I thought that would remove the entirly from the scene but since I'll die if I move there something is still there
Here is the whole function:
def enemy_smash(self, enemy): enemy.destroyed = True enemy.remove_from_parent() debree = SpriteNode('spc:PlayerShip1Damage1', parent=self) debree.position = enemy.position debree.run_action(A.move_by(10, 10, 1.6, TIMING_EASE_OUT)) ui.delay(debree.remove_from_parent,1)```
omz last edited by omz
I'm not sure I fully understand the problem here. Is the
enemyobject still visible in the scene after calling
As an aside, I wouldn't recommend using
ui.delayto remove a node after a delay. Use something like
@omz Hello, no the enemy is gone and everything looks good but if I move my ship to the position where the enemy ship was destroyed my ship will die as if it was hit by the enemy.
Ok good to know will fix that thank you
omz last edited by
@Bjucha When you remove a
Nodefrom its parent (either via
Node.remove_from_parent()), all it does is that the node is no longer visible, and if you don't keep a reference to it somewhere, it will get garbage-collected.
You still have to use your own logic to determine, whether a node collides with another. E.g. check the
parentproperty of a node before hit testing (it'll be
Noneif the node isn't part of the scene anymore).
@omz thank you. I'm gonna test it
@omz Fixed it! Really appriciate all the help.