DMC libray

Hi ,

Here i am using DMC Library in this i can create only shapes such as rect square etc …

But i want to drag a image and drop that in a target , but i couldnt do that it is possible or not .

Pls tell me some solution.

hey there,

the code examples from the library use simple objects such as squares for drag initiators, targets, and proxies, but you can use any Corona display object such as an image ( eg display.newImage() ).

this code snippet from the docs shows creating a custom proxy. again, here we just create a square, but you can use an image, too.

http://docs.davidmccuskey.com/display/docs/Quick+Guide±+dmc_dragdrop

local function dragItemTouchHandler( event ) if event.phase == "began" then local target = event.target -- create Drag Proxy - item dragged around the screen local dragProxy = display.newRect( 0, 0, 75, 75 ) s.strokeWidth = 3 s:setFillColor( 90, 170, 255 ) s:setStrokeColor( 180, 180, 180 ) -- setup info about the drag operation local drag\_info = { proxy = dragProxy, format = "red", yOffset = -30, } -- now tell the Drag Manager about it DragMgr:doDrag( target, event, drag\_info ) end return true end

cheers,
dmc

Hi ,

 Well , i used the proxy , but still i can’t move the actual object instead of that a rectangle is created and its being moved . why this is happening and to over come. take a look at this code which i am using.

local DragMgr = require ( “dmc_dragdrop” )

local dropTarget3 = display.newImage(“pair+.png”,160,180)
dropTarget3.x = 160 ; dropTarget3.y =  110

DragMgr:register( dropTarget3 )

local function dragItemTouchHandler( event )

    if event.phase == “began” then

        local target = event.target

        – setup info about the drag operation
        local drag_info = {
            proxy = dragItem,
            id = 1
            --yOffset = -30,
        }

        – now tell the Drag Manager about it
        DragMgr:doDrag( target, event, drag_info )
    end

    return true
end

– this is the drag target, the location from which we start a drag
local dragItem = display.newImage(“money10.png”,160,400)
dragItem.x = 160 ; dragItem.y = y_base

dragItem:addEventListener( “touch”, dragItemTouchHandler )
 

Is this correct , if not tell me the changes which i have to make.

it appears that you are trying to use the dragItem as the drag proxy. this is not really how the library is intended to be used.

by default the library will create a drag proxy for you AND THEN DELETE IT when drag is over. the drag proxy is meant to be temporary and is just a *representation* of the object you want to move. because it’s deleted in the end, you probably don’t want it to be your real object.

i have attached an image of me dragging a file around on the Mac OS desktop. in it you can see that the *original* file is still in the starting position, and there is a drag proxy created for me to represent the original. when i stop dragging the proxy, the original is moved to the final position if the drag was successful. the take-away is that there are TWO different items in this process.

of course, you need to decide how you want drag/drop to behave in *your* app. if you don’t want the original object to show you could possibly

* start the drag

* create your drag proxy (image duplicate)

* hide the real image object

* drag the proxy to new location

* when drag done, unhide the real image object, moving it to its new position if the drag succeeded.

* library removes the drag proxy for you.

if you just want to move something around the screen, it might be easier to just move the objects around yourself instead of using the library.

i’ve also added some comments in your code:

