Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

"Drag object in opposite Direction"
Started by avinashkhubchandani101 Jun 02 2019 12:00 AM

2 replies to this topic
#drag #dragging #direction
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

avinashkhubchandani101

[GLOBAL: userInfoPane.html]
avinashkhubchandani101
  • Observer

  • 3 posts
  • Corona SDK

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)


[TOPIC: post.html]
#2

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 731 posts
  • Corona SDK

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.


  • avinashkhubchandani101 likes this

[TOPIC: post.html]
#3

avinashkhubchandani101

[GLOBAL: userInfoPane.html]
avinashkhubchandani101
  • Observer

  • 3 posts
  • Corona SDK

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




[topic_controls]
[/topic_controls]