get object by Coordinate

Hello! How i can get object Id by coordinate?

getObjectId(X,Y) // if background, get “background” , if unit1 get “one” or etc

Its need for this:

I have 2 object,
http://images.megapk.ru/images/625650c2875eb6bc622c03390d13d51e.png
Unit1 and Unit2

and i using
[lua]transition.to [/lua]
for move object and i need fix this:
http://images.megapk.ru/images/0a90569d3beccb2f8afb59c96da881b8.png

It was impossible to try to go through the second object?
An example of what I mean:
http://images.megapk.ru/images/52123992d2d617395c901ddaf1013563.png

I setup for object this:
[lua] physics.addBody( characterOne,“kinematic”, { density=1.0, friction=0.3, bounce=0.3, shape=pentagonShape } )
physics.addBody( characterTwo,“kinematic”, { density=1.0, friction=0.3, bounce=0.3, shape=pentagonShape } )[/lua]

Sorry for my Bad english!
What need using for this task? What better use?

I wait answer!
Thanks, best regards Ivan.
[import]uid: 211767 topic_id: 34758 reply_id: 334758[/import]

You could try something like this (totally untested)

local function getObjectAt(group, x, y)  
 for i = #group, 1, -1 do  
 local left = x \<= group[i].contentBounds.xMin and x \>= group[i].contentBounds.xMin  
 local right = x \>= group[i].contentBounds.xMin and x \<= group[i].contentBounds.xMax  
 local up = y \<= group[i].contentBounds.yMin and y \>= group[i].contentBounds.yMin  
 local down = y \>= group[i].contentBounds.yMin and y \<= group[i].contentBounds.yMax  
 if (left or right) and (up or down) then   
 return(group[i])  
 end  
 end  
end  

The idea requires all the things to be in the same display group. You loop through the group backwards (first thing in is the background, last thing is the top most object) and check to see if the X, Y are inside the box of the object. Most of the code is taken from a function that tells me if two blocks overlap that works rather well. I modified it to just check for a single point, but I’ve not had a chance to try it yet.
[import]uid: 199310 topic_id: 34758 reply_id: 138202[/import]

Hello! Thanks for answer! I will try! [import]uid: 211767 topic_id: 34758 reply_id: 138251[/import]

Hello Again! We will testing this, and its don`t work, maybe we have second option? [import]uid: 211767 topic_id: 34758 reply_id: 138538[/import]

Can you post your code so I can see how you’re constructing your objects. [import]uid: 199310 topic_id: 34758 reply_id: 138539[/import]

You could try something like this (totally untested)

local function getObjectAt(group, x, y)  
 for i = #group, 1, -1 do  
 local left = x \<= group[i].contentBounds.xMin and x \>= group[i].contentBounds.xMin  
 local right = x \>= group[i].contentBounds.xMin and x \<= group[i].contentBounds.xMax  
 local up = y \<= group[i].contentBounds.yMin and y \>= group[i].contentBounds.yMin  
 local down = y \>= group[i].contentBounds.yMin and y \<= group[i].contentBounds.yMax  
 if (left or right) and (up or down) then   
 return(group[i])  
 end  
 end  
end  

The idea requires all the things to be in the same display group. You loop through the group backwards (first thing in is the background, last thing is the top most object) and check to see if the X, Y are inside the box of the object. Most of the code is taken from a function that tells me if two blocks overlap that works rather well. I modified it to just check for a single point, but I’ve not had a chance to try it yet.
[import]uid: 199310 topic_id: 34758 reply_id: 138202[/import]

Hello! Thanks for answer! I will try! [import]uid: 211767 topic_id: 34758 reply_id: 138251[/import]

Hello Again! We will testing this, and its don`t work, maybe we have second option? [import]uid: 211767 topic_id: 34758 reply_id: 138538[/import]

Can you post your code so I can see how you’re constructing your objects. [import]uid: 199310 topic_id: 34758 reply_id: 138539[/import]

Hello!

I have this:
[lua]local array =display.newGroup()
array:insert( characterOne )
array:insert( characterTwo )
getObjectAt(array,newX,newY)[/lua]
and i click character, but in console nothing!

Method:

[lua]local function getObjectAt(group, x, y)
print (“start search”)
for i = #group, 1, -1 do
local left = x <= group[i].contentBounds.xMin and x >= group[i].contentBounds.xMin
local right = x >= group[i].contentBounds.xMin and x <= group[i].contentBounds.xMax
local up = y <= group[i].contentBounds.yMin and y >= group[i].contentBounds.yMin
local down = y >= group[i].contentBounds.yMin and y <= group[i].contentBounds.yMax
if (left or right) and (up or down) then
print ("GROUP: "… group[i])
return(group[i])
end
end
end[/lua]

in console only:

2013-01-23 11:46:30.339 Corona Simulator[6098:707] start search

and nothing. [import]uid: 211767 topic_id: 34758 reply_id: 140055[/import]

Try this. I’ve not tested it, but it should do the trick.

local function getObjectAt(group, x, y) print ("start search") for i = #group, 1, -1 do if x \>= group[i].contentBounds.xMin and x \<= group[i].contentBounds.xMax and y \>= group[i].contentBounds.yMin and y \<= group[i].contentBounds.yMax then print ("GROUP: ".. group[i]) return(group[i]) end end end [import]uid: 199310 topic_id: 34758 reply_id: 140130[/import]

Hello!

I have this:
[lua]local array =display.newGroup()
array:insert( characterOne )
array:insert( characterTwo )
getObjectAt(array,newX,newY)[/lua]
and i click character, but in console nothing!

Method:

[lua]local function getObjectAt(group, x, y)
print (“start search”)
for i = #group, 1, -1 do
local left = x <= group[i].contentBounds.xMin and x >= group[i].contentBounds.xMin
local right = x >= group[i].contentBounds.xMin and x <= group[i].contentBounds.xMax
local up = y <= group[i].contentBounds.yMin and y >= group[i].contentBounds.yMin
local down = y >= group[i].contentBounds.yMin and y <= group[i].contentBounds.yMax
if (left or right) and (up or down) then
print ("GROUP: "… group[i])
return(group[i])
end
end
end[/lua]

in console only:

2013-01-23 11:46:30.339 Corona Simulator[6098:707] start search

and nothing. [import]uid: 211767 topic_id: 34758 reply_id: 140055[/import]

Try this. I’ve not tested it, but it should do the trick.

local function getObjectAt(group, x, y) print ("start search") for i = #group, 1, -1 do if x \>= group[i].contentBounds.xMin and x \<= group[i].contentBounds.xMax and y \>= group[i].contentBounds.yMin and y \<= group[i].contentBounds.yMax then print ("GROUP: ".. group[i]) return(group[i]) end end end [import]uid: 199310 topic_id: 34758 reply_id: 140130[/import]