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...")
 
 
Line 14: Line 14:
 
'''children''': (table) a table of index positions and the children sprites<br/>
 
'''children''': (table) a table of index positions and the children sprites<br/>
  
=== Example ===
+
=== Examples ===
 +
<syntaxhighlight lang="lua">
 +
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:addChildrenAt ( { pix3, pix2, pix } )
 +
 
 +
stage:addChild(sprite)
 +
</syntaxhighlight>
 +
 
 +
'''Same as above but with index numbers'''
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
print("*** Gideros 2025.10 ***")
 
print("*** Gideros 2025.10 ***")

Latest revision as of 16:29, 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

Examples

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:addChildrenAt ( { pix3, pix2, pix } )

stage:addChild(sprite)

Same as above but with index numbers

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)