q5play
    Preparing search index...

    Class Group

    A Group is a collection of and blueprint for sprites with similar traits and behaviors.

    Hierarchy (View Summary)

    Indexable

    Index

    Constructors

    • A Group is a collection of and blueprint for sprites with similar traits and behaviors.

      Group extends Visuals which extends Array, so you can use them in for loops. They've got all the functions and properties of standard arrays such as group.length and functions like group.includes().

      Changing a group setting changes it for all the sprites in the group ("dynamic inheritance").

      All groups inherit from the base group allSprites.

      Groups can have subgroups, creating a hierarchy of inheritance.

      Parameters

      • Optional...sprites: Sprite[]

        the sprites to add to the group

      Returns Group

    Properties

    "[unscopables]": {
        "[iterator]"?: boolean;
        "[unscopables]"?: boolean;
        at?: boolean;
        concat?: boolean;
        copyWithin?: boolean;
        entries?: boolean;
        every?: boolean;
        fill?: boolean;
        filter?: boolean;
        find?: boolean;
        findIndex?: boolean;
        findLast?: boolean;
        findLastIndex?: boolean;
        flat?: boolean;
        flatMap?: boolean;
        forEach?: boolean;
        includes?: boolean;
        indexOf?: boolean;
        join?: boolean;
        keys?: boolean;
        lastIndexOf?: boolean;
        length?: boolean;
        map?: boolean;
        pop?: boolean;
        push?: boolean;
        reduce?: boolean;
        reduceRight?: boolean;
        reverse?: boolean;
        shift?: boolean;
        slice?: boolean;
        some?: boolean;
        sort?: boolean;
        splice?: boolean;
        toLocaleString?: boolean;
        toReversed?: boolean;
        toSorted?: boolean;
        toSpliced?: boolean;
        toString?: boolean;
        unshift?: boolean;
        values?: boolean;
        with?: boolean;
        [key: number]: boolean | undefined;
    }

    Is an object whose properties have the value 'true' when they will be absent when used in a 'with' statement.

    Type Declaration

    • [key: number]: boolean | undefined
    • Optional[iterator]?: boolean
    • Optional Readonly[unscopables]?: boolean

      Is an object whose properties have the value 'true' when they will be absent when used in a 'with' statement.

    • Optionalat?: boolean
    • Optionalconcat?: boolean
    • OptionalcopyWithin?: boolean
    • Optionalentries?: boolean
    • Optionalevery?: boolean
    • Optionalfill?: boolean
    • Optionalfilter?: boolean
    • Optionalfind?: boolean
    • OptionalfindIndex?: boolean
    • OptionalfindLast?: boolean
    • OptionalfindLastIndex?: boolean
    • Optionalflat?: boolean
    • OptionalflatMap?: boolean
    • OptionalforEach?: boolean
    • Optionalincludes?: boolean
    • OptionalindexOf?: boolean
    • Optionaljoin?: boolean
    • Optionalkeys?: boolean
    • OptionallastIndexOf?: boolean
    • Optionallength?: boolean

      Gets or sets the length of the array. This is a number one higher than the highest index in the array.

    • Optionalmap?: boolean
    • Optionalpop?: boolean
    • Optionalpush?: boolean
    • Optionalreduce?: boolean
    • OptionalreduceRight?: boolean
    • Optionalreverse?: boolean
    • Optionalshift?: boolean
    • Optionalslice?: boolean
    • Optionalsome?: boolean
    • Optionalsort?: boolean
    • Optionalsplice?: boolean
    • OptionaltoLocaleString?: boolean
    • OptionaltoReversed?: boolean
    • OptionaltoSorted?: boolean
    • OptionaltoSpliced?: boolean
    • OptionaltoString?: boolean
    • Optionalunshift?: boolean
    • Optionalvalues?: boolean
    • Optionalwith?: boolean
    add: (...sprites: Sprite[]) => number

    Alias for group.push.

    Adds a sprite to the end of the group.

    allowSleeping: boolean

    Controls the ability for group sprites to "sleep".

    "Sleeping" sprites are not included in the physics simulation, a sprite starts "sleeping" when it stops moving and doesn't collide with anything that it wasn't already colliding with.

    ani: Ani

    Current animation.

    autoCull: boolean

    A property of the allSprites group only, that controls whether sprites are automatically deleted when they are 10,000 pixels away from the camera.

    It only needs to be set to false once and then it will remain false for the rest of the sketch, unless changed.

    autoDraw: boolean

    If true, group sprites are drawn by q5play after each physics update.

    autoUpdate: number

    If true, group sprites are updated by q5play before each physics update.

    bearing: number

    A bearing indicates the direction that needs to be followed to reach a destination.

    Setting a group sprites' bearing doesn't do anything by itself. You can apply a force to the group sprites at its bearing angle using the applyForce function.

    bounciness: number

    The bounciness of the group sprites' physics body.

    color: Color

    The group sprites' current fill color.

    By default sprites get a random color.

    contains: (searchElement: Sprite, fromIndex?: number) => boolean

    Alias for group.includes.

    Check if a sprite is in the group.

    d: number

    The diameter of a circular sprite.

    debug: boolean

    If true, outlines of the group sprites' colliders and sensors will be drawn.

    Use the keyboard shortcut Command+B to toggle allSprites.debug.

    density: number

    The density of the group sprites' physics body.

    diameter: number

    The diameter of a circular sprite.

    direction: number

    The angle of the group sprites' movement.

    drag: number

    The amount of resistance group sprites has to being moved.

    friction: number

    The amount the group sprites' colliders resist moving when rubbing against other colliders.

    grabbable: boolean

    Whether the group sprites can be grabbed by a pointer.

    gravityScale: number

    A ratio that defines how much the group sprites are affected by gravity.

    Group: typeof Group

    Creates a new subgroup that inherits the traits of the group.

    h: number

    The height of the group sprites.

    heading: string

    The group sprites' heading. This is a string that can be set to "up", "down", "left", "right", "upRight", "upLeft", "downRight"

    The setter's input parser ignores capitalization, spaces, underscores, dashes, and cardinal direction word order.

    height: number

    The height of the group sprites.

    idNum: number

    Each group has a unique id number. Don't change it! It's useful for debugging.

    img: Image

    Current image.

    isSuperFast: boolean

    Set this to true if the group sprites goes really fast to prevent inaccurate physics simulation.

    layer: number

    Sprites with the highest layer value get drawn first.

    By default sprites are drawn in the order they were created in.

    length: number

    Gets or sets the length of the array. This is a number one higher than the highest index in the array.

    life: number

    When the physics simulation is progressed in world.physicsUpdate, each sprite's life is decreased by world.timeScale.

    If life becomes less than or equal to 0, the group sprites will be removed.

    mass: number

    The mass of the group sprites' physics body.

    parent: any

    The direct parent group that this group inherits properties from.

    physics: string

    The physics type of the group sprites, which determines how it interacts with other sprites in the physics simulation.

    It can be set to DYNAMIC/DYN, STATIC/STA, or KINEMATIC/KIN.

    physicsEnabled: boolean

    If true, the group sprites' physics body is included in the physics simulation.

    physicsType: string

    The physics type of the group sprites, which determines how it interacts with other sprites in the physics simulation.

    It can be set to DYNAMIC/DYN, STATIC/STA, or KINEMATIC/KIN.

    pixelPerfect: boolean

    If true, q5play will draw sprites at integer pixel precision.

    This is useful for making retro games.

    By default q5play draws sprites with subpixel rendering.

    rollingResistance: number

    Simulates friction that slows down group sprites rolling on another sprite, like a soccer ball rolling to a stop on high grass.

    rotation: number

    The angle of the group sprites' rotation, not the direction it's moving.

    If angleMode is set to "degrees", the value will be returned in a range of -180 to 180.

    rotationDrag: number

    The amount the group sprites resists rotating.

    rotationLock: boolean

    If true, the group sprites can not rotate.

    rotationSpeed: number

    The speed of the group sprites' rotation in angles per frame.

    scale: number | [] | { x: number; y: number }

    Horizontal and vertical scale of the group sprites.

    Components can be negative to flip/mirror the group sprites on an axis.

    The valueOf function for sprite.scale returns the scale as a number. This enables users to do things like sprite.scale *= 2 to double the group sprites' scale.

    sleeping: boolean

    Wake group sprites up or put it to sleep.

    "Sleeping" sprites are not included in the physics simulation, a sprite starts "sleeping" when it stops moving and doesn't collide with anything that it wasn't already colliding with.

    speed: number

    The group sprites' speed.

    Setting speed to a negative value will make the group sprites move 180 degrees opposite of its current direction angle.

    Sprite: typeof Sprite

    Creates a new sprite with the traits of the group and adds it to the group.

    stroke: Color

    The group sprites' stroke color.

    strokeWeight: number

    The group sprites' stroke weight, the thickness of its outline.

    subgroups: { [x: string]: any }[]

    Groups can have subgroups, which inherit the properties of their parent groups.

    []
    
    surfaceSpeed: number

    The group sprites' speed along the surface of its collider(s), like a conveyor belt.

    text: number

    Text displayed at the center of the group sprites.

    textFill: Color

    The group sprites' text fill color. Black by default.

    textSize: number

    The group sprites' text size, the sketch's current textSize by default.

    textStroke: Color

    The group sprites' text stroke color. No stroke by default, does not inherit from the sketch's stroke color.

    textStrokeWeight: number

    The group sprites' text stroke weight, the thickness of its outline. No stroke by default, does not inherit from the sketch's stroke weight.

    tile: string

    The tile character that represents the Visuals or Group in a tile map.

    vel: number

    Velocity of group sprites.

    velocity: number

    Velocity of group sprites.

    visible: boolean

    If true the group sprites are shown, if set to false the group sprites are hidden.

    Becomes null when the group sprites are off screen but will be drawn and set to true again if it goes back on screen.

    visualOnly: boolean

    New group sprites will not have physics bodies (can't have colliders).

    w: number

    The width of the group sprites.

    width: number

    The width of the group sprites.

    x: number

    Horizontal position of group sprites.

    y: number

    Vertical position of group sprites.

    "[species]": ArrayConstructor

    Accessors

    • get amount(): number

      Depending on the value that the amount property is set to, the group will either add or delete sprites.

      Returns number

    • set amount(val: number): void

      Parameters

      • val: number

      Returns void

    • get anis(): Anis

      Stores animations. Keys are the animation label, values are Ani objects

      Returns Anis

    Methods

    • Iterator

      Returns ArrayIterator<Sprite>

    • Adds an animation to the Group or Visuals array.

      Parameters

      • spriteSheetURL: string

        the URL of the sprite sheet image

      • frameCount: number

        the number of frames in the sprite sheet

      Returns Promise<void>

      A promise that fulfills when the animation is loaded

    • Add multiple animations to the Group or Visuals array.

      Parameters

      • atlases: {}

        an object with animation names as keys and an animation or animation atlas as values

      Returns Promise<void>

      A promise that fulfills when the animations are loaded

    • Add multiple animations to the Group or Visuals array.

      Parameters

      • spriteSheetURL: string

        the URL of the sprite sheet image

      • atlases: {}

        an object with animation names as keys and an animation or animation atlas as values

      Returns Promise<void>

      A promise that fulfills when the animations are loaded

    • Add multiple animations to the Group or Visuals array.

      Parameters

      • spriteSheetURL: string

        the URL of the sprite sheet image

      • frameSize: string

        the size of each frame in the sprite sheet in the format "WIDTHxHEIGHT" (example: "32x32")

      • atlases: {}

        an object with animation names as keys and an animation or animation atlas as values

      Returns Promise<void>

      A promise that fulfills when the animations are loaded

    • Adds sprites to the group based on a tile map.

      Parameters

      • tiles: string | string[]
      • Optionalx: number

        x coordinate of the top left corner of the tile map, default is -colWidth * longest row / 2

      • Optionaly: number

        y coordinate of the top left corner of the tile map, default is -rowHeight * number of rows / 2

      • OptionalcolWidth: number

        column width including spacing, default is the width of the first tile

      • OptionalrowHeight: number

        row height including spacing, default is the height of the first tile

      Returns void

    • Applies a force magnitude to the group at its bearing.

      Parameters

      • amount: number
      • Optionalorigin: { x: number; y: number }

      Returns void

    • Applies a force vector to the group.

      Parameters

      • force: { x: number; y: number }
      • Optionalorigin: { x: number; y: number }

      Returns void

    • Applies a force scaled to member masses using a magnitude.

      Parameters

      • amount: number
      • Optionalorigin: { x: number; y: number }

      Returns void

    • Applies a force scaled to member masses using a vector.

      Parameters

      • force: { x: number; y: number }
      • Optionalorigin: { x: number; y: number }

      Returns void

    • Parameters

      • torque: any

      Returns void

    • Parameters

      • speed: number
      • angle: number
      • Optionaldrag: number
      • Optionallift: number

      Returns void

    • Returns the item located at the specified index.

      Parameters

      • index: number

        The zero-based index of the desired code unit. A negative index will count back from the last item.

      Returns Sprite | undefined

    • Applies a force to the group's center of mass attracting it to the given position.

      Parameters

      • x: number
      • y: number
      • Optionalforce: number

      Returns void

    • Applies a force to the group's center of mass attracting it to the given position.

      Parameters

      • pos: { x: number; y: number }
      • Optionalforce: number

      Returns void

    • Returns true on the first frame that the group no longer overlaps with the target group.

      Parameters

      • target: Group
      • Optionalcallback: Function

      Returns boolean

    • Returns true on the first frame that the group collides with the target group.

      Custom collision event handling can be done by using this function in an if statement or adding a callback as the second parameter.

      Parameters

      • target: Group
      • Optionalcallback: Function

      Returns boolean

    • Returns the amount of frames that the group has been colliding with the target group for, which is a truthy value. Returns 0 if the group is not colliding with the target group.

      Parameters

      • target: Group
      • Optionalcallback: Function

      Returns number

      frames

    • Combines two or more arrays. This method returns a new array without modifying any existing arrays.

      Parameters

      • ...items: ConcatArray<Sprite>[]

        Additional arrays and/or items to add to the end of the array.

      Returns Sprite[]

    • Combines two or more arrays. This method returns a new array without modifying any existing arrays.

      Parameters

      • ...items: (Sprite | ConcatArray<Sprite>)[]

        Additional arrays and/or items to add to the end of the array.

      Returns Sprite[]

    • Returns the this object after copying a section of the array identified by start and end to the same array starting at position target

      Parameters

      • target: number

        If target is negative, it is treated as length+target where length is the length of the array.

      • start: number

        If start is negative, it is treated as length+start. If end is negative, it is treated as length+end.

      • Optionalend: number

        If not specified, length of the this object is used as its default value.

      Returns this

    • Detects when sprites go outside the given culling boundary relative to the camera.

      By default, culled sprites are deleted, but a callback function can be provided to perform other operations on the culled sprites.

      Parameters

      • Optionaltop: number

        the distance that sprites can move below the canvas before they are removed

      • Optionalbottom: number

        the distance that sprites can move below the canvas before they are removed

      • Optionalleft: number

        the distance that sprites can move beyond the left side of the canvas before they are removed

      • Optionalright: number

        the distance that sprites can move beyond the right side of the canvas before they are removed

      • Optionalcb: Function

        the function to be run when a sprite is culled, it's given the sprite being culled, if no callback is given then the sprite is removed

      Returns number

      the number of sprites culled

    • Deletes the group and all its sprites from the world and every other group they belong to.

      Don't attempt to use a group after deleting it.

      Returns void

    • Deletes all the sprites in the group.

      Does not delete the group itself.

      Returns void

    • Returns an iterable of key, value pairs for every entry in the array

      Returns ArrayIterator<[number, Sprite]>

    • Determines whether all the members of an array satisfy the specified test.

      Type Parameters

      Parameters

      • predicate: (value: Sprite, index: number, array: Sprite[]) => value is S

        A function that accepts up to three arguments. The every method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value false, or until the end of the array.

      • OptionalthisArg: any

        An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

      Returns this is S[]

    • Determines whether all the members of an array satisfy the specified test.

      Parameters

      • predicate: (value: Sprite, index: number, array: Sprite[]) => unknown

        A function that accepts up to three arguments. The every method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value false, or until the end of the array.

      • OptionalthisArg: any

        An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

      Returns boolean

    • Changes all array elements from start to end index to a static value and returns the modified array

      Parameters

      • value: Sprite

        value to fill array section with

      • Optionalstart: number

        index to start filling the array at. If start is negative, it is treated as length+start where length is the length of the array.

      • Optionalend: number

        index to stop filling the array at. If end is negative, it is treated as length+end.

      Returns this

    • Returns the elements of an array that meet the condition specified in a callback function.

      Type Parameters

      Parameters

      • predicate: (value: Sprite, index: number, array: Sprite[]) => value is S

        A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.

      • OptionalthisArg: any

        An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

      Returns S[]

    • Returns the elements of an array that meet the condition specified in a callback function.

      Parameters

      • predicate: (value: Sprite, index: number, array: Sprite[]) => unknown

        A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.

      • OptionalthisArg: any

        An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

      Returns Sprite[]

    • Returns the value of the first element in the array where predicate is true, and undefined otherwise.

      Type Parameters

      Parameters

      • predicate: (value: Sprite, index: number, obj: Sprite[]) => value is S

        find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, find immediately returns that element value. Otherwise, find returns undefined.

      • OptionalthisArg: any

        If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.

      Returns S | undefined

    • Parameters

      • predicate: (value: Sprite, index: number, obj: Sprite[]) => unknown
      • OptionalthisArg: any

      Returns Sprite | undefined

    • Returns the index of the first element in the array where predicate is true, and -1 otherwise.

      Parameters

      • predicate: (value: Sprite, index: number, obj: Sprite[]) => unknown

        find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, findIndex immediately returns that element index. Otherwise, findIndex returns -1.

      • OptionalthisArg: any

        If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.

      Returns number

    • Returns the value of the last element in the array where predicate is true, and undefined otherwise.

      Type Parameters

      Parameters

      • predicate: (value: Sprite, index: number, array: Sprite[]) => value is S

        findLast calls predicate once for each element of the array, in descending order, until it finds one where predicate returns true. If such an element is found, findLast immediately returns that element value. Otherwise, findLast returns undefined.

      • OptionalthisArg: any

        If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.

      Returns S | undefined

    • Parameters

      • predicate: (value: Sprite, index: number, array: Sprite[]) => unknown
      • OptionalthisArg: any

      Returns Sprite | undefined

    • Returns the index of the last element in the array where predicate is true, and -1 otherwise.

      Parameters

      • predicate: (value: Sprite, index: number, array: Sprite[]) => unknown

        findLastIndex calls predicate once for each element of the array, in descending order, until it finds one where predicate returns true. If such an element is found, findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.

      • OptionalthisArg: any

        If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.

      Returns number

    • Returns a new array with all sub-array elements concatenated into it recursively up to the specified depth.

      Type Parameters

      • A
      • D extends number = 1

      Parameters

      • this: A
      • Optionaldepth: D

        The maximum recursion depth

      Returns FlatArray<A, D>[]

    • Calls a defined callback function on each element of an array. Then, flattens the result into a new array. This is identical to a map followed by flat with depth 1.

      Type Parameters

      • U
      • This = undefined

      Parameters

      • callback: (this: This, value: Sprite, index: number, array: Sprite[]) => U | readonly U[]

        A function that accepts up to three arguments. The flatMap method calls the callback function one time for each element in the array.

      • OptionalthisArg: This

        An object to which the this keyword can refer in the callback function. If thisArg is omitted, undefined is used as the this value.

      Returns U[]

    • Performs the specified action for each element in an array.

      Parameters

      • callbackfn: (value: Sprite, index: number, array: Sprite[]) => void

        A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.

      • OptionalthisArg: any

        An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

      Returns void

    • Determines whether an array includes a certain element, returning true or false as appropriate.

      Parameters

      • searchElement: Sprite

        The element to search for.

      • OptionalfromIndex: number

        The position in this array at which to begin searching for searchElement.

      Returns boolean

    • Returns the index of the first occurrence of a value in an array, or -1 if it is not present.

      Parameters

      • searchElement: Sprite

        The value to locate in the array.

      • OptionalfromIndex: number

        The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.

      Returns number

    • Adds all the elements of an array into a string, separated by the specified separator string.

      Parameters

      • Optionalseparator: string

        A string used to separate one element of the array from the next in the resulting string. If omitted, the array elements are separated with a comma.

      Returns string

    • Returns an iterable of keys in the array

      Returns ArrayIterator<number>

    • Returns the index of the last occurrence of a specified value in an array, or -1 if it is not present.

      Parameters

      • searchElement: Sprite

        The value to locate in the array.

      • OptionalfromIndex: number

        The array index at which to begin searching backward. If fromIndex is omitted, the search starts at the last index in the array.

      Returns number

    • Calls a defined callback function on each element of an array, and returns an array that contains the results.

      Type Parameters

      • U

      Parameters

      • callbackfn: (value: Sprite, index: number, array: Sprite[]) => U

        A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.

      • OptionalthisArg: any

        An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

      Returns U[]

    • Moves each sprite in the group to a destination at a constant speed, maintaining their relative offsets from the group's centroid.

      Parameters

      • x: number | null
      • y: number | null
      • Optionalspeed: number

      Returns PromiseLike<boolean>

    • Moves each sprite in the group to a destination at a constant speed, maintaining their relative offsets from the group's centroid.

      Parameters

      • pos: { x: number | null; y: number | null }
      • Optionalspeed: number

      Returns PromiseLike<boolean>

    • Moves the group towards a position.

      Parameters

      • x: number | null
      • y: number | null
      • Optionaltracking: number

      Returns void

    • Moves the group towards a position.

      Parameters

      • pos: { x: number | null; y: number | null }
      • Optionaltracking: number

      Returns void

    • Returns true on the first frame that the group no longer overlaps with the target group.

      Parameters

      • target: Group
      • Optionalcallback: Function

      Returns boolean

    • Returns the amount of frames that the group has been overlapping with the target group for, which is a truthy value. Returns 0 if the group is not overlapping with the target group.

      Parameters

      • target: Group
      • Optionalcallback: Function

      Returns number

      frames

    • Returns true on the first frame that the group overlaps with the target group.

      Custom overlap event handling can be done by using this function in an if statement or adding a callback as the second parameter.

      Parameters

      • target: Group
      • Optionalcallback: Function

      Returns boolean

    • Sets a pass through contact relationship between the group and the target group.

      Parameters

      Returns void

    • Sets a pass through contact relationship between the group and the target group.

      Parameters

      Returns void

    • Removes the last element from an array and returns it. If the array is empty, undefined is returned and the array is not modified.

      Returns Sprite | undefined

    • Appends new elements to the end of an array, and returns the new length of the array.

      Parameters

      • ...items: Sprite[]

        New elements to add to the array.

      Returns number

    • Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

      Parameters

      • callbackfn: (
            previousValue: Sprite,
            currentValue: Sprite,
            currentIndex: number,
            array: Sprite[],
        ) => Sprite

        A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.

      Returns Sprite

    • Parameters

      • callbackfn: (
            previousValue: Sprite,
            currentValue: Sprite,
            currentIndex: number,
            array: Sprite[],
        ) => Sprite
      • initialValue: Sprite

      Returns Sprite

    • Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

      Type Parameters

      • U

      Parameters

      • callbackfn: (
            previousValue: U,
            currentValue: Sprite,
            currentIndex: number,
            array: Sprite[],
        ) => U

        A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.

      • initialValue: U

        If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.

      Returns U

    • Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

      Parameters

      • callbackfn: (
            previousValue: Sprite,
            currentValue: Sprite,
            currentIndex: number,
            array: Sprite[],
        ) => Sprite

        A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.

      Returns Sprite

    • Parameters

      • callbackfn: (
            previousValue: Sprite,
            currentValue: Sprite,
            currentIndex: number,
            array: Sprite[],
        ) => Sprite
      • initialValue: Sprite

      Returns Sprite

    • Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

      Type Parameters

      • U

      Parameters

      • callbackfn: (
            previousValue: U,
            currentValue: Sprite,
            currentIndex: number,
            array: Sprite[],
        ) => U

        A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.

      • initialValue: U

        If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.

      Returns U

    • Removes a sprite from this group and its sub groups (if any), but does not delete it from the world.

      Parameters

      • item: number | Sprite

        the sprite to be deleted or its index

      Returns Sprite

      the deleted sprite or undefined if the specified sprite was not found

    • Removes all sprites from this group without deleting them.

      Returns Sprite[]

      the removed sprites

    • Applies a repelling force from a position.

      Parameters

      • x: number
      • y: number
      • Optionalforce: number

      Returns void

    • Applies a repelling force from a position.

      Parameters

      • pos: { x: number; y: number }
      • Optionalforce: number

      Returns void

    • Reverses the elements in an array in place. This method mutates the array and returns a reference to the same array.

      Returns Sprite[]

    • Rotates each sprite in the group by the given angle amount at the given speed.

      Parameters

      • angle: number
      • Optionalspeed: number

      Returns PromiseLike<boolean>

    • Rotates each sprite in the group by the smallest angular distance to a target angle, stopping when they arrive.

      Parameters

      • angle: number
      • Optionalspeed: number

      Returns PromiseLike<boolean>

    • Rotates each sprite in the group by the smallest angular distance to face a position, stopping when they arrive.

      Parameters

      • pos: { x: number; y: number }
      • Optionalspeed: number
      • Optionalfacing: number

      Returns PromiseLike<boolean>

    • Rotates each sprite in the group to a target angle. The sign of speed determines direction: positive = CW, negative = CCW.

      Parameters

      • angle: number
      • Optionalspeed: number

      Returns PromiseLike<boolean>

    • Rotates each sprite in the group to face a position. The sign of speed determines direction: positive = CW, negative = CCW.

      Parameters

      • pos: { x: number; y: number }
      • Optionalspeed: number
      • Optionalfacing: number

      Returns PromiseLike<boolean>

    • Rotates each sprite in the group towards an angle.

      Parameters

      • angle: number
      • Optionaltracking: number

      Returns void

    • Rotates each sprite in the group towards a position.

      Parameters

      • pos: { x: number; y: number }
      • Optionaltracking: number
      • Optionalfacing: number

      Returns void

    • Removes the first element from an array and returns it. If the array is empty, undefined is returned and the array is not modified.

      Returns Sprite | undefined

    • Returns a copy of a section of an array. For both start and end, a negative index can be used to indicate an offset from the end of the array. For example, -2 refers to the second to last element of the array.

      Parameters

      • Optionalstart: number

        The beginning index of the specified portion of the array. If start is undefined, then the slice begins at index 0.

      • Optionalend: number

        The end index of the specified portion of the array. This is exclusive of the element at the index 'end'. If end is undefined, then the slice extends to the end of the array.

      Returns Sprite[]

    • Determines whether the specified callback function returns true for any element of an array.

      Parameters

      • predicate: (value: Sprite, index: number, array: Sprite[]) => unknown

        A function that accepts up to three arguments. The some method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value true, or until the end of the array.

      • OptionalthisArg: any

        An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

      Returns boolean

    • Sorts an array in place. This method mutates the array and returns a reference to the same array.

      Parameters

      • OptionalcompareFn: (a: Sprite, b: Sprite) => number

        Function used to determine the order of the elements. It is expected to return a negative value if the first argument is less than the second argument, zero if they're equal, and a positive value otherwise. If omitted, the elements are sorted in ascending, UTF-16 code unit order.

        [11,2,22,1].sort((a, b) => a - b)
        

      Returns this

    • If removalCount is greater than 0, that amount of sprites starting from the start index will be removed from this group and its sub groups recursively (if any),

      Then any provided sprites will be added at the start index to this group and at the end of each of its parent groups recursively, if not already present in parent groups.

      Parameters

      • start: number

        start index

      • removalCount: number

        number of sprites to remove, starting from the start index

      • ...sprites: Sprite[]

        sprites to add at start index

      Returns Sprite[]

      the removed sprites

    • Returns a string representation of an array. The elements are converted to string using their toLocaleString methods.

      Returns string

    • Parameters

      • locales: string | string[]
      • Optionaloptions: NumberFormatOptions & DateTimeFormatOptions

      Returns string

    • Returns a copy of an array with its elements reversed.

      Returns Sprite[]

    • Returns a copy of an array with its elements sorted.

      Parameters

      • OptionalcompareFn: (a: Sprite, b: Sprite) => number

        Function used to determine the order of the elements. It is expected to return a negative value if the first argument is less than the second argument, zero if they're equal, and a positive value otherwise. If omitted, the elements are sorted in ascending, UTF-16 code unit order.

        [11, 2, 22, 1].toSorted((a, b) => a - b) // [1, 2, 11, 22]
        

      Returns Sprite[]

    • Copies an array and removes elements and, if necessary, inserts new elements in their place. Returns the copied array.

      Parameters

      • start: number

        The zero-based location in the array from which to start removing elements.

      • deleteCount: number

        The number of elements to remove.

      • ...items: Sprite[]

        Elements to insert into the copied array in place of the deleted elements.

      Returns Sprite[]

      The copied array.

    • Copies an array and removes elements while returning the remaining elements.

      Parameters

      • start: number

        The zero-based location in the array from which to start removing elements.

      • OptionaldeleteCount: number

        The number of elements to remove.

      Returns Sprite[]

      A copy of the original array with the remaining elements.

    • Returns a string representation of an array.

      Returns string

    • Moves and rotates each sprite in the group towards a target transform, maintaining their relative offsets from the group's centroid.

      Parameters

      • x: number
      • y: number
      • Optionalrotation: number
      • Optionaltracking: number

      Returns void

    • Moves and rotates each sprite in the group towards a target transform, maintaining their relative offsets from the group's centroid.

      Parameters

      • pos: { x: number; y: number }
      • Optionalrotation: number
      • Optionaltracking: number

      Returns void

    • Inserts new elements at the start of an array, and returns the new length of the array.

      Parameters

      • ...items: Sprite[]

        Elements to insert at the start of the array.

      Returns number

    • Updates all the sprites in the group.

      Returns void

    • Returns an iterable of values in the array

      Returns ArrayIterator<Sprite>

    • Copies an array, then overwrites the value at the provided index with the given value. If the index is negative, then it replaces from the end of the array.

      Parameters

      • index: number

        The index of the value to overwrite. If the index is negative, then it replaces from the end of the array.

      • value: Sprite

        The value to write into the copied array.

      Returns Sprite[]

      The copied array with the updated value.

    • Creates an array from an array-like object.

      Type Parameters

      • T

      Parameters

      • arrayLike: ArrayLike<T>

        An array-like object to convert to an array.

      Returns T[]

    • Creates an array from an iterable object.

      Type Parameters

      • T
      • U

      Parameters

      • arrayLike: ArrayLike<T>

        An array-like object to convert to an array.

      • mapfn: (v: T, k: number) => U

        A mapping function to call on every element of the array.

      • OptionalthisArg: any

        Value of 'this' used to invoke the mapfn.

      Returns U[]

    • Creates an array from an iterable object.

      Type Parameters

      • T

      Parameters

      • iterable: Iterable<T, any, any> | ArrayLike<T>

        An iterable object to convert to an array.

      Returns T[]

    • Creates an array from an iterable object.

      Type Parameters

      • T
      • U

      Parameters

      • iterable: Iterable<T, any, any> | ArrayLike<T>

        An iterable object to convert to an array.

      • mapfn: (v: T, k: number) => U

        A mapping function to call on every element of the array.

      • OptionalthisArg: any

        Value of 'this' used to invoke the mapfn.

      Returns U[]

    • Parameters

      • arg: any

      Returns arg is any[]

    • Returns a new array from a set of elements.

      Type Parameters

      • T

      Parameters

      • ...items: T[]

        A set of elements to include in the new array object.

      Returns T[]