API Docs for:
Show:

LS.CompositePattern Class

Module: LS

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

()

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:

Array:

o array containing all serialized data

findNode

(
  • name_or_uid
)
SceneNode

Search for a node using a string that could be a name, a fullname or a uid

Parameters:

  • name_or_uid String

Returns:

SceneNode:

the node or null

findNodeByName

(
  • name
)
SceneNode

search a node by its name this function gets called a lot when using animations

Parameters:

  • name String

Returns:

SceneNode:

the node or null

findNodeByUId

(
  • id
)
SceneNode

search a node by its uid

Parameters:

  • id String

Returns:

SceneNode:

the node or null

getChildByIndex

(
  • index
)
SceneNode

Returns the child in the index position

Parameters:

  • index Number

    the index in the array

Returns:

SceneNode:

the child in that position

getChildByName

(
  • name
)
SceneNode

Returns the child that matches that name

Parameters:

  • name String

Returns:

SceneNode:

the child with that name otherwise returns null;

getChildIndex

(
  • child
)
Number

returns the index of a child in the children array

Parameters:

  • child SceneNode

    the child to search for

Returns:

Number:

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 Array

    array containing the children

getDescendants

() Array

get all nodes below this in the hierarchy (children and children of children)

Returns:

Array:

array containing all descendants

getHierarchyLevel

() Number

returns how many levels deep is the node in the hierarchy

Returns:

Number:

the level, 0 if it is the root

getParent

() SceneNode

Returns parent node

Returns:

SceneNode:

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:

String:

the pathname

moveAfter

(
  • sibling
)
Number

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:

Number:

new index

moveBefore

(
  • sibling
)
Number

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:

Number:

new index

removeAllChildren

()

Remove every child node

removeChild

(
  • node
  • param1
  • param2
)
Boolean

Removes the node from its parent (and from the scene tree)

Parameters:

  • node Node

    this child to remove

  • param1

    data passed to onChildRemoved

  • param2

    data passed to onChildRemoved as second parameter

Returns:

Boolean:

returns true if it was found and removed

serializeChildren

() Array

Serialize the data from all the children

Returns:

Array:

array containing all serialized data from every children