Inserts an object into a group.
group:insert( [index,] child, [, resetTransform] )
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 )
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:
group is at the bottom of the group.
group is in the middle of the group.
group is 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).
object: An object to insert 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 x, y, rotation, xScale, and yScale properties of
child are reset to 0, 0, 0, 1, and 1, respectively). The default value for resetTransform is false.
Note: Inserting display objects into a group, removes the object from it current group (objects cannot be in multiple groups). All display objects are part of "current stage" when first created. (At this time Corona only has one stage, which is the entire screen area. You could think of this as the "main stage" group.)
Supported on operating systems and platforms for build numbers shown:
- Mac OS X:Corona SDK 1.0
- Windows:Corona SDK 2.0
- iOS:Corona SDK 1.0
- Android:Corona SDK 2.0