Difference between revisions of "Sprite:addChild"

From GiderosMobile
(added example + formatting)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
 
 
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
 
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
 
'''<translate>Class</translate>:''' [[Special:MyLanguage/Sprite|Sprite]]<br/>
 
'''<translate>Class</translate>:''' [[Special:MyLanguage/Sprite|Sprite]]<br/>
=== <translate>Description</translate> ===
+
 
<translate><br />
+
=== Description ===
Adds a sprite as a child to this sprite. The child is<br />
+
Adds a sprite as a child to this sprite. The child is added as a last child of this [[Special:MyLanguage/Sprite|Sprite]] instance.
added as a last child of this [[Special:MyLanguage/Sprite|Sprite]] instance.<br />
+
 
<br />
+
Sprites can have only 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.
Sprites can have only one parent. Therefore if you add a child<br />
 
object that already has a different sprite as a parent,<br />
 
the sprite is removed from the child list of the other sprite<br />
 
and then added to this sprite.<br />
 
<br /></translate>
 
 
<source lang="lua">
 
<source lang="lua">
Sprite:addChild(child)
+
Sprite:addChild(child)
 +
</source>
 +
 
 +
=== Parameters ===
 +
'''child''': (Sprite) the child sprite to add<br/>
 +
 
 +
=== Example ===
 +
<source lang="lua">
 +
local sprite1 = Sprite.new()
 +
local sprite2 = Sprite.new()
 +
sprite1:setPosition(1 * 64, 64)
 +
sprite2:setPosition(3 * 64, 64)
 +
 
 +
local mypixel = Pixel.new(0xFF0000, 1, 32, 32)
 +
 
 +
sprite1:addChild(mypixel)
 +
sprite2:addChild(mypixel)
 +
 
 +
stage:addChild(sprite1)
 +
stage:addChild(sprite2)
 
</source>
 
</source>
=== <translate>Parameters</translate> ===
 
'''child''': (Sprite) <translate>The child sprite to add.</translate> <br/>
 
  
 
{{Sprite}}
 
{{Sprite}}

Revision as of 03:06, 26 August 2020

Available since: Gideros 2011.6
Class: Sprite

Description

Adds a sprite as a child to this sprite. The child is added as a last child of this Sprite instance.

Sprites can have only 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.

Sprite:addChild(child)

Parameters

child: (Sprite) the child sprite to add

Example

local sprite1 = Sprite.new()
local sprite2 = Sprite.new()
sprite1:setPosition(1 * 64, 64)
sprite2:setPosition(3 * 64, 64)

local mypixel = Pixel.new(0xFF0000, 1, 32, 32)

sprite1:addChild(mypixel)
sprite2:addChild(mypixel)

stage:addChild(sprite1)
stage:addChild(sprite2)