API Docs for: 1.0.0
Show:

Kiwi.Group Class

Defined in: src\core\Group.ts:9
Module: Kiwi

The group class is central to creating the scene graph that contains all objects in a state. A group can contain entities or other groups, thereby enabling a nested tree scene graph. The members of the Group's coordinates are also in relation to the Group that they were added to. So if you moved an entire Group, each member of that Group would also 'move'.

Constructor

Kiwi.Group

(
  • state
  • [name='']
)
Kiwi.Group

Defined in src\core\Group.ts:9

Parameters:

  • state Kiwi.State

    The State that this Group is a part of.

  • [name=''] String optional

    The name of this group.

Returns:

Methods

addChild

(
  • child
)
Object public

Adds an Entity to this Group. The Entity must not already be in this Group.

Parameters:

  • child Object

    The child to be added.

Returns:

Object:

The child that was added.

addChildAfter

(
  • child
  • beforeChild
)
Object public

Adds an Entity to this Group after another child. The Entity must not already be in this Group and it must be supported by the Group..

Parameters:

  • child Object

    The child to be added.

  • beforeChild Object

    The child after which the child will be added.

Returns:

Object:

The child.

addChildAt

(
  • child
  • index
)
Object public

Adds an Entity to this Group in the specific location. The Entity must not already be in this Group and it must be supported by the Group.

Parameters:

  • child Object

    The child to be added.

  • index Number

    The index the child will be set at.

Returns:

Object:

The child.

addChildBefore

(
  • child
  • beforeChild
)
Object public

Adds an Entity to this Group before another child. The Entity must not already be in this Group and it must be supported by the Group.

Parameters:

  • child Object

    The child to be added.

  • beforeChild Entity

    The child before which the child will be added.

Returns:

Object:

The child.

callAll

(
  • componentName
  • functionName
  • args
)
public

Calls a function on every member. If componentName is null the function is called on the entity itself, otherwise it is called on the named component. Uses runtime string property lookups. Not optimal for large groups if speed is an issue.

Parameters:

  • componentName String

    The name of the component to call the function on - set to null to call a function on the entity.

  • functionName String

    The name of the function to call.

  • args Array

    An array of arguments to pas to the function.

clear

() public

Clear all children from this Group

contains

(
  • child
)
Boolean public

Checks if the given entity is in this group

Parameters:

  • child IChild

    The IChild that you want to checked.

Returns:

Boolean:

true if entity exists in group.

containsAncestor

(
  • descendant
  • ancestor
)
Boolean public

Checks to see if one child is an ansector of another child.

Parameters:

  • descendant Object

    The object that you are checking.

  • ancestor Group

    The parent (ancestor) that you are checking for.

Returns:

Boolean:

containsDescendant

(
  • child
)
Boolean public

Checks to see if the given object is contained in this group as a descendant

Parameters:

  • child Object

    The IChild that you want to check.

Returns:

Boolean:

countDead

() Number public

Returns the number of member which are not marked as 'alive'

Returns:

Number:

countLiving

() Number public

Returns the number of member which are marked as 'alive'

Returns:

Number:

destroy

(
  • [immediate=false]
  • [destroyChildren=true]
)
public

Removes all children and destroys the Group.

Parameters:

  • [immediate=false] Boolean optional

    If the object should be immediately removed or if it should be removed at the end of the next update loop.

  • [destroyChildren=true] Boolean optional

    If all of the children on the group should also have their destroy methods called.

forEach

(
  • context
  • callback
  • [params]
)
public

Loops through each member in the group and run a method on for each one.

Parameters:

  • context Any

    The context that the callbacks are to have when called.

  • callback Any

    The callback method to execute on each member.

  • [params] Any optional multiple

    Any extra parameters.

forEachAlive

(
  • context
  • callback
  • [params]
)
public

Loop through each member of the groups that is alive.

Parameters:

  • context Any

    The context that the callbacks are to have when called.

  • callback Any

    The callback method to execute on each member.

  • [params] Any optional multiple

    Any extra parameters.

getChildAt

(
  • index
)
Object public

Get the child at a specific position in this Group by its index.

Parameters:

  • index Number

    The index of the child

Returns:

Object:

The child, if found or null if not.

getChildByID

(
  • id
)
Object public

Get a child from this Group by its UUID.

Parameters:

  • id String

    The ID of the child.

Returns:

Object:

The child, if found or null if not.

getChildByName

(
  • name
)
Object public

Get a child from this Group by its name.

Parameters:

  • name String

    The name of the child

Returns:

Object:

The child, if found or null if not.

getChildIndex

(
  • child
)
Number public

Returns the index position of the Entity or -1 if not found.

Parameters:

  • child Object

    The child.

Returns:

Number:

The index of the child or -1 if not found.

getFirstAlive

() Object public

Returns the first Entity from this Group marked as 'alive' or null if no members are alive

Returns:

Object:

getFirstDead

() Object public

Returns the first member of the Group which is not 'alive', returns null if all members are alive.

Returns:

Object:

numChildren

() Number public

