Difference between revisions of "Sprite:addChildrenAt"

From GiderosMobile
(Created page with "__NOTOC__ '''Available since:''' Gideros 2025.10<br/> '''Class:''' Sprite<br/> === Description === Adds several Sprites at once as children to this Sprite (faster). The c...")
(No difference)

Revision as of 15:36, 17 October 2025

Available since: Gideros 2025.10
Class: Sprite

Description

Adds several Sprites at once as children to this Sprite (faster). The children are added at their index positions specified. Indices start from 1.

Sprite:addChildrenAt(children)

Sprites can only have one parent. Therefore if you add a child object that already has a different sprite as a parent, the sprite is removed from the child list of the other sprite and then added to this sprite.

Parameters

children: (table) a table of index positions and the children sprites

Example

print("***	Gideros 2025.10	***")
local sprite = Sprite.new()
local pix = Pixel.new(0xff0000, 1, 32, 32)
pix2 = pix:clone()
pix3 = pix:clone()
pix2:setColor(0x00ff00)
pix3:setColor(0x0000ff)
-- position
pix:setPosition(1*32, 1*32)
pix2:setPosition(1.5*32, 1.5*32)
pix3:setPosition(2*32, 2*32)
-- order
sprite:addChild(pix)
sprite:addChildrenAt( { [1]=pix3, [3]=pix2 } )

stage:addChild(sprite)