omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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?

    Pythonista
    node scene
    2
    6
    3638
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Bjucha
      Bjucha last edited by

      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)```
      1 Reply Last reply Reply Quote 0
      • omz
        omz last edited by 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 1 Reply Last reply Reply Quote 0
        • Bjucha
          Bjucha @omz last edited by

          @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

          1 Reply Last reply Reply Quote 0
          • omz
            omz last edited by

            @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 2 Replies Last reply Reply Quote 0
            • Bjucha
              Bjucha @omz last edited by

              @omz thank you. I'm gonna test it

              1 Reply Last reply Reply Quote 0
              • Bjucha
                Bjucha @omz last edited by

                @omz Fixed it! Really appriciate all the help.

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post
                Powered by NodeBB Forums | Contributors