It looks like you're new here. If you want to get involved, click one of these buttons!
function ShootGame:onTouchesMove(event) local planeMinY = 0 -- Plane can reach the top. local planeMaxY = resolution:getGameHeight() - plane:getHeight() -- Plane can reach the bottom. local planeMovement = 15 if (plane.touchId == event.touch.id) and plane.dragging then local dx = event.touch.x - startTouchX local dy = event.touch.y - startTouchY -- Get the absolute movement in x and y direction. local fingerMovementXY = math.floor(math.sqrt(math.pow(dx, 2) + math.pow(dy, 2))) -- Finger up more than 1px. if (dy < - 1) then targetPlaneY = plane.y - (fingerMovementXY * planeMovement) -- New plane position. if targetPlaneY < planeMinY then targetPlaneY = planeMinY end startTouchX = event.touch.x -- Set new startX. startTouchY = event.touch.y -- Set new startY. end -- Finger down more than 1px. if (dy > 1) then targetPlaneY = plane.y + (fingerMovementXY * planeMovement) if targetPlaneY > planeMaxY then targetPlaneY = planeMaxY end startTouchX = event.touch.x -- Set new startX. startTouchY = event.touch.y -- Set new startY. end end end function ShootGame:onEnterFrame() // THIS IS A PART OF THE COMPLETE FUNCTION -- Move the plane in vertical direction. if (plane ~= nil) then if (plane.y > targetPlaneY) then -- Move down. plane.y = plane.y - 2 end if (plane.y < targetPlaneY) then -- Move up. plane.y = plane.y + 2 end plane:setPosition(plane.x, plane.y) end end |
Comments
Wouldn't you want to move it to the amount fingers have moved vertically?
I was just experimenting. The plane is in a fixed horizontal position. The background is scrolling. By placing your thumb on the right side of the screen you can move the plane vertically. Challenge is to let the plane move smoothly from top to bottom by moving your finger over a small range. So for example if I have a resolution of 1500x500, when I move my thumb 1 pixel the plane has to move 10 pixels and when I move it 25 pixels it will be move to top or bottom (250 pixels). I am not shure what the optimum values are. See it as an analog joystick.
Best regards,
Marc
the onTouchesMove method is not a proper place for moving spaceship because event.x and event.y is not consistent and smooth.
Try onEnterFrame and place your logic there.
you can obtain starting place from onTouchesDown.
Create a table with 10-20 member and save (currentPlace - startingPlace) there and update it in onTouchesMove.
The average of this table can be the input for onEnterFrame.
Thanks for your reply. In the code above the fingermovement will be determined in the onTouchedMove. The planemovement will be done in the onEnterFrame.
Regards,
Marc