Hi,
I suck at maths. I have a dummy object in the screen and want the player to turn it’s face (flip) to this object.
I suck at explainig things too ;d so here is the picture explaining the situation…

Hi,
I suck at maths. I have a dummy object in the screen and want the player to turn it’s face (flip) to this object.
I suck at explainig things too ;d so here is the picture explaining the situation…

xScale can control the direction in which an object faces. If you include code in your dummy object spawning code to flip the player’s xScale value (usually by multiplying by -1) then the player sprite should flip to your object.
http://docs.coronalabs.com/api/type/DisplayObject/xScale.html
To break it down further for your particular example, firstly you need to check whether the object is on the left or right side of the screen (I would do this in an enter frame function):
if myObject.x \< display.contentWidth \* 0.5 then --object is on left myPlayer.xScale = -1 else --object is on right myPlayer.xScale = 1 end
This example assumes that the sprite has initially been drawn facing to the right.
Note if you want the player to “turn” (or flip) on the spot, you will need to set its reference point to “display.CenterReferencePoint”.
^Thanks! it is solved now.
xScale can control the direction in which an object faces. If you include code in your dummy object spawning code to flip the player’s xScale value (usually by multiplying by -1) then the player sprite should flip to your object.
http://docs.coronalabs.com/api/type/DisplayObject/xScale.html
To break it down further for your particular example, firstly you need to check whether the object is on the left or right side of the screen (I would do this in an enter frame function):
if myObject.x \< display.contentWidth \* 0.5 then --object is on left myPlayer.xScale = -1 else --object is on right myPlayer.xScale = 1 end
This example assumes that the sprite has initially been drawn facing to the right.
Note if you want the player to “turn” (or flip) on the spot, you will need to set its reference point to “display.CenterReferencePoint”.
^Thanks! it is solved now.