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

    An Arcade Physics Group object.

    The primary use of a Physics Group is a way to collect together physics enable objects that share the same intrinsic structure into a single pool. They can they be easily compared against other Groups, or Game Objects.

    All Game Objects created by, or added to this Group will automatically be given dynamic Arcade Physics bodies (if they have no body already) and the bodies will receive the Groups default values.

    You should not pass objects into this Group that should not receive a body. For example, do not add basic Geometry or Tilemap Layers into a Group, as they will not behave in the way you may expect. Groups should all ideally have objects of the same type in them.

    If you wish to create a Group filled with Static Bodies, please see Phaser.Physics.Arcade.StaticGroup.

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Properties

    active: boolean

    Whether this group runs its Phaser.GameObjects.Group#preUpdate method (which may update any members).

    children: Set<GameObject>

    Members of this group.

    classType: Function

    The class to create new Group members from.

    This should be either Phaser.Physics.Arcade.Image, Phaser.Physics.Arcade.Sprite, or a class extending one of those.

    The constructor arguments must match (scene, x, y, texture, frame).

    collisionCategory: number

    The Arcade Physics Group Collision Category.

    This can be set to any valid collision bitfield value.

    See the setCollisionCategory method for more details.

    collisionMask: number

    The Arcade Physics Group Collision Mask.

    See the setCollidesWith method for more details.

    createCallback: GroupCallback

    A function to be called when adding or creating group members.

    createMultipleCallback: GroupMultipleCreateCallback

    A function to be called when creating several group members at once.

    defaultFrame: string | number

    A default texture frame to use when creating new group members.

    defaultKey: string

    A default texture key to use when creating new group members.

    This is used in Phaser.GameObjects.Group#create but not in Phaser.GameObjects.Group#createMultiple.

    Default physics properties applied to Game Objects added to the Group or created by the Group. Derived from the config argument.

    You can remove the default values by setting this property to {}.

    isParent: boolean

    A flag identifying this object as a group.

    maxSize: number

    The maximum size of this group, if used as a pool. -1 is no limit.

    name: string

    The name of this group. Empty by default and never populated by Phaser, this is left for developers to use.

    physicsType: number

    The physics type of the Group's members.

    removeCallback: GroupCallback

    A function to be called when removing group members.

    runChildUpdate: boolean

    Whether to call the update method of any members.

    scene: Scene

    This scene this group belongs to.

    type: string

    A textual representation of this Game Object. Used internally by Phaser but is available for your own custom classes to populate.

    The physics simulation.

    Methods

    • Adds the given Collision Category to the list of those that this Arcade Physics Body will collide with.

      Parameters

      • category: number

        The collision category to add.

      Returns this

    • Add a listener for a given event.

      Parameters

      • event: string | symbol

        The event name.

      • fn: Function

        The listener function.

      • Optionalcontext: any

        The context to invoke the listener with. Default this.

      Returns this

    • Sets the angle of each group member.

      Parameters

      • value: number

        The amount to set the angle to, in degrees.

      • Optionalstep: number

        This is added to the value amount, multiplied by the iteration counter. Default 0.

      Returns this

    • Removes all members of this Group and optionally removes them from the Scene and / or destroys them.

      Does not call Phaser.GameObjects.Group#removeCallback.

      Parameters

      • OptionalremoveFromScene: boolean

        Optionally remove each Group member from the Scene. Default false.

      • OptionaldestroyChild: boolean

        Optionally call destroy on the removed Group members. Default false.

      Returns this

    • Counts the number of active (or inactive) group members.

      Parameters

      • Optionalvalue: boolean

        Count active (true) or inactive (false) group members. Default true.

      Returns number

    • Creates a new Game Object and adds it to this group, unless the group is full.

      Calls Phaser.GameObjects.Group#createCallback.

      Parameters

      • Optionalx: number

        The horizontal position of the new Game Object in the world. Default 0.

      • Optionaly: number

        The vertical position of the new Game Object in the world. Default 0.

      • Optionalkey: string

        The texture key of the new Game Object. Default defaultKey.

      • Optionalframe: string | number

        The texture frame of the new Game Object. Default defaultFrame.

      • Optionalvisible: boolean

        The Phaser.GameObjects.Components.Visible#visible state of the new Game Object. Default true.

      • Optionalactive: boolean

        The Phaser.GameObjects.GameObject#active state of the new Game Object. Default true.

      Returns any

    • Enables a Game Object's Body and assigns defaults. Called when a Group member is added or created.

      Parameters

      Returns void

    • Empties this Group of all children and removes it from the Scene.

      Does not call Phaser.GameObjects.Group#removeCallback.

      Children of this Group will not be removed from the Scene by calling this method unless you specify the removeFromScene parameter.

      Children of this Group will also not be destroyed by calling this method unless you specify the destroyChildren parameter.

      Parameters

      • OptionaldestroyChildren: boolean

        Also Phaser.GameObjects.GameObject#destroy each Group member. Default false.

      • OptionalremoveFromScene: boolean

        Optionally remove each Group member from the Scene. Default false.

      Returns void

    • Calls each of the listeners registered for a given event.

      Parameters

      • event: string | symbol

        The event name.

      • ...args: any[]

        Additional arguments that will be passed to the event handler.

      Returns boolean

    • Return an array listing the events for which the emitter has registered listeners.

      Returns (string | symbol)[]

    • Scans the group for the first member that has an Phaser.GameObjects.GameObject#active state set to false, assigns x and y, and returns the member.

      If no inactive member is found and the group isn't full then it will create a new Game Object using x, y, key, frame, and visible. The new Game Object will have its active state set to true. Unless a new member is created, key, frame, and visible are ignored.

      Parameters

      • Optionalx: number

        The horizontal position of the Game Object in the world.

      • Optionaly: number

        The vertical position of the Game Object in the world.

      • Optionalkey: string

        The texture key assigned to a new Game Object (if one is created). Default defaultKey.

      • Optionalframe: string | number

        A texture frame assigned to a new Game Object (if one is created). Default defaultFrame.

      • Optionalvisible: boolean

        The Phaser.GameObjects.Components.Visible#visible state of a new Game Object (if one is created). Default true.

      Returns any

    • Scans the Group, from top to bottom, for the first member that has an Phaser.GameObjects.GameObject#active state matching the argument, assigns x and y, and returns the member.

      If no matching member is found and createIfNull is true and the group isn't full then it will create a new Game Object using x, y, key, frame, and visible. Unless a new member is created, key, frame, and visible are ignored.

      Parameters

      • Optionalstate: boolean

        The Phaser.GameObjects.GameObject#active value to match. Default false.

      • OptionalcreateIfNull: boolean

        Create a new Game Object if no matching members are found, using the following arguments. Default false.

      • Optionalx: number

        The horizontal position of the Game Object in the world.

      • Optionaly: number

        The vertical position of the Game Object in the world.

      • Optionalkey: string

        The texture key assigned to a new Game Object (if one is created). Default defaultKey.

      • Optionalframe: string | number

        A texture frame assigned to a new Game Object (if one is created). Default defaultFrame.

      • Optionalvisible: boolean

        The Phaser.GameObjects.Components.Visible#visible state of a new Game Object (if one is created). Default true.

      Returns any

    • Scans the group for the first member that has an Phaser.GameObjects.GameObject#active state set to true, assigns x and y, and returns the member.

      If no active member is found and createIfNull is true and the group isn't full then it will create a new one using x, y, key, frame, and visible. Unless a new member is created, key, frame, and visible are ignored.

      Parameters

      • OptionalcreateIfNull: boolean

        Create a new Game Object if no matching members are found, using the following arguments. Default false.

      • Optionalx: number

        The horizontal position of the Game Object in the world.

      • Optionaly: number

        The vertical position of the Game Object in the world.

      • Optionalkey: string

        The texture key assigned to a new Game Object (if one is created). Default defaultKey.

      • Optionalframe: string | number

        A texture frame assigned to a new Game Object (if one is created). Default defaultFrame.

      • Optionalvisible: boolean

        The Phaser.GameObjects.Components.Visible#visible state of a new Game Object (if one is created). Default true.

      Returns any

    • Scans the group for the first member that has an Phaser.GameObjects.GameObject#active state set to false, assigns x and y, and returns the member.

      If no inactive member is found and createIfNull is true and the group isn't full then it will create a new one using x, y, key, frame, and visible. The new Game Object will have an active state set to true. Unless a new member is created, key, frame, and visible are ignored.

      Parameters

      • OptionalcreateIfNull: boolean

        Create a new Game Object if no matching members are found, using the following arguments. Default false.

      • Optionalx: number

        The horizontal position of the Game Object in the world.

      • Optionaly: number

        The vertical position of the Game Object in the world.

      • Optionalkey: string

        The texture key assigned to a new Game Object (if one is created). Default defaultKey.

      • Optionalframe: string | number

        A texture frame assigned to a new Game Object (if one is created). Default defaultFrame.

      • Optionalvisible: boolean

        The Phaser.GameObjects.Components.Visible#visible state of a new Game Object (if one is created). Default true.

      Returns any

    • Scans the Group, from top to bottom, for the nth member that has an Phaser.GameObjects.GameObject#active state matching the argument, assigns x and y, and returns the member.

      If no matching member is found and createIfNull is true and the group isn't full then it will create a new Game Object using x, y, key, frame, and visible. Unless a new member is created, key, frame, and visible are ignored.

      Parameters

      • nth: number

        The nth matching Group member to search for.

      • Optionalstate: boolean

        The Phaser.GameObjects.GameObject#active value to match. Default false.

      • OptionalcreateIfNull: boolean

        Create a new Game Object if no matching members are found, using the following arguments. Default false.

      • Optionalx: number

        The horizontal position of the Game Object in the world.

      • Optionaly: number

        The vertical position of the Game Object in the world.

      • Optionalkey: string

        The texture key assigned to a new Game Object (if one is created). Default defaultKey.

      • Optionalframe: string | number

        A texture frame assigned to a new Game Object (if one is created). Default defaultFrame.

      • Optionalvisible: boolean

        The Phaser.GameObjects.Components.Visible#visible state of a new Game Object (if one is created). Default true.

      Returns any

    • Scans the Group for the last member that has an Phaser.GameObjects.GameObject#active state matching the argument, assigns x and y, and returns the member.

      If no matching member is found and createIfNull is true and the group isn't full then it will create a new Game Object using x, y, key, frame, and visible. Unless a new member is created, key, frame, and visible are ignored.

      Parameters

      • Optionalstate: boolean

        The Phaser.GameObjects.GameObject#active value to match. Default false.

      • OptionalcreateIfNull: boolean

        Create a new Game Object if no matching members are found, using the following arguments. Default false.

      • Optionalx: number

        The horizontal position of the Game Object in the world.

      • Optionaly: number

        The vertical position of the Game Object in the world.

      • Optionalkey: string

        The texture key assigned to a new Game Object (if one is created). Default defaultKey.

      • Optionalframe: string | number

        A texture frame assigned to a new Game Object (if one is created). Default defaultFrame.

      • Optionalvisible: boolean

        The Phaser.GameObjects.Components.Visible#visible state of a new Game Object (if one is created). Default true.

      Returns any

    • Scans the Group for the last nth member that has an Phaser.GameObjects.GameObject#active state matching the argument, assigns x and y, and returns the member.

      If no matching member is found and createIfNull is true and the group isn't full then it will create a new Game Object using x, y, key, frame, and visible. Unless a new member is created, key, frame, and visible are ignored.

      Parameters

      • nth: number

        The nth matching Group member to search for.

      • Optionalstate: boolean

        The Phaser.GameObjects.GameObject#active value to match. Default false.

      • OptionalcreateIfNull: boolean

        Create a new Game Object if no matching members are found, using the following arguments. Default false.

      • Optionalx: number

        The horizontal position of the Game Object in the world.

      • Optionaly: number

        The vertical position of the Game Object in the world.

      • Optionalkey: string

        The texture key assigned to a new Game Object (if one is created). Default defaultKey.

      • Optionalframe: string | number

        A texture frame assigned to a new Game Object (if one is created). Default defaultFrame.

      • Optionalvisible: boolean

        The Phaser.GameObjects.Components.Visible#visible state of a new Game Object (if one is created). Default true.

      Returns any

    • Returns all children in this Group that match the given criteria based on the property and value arguments.

      For example: getMatching('visible', true) would return only children that have their visible property set.

      Optionally, you can specify a start and end index. For example if the Group has 100 elements, and you set startIndex to 0 and endIndex to 50, it would return matches from only the first 50.

      Parameters

      • Optionalproperty: string

        The property to test on each array element.

      • Optionalvalue: any

        The value to test the property against. Must pass a strict (===) comparison check.

      • OptionalstartIndex: number

        An optional start index to search from.

      • OptionalendIndex: number

        An optional end index to search to.

      Returns any[]

    • Adds the given value to the x of each group member.

      Parameters

      • value: number

        The amount to be added to the x property.

      • Optionalstep: number

        This is added to the value amount, multiplied by the iteration counter. Default 0.

      Returns this

    • Adds the given value to the x, y of each group member.

      Parameters

      • x: number

        The amount to be added to the x property.

      • Optionaly: number

        The amount to be added to the y property. If undefined or null it uses the x value. Default x.

      • OptionalstepX: number

        This is added to the x amount, multiplied by the iteration counter. Default 0.

      • OptionalstepY: number

        This is added to the y amount, multiplied by the iteration counter. Default 0.

      Returns this

    • Adds the given value to the y of each group member.

      Parameters

      • value: number

        The amount to be added to the y property.

      • Optionalstep: number

        This is added to the value amount, multiplied by the iteration counter. Default 0.

      Returns this

    • Return the number of listeners listening to a given event.

      Parameters

      • event: string | symbol

        The event name.

      Returns number

    • Return the listeners registered for a given event.

      Parameters

      • event: string | symbol

        The event name.

      Returns Function[]

    • Remove the listeners of a given event.

      Parameters

      • event: string | symbol

        The event name.

      • Optionalfn: Function

        Only remove the listeners that match this function.

      • Optionalcontext: any

        Only remove the listeners that have this context.

      • Optionalonce: boolean

        Only remove one-time listeners.

      Returns this

    • Add a listener for a given event.

      Parameters

      • event: string | symbol

        The event name.

      • fn: Function

        The listener function.

      • Optionalcontext: any

        The context to invoke the listener with. Default this.

      Returns this

    • Add a one-time listener for a given event.

      Parameters

      • event: string | symbol

        The event name.

      • fn: Function

        The listener function.

      • Optionalcontext: any

        The context to invoke the listener with. Default this.

      Returns this

    • Plays an animation for all members of this group.

      Parameters

      • key: string

        The string-based key of the animation to play.

      • OptionalstartFrame: string

        Optionally start the animation playing from this frame index. Default 0.

      Returns this

    • Adds the given value to the property as defined in key of each group member.

      Parameters

      • key: string

        The property to be updated.

      • value: number

        The amount to set the property to.

      • Optionalstep: number

        This is added to the value amount, multiplied by the iteration counter. Default 0.

      • Optionalindex: number

        An optional offset to start searching from within the items array. Default 0.

      • Optionaldirection: number

        The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1.

      Returns this

    • Sets the property as defined in key of each group member to the given value.

      Parameters

      • key: string

        The property to be updated.

      • value: number

        The amount to set the property to.

      • Optionalstep: number

        This is added to the value amount, multiplied by the iteration counter. Default 0.

      • Optionalindex: number

        An optional offset to start searching from within the items array. Default 0.

      • Optionaldirection: number

        The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1.

      Returns this

    • Removes a member of this Group and optionally removes it from the Scene and / or destroys it.

      Calls Phaser.GameObjects.Group#removeCallback.

      Parameters

      • child: GameObject

        The Game Object to remove.

      • OptionalremoveFromScene: boolean

        Optionally remove the Group member from the Scene it belongs to. Default false.

      • OptionaldestroyChild: boolean

        Optionally call destroy on the removed Group member. Default false.

      Returns this

    • Remove all listeners, or those of the specified event.

      Parameters

      • Optionalevent: string | symbol

        The event name.

      Returns this

    • Disables a Game Object's Body. Called when a Group member is removed.

      Parameters

      Returns void

    • Removes the given Collision Category from the list of those that this Arcade Physics Body will collide with.

      Parameters

      • category: number

        The collision category to add.

      Returns this

    • Remove the listeners of a given event.

      Parameters

      • event: string | symbol

        The event name.

      • Optionalfn: Function

        Only remove the listeners that match this function.

      • Optionalcontext: any

        Only remove the listeners that have this context.

      • Optionalonce: boolean

        Only remove one-time listeners.

      Returns this

    • Sets the rotation of each group member.

      Parameters

      • value: number

        The amount to set the rotation to, in radians.

      • Optionalstep: number

        This is added to the value amount, multiplied by the iteration counter. Default 0.

      Returns this

    • Rotates each group member around the given point by the given angle.

      Parameters

      • point: Vector2Like

        Any object with public x and y properties.

      • angle: number

        The angle to rotate by, in radians.

      Returns this

    • Rotates each group member around the given point by the given angle and distance.

      Parameters

      • point: Vector2Like

        Any object with public x and y properties.

      • angle: number

        The angle to rotate by, in radians.

      • distance: number

        The distance from the point of rotation in pixels.

      Returns this

    • Sets the scaleX of each group member.

      Parameters

      • value: number

        The amount to set the property to.

      • Optionalstep: number

        This is added to the value amount, multiplied by the iteration counter. Default 0.

      Returns this

    • Sets the scaleX, scaleY of each group member.

      Parameters

      • scaleX: number

        The amount to be added to the scaleX property.

      • OptionalscaleY: number

        The amount to be added to the scaleY property. If undefined or null it uses the scaleX value.

      • OptionalstepX: number

        This is added to the scaleX amount, multiplied by the iteration counter. Default 0.

      • OptionalstepY: number

        This is added to the scaleY amount, multiplied by the iteration counter. Default 0.

      Returns this

    • Sets the scaleY of each group member.

      Parameters

      • value: number

        The amount to set the property to.

      • Optionalstep: number

        This is added to the value amount, multiplied by the iteration counter. Default 0.

      Returns this

    • Sets the active property of this Group. When active, this Group runs its preUpdate method.

      Parameters

      • value: boolean

        True if this Group should be set as active, false if not.

      Returns this

    • Sets the alpha of each group member.

      Parameters

      • value: number

        The amount to set the alpha to.

      • Optionalstep: number

        This is added to the value amount, multiplied by the iteration counter. Default 0.

      Returns this

    • Sets the blendMode of each group member.

      Parameters

      • value: number

        The amount to set the property to.

      Returns this

    • Sets all of the Collision Categories that this Arcade Physics Body will collide with. You can either pass a single category value, or an array of them.

      Calling this method will reset all of the collision categories, so only those passed to this method are enabled.

      If you wish to add a new category to the existing mask, call the addCollisionCategory method.

      If you wish to reset the collision category and mask, call the resetCollisionCategory method.

      Parameters

      • categories: number | number[]

        The collision category to collide with, or an array of them.

      Returns this

    • Sets the Collision Category that this Arcade Physics Body will use in order to determine what it can collide with.

      It can only have one single category assigned to it.

      If you wish to reset the collision category and mask, call the resetCollisionCategory method.

      Parameters

      • category: number

        The collision category.

      Returns this

    • Sets the depth of each group member.

      Parameters

      • value: number

        The amount to set the property to.

      • Optionalstep: number

        This is added to the value amount, multiplied by the iteration counter. Default 0.

      Returns this

    • Passes all group members to the Input Manager to enable them for input with identical areas and callbacks.

      Parameters

      • hitArea: any

        Either an input configuration object, or a geometric shape that defines the hit area for the Game Object. If not specified a Rectangle will be used.

      • hitAreaCallback: HitAreaCallback

        A callback to be invoked when the Game Object is interacted with. If you provide a shape you must also provide a callback.

      Returns this

    • Sets the name property of this Group. The name property is not populated by Phaser and is presented for your own use.

      Parameters

      • value: string

        The name to be given to this Group.

      Returns this

    • Sets the originX, originY of each group member.

      Parameters

      • originX: number

        The amount to set the originX property to.

      • OptionaloriginY: number

        The amount to set the originY property to. If undefined or null it uses the originX value.

      • OptionalstepX: number

        This is added to the originX amount, multiplied by the iteration counter. Default 0.

      • OptionalstepY: number

        This is added to the originY amount, multiplied by the iteration counter. Default 0.

      Returns this

    • Sets the tint of each group member.

      Parameters

      • topLeft: number

        The tint being applied to top-left corner of item. If other parameters are given no value, this tint will be applied to whole item.

      • OptionaltopRight: number

        The tint to be applied to top-right corner of item.

      • OptionalbottomLeft: number

        The tint to be applied to the bottom-left corner of item.

      • OptionalbottomRight: number

        The tint to be applied to the bottom-right corner of item.

      Returns this

    • Sets the velocity of each Group member.

      Parameters

      • x: number

        The horizontal velocity.

      • y: number

        The vertical velocity.

      • Optionalstep: number

        The velocity increment. When set, the first member receives velocity (x, y), the second (x + step, y + step), and so on. Default 0.

      Returns Physics.Arcade.Group

    • Sets the horizontal velocity of each Group member.

      Parameters

      • value: number

        The velocity value.

      • Optionalstep: number

        The velocity increment. When set, the first member receives velocity (x), the second (x + step), and so on. Default 0.

      Returns Physics.Arcade.Group

    • Sets the vertical velocity of each Group member.

      Parameters

      • value: number

        The velocity value.

      • Optionalstep: number

        The velocity increment. When set, the first member receives velocity (y), the second (y + step), and so on. Default 0.

      Returns Physics.Arcade.Group

    • Sets the visible of each group member.

      Parameters

      • value: boolean

        The value to set the property to.

      • Optionalindex: number

        An optional offset to start searching from within the items array. Default 0.

      • Optionaldirection: number

        The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1.

      Returns this

    • Sets the x of each group member.

      Parameters

      • value: number

        The amount to set the property to.

      • Optionalstep: number

        This is added to the value amount, multiplied by the iteration counter. Default 0.

      Returns this

    • Sets the x, y of each group member.

      Parameters

      • x: number

        The amount to set the x property to.

      • Optionaly: number

        The amount to set the y property to. If undefined or null it uses the x value. Default x.

      • OptionalstepX: number

        This is added to the x amount, multiplied by the iteration counter. Default 0.

      • OptionalstepY: number

        This is added to the y amount, multiplied by the iteration counter. Default 0.

      Returns this

    • Sets the y of each group member.

      Parameters

      • value: number

        The amount to set the property to.

      • Optionalstep: number

        This is added to the value amount, multiplied by the iteration counter. Default 0.

      Returns this

    • Iterate through the group members changing the position of each element to be that of the element that came before it in the array (or after it if direction = 1)

      The first group member position is set to x/y.

      Parameters

      • x: number

        The x coordinate to place the first item in the array at.

      • y: number

        The y coordinate to place the first item in the array at.

      • Optionaldirection: number

        The iteration direction. 0 = first to last and 1 = last to first. Default 0.

      Returns this

    • Checks to see if the given Collision Category will collide with this Arcade Physics object or not.

      Parameters

      • category: number

        Collision category value to test.

      Returns boolean