Type Function Object GroupObject Library display.* Return value none Revision 2017.3179 Keywords insert, group insert See also Group Programming (guide)
Inserts an object into a group.
Inserting display objects into a group also removes the object from it current group (objects cannot be in multiple groups). All display objects are part of stage object when first created. At this time, Corona only has one stage, which is the entire screen area.
group:insert( [index,] child, [, resetTransform] )
Number. Inserts child at
index into group, shifting up other elements as necessary. The default value index is
n is the number of children in the group.
An easy way to move an object above all its siblings (top) is to re-insert it:
object.parent:insert( object ).
If a group has 3 display objects:
groupis at the bottom of the group.
groupis in the middle of the group.
groupis at the top of the group.
Objects at the higher index numbers will be displayed on top of objects with lower index numbers (if the objects overlap).
DisplayObject. Object to be inserted into the group.
Boolean. Determines what happens to child’s transform. When
false, child’s local position, rotation, and scale properties are preserved, except the local origin is now relative to the new parent group, not its former parent; When
true, child’s transform is reset (i.e. the
yScale properties of child are reset to
1, respectively). The default value for
local txt = display.newText( "Hello", 0, 0 ) local g1 = display.newGroup() local g2 = display.newGroup() -- Insert text object into g1 g1:insert( txt ) -- Insert same text object into g2 g2:insert( txt ) print( "g1: " .. tostring(g1) ) -- prints nil print( "g2: " .. tostring(g2) ) -- prints textObject print( "number of children in g1 and g2: " .. g1.numChildren, g2.numChildren )