Can you create a child object of an existing object?

Hi,

I was wondering if it is possible (and if it is then how?) to create a child as a child of an existing object?

So for example if I add a button and I want to create a text as a child of that button?

Or if I have a character with multiple layers associated with the character then I want to make each layer a child of the main character layer. For example if I have face image created and I want to add a hat image, glasses image and facial hair image as children of the main face image. I want to do this because if I move the face image using translate then I want all the other objects to move as well without needing to worry about translating each and every one of them too.

Thanks in advance,

Eli

Yes… If you make buttons like SSK, then the button handle is a display group and you can insert objects into the button/group.

No… most display objects are NOT groups, so you can’ insert objects into them.

However, you can add a reference to a text object onto another object for tracking purposes:

local button = display.newText(...) button.label = display.newText(...)

Moving the ‘button’ won’t move the text, but you can get the buttons text object reference later if you need it.

Finally, the best way to GROUP things is with display groups:

https://docs.coronalabs.com/api/library/display/newGroup.html

Moving the group, moves the children.

Yes… If you make buttons like SSK, then the button handle is a display group and you can insert objects into the button/group.

No… most display objects are NOT groups, so you can’ insert objects into them.

However, you can add a reference to a text object onto another object for tracking purposes:

local button = display.newText(...) button.label = display.newText(...)

Moving the ‘button’ won’t move the text, but you can get the buttons text object reference later if you need it.

Finally, the best way to GROUP things is with display groups:

https://docs.coronalabs.com/api/library/display/newGroup.html

Moving the group, moves the children.