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.


    Updating multi touch issues

    Pythonista
    3
    4
    2152
    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.
    • Auer
      Auer last edited by

      This full code has a small section that throws no errors but for some reason doesn't work.

      n0de.position=touch.location
      

      ^Works just fine... but the following

      if n0de.position.x>touch.location.x:
      				n0de.position.x-=self.speed
      		elif n0de.position.x <touch.location.x:
      				n0de.position.x+=self.speed
      		if n0de.position.y >touch.location.y:
      				n0de.position.y-=self.speed
      		elif n0de.position.y<touch.location.y:
      				n0de.position.y+=self.speed
      

      Doesn't do anything. Tho when I replace the position changing lines with print statements it works fine.
      eg

      if n0de.position.y >touch.location.y:
         print('moves down')
      

      I assume I'm missing something about updating Sprite positions?

      Thanks.

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

        I don't know why it is the way it is, but you have to say

        n0de.position += (self.speed, 0)
        

        Or

        n0de.position = (n0de.position.x + self.speed, 0)
        
        1 Reply Last reply Reply Quote 0
        • Drizzel
          Drizzel last edited by

          I had the same issue in my own game, and that's how I fixed it

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

            vector2's can be added, subtracted, scaled, etc, so you could simplify that whole if/else block as

            deltaPos=touch.location-n0de.position
            n0de.position = self.speed * deltaPos/abs(deltaPos)
            

            (well, not quite, but it probably does what you intended, which is to move in the direction of your finger by self.speed. your code would technically be moving faster along diagonals)

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