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
-
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.
egif n0de.position.y >touch.location.y: print('moves down')
I assume I'm missing something about updating Sprite positions?
Thanks.
-
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)
-
I had the same issue in my own game, and that's how I fixed it
-
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)