I am trying to create a simple demo that will rotate an image by detecting a finger being moved across the screen. I have created this code, but it seems messy, long winded and doesn’t work 100% ie. when the user moves up and down before removing their finger. The idea of the code is that it finds out the x,y location where the finger starts the touch and then works out if it is going up or down the screen. Depending on the direction the graphic is rotated in that direction. I have linked this code to an event listener for the background image rather than the image as I thought that this would give me more flexibility.
-----
oldY = 0
newY = 0
function fingerMove(event)
if event.phase == "began" then
oldY=event.yStart
print("Started" .. newY)
end
if event.phase =="moved" then
newY=event.y
print ("Moved oldY=" .. oldY .. " newY="..newY)
if newY\>oldY+10 then
--move down
print("down")
cannonRotation = cannonRotation + 1
if (cannonRotation \>= rotateMax) then
cannonRotation = rotateMax
end
cannonBarrel.rotation = cannonRotation
fireButton.rotation = cannonRotation
elseif newY<oldy then> --move up<br> print("up")<br> cannonRotation = cannonRotation - 1<br> if (cannonRotation <= rotateMin) then<br> cannonRotation = rotateMin<br> end<br> cannonBarrel.rotation = cannonRotation<br> fireButton.rotation = cannonRotation<br> end<br> end <br> if event.phase == "ended" or event.phase == "cancelled" then<br> print("ended")<br> oldY=newY<br> end<br>end<br>-----------<br></oldy>
Any suggestions or improvements appreciated. A simple solution would be nice as I’m still a newby and so need to understand what is happening in the code.
[import]uid: 116086 topic_id: 35374 reply_id: 335374[/import]