LS.CompositePattern Class
CompositePattern implements the Composite Pattern, which allows to one class to contain instances of its own class creating a tree-like structure.
Constructor
LS.CompositePattern
()
Item Index
Methods
addChild
-
child
-
index
-
options
Adds one child to this instance
Parameters:
-
child
-
index
Number[optional] in which position you want to insert it, if not specified it goes to the last position
-
options
[optional] data to be passed when adding it, used for special cases when moving nodes around
configureChildren
()
Array
Configure every children with the data
Returns:
o array containing all serialized data
findNode
-
name_or_uid
Search for a node using a string that could be a name, a fullname or a uid
Parameters:
-
name_or_uid
String
Returns:
the node or null
findNodeByName
-
name
search a node by its name this function gets called a lot when using animations
Parameters:
-
name
String
Returns:
the node or null
findNodeByUId
-
id
search a node by its uid
Parameters:
-
id
String
Returns:
the node or null
getChildByIndex
-
index
Returns the child in the index position
Parameters:
-
index
Numberthe index in the array
Returns:
the child in that position
getChildByName
-
name
Returns the child that matches that name
Parameters:
-
name
String
Returns:
the child with that name otherwise returns null;
getChildIndex
-
child
returns the index of a child in the children array
Parameters:
-
child
SceneNodethe child to search for
Returns:
the index of this child in the array, if it is not inside returns -1
getChildren
-
Original
returns a list with all direct children (if you want below that use getDescendants)
Parameters:
-
Original
Arrayarray containing the children
getDescendants
()
Array
get all nodes below this in the hierarchy (children and children of children)
Returns:
array containing all descendants
getHierarchyLevel
()
Number
returns how many levels deep is the node in the hierarchy
Returns:
the level, 0 if it is the root
getParent
()
SceneNode
Returns parent node
Returns:
parent node
getPathName
()
String
Returns the path name of the node (a path name is a concatenation of the name of the nodes an its ancestors: "root|parent|child"
Returns:
the pathname
moveAfter
-
sibling
Swaps the index in the children array so it is before
Parameters:
-
sibling
SceneNode[optional] allows to put after given node, otherwise it will be moved one position after current position
Returns:
new index
moveBefore
-
sibling
Swaps the index in the children array so it is before
Parameters:
-
sibling
SceneNode[optional] allows to put before given node, otherwise it will be moved one position before of current position
Returns:
new index
removeAllChildren
()
Remove every child node
removeChild
-
node
-
param1
-
param2
Removes the node from its parent (and from the scene tree)
Parameters:
-
node
Nodethis child to remove
-
param1
data passed to onChildRemoved
-
param2
data passed to onChildRemoved as second parameter
Returns:
returns true if it was found and removed
serializeChildren
()
Array
Serialize the data from all the children
Returns:
array containing all serialized data from every children