Select and drag an object

Hi Corona Forums!

I’m stuck adding some functionality using MTE/Corona.

I’m trying  to select an object on the map and then drag that object to another location (a tree, or rock, or special object) 

I want to:

  1.  Select an object on the map

  2.  Tint that selected object

  3.  Drag that object to another location on the map

  4.  Underneath the object (while it is being dragged), tint the tiles green where the object can be placed or tint the tiles red where the object cannot be placed.  I don’t want to overlap objects and mess up collision detection.

I’d be happy to send you my current source to view the code and maps.

Help!

  1. The selecting object probably would need more description on what specifically you want to do with it and how it is selected, not overally sure on what you want to do.

local flash = function(event)     if event ~= nil then         event.lighting = false         event:setFillColor(255, 0, 0, 0.6)         local unflash = function(object)             if object ~= nil then                 object.lighting = true                     object:setFillColor(255, 255, 255)                 return object             end         end         local closure = function()             return unflash(event)         end         local timer = timer.performWithDelay(80, closure, 1)     end     return true end

There is a tinting function that flashes red for a small amount of time, for sure you could disable the flashing part and just keep the object tinted…should easily work
3) The dragging stuff should be well documented examples in corona sample projects i’ve seen a lot of stuff like that.

  1. Setup some type of runtime listener for the dragged object and start tinting tiles it touches making the floors sensors? Could maybe do some type of layer tinting too for other stuff. I’m not sure of any optimized way of approaching this because I think everything will need unique identifiers and that sounds like a pain.

Yes code would help people understand and answer your questions properly, as code explains what you want more :slight_smile:

Thanks Azmar for your response.  Please check your PM.

Have you looked at the DMC dragdrop library? I’m using it for my current project and it’s saved me hours of work.

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

Thanks Nick.  Check your PM.

  1. The selecting object probably would need more description on what specifically you want to do with it and how it is selected, not overally sure on what you want to do.

local flash = function(event)     if event ~= nil then         event.lighting = false         event:setFillColor(255, 0, 0, 0.6)         local unflash = function(object)             if object ~= nil then                 object.lighting = true                     object:setFillColor(255, 255, 255)                 return object             end         end         local closure = function()             return unflash(event)         end         local timer = timer.performWithDelay(80, closure, 1)     end     return true end

There is a tinting function that flashes red for a small amount of time, for sure you could disable the flashing part and just keep the object tinted…should easily work
3) The dragging stuff should be well documented examples in corona sample projects i’ve seen a lot of stuff like that.

  1. Setup some type of runtime listener for the dragged object and start tinting tiles it touches making the floors sensors? Could maybe do some type of layer tinting too for other stuff. I’m not sure of any optimized way of approaching this because I think everything will need unique identifiers and that sounds like a pain.

Yes code would help people understand and answer your questions properly, as code explains what you want more :slight_smile:

Thanks Azmar for your response.  Please check your PM.

Have you looked at the DMC dragdrop library? I’m using it for my current project and it’s saved me hours of work.

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

Thanks Nick.  Check your PM.