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.


    SpriteNode movement trouble

    Pythonista
    action spritenode scene
    2
    3
    2415
    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
      Im having a problem with getting my SpriteNode to move several times
      Moving it from one place to an other is no problem but if I would like it to make a new movement when the first one is complete it will not work
      This is how I tried:

      def mini_attack(self, boss3):
      		mini = Mini(parent=self)
      		mini.position = boss3.position
      		x,y = self.ship.position
      		action = [A.move_to(300,300, 1.5)]
      		mini.run_action(A.sequence(action))
      		mini.remove_action(A.sequence(Action))
      		if mini.position == (300,300):
      			action2 = [A.move_to(x +10,y + 20, 1.5)]
      			mini.run_action(A.sequence(action2))
      		```
      
      it's the action2 that will not happen...
      Appreciate any help
      1 Reply Last reply Reply Quote 0
      • omz
        omz last edited by

        Your check for mini.position == (300,300) will never be true unless that happens to be the sprite's starting position. You have to understand that running an Action doesn't block execution until it's completed, but it basically just "schedules" the movement for the following animation frames.

        To run an action after another action has completed, you can use Action.sequence, but you have to use multiple actions in one sequence for it to have any effect. There's no need to check the sprite's position at all when you use a sequence. It'll run the next action automatically when the first one has finished, i.e. when the sprite has reached its first "waypoint".

        So your code should look something like this:

        def mini_attack(self, boss3):
            mini = Mini(parent=self)
            mini.position = boss3.position
            x, y = self.ship.position
            action1 = A.move_to(300, 300, 1.5)
            action2 = A.move_to(x +10, y + 20, 1.5)
            mini.run_action(A.sequence([action1, action2]))
        
        Bjucha 1 Reply Last reply Reply Quote 0
        • Bjucha
          Bjucha @omz last edited by

          @omz thank you very much!!! Gonna try it

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