Forum Archive

Node.Remove_from_parent, not really gone?

Bjucha

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 enemy.remove_from_parent()
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

I'm not sure I fully understand the problem here. Is the enemy object still visible in the scene after calling remove_from_parent?

As an aside, I wouldn't recommend using ui.delay to remove a node after a delay. Use something like debree.run_action(A.sequence(A.wait(1), A.remove())).

Bjucha

@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

@Bjucha When you remove a Node from its parent (either via Action.remove() or 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 parent property of a node before hit testing (it'll be None if the node isn't part of the scene anymore).

Bjucha

@omz thank you. I'm gonna test it

Bjucha

@omz Fixed it! Really appriciate all the help.