Returns the total number of children in this Group. Doesn't distinguish between alive and dead children.

Returns:

Number:

The number of children in this Group

objType

() String public

Returns the type of this object

Returns:

String:

The type of this object

removeChild

(
  • child
  • [destroy=false]
)
Object public

Removes an Entity from this Group if it is a child of it.

Parameters:

  • child Object

    The child to be removed.

  • [destroy=false] Boolean optional

    If the entity that gets removed should be destroyed as well.

Returns:

Object:

The child.

removeChildAt

(
  • index
)
Object

Removes the Entity from this Group at the given position.

Parameters:

  • index Number

    The index of the child to be removed.

Returns:

Object:

The child, or null.

removeChildren

(
  • begin
  • end
  • destroy
)
Number public

Removes all Entities from this Group within the given range.

Parameters:

  • begin Number

    The begining index.

  • end Number

    The last index of the range.

  • destroy Number

    If the children should be destroyed as well.

Returns:

Number:

The number of removed entities.

removeFirstAlive

(
  • [destroy=false]
)
Object public

Removes the first Entity from this Group marked as 'alive'

Parameters:

  • [destroy=false] Boolean optional

    If the entity should run the destroy method when it is removed.

Returns:

Object:

The Entity that was removed from this Group if alive, otherwise null

render

(
  • camera
)
public

The render method that is required by the IChild. This method never gets called as the render is only worried about rendering entities.

Parameters:

replaceChild

(
  • oldChild
  • newChild
)
Boolean public

Replaces a child Entity in this Group with a new one.

Parameters:

  • oldChild Object

    The Entity in this Group to be removed.

  • newChild Object

    The new Entity to insert into this Group at the old Entities position.

Returns:

Boolean:

true if the Entities were replaced successfully, otherwise false.

setAll

(
  • componentName
  • property
  • value
)
public

Sets a property on every member. If componentName is null the property is set on the entity itself, otherwise it is set on the named component. Uses runtime string property lookups. Not optimal for large groups if speed is an issue.

Parameters:

  • componentName String

    The name of the component to set the property on - set to null to set a property on the entity.

  • property String

    The name of the property to set.

  • value Any

    The value to set the property to.

setChildIndex

(
  • child
  • index
)
Boolean public

Sets a new position of an existing Entity within the Group.

Parameters:

  • child Object

    The child in this Group to change.

  • index Number

    The index for the child to be set at.

Returns:

Boolean:

true if the Entity was moved to the new position, otherwise false.

swapChildren

(
  • child1
  • child2
)
Boolean public

Swaps the position of two existing Entities that are a direct child of this group.

Parameters:

  • child1 Object

    The first child in this Group to swap.

  • child2 Object

    The second child in this Group to swap.

Returns:

Boolean:

true if the Entities were swapped successfully, otherwise false.

swapChildrenAt

(
  • index1
  • index2
)
Boolean public

Swaps the position of two existing Entities within the Group based on their index.

Parameters:

  • index1 Number

    The position of the first Entity in this Group to swap.

  • index2 Number

    The position of the second Entity in this Group to swap.

Returns:

Boolean:

true if the Entities were swapped successfully, otherwise false.

update

() public

The update loop for this group.

Properties

_active

Boolean private

An active Entity is one that has its update method called by its parent.

Default: true

_destroyRemoveChildren

Boolean private

A temporary property that holds a boolean indicating whether or not the group's children should be destroyed or not.

_dirty

Boolean private

An indication of whether or not this group is 'dirty' and thus needs to be re-rendered or not.

_parent

Kiwi.Group private

The parent group of this group.

_willRender

Boolean private

Controls whether render is automatically called by the parent.

active

Boolean public

Toggles the active state of this Entity. An Entity that is active has its update method called by its parent. This method should be over-ridden to handle specific dom/canvas/webgl implementations.

Default: true

components

Kiwi.ComponentManager public

The Component Manager

dirty

Boolean public

Sets all children of the Group to be dirty.

exists

Boolean private

If an Entity no longer exists it is cleared for garbage collection or pool re-allocation

exists

Boolean public

Toggles the exitence of this Group. An Entity that no longer exists can be garbage collected or re-allocated in a pool This method should be over-ridden to handle specific canvas/webgl implementations.

game

Kiwi.Game public

The game this Group belongs to

id

String public

A unique identifier for this Group within the game used internally by the framework. See the name property for a friendly version.

members

Array public

The collection of children belonging to this group

name

String public

A name for this Group. This is not checked for uniqueness within the Game, but is very useful for debugging.

Default: ''

parent

Kiwi.Group public

Set's the parent of this entity. Note that this also sets the transforms parent of this entity to be the passed groups transform.

state

Kiwi.State public

The State that this Group belongs to

transform

Kiwi.Geom.Transform public

The transform object for this group. Transform handles the calculation of coordinates/rotation/scale e.t.c in the Game World.

willRender

Boolean public

Controls whether render is automatically caleld by the parent.

x

Number public

The X coordinate of this group. This is just aliased to the transform property.

y

Number public

The Y coordinate of this group. This is just aliased to the transform property.