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.


    How to restart a scene?

    Pythonista
    scene
    2
    3
    1018
    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.
    • borrax
      borrax last edited by

      I wrote a simple solitaire game, everything works, but I would like to include a reset button. My first attempt failed, simply calling run() again did not work. So how to reset a scene?

      cvp 1 Reply Last reply Reply Quote 0
      • cvp
        cvp @borrax last edited by cvp

        @borrax Perhaps you could remove all children tree, then call self.setup()

        from scene import *
        
        class MyScene (Scene):
            def setup(self):
                self.background_color = 'midnightblue'
                self.ship = SpriteNode('spc:PlayerShip1Orange')
                self.ship.position = self.size / 2
                self.add_child(self.ship)
        
            def touch_began(self, touch):
                # touch top of screen to reset
                if touch.location[1] > (ui.get_screen_size()[1]-50):
                    for child in self.children:
                       child.remove_from_parent()
                    self.setup()
                    return
                x, y = touch.location
                move_action = Action.move_to(x, y, 0.7, TIMING_SINODIAL)
                self.ship.run_action(move_action)
        
        run(MyScene())
        
        1 Reply Last reply Reply Quote 1
        • borrax
          borrax last edited by

          @cvp, thanks, that worked.

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