Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
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
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 thereHere 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)```
-
I'm not sure I fully understand the problem here. Is the
enemy
object still visible in the scene after callingremove_from_parent
?As an aside, I wouldn't recommend using
ui.delay
to remove a node after a delay. Use something likedebree.run_action(A.sequence(A.wait(1), A.remove()))
. -
@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
-
@Bjucha When you remove a
Node
from its parent (either viaAction.remove()
orNode.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 beNone
if 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.