Class: Phaser.ArraySet
Constructor
new ArraySet(list)
ArraySet is a Set data structure (items must be unique within the set) that also maintains order.
This allows specific items to be easily added or removed from the Set.
Item equality (and uniqueness) is determined by the behavior of Array.indexOf
.
This used primarily by the Input subsystem.
Parameters
Name | Type | Argument | Default | Description |
---|---|---|---|---|
list | Array.<any> | <optional> | (new array) | The backing array: if specified the items in the list must be unique, per |
- Source code: utils/ArraySet.js (Line 19)
Public Properties
- Source code: utils/ArraySet.js (Line 231)
- Array.<any>
- Source code: utils/ArraySet.js (Line 32)
- Source code: utils/ArraySet.js (Line 256)
- Source code: utils/ArraySet.js (Line 26)
- Source code: utils/ArraySet.js (Line 217)
first :any
Returns the first item and resets the cursor to the start.
list : Array.<any>
The backing array.
Type
next :any
Returns the the next item (based on the cursor) and advances the cursor.
position : integer
Current cursor position as established by first
and next
.
total : integer
Number of items in the ArraySet. Same as list.length
.
Public Methods
- Source code: utils/ArraySet.js (Line 38)
- Source code: utils/ArraySet.js (Line 159)
- Source code: utils/ArraySet.js (Line 95)
- Source code: utils/ArraySet.js (Line 70)
- Source code: utils/ArraySet.js (Line 57)
- Source code: utils/ArraySet.js (Line 119)
- Source code: utils/ArraySet.js (Line 185)
- Source code: utils/ArraySet.js (Line 108)
- Source code: utils/ArraySet.js (Line 138)
add(item) → {any}
Adds a new element to the end of the list.
If the item already exists in the list it is not moved.
Parameters
Name | Type | Description |
---|---|---|
item | any | The element to add to this list. |
Returns
The item that was added.
callAll(key, parameter)
Calls a function on all members of this list, using the member as the context for the callback.
If the key
property is present it must be a function.
The function is invoked using the item as the context.
Parameters
Name | Type | Argument | Description |
---|---|---|---|
key | string | The name of the property with the function to call. | |
parameter | * | <repeatable> | Additional parameters that will be passed to the callback. |
exists(item) → {boolean}
Checks for the item within this list.
Parameters
Name | Type | Description |
---|---|---|
item | any | The element to get the list index for. |
Returns
True if the item is found in the list, otherwise false.
getByKey(property, value) → {any}
Gets an item from the set based on the property strictly equaling the value given.
Returns null if not found.
Parameters
Name | Type | Description |
---|---|---|
property | string | The property to check against the value. |
value | any | The value to check if the property strictly equals. |
Returns
The item that was found, or null if nothing matched.
getIndex(item) → {integer}
Gets the index of the item in the list, or -1 if it isn't in the list.
Parameters
Name | Type | Description |
---|---|---|
item | any | The element to get the list index for. |
Returns
The index of the item or -1 if not found.
remove(item) → {any}
Removes the given element from this list if it exists.
Parameters
Name | Type | Description |
---|---|---|
item | any | The item to be removed from the list. |
Returns
item - The item that was removed.
removeAll(destroy)
Removes every member from this ArraySet and optionally destroys it.
Parameters
Name | Type | Argument | Default | Description |
---|---|---|---|---|
destroy | boolean | <optional> | false | Call |
reset()
Removes all the items.
setAll(key, value)
Sets the property key
to the given value on all members of this list.
Parameters
Name | Type | Description |
---|---|---|
key | any | The property of the item to set. |
value | any | The value to set the property to. |
© 2016 Richard Davey, Photon Storm Ltd.
Licensed under the MIT License.
http://phaser.io/docs/2.6.2/Phaser.ArraySet.html