类型 函数 对象 GroupObject 库 display.* 返回值 无 修改 2024.3703 版 关键词 insert、群组 insert 另请参见 群组编程 (指南)
在群组中插入对象。
将显示对象插入到群组中也会从其当前群组中删除该对象(对象不能属于多个群组)。所有显示对象在初次创建时都会成为 舞台 对象的一部分。目前,Corona 只有一个舞台,即整个屏幕区域。
group:insert( [index,] child, [, resetTransform] )
数字。在 group 中的 index
处插入子项,必要时向上移动其他元素。默认值 index 为 n+1
,其中 n
为群组中子项的数量。
将对象移动到其所有同级对象(顶部)之上的一个简单方法是对其重新插入:object.parent:insert( object )
。
如果群组有 3 个显示对象
group[1]
位于群组底部。group[2]
位于群组中间。group[3]
位于群组顶部。索引号更高的对象将显示在索引号较低的对象之上(如果这些对象重叠的话)。
DisplayObject。要插入到该群组的对象。
布尔值。确定子项的转换内容。如果为 false
,则将保留子项的本地位置、旋转和比例属性,但本地原点现在基于新的父群组而非其之前的父群组;如果为 true
,则重置子项的转换(即子项的 x
、y
、rotation
、xScale
和 yScale
属性分别重置为 0
、0
、0
、1
和 1
)。resetTransform
的默认值为 false
。
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[1]: " .. tostring(g1[1]) ) -- prints nil print( "g2[1]: " .. tostring(g2[1]) ) -- prints textObject print( "number of children in g1 and g2: " .. g1.numChildren, g2.numChildren )