I want to create a game where user moves his finger in the screen and an object is dragged corresponding to finger position.But the user will move his finger for short distance.But the object should move for long distance.
For example if the user moves his finger for 10px left ,then the object should move (10*5)=50px left.
pink circle is the object.
black rectangle is where object should move.
red rectangle is where user can swipe his/her finger
My code to drag is below
local physics = require"physics" physics.start() local xc = display.contentCenterX local yc = display.contentCenterY local w = display.actualContentWidth local ball=display.newCircle(xc,yc,30) ball.radius=30 local function drag(event) phase=event.phase if ("began" == phase) then display.currentStage:setFocus(ball) ball.touchOffsetX = event.x - ball.x elseif ("moved" == phase) then if (event.x - ball.touchOffsetX \> ball.radius and event.x - ball.touchOffsetX \< display.viewableContentWidth - ball.radius) then ball.x = event.x - ball.touchOffsetX end elseif ("ended" == phase or "cancelled" == phase) then display.currentStage:setFocus(nil) end end Runtime:addEventListener( "touch", drag)