Layers and relation of X & Y values

Hey Guys,
Can’t find any information in the forums on this. In my app I am trying to create somewhat of a sticker feature. A tray of stickers is at the bottom of the screen, the user can touch and drag the stickers off the tray and place them in the correct places on the background image. I have all the stickers in their own group, and the background image is in its own group as well. To make a long story short, the sticker tray does some sliding up and down and what not. When the user drags a sticker onto the background, I remove the sticker they dragged from the tray displayGroup and add it to the displayGroup that the background image belongs too.

The issue is that when changing which displayGroup the sticker object belongs too, this seems to mess with the X & Y positioning off everything. I have specific X & Y coordinates of where stickers will “Lock” into place… Using the above method they will not lock into place, I assume because somehow the x and y coordinates are different? If I have my sticker object belong to the displayGroup of the background from the beginning, then the stickers find and lock in place just perfect.

Any ideas of how this works or what the problem may be? Does Corona have in built in functions for resolving this? Much thanks in advance.

Marc [import]uid: 19620 topic_id: 29246 reply_id: 329246[/import]

The object.x and object.y values of any display object are subject to the display group you insert them to - basically, x and y are local coordinates. If your display group.x is 600, that means your object within it is display group.x + object.x.

So I suggest this approach:

  1. Before remove/insert, record the old real value, like this:

[code]myobject.worldX = myobject.x + myobject.parent.x
myobject.worldY = myobject.y + myobject.parent.y

–or

myobject.worldX = myobject.x + mygroup.x
– etc…[/code]

  1. AFAIK you don’t need to remove a display object from a display group unless you have some specific reason to do so. In this case you should just be able to insert it into the new group. (display objects can only have one parent group.)

  2. After inserting into the new group, just set new to old:

myobject.x = myobject.worldX; myobject.y = myobject.worldY

Ahhh that does make sense, thank you so much for the example I am going to give it a try now! [import]uid: 19620 topic_id: 29246 reply_id: 117646[/import]