Game Development Reference
In-Depth Information
Groups
A group is a container of different display objects. When the attributes of the group are altered, it
affects all of the display objects contained in the group. The stage is a group; in fact it is the root
group, which is the container for all of the other display objects. The way to add an object to a group
is using the following syntax:
group:addChild(displayObject)
To remove an object from the group, you use this function:
displayObject:removeFromParent()
Gideros class:
myUtils.lua file:
local obj = Core.class(Sprite).new()
stage:addChild(obj)
return obj
end
We can use this henceforth to create a group object.
We use stage:addChild to add most of the objects to the stage. We can now use this function to
add an object to a group by using the group:addChild .
To get the handle of an object in a particular group, we can get it using the function getChildAt by
passing it the index. Alternatively, we can get the index position by passing the object to the function
getChildIndex . We can also use this to check if a particular parent group contains a display object
or not by using this function by passing it the display object.
We can determine the number of objects contained in the parent by using the group:getNumChildren
function.
After we are done with the group or the objects in the group, we can remove the objects from the
stage or the group using the removeChild or removeFromParent function, or using the removeChildAt
function, which takes the index of the display object.
object:removeChild()
group:removeChildAt(index)
group:removeFromParent(object)
There is another function, addChildAt , which allows for adding a child at a particular index position.
This allows for positioning display objects that is equivalent of moving an object to the front or to the
back relative to the other objects.
 
Search WWH ::




Custom Search