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.


    Repeated UI/Scene actions

    Pythonista
    2
    7
    4422
    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.
    • Strassboom
      Strassboom last edited by

      Hello all!
      I’m looking for a way to have a push button action be performed repeatedly until a button is released. I’m making a game where the player character will move by pressing buttons, and would like them to move continuously in a direction according button they’re pressing I.e. pressing the left button will make the character move left until it is released, or pressing the right button will make the character move right until it is released. I’ve followed these forums since fall 2016 since I’ve been unable to find any questions like this or pythonista games that implement this feature, I’ve finally made an account.

      Methods attempted:
      Looping touch_began and touch_ended functions for the scene module, with the exit condition being whether a stack containing the most recent touch action was a press or release.

      Integrating these conditions into the update function.

      Using a SceneView. However upon finding the delegates for the uiButton, I realised there are no delegate functions besides button_tapped.

      Much thanks!

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

        if your touch-begin, but don't move, touch_moved doesn,t get called, as you have found.

        Scene keeps track of active touches in Scene.touches. So, you can simply check the status in Scene.update, and then take action there.

        1 Reply Last reply Reply Quote 1
        • JonB
          JonB last edited by

          https://gist.github.com/85df3ebd9ae388e1f6fdc6c45a8e98c2
          Here I converted the Game Tutorial Tutorial3.py to use touch input, instead of gravity input. I am showing a linear joystick like control, but you could just use a fixed speed, and check if touch in right_button.bbox, etc.

          Strassboom 1 Reply Last reply Reply Quote 1
          • Strassboom
            Strassboom @JonB last edited by

            @JonB thank you for the swift response. I’ve been trying to figure out the box for the last hour or so. Any advice on bboxes? So far all attempts of the classic “< x < “ tuple comparison don’t work, as it’s giving me an error about how a dict values object does not support indexing, even though it displays as a tuple.

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

              bbox's implement __contains__ so you can do things like

              if touch.location in self.right_button.bbox:
                  #do something
              

              See example here, refactored dor movement buttons
              https://gist.github.com/0f3d7e3722ec71daf10befb95f15be6c

              Strassboom 2 Replies Last reply Reply Quote 1
              • Strassboom
                Strassboom @JonB last edited by

                @JonB thank you! I actually ended up spending an hour just finding the bounds of the buttons I made manually and then having the update method check the touch’s location against the bounds of the buttons in a 4 part if-elif-else block. Thank you for the solution earlier, it helped immensely! I will test this one as well tonight/tomorrow and get back to you on my results!

                1 Reply Last reply Reply Quote 0
                • Strassboom
                  Strassboom @JonB last edited by

                  @JonB it works perfectly! Thank you!

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