Forum Archive

Updating multi touch issues

Auer

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.

Drizzel

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)
Drizzel

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

JonB

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)