local DragMgr = require ( "dmc\_dragdrop" ) &nbsp; local dropTarget3 = display.newImage("pair+.png",160,180) dropTarget3.x = 160 ; dropTarget3.y = &nbsp;110 &nbsp; DragMgr:register( dropTarget3 ) &nbsp; &nbsp; local function dragItemTouchHandler( event ) &nbsp; &nbsp; &nbsp; if event.phase == "began" then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local target = event.target &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- you havent created a drag proxy here &nbsp; &nbsp; &nbsp; &nbsp; -- you instead try to reference dragItem, but its likely to be nil &nbsp; &nbsp; &nbsp; &nbsp; -- because of how your code is setup &nbsp; &nbsp; &nbsp; &nbsp; -- because its nil, the library is still creating drag proxy for you &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- setup info about the drag operation &nbsp; &nbsp; &nbsp; &nbsp; local drag\_info = { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proxy = dragItem, &nbsp;-- \<\<\<\<\<\< this is likely to be nil !! &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; id = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --yOffset = -30, &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- now tell the Drag Manager about it &nbsp; &nbsp; &nbsp; &nbsp; DragMgr:doDrag( target, event, drag\_info ) &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; return true end &nbsp; -- this is the drag target, the location from which we start a drag local dragItem = display.newImage("money10.png",160,400) dragItem.x = 160 ; dragItem.y = y\_base dragItem:addEventListener( "touch", dragItemTouchHandler ) &nbsp;

cheers,

dmc

hey there,

the code examples from the library use simple objects such as squares for drag initiators, targets, and proxies, but you can use any Corona display object such as an image ( eg display.newImage() ).

this code snippet from the docs shows creating a custom proxy. again, here we just create a square, but you can use an image, too.

http://docs.davidmccuskey.com/display/docs/Quick+Guide±+dmc_dragdrop

local function dragItemTouchHandler( event ) if event.phase == "began" then local target = event.target -- create Drag Proxy - item dragged around the screen local dragProxy = display.newRect( 0, 0, 75, 75 ) s.strokeWidth = 3 s:setFillColor( 90, 170, 255 ) s:setStrokeColor( 180, 180, 180 ) -- setup info about the drag operation local drag\_info = { proxy = dragProxy, format = "red", yOffset = -30, } -- now tell the Drag Manager about it DragMgr:doDrag( target, event, drag\_info ) end return true end

cheers,
dmc

Hi ,

 Well , i used the proxy , but still i can’t move the actual object instead of that a rectangle is created and its being moved . why this is happening and to over come. take a look at this code which i am using.

local DragMgr = require ( “dmc_dragdrop” )

local dropTarget3 = display.newImage(“pair+.png”,160,180)
dropTarget3.x = 160 ; dropTarget3.y =  110

DragMgr:register( dropTarget3 )

local function dragItemTouchHandler( event )

    if event.phase == “began” then

        local target = event.target

        – setup info about the drag operation
        local drag_info = {
            proxy = dragItem,
            id = 1
            --yOffset = -30,
        }

        – now tell the Drag Manager about it
        DragMgr:doDrag( target, event, drag_info )
    end

    return true
end

– this is the drag target, the location from which we start a drag
local dragItem = display.newImage(“money10.png”,160,400)
dragItem.x = 160 ; dragItem.y = y_base

dragItem:addEventListener( “touch”, dragItemTouchHandler )
 

Is this correct , if not tell me the changes which i have to make.

it appears that you are trying to use the dragItem as the drag proxy. this is not really how the library is intended to be used.

by default the library will create a drag proxy for you AND THEN DELETE IT when drag is over. the drag proxy is meant to be temporary and is just a *representation* of the object you want to move. because it’s deleted in the end, you probably don’t want it to be your real object.

i have attached an image of me dragging a file around on the Mac OS desktop. in it you can see that the *original* file is still in the starting position, and there is a drag proxy created for me to represent the original. when i stop dragging the proxy, the original is moved to the final position if the drag was successful. the take-away is that there are TWO different items in this process.

of course, you need to decide how you want drag/drop to behave in *your* app. if you don’t want the original object to show you could possibly

* start the drag

* create your drag proxy (image duplicate)

* hide the real image object

* drag the proxy to new location

* when drag done, unhide the real image object, moving it to its new position if the drag succeeded.

* library removes the drag proxy for you.

if you just want to move something around the screen, it might be easier to just move the objects around yourself instead of using the library.

i’ve also added some comments in your code:

local DragMgr = require ( "dmc\_dragdrop" ) &nbsp; local dropTarget3 = display.newImage("pair+.png",160,180) dropTarget3.x = 160 ; dropTarget3.y = &nbsp;110 &nbsp; DragMgr:register( dropTarget3 ) &nbsp; &nbsp; local function dragItemTouchHandler( event ) &nbsp; &nbsp; &nbsp; if event.phase == "began" then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local target = event.target &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- you havent created a drag proxy here &nbsp; &nbsp; &nbsp; &nbsp; -- you instead try to reference dragItem, but its likely to be nil &nbsp; &nbsp; &nbsp; &nbsp; -- because of how your code is setup &nbsp; &nbsp; &nbsp; &nbsp; -- because its nil, the library is still creating drag proxy for you &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- setup info about the drag operation &nbsp; &nbsp; &nbsp; &nbsp; local drag\_info = { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proxy = dragItem, &nbsp;-- \<\<\<\<\<\< this is likely to be nil !! &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; id = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --yOffset = -30, &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- now tell the Drag Manager about it &nbsp; &nbsp; &nbsp; &nbsp; DragMgr:doDrag( target, event, drag\_info ) &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; return true end &nbsp; -- this is the drag target, the location from which we start a drag local dragItem = display.newImage("money10.png",160,400) dragItem.x = 160 ; dragItem.y = y\_base dragItem:addEventListener( "touch", dragItemTouchHandler ) &nbsp;

cheers,

dmc