[Solved] Orientation flip makes touch events invert

Hi!
I’m making a juggle game where there is a paddle that you move with the touch of your finger. Everything works fine, but now I have implemented some orientation code so that you can flip the device from landscapeLeft to landscapeRight and vice versa (in main.lua):

http://developer.anscamobile.com/code/proper-orientation-rotation-animation

My default is landscapeLeft, but when I flip it to landscapeRight the touch event inverts! So when I try to move the paddle to the left (by touching to the left) it moves to the right and vice versa.

How do I do to fix this?

My code to move paddle:

[code]
function movePaddle:touch(e)
if(e.phase == ‘began’) then
lastX = e.x - paddle.x
elseif(e.phase == ‘moved’) then
paddle.x = e.x - lastX
end
end

Best regards,
joelwe
[/code] [import]uid: 54640 topic_id: 22298 reply_id: 322298[/import]

If your using that add on to rotate, rather than just doing it automatically via build.settings there are fixes listed in the comments to solve that problem

http://developer.anscamobile.com/code/proper-orientation-rotation-animation

And specifically http://developer.anscamobile.com/code/proper-orientation-rotation-animation#comment-58273
[import]uid: 84637 topic_id: 22298 reply_id: 88891[/import]

Thanks Danny! I just found it too in the link I (and you posted) :stuck_out_tongue:

function movePaddle:touch(e)  
 --Just added this  
 if isRotated then  
 e.x = display.contentWidth - e.x  
 end  
 --That's all!  
  
 if(e.phase == 'began') then  
 lastX = e.x - paddle.x  
 elseif(e.phase == 'moved') then  
 paddle.x = e.x - lastX  
 end  
end  

It works great! Thanks!

Best regards,
joelwe [import]uid: 54640 topic_id: 22298 reply_id: 88894[/import]