Class: Container

me. Container

new Container(x, y, w, h)

me.Container represents a collection of child objects
Parameters:
Name Type Argument Default Description
x Number <optional>
0 position of the container
y Number <optional>
0 position of the container
w Number <optional>
me.game.viewport.width width of the container
h number <optional>
me.game.viewport.height height of the container
Source:
container.js, line 29

Extends

Classes

Error

Members

<static> autoDepth :Boolean

Specify if the children z index should automatically be managed by the parent container
Type:
  • Boolean
Default Value:
  • true
Source:
container.js, line 88

<static> autoSort :Boolean

Specify if the children list should be automatically sorted when adding a new child
Type:
  • Boolean
Default Value:
  • true
Source:
container.js, line 78

<static> childBounds :me.Rect

The bounds that contains all its children
Type:
Source:
container.js, line 104

<static> sortOn :String

The property of the child object that should be used to sort on
value : "x", "y", "z"
Type:
  • String
Default Value:
  • me.game.sortOn
Source:
container.js, line 67

alpha :Number

Define the renderable opacity
Set to zero if you do not wish an object to be drawn
Type:
  • Number
Inherited From:
Default Value:
  • 1.0
Source:
renderable.js, line 151
See:
  • me.Renderable#setOpacity
  • me.Renderable#getOpacity

ancestor :me.Container

a reference to the Container object that contains this renderable, or undefined if it has not been added to one.
Type:
Inherited From:
Default Value:
  • undefined
Source:
renderable.js, line 163

Methods

<static> addChild(child, z) → {me.Renderable}

Add a child to the container
if auto-sort is disable, the object will be appended at the bottom of the list
Parameters:
Name Type Argument Description
child me.Renderable
z number <optional>
forces the z index of the child to the specified value
Source:
container.js, line 118
Returns:
the added child
Type
me.Renderable

<static> addChildAt(child, index) → {me.Renderable}

Add a child to the container at the specified index
(the list won't be sorted after insertion)
Parameters:
Name Type Description
child me.Renderable
index Number
Source:
container.js, line 164
Returns:
the added child
Type
me.Renderable

<static> forEach(callback, thisArg)

The forEach() method executes a provided function once per child element.
callback is invoked with three arguments:
- the element value
- the element index
- the array being traversed
Parameters:
Name Type Argument Description
callback function
thisArg Object <optional>
value to use as this(i.e reference Object) when executing callback.
Source:
container.js, line 202
Example
// iterate through all children of the root container
me.game.world.forEach(function (child) {
   // do something with the child
});

<static> getChildAt(index)

Returns the Child at the specified index
Parameters:
Name Type Description
index Number
Source:
container.js, line 264

<static> getChildAt(child)

Returns the index of the Child
Parameters:
Name Type Description
child me.Renderable
Source:
container.js, line 280

<static> getChildByGUID(GUID) → {me.Renderable}

return the child corresponding to the specified GUID
note : avoid calling this function every frame since it parses the whole object list each time
Parameters:
Name Type Description
GUID String | RegExp | Number | Boolean entity GUID
Source:
container.js, line 394
Returns:
corresponding child or null
Type
me.Renderable

<static> getChildByName(name) → {Array.<me.Renderable>}

returns the list of childs with the specified name
as defined in Tiled (Name field of the Object Properties)
note : avoid calling this function every frame since it parses the whole object list each time
Parameters:
Name Type Description
name String | RegExp | Number | Boolean entity name
Source:
container.js, line 378
Returns:
Array of children
Type
Array.<me.Renderable>

<static> getChildByProp(prop, value) → {Array.<me.Renderable>}

return the child corresponding to the given property and value.
note : avoid calling this function every frame since it parses the whole object tree each time
Parameters:
Name Type Description
prop String Property name
value String | RegExp | Number | Boolean Value of the property
Source:
container.js, line 303
Returns:
Array of childs
Type
Array.<me.Renderable>
Example
// get the first child object called "mainPlayer" in a specific container :
var ent = myContainer.getChildByProp("name", "mainPlayer");

// or query the whole world :
var ent = me.game.world.getChildByProp("name", "mainPlayer");

// partial property matches are also allowed by using a RegExp.
// the following matches "redCOIN", "bluecoin", "bagOfCoins", etc :
var allCoins = me.game.world.getChildByProp("name", /coin/i);

// searching for numbers or other data types :
var zIndex10 = me.game.world.getChildByProp("z", 10);
var inViewport = me.game.world.getChildByProp("inViewport", true);

<static> getChildByType(class) → {Array.<me.Renderable>}

returns the list of childs with the specified class type
Parameters:
Name Type Description
class Object type
Source:
container.js, line 354
Returns:
Array of children
Type
Array.<me.Renderable>

<static> hasChild(child) → {Boolean}

Returns true if contains the specified Child
Parameters:
Name Type Description
child me.Renderable
Source:
container.js, line 291
Returns:
Type
Boolean

<private, static> isAttachedToRoot()

Checks if this container is root or if ti's attached to the root container.
Source:
container.js, line 439
Returns:
Boolean

<static> moveDown(child)

Move the child in the group one step backward (z depth).
Parameters:
Name Type Description
child me.Renderable
Source:
container.js, line 586

<static> moveToBottom(child)

Move the specified child the bottom (z depth).
Parameters:
Name Type Description
child me.Renderable
Source:
container.js, line 618

<static> moveToTop(child)

Move the specified child to the top(z depth).
Parameters:
Name Type Description
child me.Renderable
Source:
container.js, line 601

<static> moveUp(child)

Move the child in the group one step forward (z depth).
Parameters:
Name Type Description
child me.Renderable
Source:
container.js, line 571

<static> removeChild(child, keepalive)

Invokes the removeChildNow in a defer, to ensure the child is removed safely after the update & draw stack has completed
Parameters:
Name Type Argument Default Description
child me.Renderable
keepalive Boolean <optional>
False True to prevent calling child.destroy()
Source:
container.js, line 499

<static> removeChildNow(child, keepalive)

Removes (and optionally destroys) a child from the container.
(removal is immediate and unconditional)
Never use keepalive=true with objects from me.pool. Doing so will create a memory leak.
Parameters:
Name Type Argument Default Description
child me.Renderable
keepalive Boolean <optional>
False True to prevent calling child.destroy()
Source:
container.js, line 518

<static> setChildsProperty(property, value, recursive)

Automatically set the specified property of all childs to the given value
Parameters:
Name Type Argument Default Description
property String property name
value Object property value
recursive Boolean <optional>
false recursively apply the value to child containers if true
Source:
container.js, line 552

<static> sort(recursive)

Manually trigger the sort of all the childs in the container

Parameters:
Name Type Argument Default Description
recursive Boolean <optional>
false recursively sort all containers if true
Source:
container.js, line 635

<static> swapChildren(child, child2)

Swaps the position (z-index) of 2 children
Parameters:
Name Type Description
child me.Renderable
child2 me.Renderable
Source:
container.js, line 238

<private, static> updateBoundsPos()

update the renderable's bounding rect (private)
Source:
container.js, line 462

<static> updateChildBounds() → {me.Rect}

resizes the child bounds rectangle, based on children bounds.
Source:
container.js, line 410
Returns:
updated child bounds
Type
me.Rect
Copyright © 2011 - 2017, Olivier Biot, Jason Oster, Aaron McLeod
Documentation generated by JSDoc 3.4.0 on 2017-02-28T11:37:40+08:00 using the DocStrap template modified by codename-.