phaser - v4.0.0-rc.4
    Preparing search index...

    List is a generic implementation of an ordered list which contains utility methods for retrieving, manipulating, and iterating items.

    Type Parameters

    • T

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    _sortKey: string

    The property key to sort by.

    addCallback: Function

    A callback that is invoked every time a child is added to this list.

    first: T

    The first item in the List or null for an empty List.

    last: T

    The last item in the List, or null for an empty List.

    length: number

    The number of items inside the List.

    list: T[]

    The objects that belong to this collection.

    next: T

    The next item in the List, or null if the entire List has been traversed.

    This property can be read successively after reading #first or manually setting the #position to iterate the List.

    parent: any

    The parent of this list.

    position: number

    The index of the current element.

    This is used internally when iterating through the list with the #first, #last, #get, and #previous properties.

    previous: T

    The previous item in the List, or null if the entire List has been traversed.

    This property can be read successively after reading #last or manually setting the #position to iterate the List backwards.

    removeCallback: Function

    A callback that is invoked every time a child is removed from this list.

    Methods

    • Adds the given item to the end of the list. Each item must be unique.

      Parameters

      • child: any

        The item, or array of items, to add to the list.

      • OptionalskipCallback: boolean

        Skip calling the List.addCallback if this child is added successfully. Default false.

      Returns any

    • Adds an item to list, starting at a specified index. Each item must be unique within the list.

      Parameters

      • child: T | T[]

        The item, or array of items, to add to the list.

      • Optionalindex: number

        The index in the list at which the element(s) will be inserted. Default 0.

      • OptionalskipCallback: boolean

        Skip calling the List.addCallback if this child is added successfully. Default false.

      Returns T | T[]

    • Brings the given child to the top of this List.

      Parameters

      • child: T

        The item to bring to the top of the List.

      Returns T

    • Returns the total number of items in the List which have a property matching the given value.

      Parameters

      • property: string

        The property to test on each item.

      • value: T

        The value to test the property against.

      Returns number

    • Passes all children to the given callback.

      Parameters

      • callback: EachListCallback<T>

        The function to call.

      • Optionalcontext: any

        Value to use as this when executing callback.

      • ...args: any[]

        Additional arguments that will be passed to the callback, after the child.

      Returns void

    • Checks if an item exists within the List.

      Parameters

      • child: T

        The item to check for the existence of.

      Returns boolean

    • Returns all children in this List.

      You can optionally specify a matching criteria using the property and value arguments.

      For example: getAll('parent') would return only children that have a property called parent.

      You can also specify a value to compare the property to:

      getAll('visible', true) would return only children that have their visible property set to true.

      Optionally you can specify a start and end index. For example if this List had 100 children, and you set startIndex to 0 and endIndex to 50, it would return matches from only the first 50 children in the List.

      Parameters

      • Optionalproperty: string

        An optional property to test against the value argument.

      • Optionalvalue: any

        If property is set then Child.property must strictly equal this value to be included in the results.

      • OptionalstartIndex: number

        The first child index to start the search from.

      • OptionalendIndex: number

        The last child index to search up until.

      Returns T[]

    • Retrieves the item at a given position inside the List.

      Parameters

      • index: number

        The index of the item.

      Returns T

    • Searches for the first instance of a child with its name property matching the given argument. Should more than one child have the same name only the first is returned.

      Parameters

      • name: string

        The name to search for.

      Returns T

    • Returns the first element in a given part of the List which matches a specific criterion.

      Parameters

      • property: string

        The name of the property to test or a falsey value to have no criterion.

      • value: any

        The value to test the property against, or undefined to allow any value and only check for existence.

      • OptionalstartIndex: number

        The position in the List to start the search at. Default 0.

      • OptionalendIndex: number

        The position in the List to optionally stop the search at. It won't be checked.

      Returns T

    • Locates an item within the List and returns its index.

      Parameters

      • child: T

        The item to locate.

      Returns number

    • Returns a random child from the group.

      Parameters

      • OptionalstartIndex: number

        Offset from the front of the group (lowest child). Default 0.

      • Optionallength: number

        Restriction on the number of values you want to randomly select from. Default (to top).

      Returns T

    • Moves an item above another one in the List. If the given item is already above the other, it isn't moved. Above means toward the end of the List.

      Parameters

      • child1: T

        The element to move above base element.

      • child2: T

        The base element.

      Returns void

    • Moves an item below another one in the List. If the given item is already below the other, it isn't moved. Below means toward the start of the List.

      Parameters

      • child1: T

        The element to move below base element.

      • child2: T

        The base element.

      Returns void

    • Moves the given child down one place in this group unless it's already at the bottom.

      Parameters

      • child: T

        The item to move down.

      Returns T

    • Moves an item in the List to a new position.

      Parameters

      • child: T

        The item to move.

      • index: number

        Moves an item in the List to a new position.

      Returns T

    • Moves the given child up one place in this group unless it's already at the top.

      Parameters

      • child: T

        The item to move up.

      Returns T

    • Removes one or many items from the List.

      Parameters

      • child: any

        The item, or array of items, to remove.

      • OptionalskipCallback: boolean

        Skip calling the List.removeCallback. Default false.

      Returns any

    • Removes all the items.

      Parameters

      • OptionalskipCallback: boolean

        Skip calling the List.removeCallback. Default false.

      Returns this

    • Removes the item at the given position in the List.

      Parameters

      • index: number

        The position to remove the item from.

      • OptionalskipCallback: boolean

        Skip calling the List.removeCallback. Default false.

      Returns T

    • Removes the items within the given range in the List.

      Parameters

      • OptionalstartIndex: number

        The index to start removing from. Default 0.

      • OptionalendIndex: number

        The position to stop removing at. The item at this position won't be removed.

      • OptionalskipCallback: boolean

        Skip calling the List.removeCallback. Default false.

      Returns T[]

    • Replaces a child of this List with the given newChild. The newChild cannot be a member of this List.

      Parameters

      • oldChild: T

        The child in this List that will be replaced.

      • newChild: T

        The child to be inserted into this List.

      Returns T

    • Sends the given child to the bottom of this List.

      Parameters

      • child: T

        The item to send to the back of the list.

      Returns T

    • Sets the property key to the given value on all members of this List.

      Parameters

      • property: string

        The name of the property to set.

      • value: T

        The value to set the property to.

      • OptionalstartIndex: number

        The first child index to start the search from.

      • OptionalendIndex: number

        The last child index to search up until.

      Returns void

    • Sort the contents of this List so the items are in order based on the given property. For example, sort('alpha') would sort the List contents based on the value of their alpha property.

      Parameters

      • property: string

        The property to lexically sort by.

      • Optionalhandler: Function

        Provide your own custom handler function. Will receive 2 children which it should compare and return a boolean.

      Returns T[]

    • Swaps the positions of two items in the list.

      Parameters

      • child1: T

        The first item to swap.

      • child2: T

        The second item to swap.

      Returns void