Image overlap detection

Hello,
 
I am creating a game but have come across a problem that I cannot seem to solve…
 
My game has a number of objects, some of which are irregularly shaped and may even be rotated. Before the game begins, it needs to be set up by dragging an object (A) with your finger and dropping it anywhere except on any of the other objects visible on the screen. The problem is that I cannot find a way to detect whether A overlaps/touches any of the other objects when dragged and dropped. Turning all my objects to physics objects during set-up and using simple collision detection would cause other unwanted effects (other objects start being affected by gravity, which is not suposed to happen at set-up, only when game starts), and I therefore do not think that I can do that either.
 
If you have played “Amazing Alex” you know that if you try to drag e.g. a shelf on top of another object it turns red. If you try to drop it there it snaps back to its original position. That is basically what I want to achieve.

I have looked at the otherwise splendid post by Rob where he describes non-physics collision detection (http://coronalabs.com/blog/2013/07/23/tutorial-non-physics-collision-detection/) but that solution only covers circles and rectangles and it does not take into consideration any transparent areas of the images.
 
Does anyone have an idea how to solve this?
 

the easiest way to do that is with physics. It supports custom collision shapes for your irregular objects. If you dont want any gravity then use this

physics.setGravity(0,0)

. after that you can pause or cancel physics then restart or resume.

I realize that I forgot to specify that object A is a physics object of type “static”, whereas the other objects (that A cannot be dragged over or dropped on) are both “static” or “dynamic”. However, physics requires that at least one of the objects involved in a collision is “dynamic”. Since A is static, physics will not detect when it collides with the other static objects on the screen.

not necessarily if you use the api

  ObjectA.isSensor

it will detect a collision but not produce a physical response. YOu could also temporarily change the bodytype of the object e.g when the user is dragging it it becomes dynamic and when they release then in goes back to being static

local function dragged (event)     local phase = event.phase             if phase == "began" then                 ObjectA.bodyType = "dynamic"             --execute dragging code             elseif phase == "ended" or "cancelled" then                 ObjectA.bodyType = "static"             end end  

For some reason, just using isSensor on object A as it was (i.e. static) did not work in the sense that it did not produce any collision events, although the documentation and countless examples that I found suggested it should.

However, the second suggestion worked like a charm… In the listener function that gets called when object A is moved, I temporarily changed A to dynamic at “began” and then changed it back to static at “ended”. During “move”, I could then just listen for regular collision events since A was now a “normal” dynamic object. For this to work, I had to make all the objects physics objects during the game setup, but the effects of that were “neutralized” by also setting isSensor = true and gravityScale = 0 for my object A

Many thanks for the help, 86lemonade68!

the easiest way to do that is with physics. It supports custom collision shapes for your irregular objects. If you dont want any gravity then use this

physics.setGravity(0,0)

. after that you can pause or cancel physics then restart or resume.

I realize that I forgot to specify that object A is a physics object of type “static”, whereas the other objects (that A cannot be dragged over or dropped on) are both “static” or “dynamic”. However, physics requires that at least one of the objects involved in a collision is “dynamic”. Since A is static, physics will not detect when it collides with the other static objects on the screen.

not necessarily if you use the api

  ObjectA.isSensor

it will detect a collision but not produce a physical response. YOu could also temporarily change the bodytype of the object e.g when the user is dragging it it becomes dynamic and when they release then in goes back to being static

local function dragged (event)     local phase = event.phase             if phase == "began" then                 ObjectA.bodyType = "dynamic"             --execute dragging code             elseif phase == "ended" or "cancelled" then                 ObjectA.bodyType = "static"             end end  

For some reason, just using isSensor on object A as it was (i.e. static) did not work in the sense that it did not produce any collision events, although the documentation and countless examples that I found suggested it should.

However, the second suggestion worked like a charm… In the listener function that gets called when object A is moved, I temporarily changed A to dynamic at “began” and then changed it back to static at “ended”. During “move”, I could then just listen for regular collision events since A was now a “normal” dynamic object. For this to work, I had to make all the objects physics objects during the game setup, but the effects of that were “neutralized” by also setting isSensor = true and gravityScale = 0 for my object A

Many thanks for the help, 86lemonade68!