coordinates of objects within a display group

Hi,

I’ve got a display group with an object inside it. If I then move the group how would it be possible to get the new coordiantes of the object inside?

Simplified code -
require ( “ui” )

layer1 = display.newGroup ()

local obj = display.newCircle ( 100, 100, 20 )
obj:setFillColor ( 0, 255, 0, 255 )

layer1:insert ( obj )

layer1.x = 55 – move the display group along a bit

checkX = ui.newLabel{

bounds = { 50, 50, 30, 40 },
text = obj.x, – just using this to demonstrate that the x coordinate remains 100
textColor = { 0, 255, 100, 255 },
size = 50,
align = “center”

}

Now I was hoping that obj.x would be 155 but it remains 100. What should I be doing to retrieve it’s new x value?

Thanks in advance,
Will [import]uid: 4577 topic_id: 3521 reply_id: 303521[/import]

i’m a bit unsure of the difference between x and xOrigin actually… they sound like they do the same thing

http://developer.anscamobile.com/content/objectx
http://developer.anscamobile.com/content/objectxorigin

[import]uid: 6645 topic_id: 3521 reply_id: 10632[/import]

Good question, Will. We are working on APIs to make it easier to convert between local (group) and global (stage) coordinates. Until then, at least in this particular case, you can add (obj.x + obj.parent.x) to get the object’s global coordinates.

require ( "ui" )  
  
layer1 = display.newGroup ()  
  
local obj = display.newCircle ( 10, 100, 20 )  
obj:setFillColor ( 0, 255, 0, 255 )  
  
layer1:insert ( obj )  
  
layer1.x = 55 -- move the display group along a bit  
  
checkX = ui.newLabel{  
  
 bounds = { 50, 50, 30, 40 },  
 text = obj.x + obj.parent.x, -- add parent's x location to object's x location  
 textColor = { 0, 255, 100, 255 },  
 size = 50,  
 align = "center"  
  
}   

hope this helps

Tim [import]uid: 8196 topic_id: 3521 reply_id: 10634[/import]

Great, that gives me something to work with.

Taking things a step further, what would I need to do to retrieve the objects new coordinates if I was to rotate the group instead of just moving it along the x and y?

Am I right in thinking that I’d have to start using trigonometry?

It would be very handy to be able to retrieve global coordinates more simply.

Thanks,
Will [import]uid: 4577 topic_id: 3521 reply_id: 10661[/import]