Forum Archive

Flip Player Horizontally On x-axis

lance1994

So here's the basic code for flipping it with gravity and abs :

def cmp (a, b):
return ((a> _b) - (a < b))

g = gravity()
if abs(g.x) > 0.05:

        self.player.x_scale = cmp(g.x, 0)

This basically flips the image horizontally by tilting your device , but how do I go about getting it to flip with touch location. I've tried many variations , one variation I tried only got him to turn on the negative - axis but not the positive. any suggestions? Here is my player movement code btw:

x, = touch.location
, y = self.player.position
move_action = Action.move_to(x,y,0.7,TIMING_SINODIAL)
self.player.run_action(move_action)
if (x,_ > 0.05):
self.player.x_scale = cmp(-x, 0)
x = self.player.position.x

omz

Something like this should do the trick:

self.player.x_scale = cmp(touch.location.x - self.player.position.x, 0)

(You may need to swap the operands of the subtraction, depending on which direction your player image is facing normally.)

lance1994

Perfect fit Omz thanks bro.