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.
Flip Player Horizontally On x-axis
-
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 -
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.)
-
Perfect fit Omz thanks bro.