A Fuse Powered Company

Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

DMC libray
Started by kumarks102 Oct 18 2013 12:54 AM

3 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

kumarks102

[GLOBAL: userInfoPane.html]
kumarks102
  • Starter
  • PipPipPipPipPipPip
  • 50 posts
  • Jedi

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.



[TOPIC: post.html]
#2

dmccuskey

[GLOBAL: userInfoPane.html]
dmccuskey
  • Pro
  • PipPipPipPipPipPip
  • 143 posts
  • Jedi

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

[TOPIC: post.html]
#3

kumarks102

[GLOBAL: userInfoPane.html]
kumarks102
  • Starter
  • PipPipPipPipPipPip
  • 50 posts
  • Jedi

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.



[TOPIC: post.html]
#4

dmccuskey

[GLOBAL: userInfoPane.html]
dmccuskey
  • Pro
  • PipPipPipPipPipPip
  • 143 posts
  • Jedi

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.
 
Attached File  FinderScreenSnapz001.png   89.9KB   23 downloads
 
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" )
 
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
        
        
        -- you havent created a drag proxy here
        -- you instead try to reference dragItem, but its likely to be nil
        -- because of how your code is setup
        -- because its nil, the library is still creating drag proxy for you
 
        -- setup info about the drag operation
        local drag_info = {
            proxy = dragItem,  -- <<<<<< this is likely to be nil !!
            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 )
 
 
 
cheers,
dmc
 
 
 



[topic_controls]
[/topic_controls]