"Drag object in opposite Direction"

This code works but it is not smooth and didn’t look good…

local rect = display.newRect(150,200,50,50)

local function onTouch(e)

    if e.phase == “began” then

    rect.markX =rect.x    

    rect.markY = rect.y  

   

    elseif e.phase == “moved” then

    local x = (display.contentWidth - e.x - e.xStart) + rect.markX

    local y = (display.contentHeight - e.y - e.yStart) + rect.markY

   

    rect.x = x

    rect.y = y

    elseif e.phase == “ended” then

    end

    return true

end

Runtime:addEventListener(“touch”,onTouch)

You’ve almost got it. You just need to adjust your formulas a bit.

local rect = display.newRect(150,200,50,50) local function onTouch(e) if e.phase == "began" then rect.markX = rect.x rect.markY = rect.y elseif e.phase == "moved" then rect.x = rect.markX - (e.x - e.xStart) rect.y = rect.markY - (e.y - e.yStart) end return true end Runtime:addEventListener("touch",onTouch)

This should give you exactly what you are looking for. It’ll probably still look a bit wonky since it mirrors what you are doing. Also, when posting code, please use the code tool.

Thank You Sir for helping I am new to corona and got stuck on this topic

You’ve almost got it. You just need to adjust your formulas a bit.

local rect = display.newRect(150,200,50,50) local function onTouch(e) if e.phase == "began" then rect.markX = rect.x rect.markY = rect.y elseif e.phase == "moved" then rect.x = rect.markX - (e.x - e.xStart) rect.y = rect.markY - (e.y - e.yStart) end return true end Runtime:addEventListener("touch",onTouch)

This should give you exactly what you are looking for. It’ll probably still look a bit wonky since it mirrors what you are doing. Also, when posting code, please use the code tool.

Thank You Sir for helping I am new to corona and got stuck on this topic