From a1c4923e2c340cc7c847bdd036843de19da427cb Mon Sep 17 00:00:00 2001 From: Tommy Leung Date: Fri, 1 Jan 2021 09:52:00 -0700 Subject: [PATCH] update for phaser 3.50 --- index.html | 2 +- src/scenes/GameOver.js | 2 +- src/types/phaser.d.ts | 78009 ++++++++++++++++++++++----------------- 3 files changed, 43177 insertions(+), 34836 deletions(-) diff --git a/index.html b/index.html index 101fbdd..9ff7175 100644 --- a/index.html +++ b/index.html @@ -1,7 +1,7 @@ Bunny Jump! - + diff --git a/src/scenes/GameOver.js b/src/scenes/GameOver.js index 08ae2d1..1656d29 100644 --- a/src/scenes/GameOver.js +++ b/src/scenes/GameOver.js @@ -17,7 +17,7 @@ export default class GameOver extends Phaser.Scene }) .setOrigin(0.5) - this.input.keyboard.once('keydown_SPACE', () => { + this.input.keyboard.once('keydown-SPACE', () => { this.scene.start('game') }) } diff --git a/src/types/phaser.d.ts b/src/types/phaser.d.ts index 67d6b1f..f524757 100644 --- a/src/types/phaser.d.ts +++ b/src/types/phaser.d.ts @@ -1,10 +1,12 @@ /// +declare type CameraRotateCallback = (camera: Phaser.Cameras.Scene2D.Camera, progress: number, angle: number)=>void; + declare type DataEachCallback = (parent: any, key: string, value: any, ...args: any[])=>void; declare type ContentLoadedCallback = ()=>void; -declare type CreateCallback = (bob: Phaser.GameObjects.Bob, index: integer)=>void; +declare type CreateCallback = (bob: Phaser.GameObjects.Bob, index: number)=>void; declare type EachContainerCallback = (item: any, ...args: any[])=>void; @@ -28,7 +30,7 @@ declare namespace Phaser { * @param offsetX Optional horizontal offset from the position. Default 0. * @param offsetY Optional vertical offset from the position. Default 0. */ - function AlignTo(items: G, position: integer, offsetX?: number, offsetY?: number): G; + function AlignTo(items: G, position: number, offsetX?: number, offsetY?: number): G; /** * Takes an array of Game Objects, or any objects that have a public `angle` property, @@ -43,7 +45,7 @@ declare namespace Phaser { * @param index An optional offset to start searching from within the items array. Default 0. * @param direction The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1. */ - function Angle(items: G, value: number, step?: number, index?: integer, direction?: integer): G; + function Angle(items: G, value: number, step?: number, index?: number, direction?: number): G; /** * Takes an array of objects and passes each of them to the given callback. @@ -63,7 +65,7 @@ declare namespace Phaser { * @param compare The comparison object. Each property in this object will be checked against the items of the array. * @param index An optional offset to start searching from within the items array. Default 0. */ - function GetFirst(items: G, compare: object, index?: integer): object | Phaser.GameObjects.GameObject; + function GetFirst(items: G, compare: object, index?: number): object | Phaser.GameObjects.GameObject; /** * Takes an array of objects and returns the last element in the array that has properties which match @@ -75,7 +77,7 @@ declare namespace Phaser { * @param compare The comparison object. Each property in this object will be checked against the items of the array. * @param index An optional offset to start searching from within the items array. Default 0. */ - function GetLast(items: G, compare: object, index?: integer): object | Phaser.GameObjects.GameObject; + function GetLast(items: G, compare: object, index?: number): object | Phaser.GameObjects.GameObject; /** * Takes an array of Game Objects, or any objects that have public `x` and `y` properties, @@ -98,7 +100,7 @@ declare namespace Phaser { * @param index An optional offset to start searching from within the items array. Default 0. * @param direction The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1. */ - function IncAlpha(items: G, value: number, step?: number, index?: integer, direction?: integer): G; + function IncAlpha(items: G, value: number, step?: number, index?: number, direction?: number): G; /** * Takes an array of Game Objects, or any objects that have a public `x` property, @@ -113,7 +115,7 @@ declare namespace Phaser { * @param index An optional offset to start searching from within the items array. Default 0. * @param direction The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1. */ - function IncX(items: G, value: number, step?: number, index?: integer, direction?: integer): G; + function IncX(items: G, value: number, step?: number, index?: number, direction?: number): G; /** * Takes an array of Game Objects, or any objects that have public `x` and `y` properties, @@ -130,7 +132,7 @@ declare namespace Phaser { * @param index An optional offset to start searching from within the items array. Default 0. * @param direction The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1. */ - function IncXY(items: G, x: number, y?: number, stepX?: number, stepY?: number, index?: integer, direction?: integer): G; + function IncXY(items: G, x: number, y?: number, stepX?: number, stepY?: number, index?: number, direction?: number): G; /** * Takes an array of Game Objects, or any objects that have a public `y` property, @@ -145,7 +147,7 @@ declare namespace Phaser { * @param index An optional offset to start searching from within the items array. Default 0. * @param direction The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1. */ - function IncY(items: G, value: number, step?: number, index?: integer, direction?: integer): G; + function IncY(items: G, value: number, step?: number, index?: number, direction?: number): G; /** * Takes an array of Game Objects and positions them on evenly spaced points around the perimeter of a Circle. @@ -185,7 +187,7 @@ declare namespace Phaser { * @param rect The Rectangle to position the Game Objects on. * @param shift An optional positional offset. Default 1. */ - function PlaceOnRectangle(items: G, rect: Phaser.Geom.Rectangle, shift?: integer): G; + function PlaceOnRectangle(items: G, rect: Phaser.Geom.Rectangle, shift?: number): G; /** * Takes an array of Game Objects and positions them on evenly spaced points around the edges of a Triangle. @@ -203,7 +205,7 @@ declare namespace Phaser { * @param key The name of the animation to play. * @param startFrame The starting frame of the animation with the given key. */ - function PlayAnimation(items: G, key: string, startFrame?: string | integer): G; + function PlayAnimation(items: G, key: string, startFrame?: string | number): G; /** * Takes an array of Game Objects, or any objects that have a public property as defined in `key`, @@ -219,7 +221,7 @@ declare namespace Phaser { * @param index An optional offset to start searching from within the items array. Default 0. * @param direction The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1. */ - function PropertyValueInc(items: G, key: string, value: number, step?: number, index?: integer, direction?: integer): G; + function PropertyValueInc(items: G, key: string, value: number, step?: number, index?: number, direction?: number): G; /** * Takes an array of Game Objects, or any objects that have a public property as defined in `key`, @@ -235,7 +237,7 @@ declare namespace Phaser { * @param index An optional offset to start searching from within the items array. Default 0. * @param direction The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1. */ - function PropertyValueSet(items: G, key: string, value: number, step?: number, index?: integer, direction?: integer): G; + function PropertyValueSet(items: G, key: string, value: number, step?: number, index?: number, direction?: number): G; /** * Takes an array of Game Objects and positions them at random locations within the Circle. @@ -293,7 +295,7 @@ declare namespace Phaser { * @param index An optional offset to start searching from within the items array. Default 0. * @param direction The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1. */ - function Rotate(items: G, value: number, step?: number, index?: integer, direction?: integer): G; + function Rotate(items: G, value: number, step?: number, index?: number, direction?: number): G; /** * Rotates each item around the given point by the given angle. @@ -325,7 +327,7 @@ declare namespace Phaser { * @param index An optional offset to start searching from within the items array. Default 0. * @param direction The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1. */ - function ScaleX(items: G, value: number, step?: number, index?: integer, direction?: integer): G; + function ScaleX(items: G, value: number, step?: number, index?: number, direction?: number): G; /** * Takes an array of Game Objects, or any objects that have public `scaleX` and `scaleY` properties, @@ -342,7 +344,7 @@ declare namespace Phaser { * @param index An optional offset to start searching from within the items array. Default 0. * @param direction The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1. */ - function ScaleXY(items: G, scaleX: number, scaleY?: number, stepX?: number, stepY?: number, index?: integer, direction?: integer): G; + function ScaleXY(items: G, scaleX: number, scaleY?: number, stepX?: number, stepY?: number, index?: number, direction?: number): G; /** * Takes an array of Game Objects, or any objects that have a public `scaleY` property, @@ -357,7 +359,7 @@ declare namespace Phaser { * @param index An optional offset to start searching from within the items array. Default 0. * @param direction The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1. */ - function ScaleY(items: G, value: number, step?: number, index?: integer, direction?: integer): G; + function ScaleY(items: G, value: number, step?: number, index?: number, direction?: number): G; /** * Takes an array of Game Objects, or any objects that have the public property `alpha` @@ -372,7 +374,7 @@ declare namespace Phaser { * @param index An optional offset to start searching from within the items array. Default 0. * @param direction The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1. */ - function SetAlpha(items: G, value: number, step?: number, index?: integer, direction?: integer): G; + function SetAlpha(items: G, value: number, step?: number, index?: number, direction?: number): G; /** * Takes an array of Game Objects, or any objects that have the public property `blendMode` @@ -386,7 +388,7 @@ declare namespace Phaser { * @param index An optional offset to start searching from within the items array. Default 0. * @param direction The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1. */ - function SetBlendMode(items: G, value: number, index?: integer, direction?: integer): G; + function SetBlendMode(items: G, value: number, index?: number, direction?: number): G; /** * Takes an array of Game Objects, or any objects that have the public property `depth` @@ -401,7 +403,7 @@ declare namespace Phaser { * @param index An optional offset to start searching from within the items array. Default 0. * @param direction The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1. */ - function SetDepth(items: G, value: number, step?: number, index?: integer, direction?: integer): G; + function SetDepth(items: G, value: number, step?: number, index?: number, direction?: number): G; /** * Passes all provided Game Objects to the Input Manager to enable them for input with identical areas and callbacks. @@ -426,7 +428,7 @@ declare namespace Phaser { * @param index An optional offset to start searching from within the items array. Default 0. * @param direction The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1. */ - function SetOrigin(items: G, originX: number, originY?: number, stepX?: number, stepY?: number, index?: integer, direction?: integer): G; + function SetOrigin(items: G, originX: number, originY?: number, stepX?: number, stepY?: number, index?: number, direction?: number): G; /** * Takes an array of Game Objects, or any objects that have the public property `rotation` @@ -441,7 +443,7 @@ declare namespace Phaser { * @param index An optional offset to start searching from within the items array. Default 0. * @param direction The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1. */ - function SetRotation(items: G, value: number, step?: number, index?: integer, direction?: integer): G; + function SetRotation(items: G, value: number, step?: number, index?: number, direction?: number): G; /** * Takes an array of Game Objects, or any objects that have the public properties `scaleX` and `scaleY` @@ -458,7 +460,7 @@ declare namespace Phaser { * @param index An optional offset to start searching from within the items array. Default 0. * @param direction The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1. */ - function SetScale(items: G, scaleX: number, scaleY?: number, stepX?: number, stepY?: number, index?: integer, direction?: integer): G; + function SetScale(items: G, scaleX: number, scaleY?: number, stepX?: number, stepY?: number, index?: number, direction?: number): G; /** * Takes an array of Game Objects, or any objects that have the public property `scaleX` @@ -473,7 +475,7 @@ declare namespace Phaser { * @param index An optional offset to start searching from within the items array. Default 0. * @param direction The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1. */ - function SetScaleX(items: G, value: number, step?: number, index?: integer, direction?: integer): G; + function SetScaleX(items: G, value: number, step?: number, index?: number, direction?: number): G; /** * Takes an array of Game Objects, or any objects that have the public property `scaleY` @@ -488,7 +490,7 @@ declare namespace Phaser { * @param index An optional offset to start searching from within the items array. Default 0. * @param direction The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1. */ - function SetScaleY(items: G, value: number, step?: number, index?: integer, direction?: integer): G; + function SetScaleY(items: G, value: number, step?: number, index?: number, direction?: number): G; /** * Takes an array of Game Objects, or any objects that have the public properties `scrollFactorX` and `scrollFactorY` @@ -505,7 +507,7 @@ declare namespace Phaser { * @param index An optional offset to start searching from within the items array. Default 0. * @param direction The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1. */ - function SetScrollFactor(items: G, scrollFactorX: number, scrollFactorY?: number, stepX?: number, stepY?: number, index?: integer, direction?: integer): G; + function SetScrollFactor(items: G, scrollFactorX: number, scrollFactorY?: number, stepX?: number, stepY?: number, index?: number, direction?: number): G; /** * Takes an array of Game Objects, or any objects that have the public property `scrollFactorX` @@ -520,7 +522,7 @@ declare namespace Phaser { * @param index An optional offset to start searching from within the items array. Default 0. * @param direction The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1. */ - function SetScrollFactorX(items: G, value: number, step?: number, index?: integer, direction?: integer): G; + function SetScrollFactorX(items: G, value: number, step?: number, index?: number, direction?: number): G; /** * Takes an array of Game Objects, or any objects that have the public property `scrollFactorY` @@ -535,7 +537,7 @@ declare namespace Phaser { * @param index An optional offset to start searching from within the items array. Default 0. * @param direction The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1. */ - function SetScrollFactorY(items: G, value: number, step?: number, index?: integer, direction?: integer): G; + function SetScrollFactorY(items: G, value: number, step?: number, index?: number, direction?: number): G; /** * Takes an array of Game Objects, or any objects that have the public method setTint() and then updates it to the given value(s). You can specify tint color per corner or provide only one color value for `topLeft` parameter, in which case whole item will be tinted with that color. @@ -557,7 +559,7 @@ declare namespace Phaser { * @param index An optional offset to start searching from within the items array. Default 0. * @param direction The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1. */ - function SetVisible(items: G, value: boolean, index?: integer, direction?: integer): G; + function SetVisible(items: G, value: boolean, index?: number, direction?: number): G; /** * Takes an array of Game Objects, or any objects that have the public property `x` @@ -572,7 +574,7 @@ declare namespace Phaser { * @param index An optional offset to start searching from within the items array. Default 0. * @param direction The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1. */ - function SetX(items: G, value: number, step?: number, index?: integer, direction?: integer): G; + function SetX(items: G, value: number, step?: number, index?: number, direction?: number): G; /** * Takes an array of Game Objects, or any objects that have the public properties `x` and `y` @@ -589,7 +591,7 @@ declare namespace Phaser { * @param index An optional offset to start searching from within the items array. Default 0. * @param direction The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1. */ - function SetXY(items: G, x: number, y?: number, stepX?: number, stepY?: number, index?: integer, direction?: integer): G; + function SetXY(items: G, x: number, y?: number, stepX?: number, stepY?: number, index?: number, direction?: number): G; /** * Takes an array of Game Objects, or any objects that have the public property `y` @@ -604,7 +606,7 @@ declare namespace Phaser { * @param index An optional offset to start searching from within the items array. Default 0. * @param direction The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1. */ - function SetY(items: G, value: number, step?: number, index?: integer, direction?: integer): G; + function SetY(items: G, value: number, step?: number, index?: number, direction?: number): G; /** * Iterate through the items array changing the position of each element to be that of the element that came before @@ -619,7 +621,7 @@ declare namespace Phaser { * @param direction The iteration direction. 0 = first to last and 1 = last to first. Default 0. * @param output An optional objec to store the final objects position in. */ - function ShiftPosition(items: G, x: number, y: number, direction?: integer, output?: O): O; + function ShiftPosition(items: G, x: number, y: number, direction?: number, output?: O): O; /** * Shuffles the array in place. The shuffled array is both modified and returned. @@ -691,13 +693,18 @@ declare namespace Phaser { /** * A Frame based Animation. * - * This consists of a key, some default values (like the frame rate) and a bunch of Frame objects. + * Animations in Phaser consist of a sequence of `AnimationFrame` objects, which are managed by + * this class, along with properties that impact playback, such as the animations frame rate + * or delay. + * + * This class contains all of the properties and methods needed to handle playback of the animation + * directly to an `AnimationState` instance, which is owned by a Sprite, or similar Game Object. * - * The Animation Manager creates these. Game Objects don't own an instance of these directly. - * Game Objects have the Animation Component, which are like playheads to global Animations (these objects) - * So multiple Game Objects can have playheads all pointing to this one Animation instance. + * You don't typically create an instance of this class directly, but instead go via + * either the `AnimationManager` or the `AnimationState` and use their `create` methods, + * depending on if you need a global animation, or local to a specific Sprite. */ - class Animation extends Phaser.Events.EventEmitter { + class Animation { /** * * @param manager A reference to the global Animation Manager @@ -729,19 +736,19 @@ declare namespace Phaser { /** * The frame rate of playback in frames per second (default 24 if duration is null) */ - frameRate: integer; + frameRate: number; /** * How long the animation should play for, in milliseconds. * If the `frameRate` property has been set then it overrides this value, * otherwise the `frameRate` is derived from `duration`. */ - duration: integer; + duration: number; /** * How many ms per frame, not including frame specific modifiers. */ - msPerFrame: integer; + msPerFrame: number; /** * Skip frames if the time lags, or always advanced anyway? @@ -751,17 +758,17 @@ declare namespace Phaser { /** * The delay in ms before the playback will begin. */ - delay: integer; + delay: number; /** * Number of times to repeat the animation. Set to -1 to repeat forever. */ - repeat: integer; + repeat: number; /** * The delay in ms before the a repeat play starts. */ - repeatDelay: integer; + repeatDelay: number; /** * Should the animation yoyo (reverse back down to the start) before repeating? @@ -783,57 +790,65 @@ declare namespace Phaser { */ paused: boolean; + /** + * Gets the total number of frames in this animation. + */ + getTotalFrames(): number; + + /** + * Calculates the duration, frame rate and msPerFrame values. + * @param target The target to set the values on. + * @param totalFrames The total number of frames in the animation. + * @param duration The duration to calculate the frame rate from. + * @param frameRate The frame ate to calculate the duration from. + */ + calculateDuration(target: Phaser.Animations.Animation, totalFrames: number, duration: number, frameRate: number): void; + /** * Add frames to the end of the animation. - * @param config [description] + * @param config Either a string, in which case it will use all frames from a texture with the matching key, or an array of Animation Frame configuration objects. */ - addFrame(config: string | Phaser.Types.Animations.AnimationFrame[]): Phaser.Animations.Animation; + addFrame(config: string | Phaser.Types.Animations.AnimationFrame[]): this; /** * Add frame/s into the animation. * @param index The index to insert the frame at within the animation. - * @param config [description] + * @param config Either a string, in which case it will use all frames from a texture with the matching key, or an array of Animation Frame configuration objects. */ - addFrameAt(index: integer, config: string | Phaser.Types.Animations.AnimationFrame[]): Phaser.Animations.Animation; + addFrameAt(index: number, config: string | Phaser.Types.Animations.AnimationFrame[]): this; /** * Check if the given frame index is valid. * @param index The index to be checked. */ - checkFrame(index: integer): boolean; - - /** - * [description] - * @param component [description] - */ - protected completeAnimation(component: Phaser.GameObjects.Components.Animation): void; + checkFrame(index: number): boolean; /** - * [description] - * @param component [description] - * @param includeDelay [description] Default true. + * Called internally when this Animation first starts to play. + * Sets the accumulator and nextTick properties. + * @param state The Animation State belonging to the Game Object invoking this call. */ - protected getFirstTick(component: Phaser.GameObjects.Components.Animation, includeDelay?: boolean): void; + protected getFirstTick(state: Phaser.Animations.AnimationState): void; /** * Returns the AnimationFrame at the provided index * @param index The index in the AnimationFrame array */ - protected getFrameAt(index: integer): Phaser.Animations.AnimationFrame; + protected getFrameAt(index: number): Phaser.Animations.AnimationFrame; /** - * [description] - * @param textureManager [description] - * @param frames [description] - * @param defaultTextureKey [description] + * Creates AnimationFrame instances based on the given frame data. + * @param textureManager A reference to the global Texture Manager. + * @param frames Either a string, in which case it will use all frames from a texture with the matching key, or an array of Animation Frame configuration objects. + * @param defaultTextureKey The key to use if no key is set in the frame configuration object. */ getFrames(textureManager: Phaser.Textures.TextureManager, frames: string | Phaser.Types.Animations.AnimationFrame[], defaultTextureKey?: string): Phaser.Animations.AnimationFrame[]; /** - * [description] - * @param component [description] + * Called internally. Sets the accumulator and nextTick values of the current Animation. + * @param state The Animation State belonging to the Game Object invoking this call. */ - getNextTick(component: Phaser.GameObjects.Components.Animation): void; + getNextTick(state: Phaser.Animations.AnimationState): void; /** * Returns the frame closest to the given progress value between 0 and 1. @@ -843,9 +858,9 @@ declare namespace Phaser { /** * Advance the animation frame. - * @param component The Animation Component to advance. + * @param state The Animation State to advance. */ - nextFrame(component: Phaser.GameObjects.Components.Animation): void; + nextFrame(state: Phaser.Animations.AnimationState): void; /** * Returns the animation last frame. @@ -853,35 +868,32 @@ declare namespace Phaser { getLastFrame(): Phaser.Animations.AnimationFrame; /** - * [description] - * @param component [description] + * Called internally when the Animation is playing backwards. + * Sets the previous frame, causing a yoyo, repeat, complete or update, accordingly. + * @param state The Animation State belonging to the Game Object invoking this call. */ - previousFrame(component: Phaser.GameObjects.Components.Animation): void; + previousFrame(state: Phaser.Animations.AnimationState): void; /** - * [description] - * @param frame [description] + * Removes the given AnimationFrame from this Animation instance. + * This is a global action. Any Game Object using this Animation will be impacted by this change. + * @param frame The AnimationFrame to be removed. */ - removeFrame(frame: Phaser.Animations.AnimationFrame): Phaser.Animations.Animation; + removeFrame(frame: Phaser.Animations.AnimationFrame): this; /** * Removes a frame from the AnimationFrame array at the provided index * and updates the animation accordingly. * @param index The index in the AnimationFrame array */ - removeFrameAt(index: integer): Phaser.Animations.Animation; + removeFrameAt(index: number): this; /** - * [description] - * @param component [description] + * Called internally during playback. Forces the animation to repeat, providing there are enough counts left + * in the repeat counter. + * @param state The Animation State belonging to the Game Object invoking this call. */ - repeatAnimation(component: Phaser.GameObjects.Components.Animation): void; - - /** - * Sets the texture frame the animation uses for rendering. - * @param component [description] - */ - setFrame(component: Phaser.GameObjects.Components.Animation): void; + repeatAnimation(state: Phaser.Animations.AnimationState): void; /** * Converts the animation data to JSON. @@ -889,22 +901,24 @@ declare namespace Phaser { toJSON(): Phaser.Types.Animations.JSONAnimation; /** - * [description] + * Called internally whenever frames are added to, or removed from, this Animation. */ - updateFrameSequence(): Phaser.Animations.Animation; + updateFrameSequence(): this; /** - * [description] + * Pauses playback of this Animation. The paused state is set immediately. */ - pause(): Phaser.Animations.Animation; + pause(): this; /** - * [description] + * Resumes playback of this Animation. The paused state is reset immediately. */ - resume(): Phaser.Animations.Animation; + resume(): this; /** - * [description] + * Destroys this Animation instance. It will remove all event listeners, + * remove this animation and its key from the global Animation Manager, + * and then destroy all Animation Frames in turn. */ destroy(): void; @@ -925,8 +939,9 @@ declare namespace Phaser { * @param textureFrame The key of the Frame within the Texture that this AnimationFrame uses. * @param index The index of this AnimationFrame within the Animation sequence. * @param frame A reference to the Texture Frame this AnimationFrame uses for rendering. + * @param isKeyFrame Is this Frame a Keyframe within the Animation? Default false. */ - constructor(textureKey: string, textureFrame: string | integer, index: integer, frame: Phaser.Textures.Frame); + constructor(textureKey: string, textureFrame: string | number, index: number, frame: Phaser.Textures.Frame, isKeyFrame?: boolean); /** * The key of the Texture this AnimationFrame uses. @@ -936,12 +951,12 @@ declare namespace Phaser { /** * The key of the Frame within the Texture that this AnimationFrame uses. */ - textureFrame: string | integer; + textureFrame: string | number; /** * The index of this AnimationFrame within the Animation sequence. */ - index: integer; + index: number; /** * A reference to the Texture Frame this AnimationFrame uses for rendering. @@ -980,6 +995,11 @@ declare namespace Phaser { */ readonly progress: number; + /** + * Is this Frame a KeyFrame within the Animation? + */ + isKeyFrame: boolean; + /** * Generates a JavaScript object suitable for converting to JSON. */ @@ -1032,6 +1052,13 @@ declare namespace Phaser { */ protected anims: Phaser.Structs.Map; + /** + * A list of animation mix times. + * + * See the {@link #setMix} method for more details. + */ + mixes: Phaser.Structs.Map; + /** * Whether the Animation Manager is paused along with all of its Animations. */ @@ -1047,12 +1074,64 @@ declare namespace Phaser { */ boot(): void; + /** + * Adds a mix between two animations. + * + * Mixing allows you to specify a unique delay between a pairing of animations. + * + * When playing Animation A on a Game Object, if you then play Animation B, and a + * mix exists, it will wait for the specified delay to be over before playing Animation B. + * + * This allows you to customise smoothing between different types of animation, such + * as blending between an idle and a walk state, or a running and a firing state. + * + * Note that mixing is only applied if you use the `Sprite.play` method. If you opt to use + * `playAfterRepeat` or `playAfterDelay` instead, those will take pririty and the mix + * delay will not be used. + * + * To update an existing mix, just call this method with the new delay. + * + * To remove a mix pairing, see the `removeMix` method. + * @param animA The string-based key, or instance of, Animation A. + * @param animB The string-based key, or instance of, Animation B. + * @param delay The delay, in milliseconds, to wait when transitioning from Animation A to B. + */ + addMix(animA: string | Phaser.Animations.Animation, animB: string | Phaser.Animations.Animation, delay: number): this; + + /** + * Removes a mix between two animations. + * + * Mixing allows you to specify a unique delay between a pairing of animations. + * + * Calling this method lets you remove those pairings. You can either remove + * it between `animA` and `animB`, or if you do not provide the `animB` parameter, + * it will remove all `animA` mixes. + * + * If you wish to update an existing mix instead, call the `addMix` method with the + * new delay. + * @param animA The string-based key, or instance of, Animation A. + * @param animB The string-based key, or instance of, Animation B. If not given, all mixes for Animation A will be removed. + */ + removeMix(animA: string | Phaser.Animations.Animation, animB?: string | Phaser.Animations.Animation): this; + + /** + * Returns the mix delay between two animations. + * + * If no mix has been set-up, this method will return zero. + * + * If you wish to create, or update, a new mix, call the `addMix` method. + * If you wish to remove a mix, call the `removeMix` method. + * @param animA The string-based key, or instance of, Animation A. + * @param animB The string-based key, or instance of, Animation B. + */ + getMix(animA: string | Phaser.Animations.Animation, animB: string | Phaser.Animations.Animation): number; + /** * Adds an existing Animation to the Animation Manager. * @param key The key under which the Animation should be added. The Animation will be updated with it. Must be unique. * @param animation The Animation which should be added to the Animation Manager. */ - add(key: string, animation: Phaser.Animations.Animation): Phaser.Animations.AnimationManager; + add(key: string, animation: Phaser.Animations.Animation): this; /** * Checks to see if the given key is already in use within the Animation Manager or not. @@ -1062,6 +1141,78 @@ declare namespace Phaser { */ exists(key: string): boolean; + /** + * Create one, or more animations from a loaded Aseprite JSON file. + * + * Aseprite is a powerful animated sprite editor and pixel art tool. + * + * You can find more details at https://www.aseprite.org/ + * + * To export a compatible JSON file in Aseprite, please do the following: + * + * 1. Go to "File - Export Sprite Sheet" + * + * 2. On the **Layout** tab: + * 2a. Set the "Sheet type" to "Packed" + * 2b. Set the "Constraints" to "None" + * 2c. Check the "Merge Duplicates" checkbox + * + * 3. On the **Sprite** tab: + * 3a. Set "Layers" to "Visible layers" + * 3b. Set "Frames" to "All frames", unless you only wish to export a sub-set of tags + * + * 4. On the **Borders** tab: + * 4a. Check the "Trim Sprite" and "Trim Cells" options + * 4b. Ensure "Border Padding", "Spacing" and "Inner Padding" are all > 0 (1 is usually enough) + * + * 5. On the **Output** tab: + * 5a. Check "Output File", give your image a name and make sure you choose "png files" as the file type + * 5b. Check "JSON Data" and give your json file a name + * 5c. The JSON Data type can be either a Hash or Array, Phaser doesn't mind. + * 5d. Make sure "Tags" is checked in the Meta options + * 5e. In the "Item Filename" input box, make sure it says just "{frame}" and nothing more. + * + * 6. Click export + * + * This was tested with Aseprite 1.2.25. + * + * This will export a png and json file which you can load using the Aseprite Loader, i.e.: + * + * ```javascript + * function preload () + * { + * this.load.path = 'assets/animations/aseprite/'; + * this.load.aseprite('paladin', 'paladin.png', 'paladin.json'); + * } + * ``` + * + * Once loaded, you can call this method from within a Scene with the 'atlas' key: + * + * ```javascript + * this.anims.createFromAseprite('paladin'); + * ``` + * + * Any animations defined in the JSON will now be available to use in Phaser and you play them + * via their Tag name. For example, if you have an animation called 'War Cry' on your Aseprite timeline, + * you can play it in Phaser using that Tag name: + * + * ```javascript + * this.add.sprite(400, 300).play('War Cry'); + * ``` + * + * When calling this method you can optionally provide an array of tag names, and only those animations + * will be created. For example: + * + * ```javascript + * this.anims.createFromAseprite('paladin', [ 'step', 'War Cry', 'Magnum Break' ]); + * ``` + * + * This will only create the 3 animations defined. Note that the tag names are case-sensitive. + * @param key The key of the loaded Aseprite atlas. It must have been loaded prior to calling this method. + * @param tags An array of Tag names. If provided, only animations found in this array will be created. + */ + createFromAseprite(key: string, tags?: string[]): Phaser.Animations.Animation[]; + /** * Creates a new Animation and adds it to the Animation Manager. * @@ -1086,7 +1237,34 @@ declare namespace Phaser { fromJSON(data: string | Phaser.Types.Animations.JSONAnimations | Phaser.Types.Animations.JSONAnimation, clearCurrentAnimations?: boolean): Phaser.Animations.Animation[]; /** - * [description] + * Generate an array of {@link Phaser.Types.Animations.AnimationFrame} objects from a texture key and configuration object. + * + * Generates objects with string based frame names, as configured by the given {@link Phaser.Types.Animations.GenerateFrameNames}. + * + * It's a helper method, designed to make it easier for you to extract all of the frame names from texture atlases. + * If you're working with a sprite sheet, see the `generateFrameNumbers` method instead. + * + * Example: + * + * If you have a texture atlases loaded called `gems` and it contains 6 frames called `ruby_0001`, `ruby_0002`, and so on, + * then you can call this method using: `this.anims.generateFrameNames('gems', { prefix: 'ruby_', end: 6, zeroPad: 4 })`. + * + * The `end` value tells it to look for 6 frames, incrementally numbered, all starting with the prefix `ruby_`. The `zeroPad` + * value tells it how many zeroes pad out the numbers. To create an animation using this method, you can do: + * + * ```javascript + * this.anims.create({ + * key: 'ruby', + * repeat: -1, + * frames: this.anims.generateFrameNames('gems', { + * prefix: 'ruby_', + * end: 6, + * zeroPad: 4 + * }) + * }); + * ``` + * + * Please see the animation examples for further details. * @param key The key for the texture containing the animation frames. * @param config The configuration object for the animation frame names. */ @@ -1096,6 +1274,38 @@ declare namespace Phaser { * Generate an array of {@link Phaser.Types.Animations.AnimationFrame} objects from a texture key and configuration object. * * Generates objects with numbered frame names, as configured by the given {@link Phaser.Types.Animations.GenerateFrameNumbers}. + * + * If you're working with a texture atlas, see the `generateFrameNames` method instead. + * + * It's a helper method, designed to make it easier for you to extract frames from sprite sheets. + * If you're working with a texture atlas, see the `generateFrameNames` method instead. + * + * Example: + * + * If you have a sprite sheet loaded called `explosion` and it contains 12 frames, then you can call this method using: + * `this.anims.generateFrameNumbers('explosion', { start: 0, end: 12 })`. + * + * The `end` value tells it to stop after 12 frames. To create an animation using this method, you can do: + * + * ```javascript + * this.anims.create({ + * key: 'boom', + * frames: this.anims.generateFrameNames('explosion', { + * start: 0, + * end: 12 + * }) + * }); + * ``` + * + * Note that `start` is optional and you don't need to include it if the animation starts from frame 0. + * + * To specify an animation in reverse, swap the `start` and `end` values. + * + * If the frames are not sequential, you may pass an array of frame numbers instead, for example: + * + * `this.anims.generateFrameNumbers('explosion', { frames: [ 0, 1, 2, 1, 2, 3, 4, 0, 1, 2 ] })` + * + * Please see the animation examples and `GenerateFrameNumbers` config docs for further details. * @param key The key for the texture containing the animation frames. * @param config The configuration object for the animation frames. */ @@ -1108,27 +1318,55 @@ declare namespace Phaser { get(key: string): Phaser.Animations.Animation; /** - * Load an Animation into a Game Object's Animation Component. - * @param child The Game Object to load the animation into. - * @param key The key of the animation to load. - * @param startFrame The name of a start frame to set on the loaded animation. + * Pause all animations. */ - load(child: Phaser.GameObjects.GameObject, key: string, startFrame?: string | integer): Phaser.GameObjects.GameObject; + pauseAll(): this; /** - * Pause all animations. + * Play an animation on the given Game Objects that have an Animation Component. + * @param key The string-based key of the animation to play, or an Animation instance, or a `PlayAnimationConfig` object. + * @param children An array of Game Objects to play the animation on. They must have an Animation Component. */ - pauseAll(): Phaser.Animations.AnimationManager; + play(key: string | Phaser.Animations.Animation | Phaser.Types.Animations.PlayAnimationConfig, children: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[]): this; /** - * Play an animation on the given Game Objects that have an Animation Component. - * @param key The key of the animation to play on the Game Object. - * @param child The Game Objects to play the animation on. + * Takes an array of Game Objects that have an Animation Component and then + * starts the given animation playing on them. The start time of each Game Object + * is offset, incrementally, by the `stagger` amount. + * + * For example, if you pass an array with 4 children and a stagger time of 1000, + * the delays will be: + * + * child 1: 1000ms delay + * child 2: 2000ms delay + * child 3: 3000ms delay + * child 4: 4000ms delay + * + * If you set the `staggerFirst` parameter to `false` they would be: + * + * child 1: 0ms delay + * child 2: 1000ms delay + * child 3: 2000ms delay + * child 4: 3000ms delay + * + * You can also set `stagger` to be a negative value. If it was -1000, the above would be: + * + * child 1: 3000ms delay + * child 2: 2000ms delay + * child 3: 1000ms delay + * child 4: 0ms delay + * @param key The string-based key of the animation to play, or an Animation instance, or a `PlayAnimationConfig` object. + * @param children An array of Game Objects to play the animation on. They must have an Animation Component. + * @param stagger The amount of time, in milliseconds, to offset each play time by. If a negative value is given, it's applied to the children in reverse order. + * @param staggerFirst Should the first child be staggered as well? Default true. */ - play(key: string, child: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[]): Phaser.Animations.AnimationManager; + staggerPlay(key: string | Phaser.Animations.Animation | Phaser.Types.Animations.PlayAnimationConfig, children: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[], stagger: number, staggerFirst?: boolean): G; /** - * Remove an animation. + * Removes an Animation from this Animation Manager, based on the given key. + * + * This is a global action. Once an Animation has been removed, no Game Objects + * can carry on using it. * @param key The key of the animation to remove. */ remove(key: string): Phaser.Animations.Animation; @@ -1136,23 +1374,14 @@ declare namespace Phaser { /** * Resume all paused animations. */ - resumeAll(): Phaser.Animations.AnimationManager; - - /** - * Takes an array of Game Objects that have an Animation Component and then - * starts the given animation playing on them, each one offset by the - * `stagger` amount given to this method. - * @param key The key of the animation to play on the Game Objects. - * @param children An array of Game Objects to play the animation on. They must have an Animation Component. - * @param stagger The amount of time, in milliseconds, to offset each play time by. Default 0. - */ - staggerPlay(key: string, children: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[], stagger?: number): G; + resumeAll(): this; /** - * Get the animation data as javascript object by giving key, or get the data of all animations as array of objects, if key wasn't provided. - * @param key [description] + * Returns the Animation data as JavaScript object based on the given key. + * Or, if not key is defined, it will return the data of all animations as array of objects. + * @param key The animation to get the JSONAnimation data from. If not provided, all animations are returned as an array. */ - toJSON(key: string): Phaser.Types.Animations.JSONAnimations; + toJSON(key?: string): Phaser.Types.Animations.JSONAnimations; /** * Destroy this Animation Manager and clean up animation definitions and references to other objects. @@ -1162,426 +1391,1196 @@ declare namespace Phaser { } - namespace Events { + /** + * The Animation State Component. + * + * This component provides features to apply animations to Game Objects. It is responsible for + * loading, queuing animations for later playback, mixing between animations and setting + * the current animation frame to the Game Object that owns this component. + * + * This component lives as an instance within any Game Object that has it defined, such as Sprites. + * + * You can access its properties and methods via the `anims` property, i.e. `Sprite.anims`. + * + * As well as playing animations stored in the global Animation Manager, this component + * can also create animations that are stored locally within it. See the `create` method + * for more details. + * + * Prior to Phaser 3.50 this component was called just `Animation` and lived in the + * `Phaser.GameObjects.Components` namespace. It was renamed to `AnimationState` + * in 3.50 to help better identify its true purpose when browsing the documentation. + */ + class AnimationState { /** - * The Add Animation Event. - * - * This event is dispatched when a new animation is added to the global Animation Manager. * - * This can happen either as a result of an animation instance being added to the Animation Manager, - * or the Animation Manager creating a new animation directly. + * @param parent The Game Object to which this animation component belongs. */ - const ADD_ANIMATION: any; + constructor(parent: Phaser.GameObjects.GameObject); /** - * The Animation Complete Event. + * The Game Object to which this animation component belongs. * - * This event is dispatched by an Animation instance when it completes, i.e. finishes playing or is manually stopped. + * You can typically access this component from the Game Object + * via the `this.anims` property. + */ + parent: Phaser.GameObjects.GameObject; + + /** + * A reference to the global Animation Manager. + */ + animationManager: Phaser.Animations.AnimationManager; + + /** + * A reference to the Texture Manager. + */ + protected textureManager: Phaser.Textures.TextureManager; + + /** + * The Animations stored locally in this Animation component. * - * Be careful with the volume of events this could generate. If a group of Sprites all complete the same - * animation at the same time, this event will invoke its handler for each one of them. + * Do not modify the contents of this Map directly, instead use the + * `add`, `create` and `remove` methods of this class instead. */ - const ANIMATION_COMPLETE: any; + protected anims: Phaser.Structs.Map; /** - * The Animation Repeat Event. + * Is an animation currently playing or not? + */ + isPlaying: boolean; + + /** + * Has the current animation started playing, or is it waiting for a delay to expire? + */ + hasStarted: boolean; + + /** + * The current Animation loaded into this Animation component. * - * This event is dispatched when a currently playing animation repeats. + * Will by `null` if no animation is yet loaded. + */ + currentAnim: Phaser.Animations.Animation; + + /** + * The current AnimationFrame being displayed by this Animation component. * - * The event is dispatched directly from the Animation object itself. Which means that listeners - * bound to this event will be invoked every time the Animation repeats, for every Game Object that may have it. + * Will by `null` if no animation is yet loaded. */ - const ANIMATION_REPEAT: any; + currentFrame: Phaser.Animations.AnimationFrame; /** - * The Animation Restart Event. + * The key, instance, or config of the next Animation to be loaded into this Animation component + * when the current animation completes. * - * This event is dispatched by an Animation instance when it restarts. + * Will by `null` if no animation has been queued. + */ + nextAnim: string | Phaser.Animations.Animation | Phaser.Types.Animations.PlayAnimationConfig; + + /** + * A queue of Animations to be loaded into this Animation component when the current animation completes. * - * Be careful with the volume of events this could generate. If a group of Sprites all restart the same - * animation at the same time, this event will invoke its handler for each one of them. + * Populate this queue via the `chain` method. */ - const ANIMATION_RESTART: any; + nextAnimsQueue: any[]; /** - * The Animation Start Event. + * The Time Scale factor. + * + * You can adjust this value to modify the passage of time for the animation that is currently + * playing. For example, setting it to 2 will make the animation play twice as fast. Or setting + * it to 0.5 will slow the animation down. * - * This event is dispatched by an Animation instance when it starts playing. + * You can change this value at run-time, or set it via the `PlayAnimationConfig`. * - * Be careful with the volume of events this could generate. If a group of Sprites all play the same - * animation at the same time, this event will invoke its handler for each one of them. + * Prior to Phaser 3.50 this property was private and called `_timeScale`. */ - const ANIMATION_START: any; + timeScale: number; /** - * The Pause All Animations Event. + * The frame rate of playback, of the current animation, in frames per second. * - * This event is dispatched when the global Animation Manager is told to pause. + * This value is set when a new animation is loaded into this component and should + * be treated as read-only, as changing it once playback has started will not alter + * the animation. To change the frame rate, provide a new value in the `PlayAnimationConfig` object. + */ + frameRate: number; + + /** + * The duration of the current animation, in milliseconds. * - * When this happens all current animations will stop updating, although it doesn't necessarily mean - * that the game has paused as well. + * This value is set when a new animation is loaded into this component and should + * be treated as read-only, as changing it once playback has started will not alter + * the animation. To change the duration, provide a new value in the `PlayAnimationConfig` object. */ - const PAUSE_ALL: any; + duration: number; /** - * The Remove Animation Event. + * The number of milliseconds per frame, not including frame specific modifiers that may be present in the + * Animation data. * - * This event is dispatched when an animation is removed from the global Animation Manager. + * This value is calculated when a new animation is loaded into this component and should + * be treated as read-only. Changing it will not alter playback speed. */ - const REMOVE_ANIMATION: any; + msPerFrame: number; /** - * The Resume All Animations Event. + * Skip frames if the time lags, or always advanced anyway? + */ + skipMissedFrames: boolean; + + /** + * The delay before starting playback of the current animation, in milliseconds. * - * This event is dispatched when the global Animation Manager resumes, having been previously paused. + * This value is set when a new animation is loaded into this component and should + * be treated as read-only, as changing it once playback has started will not alter + * the animation. To change the delay, provide a new value in the `PlayAnimationConfig` object. * - * When this happens all current animations will continue updating again. + * Prior to Phaser 3.50 this property was private and called `_delay`. */ - const RESUME_ALL: any; + delay: number; /** - * The Sprite Animation Complete Event. + * The number of times to repeat playback of the current animation. * - * This event is dispatched by a Sprite when an animation finishes playing on it. + * If -1, it means the animation will repeat forever. * - * Listen for it on the Sprite using `sprite.on('animationcomplete', listener)` + * This value is set when a new animation is loaded into this component and should + * be treated as read-only, as changing it once playback has started will not alter + * the animation. To change the number of repeats, provide a new value in the `PlayAnimationConfig` object. * - * This same event is dispatched for all animations. To listen for a specific animation, use the `SPRITE_ANIMATION_KEY_COMPLETE` event. + * Prior to Phaser 3.50 this property was private and called `_repeat`. */ - const SPRITE_ANIMATION_COMPLETE: any; + repeat: number; /** - * The Sprite Animation Key Complete Event. + * The number of milliseconds to wait before starting the repeat playback of the current animation. * - * This event is dispatched by a Sprite when a specific animation finishes playing on it. + * This value is set when a new animation is loaded into this component, but can also be modified + * at run-time. * - * Listen for it on the Sprite using `sprite.on('animationcomplete-key', listener)` where `key` is the key of - * the animation. For example, if you had an animation with the key 'explode' you should listen for `animationcomplete-explode`. + * You can change the repeat delay by providing a new value in the `PlayAnimationConfig` object. + * + * Prior to Phaser 3.50 this property was private and called `_repeatDelay`. */ - const SPRITE_ANIMATION_KEY_COMPLETE: any; + repeatDelay: number; /** - * The Sprite Animation Key Repeat Event. + * Should the current animation yoyo? An animation that yoyos will play in reverse, from the end + * to the start, before then repeating or completing. An animation that does not yoyo will just + * play from the start to the end. + * + * This value is set when a new animation is loaded into this component, but can also be modified + * at run-time. * - * This event is dispatched by a Sprite when a specific animation repeats playing on it. + * You can change the yoyo by providing a new value in the `PlayAnimationConfig` object. * - * Listen for it on the Sprite using `sprite.on('animationrepeat-key', listener)` where `key` is the key of - * the animation. For example, if you had an animation with the key 'explode' you should listen for `animationrepeat-explode`. + * Prior to Phaser 3.50 this property was private and called `_yoyo`. */ - const SPRITE_ANIMATION_KEY_REPEAT: any; + yoyo: boolean; /** - * The Sprite Animation Key Restart Event. + * Should the GameObject's `visible` property be set to `true` when the animation starts to play? * - * This event is dispatched by a Sprite when a specific animation restarts playing on it. + * This will happen _after_ any delay that may have been set. * - * Listen for it on the Sprite using `sprite.on('animationrestart-key', listener)` where `key` is the key of - * the animation. For example, if you had an animation with the key 'explode' you should listen for `animationrestart-explode`. + * This value is set when a new animation is loaded into this component, but can also be modified + * at run-time, assuming the animation is currently delayed. */ - const SPRITE_ANIMATION_KEY_RESTART: any; + showOnStart: boolean; /** - * The Sprite Animation Key Start Event. - * - * This event is dispatched by a Sprite when a specific animation starts playing on it. + * Should the GameObject's `visible` property be set to `false` when the animation completes? * - * Listen for it on the Sprite using `sprite.on('animationstart-key', listener)` where `key` is the key of - * the animation. For example, if you had an animation with the key 'explode' you should listen for `animationstart-explode`. + * This value is set when a new animation is loaded into this component, but can also be modified + * at run-time, assuming the animation is still actively playing. + */ + hideOnComplete: boolean; + + /** + * Is the playhead moving forwards (`true`) or in reverse (`false`) ? */ - const SPRITE_ANIMATION_KEY_START: any; + forward: boolean; /** - * The Sprite Animation Key Update Event. + * An internal trigger that tells the component if it should plays the animation + * in reverse mode ('true') or not ('false'). This is used because `forward` can + * be changed by the `yoyo` feature. * - * This event is dispatched by a Sprite when a specific animation playing on it updates. This happens when the animation changes frame, - * based on the animation frame rate and other factors like `timeScale` and `delay`. + * Prior to Phaser 3.50 this property was private and called `_reverse`. + */ + inReverse: boolean; + + /** + * Internal time overflow accumulator. * - * Listen for it on the Sprite using `sprite.on('animationupdate-key', listener)` where `key` is the key of - * the animation. For example, if you had an animation with the key 'explode' you should listen for `animationupdate-explode`. + * This has the `delta` time added to it as part of the `update` step. */ - const SPRITE_ANIMATION_KEY_UPDATE: any; + accumulator: number; /** - * The Sprite Animation Repeat Event. + * The time point at which the next animation frame will change. * - * This event is dispatched by a Sprite when an animation repeats playing on it. + * This value is compared against the `accumulator` as part of the `update` step. + */ + nextTick: number; + + /** + * A counter keeping track of how much delay time, in milliseconds, is left before playback begins. * - * Listen for it on the Sprite using `sprite.on('animationrepeat', listener)` + * This is set via the `playAfterDelay` method, although it can be modified at run-time + * if required, as long as the animation has not already started playing. + */ + delayCounter: number; + + /** + * A counter that keeps track of how many repeats are left to run. * - * This same event is dispatched for all animations. To listen for a specific animation, use the `SPRITE_ANIMATION_KEY_REPEAT` event. + * This value is set when a new animation is loaded into this component, but can also be modified + * at run-time. + */ + repeatCounter: number; + + /** + * An internal flag keeping track of pending repeats. */ - const SPRITE_ANIMATION_REPEAT: any; + pendingRepeat: boolean; /** - * The Sprite Animation Restart Event. + * Sets an animation, or an array of animations, to be played in the future, after the current one completes or stops. * - * This event is dispatched by a Sprite when an animation restarts playing on it. + * The current animation must enter a 'completed' state for this to happen, i.e. finish all of its repeats, delays, etc, + * or have one of the `stop` methods called. * - * Listen for it on the Sprite using `sprite.on('animationrestart', listener)` + * An animation set to repeat forever will never enter a completed state unless stopped. + * + * You can chain a new animation at any point, including before the current one starts playing, during it, or when it ends (via its `animationcomplete` event). + * + * Chained animations are specific to a Game Object, meaning different Game Objects can have different chained animations without impacting the global animation they're playing. * - * This same event is dispatched for all animations. To listen for a specific animation, use the `SPRITE_ANIMATION_KEY_RESTART` event. + * Call this method with no arguments to reset all currently chained animations. + * @param key The string-based key of the animation to play, or an Animation instance, or a `PlayAnimationConfig` object, or an array of them. */ - const SPRITE_ANIMATION_RESTART: any; + chain(key: string | Phaser.Animations.Animation | Phaser.Types.Animations.PlayAnimationConfig | string[] | Phaser.Animations.Animation[] | Phaser.Types.Animations.PlayAnimationConfig[]): Phaser.GameObjects.GameObject; /** - * The Sprite Animation Start Event. - * - * This event is dispatched by a Sprite when an animation starts playing on it. - * - * Listen for it on the Sprite using `sprite.on('animationstart', listener)` + * Returns the key of the animation currently loaded into this component. * - * This same event is dispatched for all animations. To listen for a specific animation, use the `SPRITE_ANIMATION_KEY_START` event. + * Prior to Phaser 3.50 this method was called `getCurrentKey`. */ - const SPRITE_ANIMATION_START: any; + getName(): string; /** - * The Sprite Animation Update Event. + * Returns the key of the animation frame currently displayed by this component. + */ + getFrameName(): string; + + /** + * Internal method used to load an animation into this component. + * @param key The string-based key of the animation to play, or a `PlayAnimationConfig` object. + */ + protected load(key: string | Phaser.Types.Animations.PlayAnimationConfig): Phaser.GameObjects.GameObject; + + /** + * Pause the current animation and set the `isPlaying` property to `false`. + * You can optionally pause it at a specific frame. + * @param atFrame An optional frame to set after pausing the animation. + */ + pause(atFrame?: Phaser.Animations.AnimationFrame): Phaser.GameObjects.GameObject; + + /** + * Resumes playback of a paused animation and sets the `isPlaying` property to `true`. + * You can optionally tell it to start playback from a specific frame. + * @param fromFrame An optional frame to set before restarting playback. + */ + resume(fromFrame?: Phaser.Animations.AnimationFrame): Phaser.GameObjects.GameObject; + + /** + * Waits for the specified delay, in milliseconds, then starts playback of the given animation. * - * This event is dispatched by a Sprite when an animation playing on it updates. This happens when the animation changes frame, - * based on the animation frame rate and other factors like `timeScale` and `delay`. + * If the animation _also_ has a delay value set in its config, it will be **added** to the delay given here. * - * Listen for it on the Sprite using `sprite.on('animationupdate', listener)` + * If an animation is already running and a new animation is given to this method, it will wait for + * the given delay before starting the new animation. + * + * If no animation is currently running, the given one begins after the delay. * - * This same event is dispatched for all animations. To listen for a specific animation, use the `SPRITE_ANIMATION_KEY_UPDATE` event. + * Prior to Phaser 3.50 this method was called 'delayedPlay' and the parameters were in the reverse order. + * @param key The string-based key of the animation to play, or an Animation instance, or a `PlayAnimationConfig` object. + * @param delay The delay, in milliseconds, to wait before starting the animation playing. */ - const SPRITE_ANIMATION_UPDATE: any; - - } + playAfterDelay(key: string | Phaser.Animations.Animation | Phaser.Types.Animations.PlayAnimationConfig, delay: number): Phaser.GameObjects.GameObject; - } - - namespace Cache { - /** - * The BaseCache is a base Cache class that can be used for storing references to any kind of data. - * - * Data can be added, retrieved and removed based on the given keys. - * - * Keys are string-based. - */ - class BaseCache { /** - * The Map in which the cache objects are stored. + * Waits for the current animation to complete the `repeatCount` number of repeat cycles, then starts playback + * of the given animation. * - * You can query the Map directly or use the BaseCache methods. + * You can use this to ensure there are no harsh jumps between two sets of animations, i.e. going from an + * idle animation to a walking animation, by making them blend smoothly into each other. + * + * If no animation is currently running, the given one will start immediately. + * @param key The string-based key of the animation to play, or an Animation instance, or a `PlayAnimationConfig` object. + * @param repeatCount How many times should the animation repeat before the next one starts? Default 1. */ - entries: Phaser.Structs.Map; + playAfterRepeat(key: string | Phaser.Animations.Animation | Phaser.Types.Animations.PlayAnimationConfig, repeatCount?: number): Phaser.GameObjects.GameObject; /** - * An instance of EventEmitter used by the cache to emit related events. + * Start playing the given animation on this Sprite. + * + * Animations in Phaser can either belong to the global Animation Manager, or specifically to this Sprite. + * + * The benefit of a global animation is that multiple Sprites can all play the same animation, without + * having to duplicate the data. You can just create it once and then play it on any Sprite. + * + * The following code shows how to create a global repeating animation. The animation will be created + * from all of the frames within the sprite sheet that was loaded with the key 'muybridge': + * + * ```javascript + * var config = { + * key: 'run', + * frames: 'muybridge', + * frameRate: 15, + * repeat: -1 + * }; + * + * // This code should be run from within a Scene: + * this.anims.create(config); + * ``` + * + * However, if you wish to create an animation that is unique to this Sprite, and this Sprite alone, + * you can call the `Animation.create` method instead. It accepts the exact same parameters as when + * creating a global animation, however the resulting data is kept locally in this Sprite. + * + * With the animation created, either globally or locally, you can now play it on this Sprite: + * + * ```javascript + * this.add.sprite(x, y).play('run'); + * ``` + * + * Alternatively, if you wish to run it at a different frame rate, for example, you can pass a config + * object instead: + * + * ```javascript + * this.add.sprite(x, y).play({ key: 'run', frameRate: 24 }); + * ``` + * + * When playing an animation on a Sprite it will first check to see if it can find a matching key + * locally within the Sprite. If it can, it will play the local animation. If not, it will then + * search the global Animation Manager and look for it there. + * + * If you need a Sprite to be able to play both local and global animations, make sure they don't + * have conflicting keys. + * + * See the documentation for the `PlayAnimationConfig` config object for more details about this. + * + * Also, see the documentation in the Animation Manager for further details on creating animations. + * @param key The string-based key of the animation to play, or an Animation instance, or a `PlayAnimationConfig` object. + * @param ignoreIfPlaying If this animation is already playing then ignore this call. Default false. */ - events: Phaser.Events.EventEmitter; + play(key: string | Phaser.Animations.Animation | Phaser.Types.Animations.PlayAnimationConfig, ignoreIfPlaying?: boolean): Phaser.GameObjects.GameObject; /** - * Adds an item to this cache. The item is referenced by a unique string, which you are responsible - * for setting and keeping track of. The item can only be retrieved by using this string. - * @param key The unique key by which the data added to the cache will be referenced. - * @param data The data to be stored in the cache. + * Start playing the given animation on this Sprite, in reverse. + * + * Animations in Phaser can either belong to the global Animation Manager, or specifically to this Sprite. + * + * The benefit of a global animation is that multiple Sprites can all play the same animation, without + * having to duplicate the data. You can just create it once and then play it on any Sprite. + * + * The following code shows how to create a global repeating animation. The animation will be created + * from all of the frames within the sprite sheet that was loaded with the key 'muybridge': + * + * ```javascript + * var config = { + * key: 'run', + * frames: 'muybridge', + * frameRate: 15, + * repeat: -1 + * }; + * + * // This code should be run from within a Scene: + * this.anims.create(config); + * ``` + * + * However, if you wish to create an animation that is unique to this Sprite, and this Sprite alone, + * you can call the `Animation.create` method instead. It accepts the exact same parameters as when + * creating a global animation, however the resulting data is kept locally in this Sprite. + * + * With the animation created, either globally or locally, you can now play it on this Sprite: + * + * ```javascript + * this.add.sprite(x, y).playReverse('run'); + * ``` + * + * Alternatively, if you wish to run it at a different frame rate, for example, you can pass a config + * object instead: + * + * ```javascript + * this.add.sprite(x, y).playReverse({ key: 'run', frameRate: 24 }); + * ``` + * + * When playing an animation on a Sprite it will first check to see if it can find a matching key + * locally within the Sprite. If it can, it will play the local animation. If not, it will then + * search the global Animation Manager and look for it there. + * + * If you need a Sprite to be able to play both local and global animations, make sure they don't + * have conflicting keys. + * + * See the documentation for the `PlayAnimationConfig` config object for more details about this. + * + * Also, see the documentation in the Animation Manager for further details on creating animations. + * @param key The string-based key of the animation to play, or an Animation instance, or a `PlayAnimationConfig` object. + * @param ignoreIfPlaying If an animation is already playing then ignore this call. Default false. */ - add(key: string, data: any): Phaser.Cache.BaseCache; + playReverse(key: string | Phaser.Animations.Animation | Phaser.Types.Animations.PlayAnimationConfig, ignoreIfPlaying?: boolean): Phaser.GameObjects.GameObject; /** - * Checks if this cache contains an item matching the given key. - * This performs the same action as `BaseCache.exists`. - * @param key The unique key of the item to be checked in this cache. + * Load the animation based on the key and set-up all of the internal values + * needed for playback to start. If there is no delay, it will also fire the start events. + * @param key The string-based key of the animation to play, or a `PlayAnimationConfig` object. */ - has(key: string): boolean; + startAnimation(key: string | Phaser.Types.Animations.PlayAnimationConfig): Phaser.GameObjects.GameObject; /** - * Checks if this cache contains an item matching the given key. - * This performs the same action as `BaseCache.has` and is called directly by the Loader. - * @param key The unique key of the item to be checked in this cache. + * Reverse the Animation that is already playing on the Game Object. */ - exists(key: string): boolean; + reverse(): Phaser.GameObjects.GameObject; /** - * Gets an item from this cache based on the given key. - * @param key The unique key of the item to be retrieved from this cache. + * Returns a value between 0 and 1 indicating how far this animation is through, ignoring repeats and yoyos. + * + * The value is based on the current frame and how far that is in the animation, it is not based on + * the duration of the animation. */ - get(key: string): any; + getProgress(): number; /** - * Removes and item from this cache based on the given key. + * Takes a value between 0 and 1 and uses it to set how far this animation is through playback. * - * If an entry matching the key is found it is removed from the cache and a `remove` event emitted. - * No additional checks are done on the item removed. If other systems or parts of your game code - * are relying on this item, it is up to you to sever those relationships prior to removing the item. - * @param key The unique key of the item to remove from the cache. + * Does not factor in repeats or yoyos, but does handle playing forwards or backwards. + * + * The value is based on the current frame and how far that is in the animation, it is not based on + * the duration of the animation. + * @param value The progress value, between 0 and 1. Default 0. */ - remove(key: string): Phaser.Cache.BaseCache; + setProgress(value?: number): Phaser.GameObjects.GameObject; /** - * Returns all keys in use in this cache. + * Sets the number of times that the animation should repeat after its first play through. + * For example, if repeat is 1, the animation will play a total of twice: the initial play plus 1 repeat. + * + * To repeat indefinitely, use -1. + * The value should always be an integer. + * + * Calling this method only works if the animation is already running. Otherwise, any + * value specified here will be overwritten when the next animation loads in. To avoid this, + * use the `repeat` property of the `PlayAnimationConfig` object instead. + * @param value The number of times that the animation should repeat. */ - getKeys(): string[]; + setRepeat(value: number): Phaser.GameObjects.GameObject; /** - * Destroys this cache and all items within it. + * Handle the removal of an animation from the Animation Manager. + * @param key The key of the removed Animation. + * @param animation The removed Animation. */ - destroy(): void; + globalRemove(key?: string, animation?: Phaser.Animations.Animation): void; - } + /** + * Restarts the current animation from its beginning. + * + * You can optionally reset the delay and repeat counters as well. + * + * Calling this will fire the `ANIMATION_RESTART` event immediately. + * + * If you `includeDelay` then it will also fire the `ANIMATION_START` event once + * the delay has expired, otherwise, playback will just begin immediately. + * @param includeDelay Whether to include the delay value of the animation when restarting. Default false. + * @param resetRepeats Whether to reset the repeat counter or not? Default false. + */ + restart(includeDelay?: boolean, resetRepeats?: boolean): Phaser.GameObjects.GameObject; - /** - * The Cache Manager is the global cache owned and maintained by the Game instance. - * - * Various systems, such as the file Loader, rely on this cache in order to store the files - * it has loaded. The manager itself doesn't store any files, but instead owns multiple BaseCache - * instances, one per type of file. You can also add your own custom caches. - */ - class CacheManager { /** + * The current animation has completed. This dispatches the `ANIMATION_COMPLETE` event. * - * @param game A reference to the Phaser.Game instance that owns this CacheManager. + * This method is called by the Animation instance and should not usually be invoked directly. + * + * If no animation is loaded, no events will be dispatched. + * + * If another animation has been queued for playback, it will be started after the events fire. */ - constructor(game: Phaser.Game); + complete(): Phaser.GameObjects.GameObject; /** - * A reference to the Phaser.Game instance that owns this CacheManager. + * Immediately stops the current animation from playing and dispatches the `ANIMATION_STOP` event. + * + * If no animation is running, no events will be dispatched. + * + * If there is another animation in the queue (set via the `chain` method) then it will start playing. */ - protected game: Phaser.Game; + stop(): Phaser.GameObjects.GameObject; /** - * A Cache storing all binary files, typically added via the Loader. + * Stops the current animation from playing after the specified time delay, given in milliseconds. + * + * It then dispatches the `ANIMATION_STOP` event. + * + * If no animation is running, no events will be dispatched. + * + * If there is another animation in the queue (set via the `chain` method) then it will start playing, + * when the current one stops. + * @param delay The number of milliseconds to wait before stopping this animation. */ - binary: Phaser.Cache.BaseCache; + stopAfterDelay(delay: number): Phaser.GameObjects.GameObject; /** - * A Cache storing all bitmap font data files, typically added via the Loader. - * Only the font data is stored in this cache, the textures are part of the Texture Manager. + * Stops the current animation from playing when it next repeats. + * + * It then dispatches the `ANIMATION_STOP` event. + * + * If no animation is running, no events will be dispatched. + * + * If there is another animation in the queue (set via the `chain` method) then it will start playing, + * when the current one stops. + * + * Prior to Phaser 3.50 this method was called `stopOnRepeat` and had no parameters. + * @param repeatCount How many times should the animation repeat before stopping? Default 1. */ - bitmapFont: Phaser.Cache.BaseCache; + stopAfterRepeat(repeatCount?: number): Phaser.GameObjects.GameObject; /** - * A Cache storing all JSON data files, typically added via the Loader. + * Stops the current animation from playing when it next sets the given frame. + * If this frame doesn't exist within the animation it will not stop it from playing. + * + * It then dispatches the `ANIMATION_STOP` event. + * + * If no animation is running, no events will be dispatched. + * + * If there is another animation in the queue (set via the `chain` method) then it will start playing, + * when the current one stops. + * @param frame The frame to check before stopping this animation. */ - json: Phaser.Cache.BaseCache; + stopOnFrame(frame: Phaser.Animations.AnimationFrame): Phaser.GameObjects.GameObject; /** - * A Cache storing all physics data files, typically added via the Loader. + * Returns the total number of frames in this animation, or returns zero if no + * animation has been loaded. */ - physics: Phaser.Cache.BaseCache; + getTotalFrames(): number; /** - * A Cache storing all shader source files, typically added via the Loader. + * The internal update loop for the AnimationState Component. + * + * This is called automatically by the `Sprite.preUpdate` method. + * @param time The current timestamp. + * @param delta The delta time, in ms, elapsed since the last frame. */ - shader: Phaser.Cache.BaseCache; + update(time: number, delta: number): void; /** - * A Cache storing all non-streaming audio files, typically added via the Loader. + * Sets the given Animation Frame as being the current frame + * and applies it to the parent Game Object, adjusting size and origin as needed. + * @param animationFrame The animation frame to change to. */ - audio: Phaser.Cache.BaseCache; + setCurrentFrame(animationFrame: Phaser.Animations.AnimationFrame): Phaser.GameObjects.GameObject; /** - * A Cache storing all non-streaming video files, typically added via the Loader. + * Advances the animation to the next frame, regardless of the time or animation state. + * If the animation is set to repeat, or yoyo, this will still take effect. + * + * Calling this does not change the direction of the animation. I.e. if it was currently + * playing in reverse, calling this method doesn't then change the direction to forwards. */ - video: Phaser.Cache.BaseCache; + nextFrame(): Phaser.GameObjects.GameObject; /** - * A Cache storing all text files, typically added via the Loader. + * Advances the animation to the previous frame, regardless of the time or animation state. + * If the animation is set to repeat, or yoyo, this will still take effect. + * + * Calling this does not change the direction of the animation. I.e. if it was currently + * playing in forwards, calling this method doesn't then change the direction to backwards. */ - text: Phaser.Cache.BaseCache; + previousFrame(): Phaser.GameObjects.GameObject; /** - * A Cache storing all html files, typically added via the Loader. + * Get an Animation instance that has been created locally on this Sprite. + * + * See the `create` method for more details. + * @param key The key of the Animation to retrieve. */ - html: Phaser.Cache.BaseCache; + get(key: string): Phaser.Animations.Animation; /** - * A Cache storing all WaveFront OBJ files, typically added via the Loader. + * Checks to see if the given key is already used locally within the animations stored on this Sprite. + * @param key The key of the Animation to check. */ - obj: Phaser.Cache.BaseCache; + exists(key: string): boolean; /** - * A Cache storing all tilemap data files, typically added via the Loader. - * Only the data is stored in this cache, the textures are part of the Texture Manager. + * Creates a new Animation that is local specifically to this Sprite. + * + * When a Sprite owns an animation, it is kept out of the global Animation Manager, which means + * you're free to use keys that may be already defined there. Unless you specifically need a Sprite + * to have a unique animation, you should favor using global animations instead, as they allow for + * the same animation to be used across multiple Sprites, saving on memory. However, if this Sprite + * is the only one to use this animation, it's sensible to create it here. + * + * If an invalid key is given this method will return `false`. + * + * If you pass the key of an animation that already exists locally, that animation will be returned. + * + * A brand new animation is only created if the key is valid and not already in use by this Sprite. + * + * If you wish to re-use an existing key, call the `remove` method first, then this method. + * @param config The configuration settings for the Animation. */ - tilemap: Phaser.Cache.BaseCache; + create(config: Phaser.Types.Animations.Animation): Phaser.Animations.Animation | false; /** - * A Cache storing all xml data files, typically added via the Loader. + * Generate an array of {@link Phaser.Types.Animations.AnimationFrame} objects from a texture key and configuration object. + * + * Generates objects with string based frame names, as configured by the given {@link Phaser.Types.Animations.GenerateFrameNames}. + * + * It's a helper method, designed to make it easier for you to extract all of the frame names from texture atlases. + * If you're working with a sprite sheet, see the `generateFrameNumbers` method instead. + * + * Example: + * + * If you have a texture atlases loaded called `gems` and it contains 6 frames called `ruby_0001`, `ruby_0002`, and so on, + * then you can call this method using: `this.anims.generateFrameNames('gems', { prefix: 'ruby_', end: 6, zeroPad: 4 })`. + * + * The `end` value tells it to look for 6 frames, incrementally numbered, all starting with the prefix `ruby_`. The `zeroPad` + * value tells it how many zeroes pad out the numbers. To create an animation using this method, you can do: + * + * ```javascript + * this.anims.create({ + * key: 'ruby', + * repeat: -1, + * frames: this.anims.generateFrameNames('gems', { + * prefix: 'ruby_', + * end: 6, + * zeroPad: 4 + * }) + * }); + * ``` + * + * Please see the animation examples for further details. + * @param key The key for the texture containing the animation frames. + * @param config The configuration object for the animation frame names. */ - xml: Phaser.Cache.BaseCache; + generateFrameNames(key: string, config?: Phaser.Types.Animations.GenerateFrameNames): Phaser.Types.Animations.AnimationFrame[]; /** - * An object that contains your own custom BaseCache entries. - * Add to this via the `addCustom` method. + * Generate an array of {@link Phaser.Types.Animations.AnimationFrame} objects from a texture key and configuration object. + * + * Generates objects with numbered frame names, as configured by the given {@link Phaser.Types.Animations.GenerateFrameNumbers}. + * + * If you're working with a texture atlas, see the `generateFrameNames` method instead. + * + * It's a helper method, designed to make it easier for you to extract frames from sprite sheets. + * If you're working with a texture atlas, see the `generateFrameNames` method instead. + * + * Example: + * + * If you have a sprite sheet loaded called `explosion` and it contains 12 frames, then you can call this method using: + * `this.anims.generateFrameNumbers('explosion', { start: 0, end: 12 })`. + * + * The `end` value tells it to stop after 12 frames. To create an animation using this method, you can do: + * + * ```javascript + * this.anims.create({ + * key: 'boom', + * frames: this.anims.generateFrameNames('explosion', { + * start: 0, + * end: 12 + * }) + * }); + * ``` + * + * Note that `start` is optional and you don't need to include it if the animation starts from frame 0. + * + * To specify an animation in reverse, swap the `start` and `end` values. + * + * If the frames are not sequential, you may pass an array of frame numbers instead, for example: + * + * `this.anims.generateFrameNumbers('explosion', { frames: [ 0, 1, 2, 1, 2, 3, 4, 0, 1, 2 ] })` + * + * Please see the animation examples and `GenerateFrameNumbers` config docs for further details. + * @param key The key for the texture containing the animation frames. + * @param config The configuration object for the animation frames. */ - custom: {[key: string]: Phaser.Cache.BaseCache}; + generateFrameNumbers(key: string, config: Phaser.Types.Animations.GenerateFrameNumbers): Phaser.Types.Animations.AnimationFrame[]; /** - * Add your own custom Cache for storing your own files. - * The cache will be available under `Cache.custom.key`. - * The cache will only be created if the key is not already in use. - * @param key The unique key of your custom cache. + * Removes a locally created Animation from this Sprite, based on the given key. + * + * Once an Animation has been removed, this Sprite cannot play it again without re-creating it. + * @param key The key of the animation to remove. */ - addCustom(key: string): Phaser.Cache.BaseCache; + remove(key: string): Phaser.Animations.Animation; /** - * Removes all entries from all BaseCaches and destroys all custom caches. + * Destroy this Animation component. + * + * Unregisters event listeners and cleans up its references. */ destroy(): void; + /** + * `true` if the current animation is paused, otherwise `false`. + */ + readonly isPaused: boolean; + } namespace Events { /** - * The Cache Add Event. + * The Add Animation Event. * - * This event is dispatched by any Cache that extends the BaseCache each time a new object is added to it. + * This event is dispatched when a new animation is added to the global Animation Manager. + * + * This can happen either as a result of an animation instance being added to the Animation Manager, + * or the Animation Manager creating a new animation directly. */ - const ADD: any; + const ADD_ANIMATION: any; /** - * The Cache Remove Event. + * The Animation Complete Event. * - * This event is dispatched by any Cache that extends the BaseCache each time an object is removed from it. + * This event is dispatched by a Sprite when an animation playing on it completes playback. + * This happens when the animation gets to the end of its sequence, factoring in any delays + * or repeats it may have to process. + * + * An animation that is set to loop, or repeat forever, will never fire this event, because + * it never actually completes. If you need to handle this, listen for the `ANIMATION_STOP` + * event instead, as this is emitted when the animation is stopped directly. + * + * Listen for it on the Sprite using `sprite.on('animationcomplete', listener)` + * + * The animation event flow is as follows: + * + * 1. `ANIMATION_START` + * 2. `ANIMATION_UPDATE` (repeated for however many frames the animation has) + * 3. `ANIMATION_REPEAT` (only if the animation is set to repeat, it then emits more update events after this) + * 4. `ANIMATION_COMPLETE` (only if there is a finite, or zero, repeat count) + * 5. `ANIMATION_COMPLETE_KEY` (only if there is a finite, or zero, repeat count) + * + * If the animation is stopped directly, the `ANIMATION_STOP` event is dispatched instead of `ANIMATION_COMPLETE`. + * + * If the animation is restarted while it is already playing, `ANIMATION_RESTART` is emitted. */ - const REMOVE: any; - - } - - } + const ANIMATION_COMPLETE: any; - namespace Cameras { - namespace Scene2D { /** - * A Base Camera class. + * The Animation Complete Dynamic Key Event. * - * The Camera is the way in which all games are rendered in Phaser. They provide a view into your game world, - * and can be positioned, rotated, zoomed and scrolled accordingly. + * This event is dispatched by a Sprite when an animation playing on it completes playback. + * This happens when the animation gets to the end of its sequence, factoring in any delays + * or repeats it may have to process. * - * A Camera consists of two elements: The viewport and the scroll values. + * An animation that is set to loop, or repeat forever, will never fire this event, because + * it never actually completes. If you need to handle this, listen for the `ANIMATION_STOP` + * event instead, as this is emitted when the animation is stopped directly. * - * The viewport is the physical position and size of the Camera within your game. Cameras, by default, are - * created the same size as your game, but their position and size can be set to anything. This means if you - * wanted to create a camera that was 320x200 in size, positioned in the bottom-right corner of your game, - * you'd adjust the viewport to do that (using methods like `setViewport` and `setSize`). + * The difference between this and the `ANIMATION_COMPLETE` event is that this one has a + * dynamic event name that contains the name of the animation within it. For example, + * if you had an animation called `explode` you could listen for the completion of that + * specific animation by using: `sprite.on('animationcomplete-explode', listener)`. Or, if you + * wish to use types: `sprite.on(Phaser.Animations.Events.ANIMATION_COMPLETE_KEY + 'explode', listener)`. * - * If you wish to change where the Camera is looking in your game, then you scroll it. You can do this - * via the properties `scrollX` and `scrollY` or the method `setScroll`. Scrolling has no impact on the - * viewport, and changing the viewport has no impact on the scrolling. + * The animation event flow is as follows: * - * By default a Camera will render all Game Objects it can see. You can change this using the `ignore` method, - * allowing you to filter Game Objects out on a per-Camera basis. + * 1. `ANIMATION_START` + * 2. `ANIMATION_UPDATE` (repeated for however many frames the animation has) + * 3. `ANIMATION_REPEAT` (only if the animation is set to repeat, it then emits more update events after this) + * 4. `ANIMATION_COMPLETE` (only if there is a finite, or zero, repeat count) + * 5. `ANIMATION_COMPLETE_KEY` (only if there is a finite, or zero, repeat count) * - * The Base Camera is extended by the Camera class, which adds in special effects including Fade, - * Flash and Camera Shake, as well as the ability to follow Game Objects. + * If the animation is stopped directly, the `ANIMATION_STOP` event is dispatched instead of `ANIMATION_COMPLETE`. * - * The Base Camera was introduced in Phaser 3.12. It was split off from the Camera class, to allow - * you to isolate special effects as needed. Therefore the 'since' values for properties of this class relate - * to when they were added to the Camera class. + * If the animation is restarted while it is already playing, `ANIMATION_RESTART` is emitted. */ - class BaseCamera extends Phaser.Events.EventEmitter implements Phaser.GameObjects.Components.Alpha, Phaser.GameObjects.Components.Visible { - /** - * - * @param x The x position of the Camera, relative to the top-left of the game canvas. - * @param y The y position of the Camera, relative to the top-left of the game canvas. - * @param width The width of the Camera, in pixels. - * @param height The height of the Camera, in pixels. - */ - constructor(x: number, y: number, width: number, height: number); + const ANIMATION_COMPLETE_KEY: any; - /** + /** + * The Animation Repeat Event. + * + * This event is dispatched by a Sprite when an animation repeats playing on it. + * This happens if the animation was created, or played, with a `repeat` value specified. + * + * An animation will repeat when it reaches the end of its sequence. + * + * Listen for it on the Sprite using `sprite.on('animationrepeat', listener)` + * + * The animation event flow is as follows: + * + * 1. `ANIMATION_START` + * 2. `ANIMATION_UPDATE` (repeated for however many frames the animation has) + * 3. `ANIMATION_REPEAT` (only if the animation is set to repeat, it then emits more update events after this) + * 4. `ANIMATION_COMPLETE` (only if there is a finite, or zero, repeat count) + * 5. `ANIMATION_COMPLETE_KEY` (only if there is a finite, or zero, repeat count) + * + * If the animation is stopped directly, the `ANIMATION_STOP` event is dispatched instead of `ANIMATION_COMPLETE`. + * + * If the animation is restarted while it is already playing, `ANIMATION_RESTART` is emitted. + */ + const ANIMATION_REPEAT: any; + + /** + * The Animation Restart Event. + * + * This event is dispatched by a Sprite when an animation restarts playing on it. + * This only happens when the `Sprite.anims.restart` method is called. + * + * Listen for it on the Sprite using `sprite.on('animationrestart', listener)` + * + * The animation event flow is as follows: + * + * 1. `ANIMATION_START` + * 2. `ANIMATION_UPDATE` (repeated for however many frames the animation has) + * 3. `ANIMATION_REPEAT` (only if the animation is set to repeat, it then emits more update events after this) + * 4. `ANIMATION_COMPLETE` (only if there is a finite, or zero, repeat count) + * 5. `ANIMATION_COMPLETE_KEY` (only if there is a finite, or zero, repeat count) + * + * If the animation is stopped directly, the `ANIMATION_STOP` event is dispatched instead of `ANIMATION_COMPLETE`. + * + * If the animation is restarted while it is already playing, `ANIMATION_RESTART` is emitted. + */ + const ANIMATION_RESTART: any; + + /** + * The Animation Start Event. + * + * This event is dispatched by a Sprite when an animation starts playing on it. + * This happens when the animation is played, factoring in any delay that may have been specified. + * This event happens after the delay has expired and prior to the first update event. + * + * Listen for it on the Sprite using `sprite.on('animationstart', listener)` + * + * The animation event flow is as follows: + * + * 1. `ANIMATION_START` + * 2. `ANIMATION_UPDATE` (repeated for however many frames the animation has) + * 3. `ANIMATION_REPEAT` (only if the animation is set to repeat, it then emits more update events after this) + * 4. `ANIMATION_COMPLETE` (only if there is a finite, or zero, repeat count) + * 5. `ANIMATION_COMPLETE_KEY` (only if there is a finite, or zero, repeat count) + * + * If the animation is stopped directly, the `ANIMATION_STOP` event is dispatched instead of `ANIMATION_COMPLETE`. + * + * If the animation is restarted while it is already playing, `ANIMATION_RESTART` is emitted. + */ + const ANIMATION_START: any; + + /** + * The Animation Stop Event. + * + * This event is dispatched by a Sprite when an animation is stopped on it. An animation + * will only be stopeed if a method such as `Sprite.stop` or `Sprite.anims.stopAfterDelay` + * is called. It can also be emitted if a new animation is started before the current one completes. + * + * Listen for it on the Sprite using `sprite.on('animationstop', listener)` + * + * The animation event flow is as follows: + * + * 1. `ANIMATION_START` + * 2. `ANIMATION_UPDATE` (repeated for however many frames the animation has) + * 3. `ANIMATION_REPEAT` (only if the animation is set to repeat, it then emits more update events after this) + * 4. `ANIMATION_COMPLETE` (only if there is a finite, or zero, repeat count) + * 5. `ANIMATION_COMPLETE_KEY` (only if there is a finite, or zero, repeat count) + * + * If the animation is stopped directly, the `ANIMATION_STOP` event is dispatched instead of `ANIMATION_COMPLETE`. + * + * If the animation is restarted while it is already playing, `ANIMATION_RESTART` is emitted. + */ + const ANIMATION_STOP: any; + + /** + * The Animation Update Event. + * + * This event is dispatched by a Sprite when an animation playing on it updates. This happens when the animation changes frame. + * An animation will change frame based on the frme rate and other factors like `timeScale` and `delay`. It can also change + * frame when stopped or restarted. + * + * Listen for it on the Sprite using `sprite.on('animationupdate', listener)` + * + * If an animation is playing faster than the game frame-rate can handle, it's entirely possible for it to emit several + * update events in a single game frame, so please be aware of this in your code. The **final** event received that frame + * is the one that is rendered to the game. + * + * The animation event flow is as follows: + * + * 1. `ANIMATION_START` + * 2. `ANIMATION_UPDATE` (repeated for however many frames the animation has) + * 3. `ANIMATION_REPEAT` (only if the animation is set to repeat, it then emits more update events after this) + * 4. `ANIMATION_COMPLETE` (only if there is a finite, or zero, repeat count) + * 5. `ANIMATION_COMPLETE_KEY` (only if there is a finite, or zero, repeat count) + * + * If the animation is stopped directly, the `ANIMATION_STOP` event is dispatched instead of `ANIMATION_COMPLETE`. + * + * If the animation is restarted while it is already playing, `ANIMATION_RESTART` is emitted. + */ + const ANIMATION_UPDATE: any; + + /** + * The Pause All Animations Event. + * + * This event is dispatched when the global Animation Manager is told to pause. + * + * When this happens all current animations will stop updating, although it doesn't necessarily mean + * that the game has paused as well. + */ + const PAUSE_ALL: any; + + /** + * The Remove Animation Event. + * + * This event is dispatched when an animation is removed from the global Animation Manager. + */ + const REMOVE_ANIMATION: any; + + /** + * The Resume All Animations Event. + * + * This event is dispatched when the global Animation Manager resumes, having been previously paused. + * + * When this happens all current animations will continue updating again. + */ + const RESUME_ALL: any; + + } + + } + + namespace Cache { + /** + * The BaseCache is a base Cache class that can be used for storing references to any kind of data. + * + * Data can be added, retrieved and removed based on the given keys. + * + * Keys are string-based. + */ + class BaseCache { + /** + * The Map in which the cache objects are stored. + * + * You can query the Map directly or use the BaseCache methods. + */ + entries: Phaser.Structs.Map; + + /** + * An instance of EventEmitter used by the cache to emit related events. + */ + events: Phaser.Events.EventEmitter; + + /** + * Adds an item to this cache. The item is referenced by a unique string, which you are responsible + * for setting and keeping track of. The item can only be retrieved by using this string. + * @param key The unique key by which the data added to the cache will be referenced. + * @param data The data to be stored in the cache. + */ + add(key: string, data: any): this; + + /** + * Checks if this cache contains an item matching the given key. + * This performs the same action as `BaseCache.exists`. + * @param key The unique key of the item to be checked in this cache. + */ + has(key: string): boolean; + + /** + * Checks if this cache contains an item matching the given key. + * This performs the same action as `BaseCache.has` and is called directly by the Loader. + * @param key The unique key of the item to be checked in this cache. + */ + exists(key: string): boolean; + + /** + * Gets an item from this cache based on the given key. + * @param key The unique key of the item to be retrieved from this cache. + */ + get(key: string): any; + + /** + * Removes and item from this cache based on the given key. + * + * If an entry matching the key is found it is removed from the cache and a `remove` event emitted. + * No additional checks are done on the item removed. If other systems or parts of your game code + * are relying on this item, it is up to you to sever those relationships prior to removing the item. + * @param key The unique key of the item to remove from the cache. + */ + remove(key: string): this; + + /** + * Returns all keys in use in this cache. + */ + getKeys(): string[]; + + /** + * Destroys this cache and all items within it. + */ + destroy(): void; + + } + + /** + * The Cache Manager is the global cache owned and maintained by the Game instance. + * + * Various systems, such as the file Loader, rely on this cache in order to store the files + * it has loaded. The manager itself doesn't store any files, but instead owns multiple BaseCache + * instances, one per type of file. You can also add your own custom caches. + */ + class CacheManager { + /** + * + * @param game A reference to the Phaser.Game instance that owns this CacheManager. + */ + constructor(game: Phaser.Game); + + /** + * A reference to the Phaser.Game instance that owns this CacheManager. + */ + protected game: Phaser.Game; + + /** + * A Cache storing all binary files, typically added via the Loader. + */ + binary: Phaser.Cache.BaseCache; + + /** + * A Cache storing all bitmap font data files, typically added via the Loader. + * Only the font data is stored in this cache, the textures are part of the Texture Manager. + */ + bitmapFont: Phaser.Cache.BaseCache; + + /** + * A Cache storing all JSON data files, typically added via the Loader. + */ + json: Phaser.Cache.BaseCache; + + /** + * A Cache storing all physics data files, typically added via the Loader. + */ + physics: Phaser.Cache.BaseCache; + + /** + * A Cache storing all shader source files, typically added via the Loader. + */ + shader: Phaser.Cache.BaseCache; + + /** + * A Cache storing all non-streaming audio files, typically added via the Loader. + */ + audio: Phaser.Cache.BaseCache; + + /** + * A Cache storing all non-streaming video files, typically added via the Loader. + */ + video: Phaser.Cache.BaseCache; + + /** + * A Cache storing all text files, typically added via the Loader. + */ + text: Phaser.Cache.BaseCache; + + /** + * A Cache storing all html files, typically added via the Loader. + */ + html: Phaser.Cache.BaseCache; + + /** + * A Cache storing all WaveFront OBJ files, typically added via the Loader. + */ + obj: Phaser.Cache.BaseCache; + + /** + * A Cache storing all tilemap data files, typically added via the Loader. + * Only the data is stored in this cache, the textures are part of the Texture Manager. + */ + tilemap: Phaser.Cache.BaseCache; + + /** + * A Cache storing all xml data files, typically added via the Loader. + */ + xml: Phaser.Cache.BaseCache; + + /** + * An object that contains your own custom BaseCache entries. + * Add to this via the `addCustom` method. + */ + custom: {[key: string]: Phaser.Cache.BaseCache}; + + /** + * Add your own custom Cache for storing your own files. + * The cache will be available under `Cache.custom.key`. + * The cache will only be created if the key is not already in use. + * @param key The unique key of your custom cache. + */ + addCustom(key: string): Phaser.Cache.BaseCache; + + /** + * Removes all entries from all BaseCaches and destroys all custom caches. + */ + destroy(): void; + + } + + namespace Events { + /** + * The Cache Add Event. + * + * This event is dispatched by any Cache that extends the BaseCache each time a new object is added to it. + */ + const ADD: any; + + /** + * The Cache Remove Event. + * + * This event is dispatched by any Cache that extends the BaseCache each time an object is removed from it. + */ + const REMOVE: any; + + } + + } + + namespace Cameras { + namespace Scene2D { + /** + * A Base Camera class. + * + * The Camera is the way in which all games are rendered in Phaser. They provide a view into your game world, + * and can be positioned, rotated, zoomed and scrolled accordingly. + * + * A Camera consists of two elements: The viewport and the scroll values. + * + * The viewport is the physical position and size of the Camera within your game. Cameras, by default, are + * created the same size as your game, but their position and size can be set to anything. This means if you + * wanted to create a camera that was 320x200 in size, positioned in the bottom-right corner of your game, + * you'd adjust the viewport to do that (using methods like `setViewport` and `setSize`). + * + * If you wish to change where the Camera is looking in your game, then you scroll it. You can do this + * via the properties `scrollX` and `scrollY` or the method `setScroll`. Scrolling has no impact on the + * viewport, and changing the viewport has no impact on the scrolling. + * + * By default a Camera will render all Game Objects it can see. You can change this using the `ignore` method, + * allowing you to filter Game Objects out on a per-Camera basis. + * + * The Base Camera is extended by the Camera class, which adds in special effects including Fade, + * Flash and Camera Shake, as well as the ability to follow Game Objects. + * + * The Base Camera was introduced in Phaser 3.12. It was split off from the Camera class, to allow + * you to isolate special effects as needed. Therefore the 'since' values for properties of this class relate + * to when they were added to the Camera class. + */ + class BaseCamera extends Phaser.Events.EventEmitter implements Phaser.GameObjects.Components.Alpha, Phaser.GameObjects.Components.Visible { + /** + * + * @param x The x position of the Camera, relative to the top-left of the game canvas. + * @param y The y position of the Camera, relative to the top-left of the game canvas. + * @param width The width of the Camera, in pixels. + * @param height The height of the Camera, in pixels. + */ + constructor(x: number, y: number, width: number, height: number); + + /** * A reference to the Scene this camera belongs to. */ scene: Phaser.Scene; @@ -1605,20 +2604,13 @@ declare namespace Phaser { * The Camera ID. Assigned by the Camera Manager and used to handle camera exclusion. * This value is a bitmask. */ - readonly id: integer; + readonly id: number; /** * The name of the Camera. This is left empty for your own use. */ name: string; - /** - * This property is un-used in v3.16. - * - * The resolution of the Game, used in most Camera calculations. - */ - readonly resolution: number; - /** * Should this camera round its pixel values to integers? */ @@ -1755,31 +2747,31 @@ declare namespace Phaser { * Calling this does not change the scrollY value. * @param x The horizontal coordinate to center on. */ - centerOnX(x: number): Phaser.Cameras.Scene2D.BaseCamera; + centerOnX(x: number): this; /** * Moves the Camera vertically so that it is centered on the given y coordinate, bounds allowing. * Calling this does not change the scrollX value. * @param y The vertical coordinate to center on. */ - centerOnY(y: number): Phaser.Cameras.Scene2D.BaseCamera; + centerOnY(y: number): this; /** * Moves the Camera so that it is centered on the given coordinates, bounds allowing. * @param x The horizontal coordinate to center on. * @param y The vertical coordinate to center on. */ - centerOn(x: number, y: number): Phaser.Cameras.Scene2D.BaseCamera; + centerOn(x: number, y: number): this; /** * Moves the Camera so that it is looking at the center of the Camera Bounds, if enabled. */ - centerToBounds(): Phaser.Cameras.Scene2D.BaseCamera; + centerToBounds(): this; /** * Moves the Camera so that it is re-centered based on its viewport size. */ - centerToSize(): Phaser.Cameras.Scene2D.BaseCamera; + centerToSize(): this; /** * Takes an array of Game Objects and returns a new array featuring only those objects @@ -1802,13 +2794,12 @@ declare namespace Phaser { * so that they are ignored by this Camera. This means they will not be rendered by this Camera. * @param entries The Game Object, or array of Game Objects, to be ignored by this Camera. */ - ignore(entries: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[] | Phaser.GameObjects.Group): Phaser.Cameras.Scene2D.BaseCamera; + ignore(entries: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[] | Phaser.GameObjects.Group): this; /** * Internal preRender step. - * @param resolution The game resolution, as set in the Scale Manager. */ - protected preRender(resolution: number): void; + protected preRender(): void; /** * Takes an x value and checks it's within the range of the Camera bounds, adjusting if required. @@ -1827,7 +2818,7 @@ declare namespace Phaser { /** * If this Camera has previously had movement bounds set on it, this will remove them. */ - removeBounds(): Phaser.Cameras.Scene2D.BaseCamera; + removeBounds(): this; /** * Set the rotation of this Camera. This causes everything it renders to appear rotated. @@ -1835,7 +2826,7 @@ declare namespace Phaser { * Rotating a camera does not rotate the viewport itself, it is applied during rendering. * @param value The cameras angle of rotation, given in degrees. Default 0. */ - setAngle(value?: number): Phaser.Cameras.Scene2D.BaseCamera; + setAngle(value?: number): this; /** * Sets the background color for this Camera. @@ -1846,7 +2837,7 @@ declare namespace Phaser { * The color value can be specified using CSS color notation, hex or numbers. * @param color The color value. In CSS, hex or numeric color notation. Default 'rgba(0,0,0,0)'. */ - setBackgroundColor(color?: string | number | Phaser.Types.Display.InputColorObject): Phaser.Cameras.Scene2D.BaseCamera; + setBackgroundColor(color?: string | number | Phaser.Types.Display.InputColorObject): this; /** * Set the bounds of the Camera. The bounds are an axis-aligned rectangle. @@ -1872,7 +2863,7 @@ declare namespace Phaser { * @param height The height of the bounds, in pixels. * @param centerOn If `true` the Camera will automatically be centered on the new bounds. Default false. */ - setBounds(x: integer, y: integer, width: integer, height: integer, centerOn?: boolean): Phaser.Cameras.Scene2D.BaseCamera; + setBounds(x: number, y: number, width: number, height: number, centerOn?: boolean): this; /** * Returns a rectangle containing the bounds of the Camera. @@ -1889,7 +2880,7 @@ declare namespace Phaser { * This value is for your own use and isn't used internally. * @param value The name of the Camera. Default ''. */ - setName(value?: string): Phaser.Cameras.Scene2D.BaseCamera; + setName(value?: string): this; /** * Set the position of the Camera viewport within the game. @@ -1898,7 +2889,7 @@ declare namespace Phaser { * @param x The top-left x coordinate of the Camera viewport. * @param y The top-left y coordinate of the Camera viewport. Default x. */ - setPosition(x: number, y?: number): Phaser.Cameras.Scene2D.BaseCamera; + setPosition(x: number, y?: number): this; /** * Set the rotation of this Camera. This causes everything it renders to appear rotated. @@ -1906,7 +2897,7 @@ declare namespace Phaser { * Rotating a camera does not rotate the viewport itself, it is applied during rendering. * @param value The rotation of the Camera, in radians. Default 0. */ - setRotation(value?: number): Phaser.Cameras.Scene2D.BaseCamera; + setRotation(value?: number): this; /** * Should the Camera round pixel values to whole integers when rendering Game Objects? @@ -1914,15 +2905,13 @@ declare namespace Phaser { * In some types of game, especially with pixel art, this is required to prevent sub-pixel aliasing. * @param value `true` to round Camera pixels, `false` to not. */ - setRoundPixels(value: boolean): Phaser.Cameras.Scene2D.BaseCamera; + setRoundPixels(value: boolean): this; /** * Sets the Scene the Camera is bound to. - * - * Also populates the `resolution` property and updates the internal size values. * @param scene The Scene the camera is bound to. */ - setScene(scene: Phaser.Scene): Phaser.Cameras.Scene2D.BaseCamera; + setScene(scene: Phaser.Scene): this; /** * Set the position of where the Camera is looking within the game. @@ -1933,7 +2922,7 @@ declare namespace Phaser { * @param x The x coordinate of the Camera in the game world. * @param y The y coordinate of the Camera in the game world. Default x. */ - setScroll(x: number, y?: number): Phaser.Cameras.Scene2D.BaseCamera; + setScroll(x: number, y?: number): this; /** * Set the size of the Camera viewport. @@ -1944,7 +2933,7 @@ declare namespace Phaser { * @param width The width of the Camera viewport. * @param height The height of the Camera viewport. Default width. */ - setSize(width: integer, height?: integer): Phaser.Cameras.Scene2D.BaseCamera; + setSize(width: number, height?: number): this; /** * This method sets the position and size of the Camera viewport in a single call. @@ -1961,7 +2950,7 @@ declare namespace Phaser { * @param width The width of the Camera viewport. * @param height The height of the Camera viewport. Default width. */ - setViewport(x: number, y: number, width: integer, height?: integer): Phaser.Cameras.Scene2D.BaseCamera; + setViewport(x: number, y: number, width: number, height?: number): this; /** * Set the zoom value of the Camera. @@ -1972,9 +2961,12 @@ declare namespace Phaser { * A value of 1 means 'no zoom' and is the default. * * Changing the zoom does not impact the Camera viewport in any way, it is only applied during rendering. - * @param value The zoom value of the Camera. The minimum it can be is 0.001. Default 1. + * + * As of Phaser 3.50 you can now set the horizontal and vertical zoom values independently. + * @param x The horizontal zoom value of the Camera. The minimum it can be is 0.001. Default 1. + * @param y The vertical zoom value of the Camera. The minimum it can be is 0.001. Default x. */ - setZoom(value?: number): Phaser.Cameras.Scene2D.BaseCamera; + setZoom(x?: number, y?: number): this; /** * Sets the mask to be applied to this Camera during rendering. @@ -1987,8 +2979,6 @@ declare namespace Phaser { * * Masks have no impact on physics or input detection. They are purely a rendering component * that allows you to limit what is visible during the render pass. - * - * Note: You cannot mask a Camera that has `renderToTexture` set. * @param mask The mask this Camera will use when rendering. * @param fixedPosition Should the mask translate along with the Camera, or be fixed in place and not impacted by the Cameras transform? Default true. */ @@ -2018,7 +3008,7 @@ declare namespace Phaser { * @param time The current timestamp as generated by the Request Animation Frame or SetTimeout. * @param delta The delta time, in ms, elapsed since the last frame. */ - protected update(time: integer, delta: number): void; + protected update(time: number, delta: number): void; /** * Destroys this Camera instance and its internal properties and references. @@ -2098,6 +3088,32 @@ declare namespace Phaser { */ zoom: number; + /** + * The Camera horizontal zoom value. Change this value to zoom in, or out of, a Scene. + * + * A value of 0.5 would zoom the Camera out, so you can now see twice as much + * of the Scene as before. A value of 2 would zoom the Camera in, so every pixel + * now takes up 2 pixels when rendered. + * + * Set to 1 to return to the default zoom level. + * + * Be careful to never set this value to zero. + */ + zoomX: number; + + /** + * The Camera vertical zoom value. Change this value to zoom in, or out of, a Scene. + * + * A value of 0.5 would zoom the Camera out, so you can now see twice as much + * of the Scene as before. A value of 2 would zoom the Camera in, so every pixel + * now takes up 2 pixels when rendered. + * + * Set to 1 to return to the default zoom level. + * + * Be careful to never set this value to zero. + */ + zoomY: number; + /** * The horizontal position of the center of the Camera's viewport, relative to the left of the game canvas. */ @@ -2185,7 +3201,7 @@ declare namespace Phaser { * * A Camera also has built-in special effects including Fade, Flash and Camera Shake. */ - class Camera extends Phaser.Cameras.Scene2D.BaseCamera implements Phaser.GameObjects.Components.Flip, Phaser.GameObjects.Components.Tint { + class Camera extends Phaser.Cameras.Scene2D.BaseCamera implements Phaser.GameObjects.Components.Flip, Phaser.GameObjects.Components.Tint, Phaser.GameObjects.Components.Pipeline { /** * * @param x The x position of the Camera, relative to the top-left of the game canvas. @@ -2224,6 +3240,12 @@ declare namespace Phaser { */ panEffect: Phaser.Cameras.Scene2D.Effects.Pan; + /** + * The Camera Rotate To effect handler. + * To rotate this camera see the `Camera.rotateTo` method. + */ + rotateToEffect: Phaser.Cameras.Scene2D.Effects.RotateTo; + /** * The Camera Zoom effect handler. * To zoom this camera see the `Camera.zoom` method. @@ -2272,120 +3294,6 @@ declare namespace Phaser { */ deadzone: Phaser.Geom.Rectangle; - /** - * Is this Camera rendering directly to the canvas or to a texture? - * - * Enable rendering to texture with the method `setRenderToTexture` (just enabling this boolean won't be enough) - * - * Once enabled you can toggle it by switching this property. - * - * To properly remove a render texture you should call the `clearRenderToTexture()` method. - */ - renderToTexture: boolean; - - /** - * If this Camera has been set to render to a texture then this holds a reference - * to the HTML Canvas Element that the Camera is drawing to. - * - * Enable texture rendering using the method `setRenderToTexture`. - * - * This is only populated if Phaser is running with the Canvas Renderer. - */ - canvas: HTMLCanvasElement; - - /** - * If this Camera has been set to render to a texture then this holds a reference - * to the Rendering Context belonging to the Canvas element the Camera is drawing to. - * - * Enable texture rendering using the method `setRenderToTexture`. - * - * This is only populated if Phaser is running with the Canvas Renderer. - */ - context: CanvasRenderingContext2D; - - /** - * If this Camera has been set to render to a texture then this holds a reference - * to the GL Texture belonging the Camera is drawing to. - * - * Enable texture rendering using the method `setRenderToTexture`. - * - * This is only set if Phaser is running with the WebGL Renderer. - */ - glTexture: WebGLTexture; - - /** - * If this Camera has been set to render to a texture then this holds a reference - * to the GL Frame Buffer belonging the Camera is drawing to. - * - * Enable texture rendering using the method `setRenderToTexture`. - * - * This is only set if Phaser is running with the WebGL Renderer. - */ - framebuffer: WebGLFramebuffer; - - /** - * If this Camera has been set to render to a texture and to use a custom pipeline, - * then this holds a reference to the pipeline the Camera is drawing with. - * - * Enable texture rendering using the method `setRenderToTexture`. - * - * This is only set if Phaser is running with the WebGL Renderer. - */ - pipeline: any; - - /** - * Sets the Camera to render to a texture instead of to the main canvas. - * - * The Camera will redirect all Game Objects it's asked to render to this texture. - * - * During the render sequence, the texture itself will then be rendered to the main canvas. - * - * Doing this gives you the ability to modify the texture before this happens, - * allowing for special effects such as Camera specific shaders, or post-processing - * on the texture. - * - * If running under Canvas the Camera will render to its `canvas` property. - * - * If running under WebGL the Camera will create a frame buffer, which is stored in its `framebuffer` and `glTexture` properties. - * - * If you set a camera to render to a texture then it will emit 2 events during the render loop: - * - * First, it will emit the event `prerender`. This happens right before any Game Object's are drawn to the Camera texture. - * - * Then, it will emit the event `postrender`. This happens after all Game Object's have been drawn, but right before the - * Camera texture is rendered to the main game canvas. It's the final point at which you can manipulate the texture before - * it appears in-game. - * - * You should not enable this unless you plan on actually using the texture it creates - * somehow, otherwise you're just doubling the work required to render your game. - * - * To temporarily disable rendering to a texture, toggle the `renderToTexture` boolean. - * - * If you no longer require the Camera to render to a texture, call the `clearRenderToTexture` method, - * which will delete the respective textures and free-up resources. - * @param pipeline An optional WebGL Pipeline to render with, can be either a string which is the name of the pipeline, or a pipeline reference. - */ - setRenderToTexture(pipeline?: string | Phaser.Renderer.WebGL.WebGLPipeline): Phaser.Cameras.Scene2D.Camera; - - /** - * Sets the WebGL pipeline this Camera is using when rendering to a texture. - * - * You can pass either the string-based name of the pipeline, or a reference to the pipeline itself. - * - * Call this method with no arguments to clear any previously set pipeline. - * @param pipeline The WebGL Pipeline to render with, can be either a string which is the name of the pipeline, or a pipeline reference. Or if left empty it will clear the pipeline. - */ - setPipeline(pipeline?: string | Phaser.Renderer.WebGL.WebGLPipeline): Phaser.Cameras.Scene2D.Camera; - - /** - * If this Camera was set to render to a texture, this will clear the resources it was using and - * redirect it to render back to the primary Canvas again. - * - * If you only wish to temporarily disable rendering to a texture then you can toggle the - * property `renderToTexture` instead. - */ - clearRenderToTexture(): Phaser.Cameras.Scene2D.Camera; - /** * Sets the Camera dead zone. * @@ -2404,7 +3312,7 @@ declare namespace Phaser { * @param width The width of the deadzone rectangle in pixels. If not specified the deadzone is removed. * @param height The height of the deadzone rectangle in pixels. */ - setDeadzone(width?: number, height?: number): Phaser.Cameras.Scene2D.Camera; + setDeadzone(width?: number, height?: number): this; /** * Fades the Camera in from the given color over the duration specified. @@ -2416,7 +3324,7 @@ declare namespace Phaser { * It is sent two arguments: A reference to the camera and a progress amount between 0 and 1 indicating how complete the effect is. * @param context The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs. */ - fadeIn(duration?: integer, red?: integer, green?: integer, blue?: integer, callback?: Function, context?: any): Phaser.Cameras.Scene2D.Camera; + fadeIn(duration?: number, red?: number, green?: number, blue?: number, callback?: Function, context?: any): this; /** * Fades the Camera out to the given color over the duration specified. @@ -2429,7 +3337,7 @@ declare namespace Phaser { * It is sent two arguments: A reference to the camera and a progress amount between 0 and 1 indicating how complete the effect is. * @param context The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs. */ - fadeOut(duration?: integer, red?: integer, green?: integer, blue?: integer, callback?: Function, context?: any): Phaser.Cameras.Scene2D.Camera; + fadeOut(duration?: number, red?: number, green?: number, blue?: number, callback?: Function, context?: any): this; /** * Fades the Camera from the given color to transparent over the duration specified. @@ -2442,7 +3350,7 @@ declare namespace Phaser { * It is sent two arguments: A reference to the camera and a progress amount between 0 and 1 indicating how complete the effect is. * @param context The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs. */ - fadeFrom(duration?: integer, red?: integer, green?: integer, blue?: integer, force?: boolean, callback?: Function, context?: any): Phaser.Cameras.Scene2D.Camera; + fadeFrom(duration?: number, red?: number, green?: number, blue?: number, force?: boolean, callback?: Function, context?: any): this; /** * Fades the Camera from transparent to the given color over the duration specified. @@ -2455,7 +3363,7 @@ declare namespace Phaser { * It is sent two arguments: A reference to the camera and a progress amount between 0 and 1 indicating how complete the effect is. * @param context The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs. */ - fade(duration?: integer, red?: integer, green?: integer, blue?: integer, force?: boolean, callback?: Function, context?: any): Phaser.Cameras.Scene2D.Camera; + fade(duration?: number, red?: number, green?: number, blue?: number, force?: boolean, callback?: Function, context?: any): this; /** * Flashes the Camera by setting it to the given color immediately and then fading it away again quickly over the duration specified. @@ -2468,7 +3376,7 @@ declare namespace Phaser { * It is sent two arguments: A reference to the camera and a progress amount between 0 and 1 indicating how complete the effect is. * @param context The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs. */ - flash(duration?: integer, red?: integer, green?: integer, blue?: integer, force?: boolean, callback?: Function, context?: any): Phaser.Cameras.Scene2D.Camera; + flash(duration?: number, red?: number, green?: number, blue?: number, force?: boolean, callback?: Function, context?: any): this; /** * Shakes the Camera by the given intensity over the duration specified. @@ -2479,7 +3387,7 @@ declare namespace Phaser { * It is sent two arguments: A reference to the camera and a progress amount between 0 and 1 indicating how complete the effect is. * @param context The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs. */ - shake(duration?: integer, intensity?: number | Phaser.Math.Vector2, force?: boolean, callback?: Function, context?: any): Phaser.Cameras.Scene2D.Camera; + shake(duration?: number, intensity?: number | Phaser.Math.Vector2, force?: boolean, callback?: Function, context?: any): this; /** * This effect will scroll the Camera so that the center of its viewport finishes at the given destination, @@ -2494,7 +3402,22 @@ declare namespace Phaser { * the current camera scroll x coordinate and the current camera scroll y coordinate. * @param context The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs. */ - pan(x: number, y: number, duration?: integer, ease?: string | Function, force?: boolean, callback?: Phaser.Types.Cameras.Scene2D.CameraPanCallback, context?: any): Phaser.Cameras.Scene2D.Camera; + pan(x: number, y: number, duration?: number, ease?: string | Function, force?: boolean, callback?: Phaser.Types.Cameras.Scene2D.CameraPanCallback, context?: any): this; + + /** + * This effect will rotate the Camera so that the viewport finishes at the given angle in radians, + * over the duration and with the ease specified. + * @param radians The destination angle in radians to rotate the Camera viewport to. If the angle is positive then the rotation is clockwise else anticlockwise + * @param shortestPath If shortest path is set to true the camera will rotate in the quickest direction clockwise or anti-clockwise. Default false. + * @param duration The duration of the effect in milliseconds. Default 1000. + * @param ease The ease to use for the rotation. Can be any of the Phaser Easing constants or a custom function. Default 'Linear'. + * @param force Force the rotation effect to start immediately, even if already running. Default false. + * @param callback This callback will be invoked every frame for the duration of the effect. + * It is sent four arguments: A reference to the camera, a progress amount between 0 and 1 indicating how complete the effect is, + * the current camera rotation angle in radians. + * @param context The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs. + */ + rotateTo(radians: number, shortestPath?: boolean, duration?: number, ease?: string | Function, force?: boolean, callback?: CameraRotateCallback, context?: any): Phaser.Cameras.Scene2D.Camera; /** * This effect will zoom the Camera to the given scale, over the duration and with the ease specified. @@ -2507,13 +3430,12 @@ declare namespace Phaser { * the current camera scroll x coordinate and the current camera scroll y coordinate. * @param context The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs. */ - zoomTo(zoom: number, duration?: integer, ease?: string | Function, force?: boolean, callback?: Phaser.Types.Cameras.Scene2D.CameraPanCallback, context?: any): Phaser.Cameras.Scene2D.Camera; + zoomTo(zoom: number, duration?: number, ease?: string | Function, force?: boolean, callback?: Phaser.Types.Cameras.Scene2D.CameraPanCallback, context?: any): this; /** * Internal preRender step. - * @param resolution The game resolution, as set in the Scale Manager. */ - protected preRender(resolution: number): void; + protected preRender(): void; /** * Sets the linear interpolation value to use when following a target. @@ -2562,20 +3484,20 @@ declare namespace Phaser { /** * Stops a Camera from following a Game Object, if previously set via `Camera.startFollow`. */ - stopFollow(): Phaser.Cameras.Scene2D.Camera; + stopFollow(): this; /** * Resets any active FX, such as a fade, flash or shake. Useful to call after a fade in order to * remove the fade. */ - resetFX(): Phaser.Cameras.Scene2D.Camera; + resetFX(): this; /** * Internal method called automatically by the Camera Manager. * @param time The current timestamp as generated by the Request Animation Frame or SetTimeout. * @param delta The delta time, in ms, elapsed since the last frame. */ - protected update(time: integer, delta: number): void; + protected update(time: number, delta: number): void; /** * Destroys this Camera instance. You rarely need to call this directly. @@ -2681,7 +3603,38 @@ declare namespace Phaser { resetFlip(): this; /** - * Fill or additive? + * The tint value being applied to the top-left vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintTopLeft: number; + + /** + * The tint value being applied to the top-right vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintTopRight: number; + + /** + * The tint value being applied to the bottom-left vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintBottomLeft: number; + + /** + * The tint value being applied to the bottom-right vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintBottomRight: number; + + /** + * The tint fill mode. + * + * `false` = An additive tint (the default), where vertices colors are blended with the texture. + * `true` = A fill tint, where the vertices colors replace the texture, but respects texture alpha. */ tintFill: boolean; @@ -2713,7 +3666,7 @@ declare namespace Phaser { * @param bottomLeft The tint being applied to the bottom-left of the Game Object. * @param bottomRight The tint being applied to the bottom-right of the Game Object. */ - setTint(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; + setTint(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; /** * Sets a fill-based tint on this Game Object. @@ -2736,42 +3689,142 @@ declare namespace Phaser { * @param bottomLeft The tint being applied to the bottom-left of the Game Object. * @param bottomRight The tint being applied to the bottom-right of the Game Object. */ - setTintFill(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; + setTintFill(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; /** - * The tint value being applied to the top-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * The tint value being applied to the whole of the Game Object. + * This property is a setter-only. Use the properties `tintTopLeft` etc to read the current tint value. */ - tintTopLeft: integer; + tint: number; /** - * The tint value being applied to the top-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * Does this Game Object have a tint applied? + * + * It checks to see if the 4 tint properties are set to the value 0xffffff + * and that the `tintFill` property is `false`. This indicates that a Game Object isn't tinted. */ - tintTopRight: integer; + readonly isTinted: boolean; /** - * The tint value being applied to the bottom-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. */ - tintBottomLeft: integer; + defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; /** - * The tint value being applied to the bottom-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * The current WebGL pipeline of this Game Object. */ - tintBottomRight: integer; + pipeline: Phaser.Renderer.WebGL.WebGLPipeline; /** - * The tint value being applied to the whole of the Game Object. - * This property is a setter-only. Use the properties `tintTopLeft` etc to read the current tint value. + * Does this Game Object have any Post Pipelines set? */ - tint: integer; + hasPostPipeline: boolean; /** - * Does this Game Object have a tint applied to it or not? + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. */ - readonly isTinted: boolean; + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; + + /** + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. + */ + pipelineData: object; + + /** + * Sets the initial WebGL Pipeline of this Game Object. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + */ + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; + + /** + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; + + /** + * Sets one, or more, Post Pipelines on this Game Object. + * + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; + + /** + * Adds an entry to the `pipelineData` object belonging to this Game Object. + * + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. + */ + setPipelineData(key: string, value?: any): this; + + /** + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. + */ + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; + + /** + * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; + + /** + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPostPipeline(resetData?: boolean): void; + + /** + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. + */ + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; + + /** + * Gets the name of the WebGL Pipeline this Game Object is currently using. + */ + getPipelineName(): string; } @@ -2798,7 +3851,7 @@ declare namespace Phaser { * viewport, and changing the viewport has no impact on the scrolling. * * By default a Camera will render all Game Objects it can see. You can change this using the `ignore` method, - * allowing you to filter Game Objects out on a per-Camera basis. The Camera Manager can manage up to 31 unique + * allowing you to filter Game Objects out on a per-Camera basis. The Camera Manager can manage up to 31 unique * 'Game Object ignore capable' Cameras. Any Cameras beyond 31 that you create will all be given a Camera ID of * zero, meaning that they cannot be used for Game Object exclusion. This means if you need your Camera to ignore * Game Objects, make sure it's one of the first 31 created. @@ -2882,7 +3935,7 @@ declare namespace Phaser { * @param makeMain Set this Camera as being the 'main' camera. This just makes the property `main` a reference to it. Default false. * @param name The name of the Camera. Default ''. */ - add(x?: integer, y?: integer, width?: integer, height?: integer, makeMain?: boolean, name?: string): Phaser.Cameras.Scene2D.Camera; + add(x?: number, y?: number, width?: number, height?: number, makeMain?: boolean, name?: string): Phaser.Cameras.Scene2D.Camera; /** * Adds an existing Camera into the Camera Manager. @@ -2907,7 +3960,7 @@ declare namespace Phaser { * If the optional `isVisible` argument is set it will only count Cameras that are currently visible. * @param isVisible Set the `true` to only include visible Cameras in the total. Default false. */ - getTotal(isVisible?: boolean): integer; + getTotal(isVisible?: boolean): number; /** * Populates this Camera Manager based on the given configuration object, or an array of config objects. @@ -2915,7 +3968,7 @@ declare namespace Phaser { * See the `Phaser.Types.Cameras.Scene2D.CameraConfig` documentation for details of the object structure. * @param config A Camera configuration object, or an array of them, to be added to this Camera Manager. */ - fromJSON(config: Phaser.Types.Cameras.Scene2D.CameraConfig | Phaser.Types.Cameras.Scene2D.CameraConfig[]): Phaser.Cameras.Scene2D.CameraManager; + fromJSON(config: Phaser.Types.Cameras.Scene2D.CameraConfig | Phaser.Types.Cameras.Scene2D.CameraConfig[]): this; /** * Gets a Camera based on its name. @@ -2946,7 +3999,7 @@ declare namespace Phaser { * @param camera The Camera, or an array of Cameras, to be removed from this Camera Manager. * @param runDestroy Automatically call `Camera.destroy` on each Camera removed from this Camera Manager. Default true. */ - remove(camera: Phaser.Cameras.Scene2D.Camera | Phaser.Cameras.Scene2D.Camera[], runDestroy?: boolean): integer; + remove(camera: Phaser.Cameras.Scene2D.Camera | Phaser.Cameras.Scene2D.Camera[], runDestroy?: boolean): number; /** * The internal render method. This is called automatically by the Scene and should not be invoked directly. @@ -2954,10 +4007,18 @@ declare namespace Phaser { * It will iterate through all local cameras and render them in turn, as long as they're visible and have * an alpha level > 0. * @param renderer The Renderer that will render the children to this camera. - * @param children An array of renderable Game Objects. - * @param interpolation Interpolation value. Reserved for future use. + * @param children The Display List for the Scene. + */ + protected render(renderer: Phaser.Renderer.Canvas.CanvasRenderer | Phaser.Renderer.WebGL.WebGLRenderer, children: Phaser.GameObjects.DisplayList): void; + + /** + * Takes an array of Game Objects and a Camera and returns a new array + * containing only those Game Objects that pass the `willRender` test + * against the given Camera. + * @param children An array of Game Objects to be checked against the camera. + * @param camera The camera to filte the Game Objects against. */ - protected render(renderer: Phaser.Renderer.Canvas.CanvasRenderer | Phaser.Renderer.WebGL.WebGLRenderer, children: Phaser.GameObjects.GameObject[], interpolation: number): void; + getVisibleChildren(children: Phaser.GameObjects.GameObject[], camera: Phaser.Cameras.Scene2D.Camera): Phaser.GameObjects.GameObject[]; /** * Resets this Camera Manager. @@ -2972,12 +4033,12 @@ declare namespace Phaser { * @param time The current timestamp as generated by the Request Animation Frame or SetTimeout. * @param delta The delta time, in ms, elapsed since the last frame. */ - protected update(time: integer, delta: number): void; + protected update(time: number, delta: number): void; /** * The event handler that manages the `resize` event dispatched by the Scale Manager. * @param gameSize The default Game Size object. This is the un-modified game dimensions. - * @param baseSize The base Size object. The game dimensions multiplied by the resolution. The canvas width / height values match this. + * @param baseSize The base Size object. The game dimensions. The canvas width / height values match this. */ onResize(gameSize: Phaser.Structs.Size, baseSize: Phaser.Structs.Size): void; @@ -3036,7 +4097,7 @@ declare namespace Phaser { /** * The duration of the effect, in milliseconds. */ - readonly duration: integer; + readonly duration: number; /** * If this effect is running this holds the current percentage of the progress, a value between 0 and 1. @@ -3055,14 +4116,14 @@ declare namespace Phaser { * It is sent two arguments: A reference to the camera and a progress amount between 0 and 1 indicating how complete the effect is. * @param context The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs. */ - start(direction?: boolean, duration?: integer, red?: integer, green?: integer, blue?: integer, force?: boolean, callback?: Phaser.Types.Cameras.Scene2D.CameraFadeCallback, context?: any): Phaser.Cameras.Scene2D.Camera; + start(direction?: boolean, duration?: number, red?: number, green?: number, blue?: number, force?: boolean, callback?: Phaser.Types.Cameras.Scene2D.CameraFadeCallback, context?: any): Phaser.Cameras.Scene2D.Camera; /** * The main update loop for this effect. Called automatically by the Camera. * @param time The current timestamp as generated by the Request Animation Frame or SetTimeout. * @param delta The delta time, in ms, elapsed since the last frame. */ - update(time: integer, delta: number): void; + update(time: number, delta: number): void; /** * Called internally by the Canvas Renderer. @@ -3072,10 +4133,10 @@ declare namespace Phaser { /** * Called internally by the WebGL Renderer. - * @param pipeline The WebGL Pipeline to render to. + * @param pipeline The WebGL Pipeline to render to. Must provide the `drawFillRect` method. * @param getTintFunction A function that will return the gl safe tint colors. */ - postRenderWebGL(pipeline: Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline, getTintFunction: Function): boolean; + postRenderWebGL(pipeline: Phaser.Renderer.WebGL.Pipelines.MultiPipeline, getTintFunction: Function): boolean; /** * Called internally when the effect completes. @@ -3126,7 +4187,7 @@ declare namespace Phaser { /** * The duration of the effect, in milliseconds. */ - readonly duration: integer; + readonly duration: number; /** * If this effect is running this holds the current percentage of the progress, a value between 0 and 1. @@ -3136,22 +4197,22 @@ declare namespace Phaser { /** * Flashes the Camera to or from the given color over the duration specified. * @param duration The duration of the effect in milliseconds. Default 250. - * @param red The amount to fade the red channel towards. A value between 0 and 255. Default 255. - * @param green The amount to fade the green channel towards. A value between 0 and 255. Default 255. - * @param blue The amount to fade the blue channel towards. A value between 0 and 255. Default 255. + * @param red The amount to flash the red channel towards. A value between 0 and 255. Default 255. + * @param green The amount to flash the green channel towards. A value between 0 and 255. Default 255. + * @param blue The amount to flash the blue channel towards. A value between 0 and 255. Default 255. * @param force Force the effect to start immediately, even if already running. Default false. * @param callback This callback will be invoked every frame for the duration of the effect. * It is sent two arguments: A reference to the camera and a progress amount between 0 and 1 indicating how complete the effect is. * @param context The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs. */ - start(duration?: integer, red?: integer, green?: integer, blue?: integer, force?: boolean, callback?: Phaser.Types.Cameras.Scene2D.CameraFlashCallback, context?: any): Phaser.Cameras.Scene2D.Camera; + start(duration?: number, red?: number, green?: number, blue?: number, force?: boolean, callback?: Phaser.Types.Cameras.Scene2D.CameraFlashCallback, context?: any): Phaser.Cameras.Scene2D.Camera; /** * The main update loop for this effect. Called automatically by the Camera. * @param time The current timestamp as generated by the Request Animation Frame or SetTimeout. * @param delta The delta time, in ms, elapsed since the last frame. */ - update(time: integer, delta: number): void; + update(time: number, delta: number): void; /** * Called internally by the Canvas Renderer. @@ -3161,10 +4222,10 @@ declare namespace Phaser { /** * Called internally by the WebGL Renderer. - * @param pipeline The WebGL Pipeline to render to. + * @param pipeline The WebGL Pipeline to render to. Must provide the `drawFillRect` method. * @param getTintFunction A function that will return the gl safe tint colors. */ - postRenderWebGL(pipeline: Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline, getTintFunction: Function): boolean; + postRenderWebGL(pipeline: Phaser.Renderer.WebGL.Pipelines.MultiPipeline, getTintFunction: Function): boolean; /** * Called internally when the effect completes. @@ -3216,7 +4277,7 @@ declare namespace Phaser { /** * The duration of the effect, in milliseconds. */ - readonly duration: integer; + readonly duration: number; /** * The starting scroll coordinates to pan the camera from. @@ -3256,14 +4317,129 @@ declare namespace Phaser { * the current camera scroll x coordinate and the current camera scroll y coordinate. * @param context The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs. */ - start(x: number, y: number, duration?: integer, ease?: string | Function, force?: boolean, callback?: Phaser.Types.Cameras.Scene2D.CameraPanCallback, context?: any): Phaser.Cameras.Scene2D.Camera; + start(x: number, y: number, duration?: number, ease?: string | Function, force?: boolean, callback?: Phaser.Types.Cameras.Scene2D.CameraPanCallback, context?: any): Phaser.Cameras.Scene2D.Camera; /** * The main update loop for this effect. Called automatically by the Camera. * @param time The current timestamp as generated by the Request Animation Frame or SetTimeout. * @param delta The delta time, in ms, elapsed since the last frame. */ - update(time: integer, delta: number): void; + update(time: number, delta: number): void; + + /** + * Called internally when the effect completes. + */ + effectComplete(): void; + + /** + * Resets this camera effect. + * If it was previously running, it stops instantly without calling its onComplete callback or emitting an event. + */ + reset(): void; + + /** + * Destroys this effect, releasing it from the Camera. + */ + destroy(): void; + + } + + /** + * A Camera Rotate effect. + * + * This effect will rotate the Camera so that the its viewport finishes at the given angle in radians, + * over the duration and with the ease specified. + * + * Camera rotation always takes place based on the Camera viewport. By default, rotation happens + * in the center of the viewport. You can adjust this with the `originX` and `originY` properties. + * + * Rotation influences the rendering of _all_ Game Objects visible by this Camera. However, it does not + * rotate the Camera viewport itself, which always remains an axis-aligned rectangle. + * + * Only the camera is rotates. None of the objects it is displaying are impacted, i.e. their positions do + * not change. + * + * The effect will dispatch several events on the Camera itself and you can also specify an `onUpdate` callback, + * which is invoked each frame for the duration of the effect if required. + */ + class RotateTo { + /** + * + * @param camera The camera this effect is acting upon. + */ + constructor(camera: Phaser.Cameras.Scene2D.Camera); + + /** + * The Camera this effect belongs to. + */ + readonly camera: Phaser.Cameras.Scene2D.Camera; + + /** + * Is this effect actively running? + */ + readonly isRunning: boolean; + + /** + * The duration of the effect, in milliseconds. + */ + readonly duration: number; + + /** + * The starting angle to rotate the camera from. + */ + source: number; + + /** + * The constantly updated value based on the force. + */ + current: number; + + /** + * The destination angle in radians to rotate the camera to. + */ + destination: number; + + /** + * The ease function to use during the Rotate. + */ + ease: Function; + + /** + * If this effect is running this holds the current percentage of the progress, a value between 0 and 1. + */ + progress: number; + + /** + * The direction of the rotation. + */ + clockwise: boolean; + + /** + * The shortest direction to the target rotation. + */ + shortestPath: boolean; + + /** + * This effect will scroll the Camera so that the center of its viewport finishes at the given angle, + * over the duration and with the ease specified. + * @param radians The destination angle in radians to rotate the Camera viewport to. If the angle is positive then the rotation is clockwise else anticlockwise + * @param shortestPath If shortest path is set to true the camera will rotate in the quickest direction clockwise or anti-clockwise. Default false. + * @param duration The duration of the effect in milliseconds. Default 1000. + * @param ease The ease to use for the Rotate. Can be any of the Phaser Easing constants or a custom function. Default 'Linear'. + * @param force Force the rotation effect to start immediately, even if already running. Default false. + * @param callback This callback will be invoked every frame for the duration of the effect. + * It is sent four arguments: A reference to the camera, a progress amount between 0 and 1 indicating how complete the effect is, + * the current camera scroll x coordinate and the current camera scroll y coordinate. + * @param context The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs. + */ + start(radians: number, shortestPath?: boolean, duration?: number, ease?: string | Function, force?: boolean, callback?: CameraRotateCallback, context?: any): Phaser.Cameras.Scene2D.Camera; + + /** + * The main update loop for this effect. Called automatically by the Camera. + * @param time The current timestamp as generated by the Request Animation Frame or SetTimeout. + * @param delta The delta time, in ms, elapsed since the last frame. + */ + update(time: number, delta: number): void; /** * Called internally when the effect completes. @@ -3314,7 +4490,7 @@ declare namespace Phaser { /** * The duration of the effect, in milliseconds. */ - readonly duration: integer; + readonly duration: number; /** * The intensity of the effect. Use small float values. The default when the effect starts is 0.05. @@ -3337,7 +4513,7 @@ declare namespace Phaser { * It is sent two arguments: A reference to the camera and a progress amount between 0 and 1 indicating how complete the effect is. * @param context The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs. */ - start(duration?: integer, intensity?: number | Phaser.Math.Vector2, force?: boolean, callback?: Phaser.Types.Cameras.Scene2D.CameraShakeCallback, context?: any): Phaser.Cameras.Scene2D.Camera; + start(duration?: number, intensity?: number | Phaser.Math.Vector2, force?: boolean, callback?: Phaser.Types.Cameras.Scene2D.CameraShakeCallback, context?: any): Phaser.Cameras.Scene2D.Camera; /** * The pre-render step for this effect. Called automatically by the Camera. @@ -3349,7 +4525,7 @@ declare namespace Phaser { * @param time The current timestamp as generated by the Request Animation Frame or SetTimeout. * @param delta The delta time, in ms, elapsed since the last frame. */ - update(time: integer, delta: number): void; + update(time: number, delta: number): void; /** * Called internally when the effect completes. @@ -3397,7 +4573,7 @@ declare namespace Phaser { /** * The duration of the effect, in milliseconds. */ - readonly duration: integer; + readonly duration: number; /** * The starting zoom value; @@ -3430,14 +4606,14 @@ declare namespace Phaser { * and the current camera zoom value. * @param context The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs. */ - start(zoom: number, duration?: integer, ease?: string | Function, force?: boolean, callback?: Phaser.Types.Cameras.Scene2D.CameraZoomCallback, context?: any): Phaser.Cameras.Scene2D.Camera; + start(zoom: number, duration?: number, ease?: string | Function, force?: boolean, callback?: Phaser.Types.Cameras.Scene2D.CameraZoomCallback, context?: any): Phaser.Cameras.Scene2D.Camera; /** * The main update loop for this effect. Called automatically by the Camera. * @param time The current timestamp as generated by the Request Animation Frame or SetTimeout. * @param delta The delta time, in ms, elapsed since the last frame. */ - update(time: integer, delta: number): void; + update(time: number, delta: number): void; /** * Called internally when the effect completes. @@ -3517,6 +4693,17 @@ declare namespace Phaser { */ const FLASH_START: any; + /** + * The Camera Follower Update Event. + * + * This event is dispatched by a Camera instance when it is following a + * Game Object and the Camera position has been updated as a result of + * that following. + * + * Listen to it from a Camera instance using: `camera.on('followupdate', listener)`. + */ + const FOLLOW_UPDATE: any; + /** * The Camera Pan Complete Event. * @@ -3551,6 +4738,20 @@ declare namespace Phaser { */ const PRE_RENDER: any; + /** + * The Camera Rotate Complete Event. + * + * This event is dispatched by a Camera instance when the Rotate Effect completes. + */ + const ROTATE_COMPLETE: any; + + /** + * The Camera Rotate Start Event. + * + * This event is dispatched by a Camera instance when the Rotate Effect starts. + */ + const ROTATE_START: any; + /** * The Camera Shake Complete Event. * @@ -3667,18 +4868,18 @@ declare namespace Phaser { /** * Starts the Key Control running, providing it has been linked to a camera. */ - start(): Phaser.Cameras.Controls.FixedKeyControl; + start(): this; /** * Stops this Key Control from running. Call `start` to start it again. */ - stop(): Phaser.Cameras.Controls.FixedKeyControl; + stop(): this; /** * Binds this Key Control to a camera. * @param camera The camera to bind this Key Control to. */ - setCamera(camera: Phaser.Cameras.Scene2D.Camera): Phaser.Cameras.Controls.FixedKeyControl; + setCamera(camera: Phaser.Cameras.Scene2D.Camera): this; /** * Applies the results of pressing the control keys to the Camera. @@ -3804,18 +5005,18 @@ declare namespace Phaser { /** * Starts the Key Control running, providing it has been linked to a camera. */ - start(): Phaser.Cameras.Controls.SmoothedKeyControl; + start(): this; /** * Stops this Key Control from running. Call `start` to start it again. */ - stop(): Phaser.Cameras.Controls.SmoothedKeyControl; + stop(): this; /** * Binds this Key Control to a camera. * @param camera The camera to bind this Key Control to. */ - setCamera(camera: Phaser.Cameras.Scene2D.Camera): Phaser.Cameras.Controls.SmoothedKeyControl; + setCamera(camera: Phaser.Cameras.Scene2D.Camera): this; /** * Applies the results of pressing the control keys to the Camera. @@ -3842,55 +5043,61 @@ declare namespace Phaser { const VERSION: string; /** - * AUTO Detect Renderer. + * This setting will auto-detect if the browser is capable of suppporting WebGL. + * If it is, it will use the WebGL Renderer. If not, it will fall back to the Canvas Renderer. */ - const AUTO: integer; + const AUTO: number; /** - * Canvas Renderer. + * Forces Phaser to only use the Canvas Renderer, regardless if the browser supports + * WebGL or not. */ - const CANVAS: integer; + const CANVAS: number; /** - * WebGL Renderer. + * Forces Phaser to use the WebGL Renderer. If the browser does not support it, there is + * no fallback to Canvas with this setting, so you should trap it and display a suitable + * message to the user. */ - const WEBGL: integer; + const WEBGL: number; /** - * Headless Renderer. + * A Headless Renderer doesn't create either a Canvas or WebGL Renderer. However, it still + * absolutely relies on the DOM being present and available. This mode is meant for unit testing, + * not for running Phaser on the server, which is something you really shouldn't do. */ - const HEADLESS: integer; + const HEADLESS: number; /** * In Phaser the value -1 means 'forever' in lots of cases, this const allows you to use it instead * to help you remember what the value is doing in your code. */ - const FOREVER: integer; + const FOREVER: number; /** * Direction constant. */ - const NONE: integer; + const NONE: number; /** * Direction constant. */ - const UP: integer; + const UP: number; /** * Direction constant. */ - const DOWN: integer; + const DOWN: number; /** * Direction constant. */ - const LEFT: integer; + const LEFT: number; /** * Direction constant. */ - const RIGHT: integer; + const RIGHT: number; /** * The Phaser.Game instance is the main controller for the entire Phaser game. It is responsible @@ -4161,22 +5368,17 @@ declare namespace Phaser { /** * The width of the underlying canvas, in pixels. */ - readonly width: integer | string; + readonly width: number | string; /** * The height of the underlying canvas, in pixels. */ - readonly height: integer | string; + readonly height: number | string; /** * The zoom factor, as used by the Scale Manager. */ - readonly zoom: Phaser.Scale.ZoomType | integer; - - /** - * The canvas device pixel resolution. Currently un-used. - */ - readonly resolution: number; + readonly zoom: Phaser.Scale.ZoomType | number; /** * A parent DOM element into which the canvas created by the renderer will be injected. @@ -4196,7 +5398,7 @@ declare namespace Phaser { /** * Automatically round the display and style sizes of the canvas. This can help with performance in lower-powered devices. */ - readonly autoRound: integer; + readonly autoRound: number; /** * Automatically center the canvas within the parent? @@ -4206,7 +5408,7 @@ declare namespace Phaser { /** * How many ms should elapse before checking if the browser size has changed? */ - readonly resizeInterval: integer; + readonly resizeInterval: number; /** * The DOM element that will be sent into full screen mode, or its `id`. If undefined Phaser will create its own div and insert the canvas into it when entering fullscreen mode. @@ -4216,22 +5418,22 @@ declare namespace Phaser { /** * The minimum width, in pixels, the canvas will scale down to. A value of zero means no minimum. */ - readonly minWidth: integer; + readonly minWidth: number; /** * The maximum width, in pixels, the canvas will scale up to. A value of zero means no maximum. */ - readonly maxWidth: integer; + readonly maxWidth: number; /** * The minimum height, in pixels, the canvas will scale down to. A value of zero means no minimum. */ - readonly minHeight: integer; + readonly minHeight: number; /** * The maximum height, in pixels, the canvas will scale up to. A value of zero means no maximum. */ - readonly maxHeight: integer; + readonly maxHeight: number; /** * Force Phaser to use a specific renderer. Can be `CONST.CANVAS`, `CONST.WEBGL`, `CONST.HEADLESS` or `CONST.AUTO` (default) @@ -4311,7 +5513,7 @@ declare namespace Phaser { /** * `preventDefault` will be called on every non-modified key which has a key code in this array. By default, it is empty. */ - readonly inputKeyboardCapture: integer[]; + readonly inputKeyboardCapture: number[]; /** * Enable the Mouse Plugin. This can be disabled in games that don't need mouse input. @@ -4324,9 +5526,24 @@ declare namespace Phaser { readonly inputMouseEventTarget: any; /** - * Should mouse events be captured? I.e. have prevent default called on them. + * Should `mousedown` DOM events have `preventDefault` called on them? + */ + readonly inputMousePreventDefaultDown: boolean; + + /** + * Should `mouseup` DOM events have `preventDefault` called on them? + */ + readonly inputMousePreventDefaultUp: boolean; + + /** + * Should `mousemove` DOM events have `preventDefault` called on them? + */ + readonly inputMousePreventDefaultMove: boolean; + + /** + * Should `wheel` DOM events have `preventDefault` called on them? */ - readonly inputMouseCapture: boolean; + readonly inputMousePreventDefaultWheel: boolean; /** * Enable the Touch Plugin. This can be disabled in games that don't need touch input. @@ -4346,12 +5563,12 @@ declare namespace Phaser { /** * The number of Pointer objects created by default. In a mouse-only, or non-multi touch game, you can leave this as 1. */ - readonly inputActivePointers: integer; + readonly inputActivePointers: number; /** * The smoothing factor to apply during Pointer movement. See {@link Phaser.Input.Pointer#smoothFactor}. */ - readonly inputSmoothFactor: integer; + readonly inputSmoothFactor: number; /** * Should Phaser listen for input events on the Window? If you disable this, events like 'POINTER_UP_OUTSIDE' will no longer fire. @@ -4403,6 +5620,11 @@ declare namespace Phaser { */ readonly fps: Phaser.Types.Core.FPSConfig; + /** + * An object mapping WebGL names to WebGLPipeline classes. These should be class constructors, not instances. + */ + readonly pipeline: Phaser.Types.Core.PipelineConfig; + /** * When set to `true`, WebGL uses linear interpolation to draw scaled or rotated textures, giving a smooth appearance. When set to `false`, WebGL uses nearest-neighbor interpolation, giving a crisper appearance. `false` also disables antialiasing of the game canvas itself, if the browser supports it, when the game canvas is scaled. */ @@ -4459,14 +5681,19 @@ declare namespace Phaser { readonly powerPreference: string; /** - * The default WebGL Batch size. + * The default WebGL Batch size. Represents the number of _quads_ that can be added to a single batch. */ - readonly batchSize: integer; + readonly batchSize: number; + + /** + * When in WebGL mode, this sets the maximum number of GPU Textures to use. The default, -1, will use all available units. The WebGL1 spec says all browsers should provide a minimum of 8. + */ + readonly maxTextures: number; /** * The maximum number of lights allowed to be visible within range of a single Camera in the LightManager. */ - readonly maxLights: integer; + readonly maxLights: number; /** * The background color of the game canvas. The default is black. This value is ignored if `transparent` is set to `true`. @@ -4506,7 +5733,7 @@ declare namespace Phaser { /** * Maximum parallel downloads allowed for resources (Default to 32). */ - readonly loaderMaxParallelDownloads: integer; + readonly loaderMaxParallelDownloads: number; /** * 'anonymous', 'use-credentials', or `undefined`. If you're not making cross-origin requests, leave this as `undefined`. See {@link https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes}. @@ -4536,7 +5763,12 @@ declare namespace Phaser { /** * Optional XHR timeout value, in ms. */ - readonly loaderTimeout: integer; + readonly loaderTimeout: number; + + /** + * Optional XHR withCredentials value. + */ + readonly loaderWithCredentials: boolean; /** * An array of global plugins to be installed. @@ -4563,6 +5795,11 @@ declare namespace Phaser { */ readonly missingImage: string; + /** + * A base64 encoded PNG that will be used as the default texture when a texture is assigned that is white or not loaded. + */ + readonly whiteImage: string; + } /** @@ -4770,7 +6007,7 @@ declare namespace Phaser { /** * The minimum fps rate you want the Time Step to run at. */ - minFps: integer; + minFps: number; /** * The target fps rate for the Time Step to run at. @@ -4779,23 +6016,23 @@ declare namespace Phaser { * the control of Phaser. Instead, it allows you to determine performance issues and if the Time Step * is spiraling out of control. */ - targetFps: integer; + targetFps: number; /** * An exponential moving average of the frames per second. */ - readonly actualFps: integer; + readonly actualFps: number; /** * The time at which the next fps rate update will take place. * When an fps update happens, the `framesThisSecond` value is reset. */ - readonly nextFpsUpdate: integer; + readonly nextFpsUpdate: number; /** * The number of frames processed this second. */ - readonly framesThisSecond: integer; + readonly framesThisSecond: number; /** * A callback to be invoked each time the Time Step steps. @@ -4828,7 +6065,7 @@ declare namespace Phaser { * The current frame the game is on. This counter is incremented once every game step, regardless of how much * time has passed and is unaffected by delta smoothing. */ - readonly frame: integer; + readonly frame: number; /** * Is the browser currently considered in focus by the Page Visibility API? @@ -4839,24 +6076,24 @@ declare namespace Phaser { /** * The delta time, in ms, since the last game step. This is a clamped and smoothed average value. */ - delta: integer; + delta: number; /** * Internal index of the delta history position. */ - deltaIndex: integer; + deltaIndex: number; /** * Internal array holding the previous delta values, used for delta smoothing. */ - deltaHistory: integer[]; + deltaHistory: number[]; /** * The maximum number of delta values that are retained in order to calculate a smoothed moving average. * * This can be changed in the Game Config via the `fps.deltaHistory` property. The default is 10. */ - deltaSmoothingMax: integer; + deltaSmoothingMax: number; /** * The number of frames that the cooldown is set to after the browser panics over the FPS rate, usually @@ -4864,7 +6101,7 @@ declare namespace Phaser { * * This can be changed in the Game Config via the `fps.panicMax` property. The default is 120. */ - panicMax: integer; + panicMax: number; /** * The actual elapsed time in ms between one update and the next. @@ -4984,8 +6221,36 @@ declare namespace Phaser { namespace Create { /** - * [description] - * @param config [description] + * Generates a texture based on the given Create configuration object. + * + * The texture is drawn using a fixed-size indexed palette of 16 colors, where the hex value in the + * data cells map to a single color. For example, if the texture config looked like this: + * + * ```javascript + * var star = [ + * '.....828.....', + * '....72227....', + * '....82228....', + * '...7222227...', + * '2222222222222', + * '8222222222228', + * '.72222222227.', + * '..787777787..', + * '..877777778..', + * '.78778887787.', + * '.27887.78872.', + * '.787.....787.' + * ]; + * + * this.textures.generate('star', { data: star, pixelWidth: 4 }); + * ``` + * + * Then it would generate a texture that is 52 x 48 pixels in size, because each cell of the data array + * represents 1 pixel multiplied by the `pixelWidth` value. The cell values, such as `8`, maps to color + * number 8 in the palette. If a cell contains a period character `.` then it is transparent. + * + * The default palette is Arne16, but you can specify your own using the `palette` property. + * @param config The Generate Texture Configuration object. */ function GenerateTexture(config: Phaser.Types.Create.GenerateTextureConfig): HTMLCanvasElement; @@ -5077,7 +6342,7 @@ declare namespace Phaser { * @param graphics The graphics object this curve should be drawn to. * @param pointsTotal The number of intermediary points that make up this curve. A higher number of points will result in a smoother curve. Default 32. */ - draw(graphics: G, pointsTotal?: integer): G; + draw(graphics: G, pointsTotal?: number): G; /** * Returns a JSON object that describes this curve. @@ -5112,12 +6377,12 @@ declare namespace Phaser { /** * The default number of divisions within the curve. */ - defaultDivisions: integer; + defaultDivisions: number; /** * The quantity of arc length divisions within the curve. */ - arcLengthDivisions: integer; + arcLengthDivisions: number; /** * An array of cached arc length values. @@ -5142,7 +6407,7 @@ declare namespace Phaser { * @param graphics The Graphics instance onto which this curve will be drawn. * @param pointsTotal The resolution of the curve. The higher the value the smoother it will render, at the cost of rendering performance. Default 32. */ - draw(graphics: G, pointsTotal?: integer): G; + draw(graphics: G, pointsTotal?: number): G; /** * Returns a Rectangle where the position and dimensions match the bounds of this Curve. @@ -5152,14 +6417,14 @@ declare namespace Phaser { * @param out The Rectangle to store the bounds in. If falsey a new object will be created. * @param accuracy The accuracy of the bounds calculations. Default 16. */ - getBounds(out?: Phaser.Geom.Rectangle, accuracy?: integer): Phaser.Geom.Rectangle; + getBounds(out?: Phaser.Geom.Rectangle, accuracy?: number): Phaser.Geom.Rectangle; /** * Returns an array of points, spaced out X distance pixels apart. * The smaller the distance, the larger the array will be. * @param distance The distance, in pixels, between each point along the curve. */ - getDistancePoints(distance: integer): Phaser.Geom.Point[]; + getDistancePoints(distance: number): Phaser.Geom.Point[]; /** * Get a point at the end of the curve. @@ -5184,7 +6449,7 @@ declare namespace Phaser { * - [divisions] All segments * @param divisions The number of divisions or segments. */ - getLengths(divisions?: integer): number[]; + getLengths(divisions?: number): number[]; /** * Get a point at a relative position on the curve, by arc length. @@ -5209,7 +6474,7 @@ declare namespace Phaser { * @param stepRate The curve distance between points, implying `divisions`. * @param out An optional array to store the points in. */ - getPoints(divisions?: integer, stepRate?: number, out?: O): O; + getPoints(divisions?: number, stepRate?: number, out?: O): O; /** * Get a random point from the curve. @@ -5225,7 +6490,7 @@ declare namespace Phaser { * @param stepRate Step between points. Used to calculate the number of points to return when divisions is falsy. Ignored if divisions is positive. * @param out An optional array to store the points in. */ - getSpacedPoints(divisions?: integer, stepRate?: number, out?: any[] | Phaser.Math.Vector2[]): Phaser.Math.Vector2[]; + getSpacedPoints(divisions?: number, stepRate?: number, out?: any[] | Phaser.Math.Vector2[]): Phaser.Math.Vector2[]; /** * Get a point at the start of the curve. @@ -5251,19 +6516,19 @@ declare namespace Phaser { getTangentAt(u: number, out?: O): O; /** - * [description] - * @param distance [description] - * @param divisions [description] + * Given a distance in pixels, get a t to find p. + * @param distance The distance, in pixels. + * @param divisions Optional amount of divisions. */ - getTFromDistance(distance: integer, divisions?: integer): number; + getTFromDistance(distance: number, divisions?: number): number; /** - * [description] - * @param u [description] - * @param distance [description] - * @param divisions [description] + * Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant. + * @param u A float between 0 and 1. + * @param distance The distance, in pixels. + * @param divisions Optional amount of divisions. */ - getUtoTmapping(u: number, distance: integer, divisions?: integer): number; + getUtoTmapping(u: number, distance: number, divisions?: number): number; /** * Calculate and cache the arc lengths. @@ -5289,7 +6554,7 @@ declare namespace Phaser { * @param clockwise Whether the ellipse angles are given as clockwise (`true`) or counter-clockwise (`false`). Default false. * @param rotation The rotation of the ellipse, in degrees. Default 0. */ - constructor(x?: number | Phaser.Types.Curves.EllipseCurveConfig, y?: number, xRadius?: number, yRadius?: number, startAngle?: integer, endAngle?: integer, clockwise?: boolean, rotation?: integer); + constructor(x?: number | Phaser.Types.Curves.EllipseCurveConfig, y?: number, xRadius?: number, yRadius?: number, startAngle?: number, endAngle?: number, clockwise?: boolean, rotation?: number); /** * The center point of the ellipse. Used for calculating rotation. @@ -5303,8 +6568,8 @@ declare namespace Phaser { getStartPoint(out?: O): O; /** - * [description] - * @param divisions [description] + * Get the resolution of the curve. + * @param divisions Optional divisions value. */ getResolution(divisions: number): number; @@ -5319,49 +6584,49 @@ declare namespace Phaser { * Sets the horizontal radius of this curve. * @param value The horizontal radius of this curve. */ - setXRadius(value: number): Phaser.Curves.Ellipse; + setXRadius(value: number): this; /** * Sets the vertical radius of this curve. * @param value The vertical radius of this curve. */ - setYRadius(value: number): Phaser.Curves.Ellipse; + setYRadius(value: number): this; /** * Sets the width of this curve. * @param value The width of this curve. */ - setWidth(value: number): Phaser.Curves.Ellipse; + setWidth(value: number): this; /** * Sets the height of this curve. * @param value The height of this curve. */ - setHeight(value: number): Phaser.Curves.Ellipse; + setHeight(value: number): this; /** * Sets the start angle of this curve. * @param value The start angle of this curve, in radians. */ - setStartAngle(value: number): Phaser.Curves.Ellipse; + setStartAngle(value: number): this; /** * Sets the end angle of this curve. * @param value The end angle of this curve, in radians. */ - setEndAngle(value: number): Phaser.Curves.Ellipse; + setEndAngle(value: number): this; /** * Sets if this curve extends clockwise or anti-clockwise. * @param value The clockwise state of this curve. */ - setClockwise(value: boolean): Phaser.Curves.Ellipse; + setClockwise(value: boolean): this; /** * Sets the rotation of this curve. * @param value The rotation of this curve, in radians. */ - setRotation(value: number): Phaser.Curves.Ellipse; + setRotation(value: number): this; /** * The x coordinate of the center of the ellipse. @@ -5445,7 +6710,7 @@ declare namespace Phaser { /** * The quantity of arc length divisions within the curve. */ - arcLengthDivisions: integer; + arcLengthDivisions: number; /** * Returns a Rectangle where the position and dimensions match the bounds of this Curve. @@ -5485,12 +6750,12 @@ declare namespace Phaser { getTangent(): O; /** - * [description] - * @param u [description] - * @param distance [description] - * @param divisions [description] + * Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant. + * @param u A float between 0 and 1. + * @param distance The distance, in pixels. + * @param divisions Optional amount of divisions. */ - getUtoTmapping(u: number, distance: integer, divisions?: integer): number; + getUtoTmapping(u: number, distance: number, divisions?: number): number; /** * Draws this curve on the given Graphics object. @@ -5515,13 +6780,14 @@ declare namespace Phaser { } /** - * A MoveTo Curve is a very simple curve consisting of only a single point. Its intended use is to move the ending point in a Path. + * A MoveTo Curve is a very simple curve consisting of only a single point. + * Its intended use is to move the ending point in a Path. */ class MoveTo { /** * - * @param x `x` pixel coordinate. - * @param y `y` pixel coordinate. + * @param x `x` pixel coordinate. Default 0. + * @param y `y` pixel coordinate. Default 0. */ constructor(x?: number, y?: number); @@ -5617,7 +6883,7 @@ declare namespace Phaser { * The Curve does not have to start where the Path ends or, for an empty Path, at its defined starting point. * @param curve The Curve to append. */ - add(curve: Phaser.Curves.Curve): Phaser.Curves.Path; + add(curve: Phaser.Curves.Curve): this; /** * Creates a circular Ellipse Curve positioned at the end of the Path. @@ -5625,7 +6891,7 @@ declare namespace Phaser { * @param clockwise `true` to create a clockwise circle as opposed to a counter-clockwise circle. Default false. * @param rotation The rotation of the circle in degrees. Default 0. */ - circleTo(radius: number, clockwise?: boolean, rotation?: number): Phaser.Curves.Path; + circleTo(radius: number, clockwise?: boolean, rotation?: number): this; /** * Ensures that the Path is closed. @@ -5634,7 +6900,7 @@ declare namespace Phaser { * * Calling this method on an empty Path will result in an error. */ - closePath(): Phaser.Curves.Path; + closePath(): this; /** * Creates a cubic bezier curve starting at the previous end point and ending at p3, using p1 and p2 as control points. @@ -5645,7 +6911,7 @@ declare namespace Phaser { * @param control2X The x coordinate of the second control point. Not used if Vector2s are provided as the first 3 arguments. * @param control2Y The y coordinate of the second control point. Not used if Vector2s are provided as the first 3 arguments. */ - cubicBezierTo(x: number | Phaser.Math.Vector2, y: number | Phaser.Math.Vector2, control1X: number | Phaser.Math.Vector2, control1Y?: number, control2X?: number, control2Y?: number): Phaser.Curves.Path; + cubicBezierTo(x: number | Phaser.Math.Vector2, y: number | Phaser.Math.Vector2, control1X: number | Phaser.Math.Vector2, control1Y?: number, control2X?: number, control2Y?: number): this; /** * Creates a Quadratic Bezier Curve starting at the ending point of the Path. @@ -5654,14 +6920,14 @@ declare namespace Phaser { * @param controlX If `x` is not a `Vector2`, the X coordinate of the first control point. * @param controlY If `x` is not a `Vector2`, the Y coordinate of the first control point. */ - quadraticBezierTo(x: number | Phaser.Math.Vector2[], y?: number, controlX?: number, controlY?: number): Phaser.Curves.Path; + quadraticBezierTo(x: number | Phaser.Math.Vector2[], y?: number, controlX?: number, controlY?: number): this; /** * Draws all Curves in the Path to a Graphics Game Object. * @param graphics The Graphics Game Object to draw to. * @param pointsTotal The number of points to draw for each Curve. Higher numbers result in a smoother curve but require more processing. Default 32. */ - draw(graphics: Phaser.GameObjects.Graphics, pointsTotal?: integer): G; + draw(graphics: Phaser.GameObjects.Graphics, pointsTotal?: number): G; /** * Creates an ellipse curve positioned at the previous end point, using the given parameters. @@ -5672,7 +6938,7 @@ declare namespace Phaser { * @param clockwise Whether the ellipse angles are given as clockwise (`true`) or counter-clockwise (`false`). Default false. * @param rotation The rotation of the ellipse, in degrees. Default 0. */ - ellipseTo(xRadius?: number, yRadius?: number, startAngle?: integer, endAngle?: integer, clockwise?: boolean, rotation?: number): Phaser.Curves.Path; + ellipseTo(xRadius?: number, yRadius?: number, startAngle?: number, endAngle?: number, clockwise?: boolean, rotation?: number): this; /** * Creates a Path from a Path Configuration object. @@ -5680,14 +6946,14 @@ declare namespace Phaser { * The provided object should be a {@link Phaser.Types.Curves.JSONPath}, as returned by {@link #toJSON}. Providing a malformed object may cause errors. * @param data The JSON object containing the Path data. */ - fromJSON(data: Phaser.Types.Curves.JSONPath): Phaser.Curves.Path; + fromJSON(data: Phaser.Types.Curves.JSONPath): this; /** * Returns a Rectangle with a position and size matching the bounds of this Path. * @param out The Rectangle to store the bounds in. * @param accuracy The accuracy of the bounds calculations. Higher values are more accurate at the cost of calculation speed. Default 16. */ - getBounds(out?: O, accuracy?: integer): O; + getBounds(out?: O, accuracy?: number): O; /** * Returns an array containing the length of the Path at the end of each Curve. @@ -5722,7 +6988,7 @@ declare namespace Phaser { * Get a sequence of points on the path. * @param divisions The number of divisions per resolution per curve. Default 12. */ - getPoints(divisions?: integer): Phaser.Math.Vector2[]; + getPoints(divisions?: number): Phaser.Math.Vector2[]; /** * Returns a randomly chosen point anywhere on the path. This follows the same rules as `getPoint` in that it may return a point on any Curve inside this path. @@ -5738,7 +7004,7 @@ declare namespace Phaser { * The resulting points are equally spaced with respect to the points' position on the path, but not necessarily equally spaced spatially. * @param divisions The amount of points to divide this Path into. Default 40. */ - getSpacedPoints(divisions?: integer): Phaser.Math.Vector2[]; + getSpacedPoints(divisions?: number): Phaser.Math.Vector2[]; /** * Returns the starting point of the Path. @@ -5746,18 +7012,25 @@ declare namespace Phaser { */ getStartPoint(out?: O): O; + /** + * Gets a unit vector tangent at a relative position on the path. + * @param t The relative position on the path, [0..1]. + * @param out A vector to store the result in. + */ + getTangent(t: number, out?: O): O; + /** * Creates a line curve from the previous end point to x/y. * @param x The X coordinate of the line's end point, or a `Vector2` containing the entire end point. * @param y The Y coordinate of the line's end point, if a number was passed as the X parameter. */ - lineTo(x: number | Phaser.Math.Vector2, y?: number): Phaser.Curves.Path; + lineTo(x: number | Phaser.Math.Vector2, y?: number): this; /** * Creates a spline curve starting at the previous end point, using the given points on the curve. * @param points The points the newly created spline curve should consist of. */ - splineTo(points: Phaser.Math.Vector2[]): Phaser.Curves.Path; + splineTo(points: Phaser.Math.Vector2[]): this; /** * Creates a "gap" in this path from the path's current end point to the given coordinates. @@ -5766,7 +7039,7 @@ declare namespace Phaser { * @param x The X coordinate of the position to move the path's end point to, or a `Vector2` containing the entire new end point. * @param y The Y coordinate of the position to move the path's end point to, if a number was passed as the X coordinate. */ - moveTo(x: number | Phaser.Math.Vector2, y: number): Phaser.Curves.Path; + moveTo(x: number | Phaser.Math.Vector2, y?: number): this; /** * Converts this Path to a JSON object containing the path information and its constituent curves. @@ -5786,7 +7059,7 @@ declare namespace Phaser { } /** - * [description] + * A quadratic Bézier curve constructed from two control points. */ class QuadraticBezier extends Phaser.Curves.Curve { /** @@ -5798,17 +7071,17 @@ declare namespace Phaser { constructor(p0: Phaser.Math.Vector2 | number[], p1: Phaser.Math.Vector2, p2: Phaser.Math.Vector2); /** - * [description] + * The start point. */ p0: Phaser.Math.Vector2; /** - * [description] + * The first control point. */ p1: Phaser.Math.Vector2; /** - * [description] + * The second control point. */ p2: Phaser.Math.Vector2; @@ -5819,8 +7092,8 @@ declare namespace Phaser { getStartPoint(out?: O): O; /** - * [description] - * @param divisions [description] + * Get the resolution of the curve. + * @param divisions Optional divisions value. */ getResolution(divisions: number): number; @@ -5832,11 +7105,14 @@ declare namespace Phaser { getPoint(t: number, out?: O): O; /** - * [description] + * Draws this curve on the given Graphics object. + * + * The curve is drawn using `Graphics.strokePoints` so will be drawn at whatever the present Graphics stroke color is. + * The Graphics object is not cleared before the draw, so the curve will appear on-top of anything else already rendered to it. * @param graphics `Graphics` object to draw onto. * @param pointsTotal Number of points to be used for drawing the curve. Higher numbers result in smoother curve but require more processing. Default 32. */ - draw(graphics: G, pointsTotal?: integer): G; + draw(graphics: G, pointsTotal?: number): G; /** * Converts the curve into a JSON compatible object. @@ -5870,7 +7146,7 @@ declare namespace Phaser { * Add a list of points to the current list of Vector2 points of the curve. * @param points The points that configure the curve. */ - addPoints(points: Phaser.Math.Vector2[] | number[] | number[][]): Phaser.Curves.Spline; + addPoints(points: Phaser.Math.Vector2[] | number[] | number[][]): this; /** * Add a point to the current list of Vector2 points of the curve. @@ -5886,8 +7162,8 @@ declare namespace Phaser { getStartPoint(out?: O): O; /** - * [description] - * @param divisions [description] + * Get the resolution of the curve. + * @param divisions Optional divisions value. */ getResolution(divisions: number): number; @@ -5925,7 +7201,7 @@ declare namespace Phaser { * @param parent The object that this DataManager belongs to. * @param eventEmitter The DataManager's event emitter. */ - constructor(parent: object, eventEmitter: Phaser.Events.EventEmitter); + constructor(parent: object, eventEmitter?: Phaser.Events.EventEmitter); /** * The object that this DataManager belongs to. @@ -6037,7 +7313,24 @@ declare namespace Phaser { * @param key The key to set the value for. Or an object or key value pairs. If an object the `data` argument is ignored. * @param data The value to set for the given key. If an object is provided as the key this argument is ignored. */ - set(key: string | object, data: any): Phaser.Data.DataManager; + set(key: string | object, data: any): this; + + /** + * Increase a value for the given key. If the key doesn't already exist in the Data Manager then it is increased from 0. + * + * When the value is first set, a `setdata` event is emitted. + * @param key The key to increase the value for. + * @param data The value to increase for the given key. + */ + inc(key: string | object, data?: any): Phaser.Data.DataManager; + + /** + * Toggle a boolean value for the given key. If the key doesn't already exist in the Data Manager then it is toggled from false. + * + * When the value is first set, a `setdata` event is emitted. + * @param key The key to toggle the value for. + */ + toggle(key: string | object): Phaser.Data.DataManager; /** * Passes all data entries to the given callback. @@ -6045,7 +7338,7 @@ declare namespace Phaser { * @param context Value to use as `this` when executing callback. * @param args Additional arguments that will be passed to the callback, after the game object, key, and data. */ - each(callback: DataEachCallback, context?: any, ...args: any[]): Phaser.Data.DataManager; + each(callback: DataEachCallback, context?: any, ...args: any[]): this; /** * Merge the given object of key value pairs into this DataManager. @@ -6055,7 +7348,7 @@ declare namespace Phaser { * @param data The data to merge. * @param overwrite Whether to overwrite existing data. Defaults to true. Default true. */ - merge(data: {[key: string]: any}, overwrite?: boolean): Phaser.Data.DataManager; + merge(data: {[key: string]: any}, overwrite?: boolean): this; /** * Remove the value for the given key. @@ -6070,7 +7363,7 @@ declare namespace Phaser { * ``` * @param key The key to remove, or an array of keys to remove. */ - remove(key: string | string[]): Phaser.Data.DataManager; + remove(key: string | string[]): this; /** * Retrieves the data associated with the given 'key', deletes it from this Data Manager, then returns it. @@ -6092,12 +7385,12 @@ declare namespace Phaser { * to create new values or update existing ones. * @param value Whether to freeze or unfreeze the Data Manager. */ - setFreeze(value: boolean): Phaser.Data.DataManager; + setFreeze(value: boolean): this; /** * Delete all data in this Data Manager and unfreeze it. */ - reset(): Phaser.Data.DataManager; + reset(): this; /** * Destroy this data manager. @@ -6113,7 +7406,7 @@ declare namespace Phaser { /** * Return the total number of entries in this Data Manager. */ - count: integer; + count: number; } @@ -6173,6 +7466,13 @@ declare namespace Phaser { */ const CHANGE_DATA_KEY: any; + /** + * The Data Manager Destroy Event. + * + * The Data Manager will listen for the destroy event from its parent, and then close itself down. + */ + const DESTROY: any; + /** * The Remove Data Event. * @@ -6598,67 +7898,67 @@ declare namespace Phaser { /** * A constant representing a top-left alignment or position. */ - const TOP_LEFT: integer; + const TOP_LEFT: number; /** * A constant representing a top-center alignment or position. */ - const TOP_CENTER: integer; + const TOP_CENTER: number; /** * A constant representing a top-right alignment or position. */ - const TOP_RIGHT: integer; + const TOP_RIGHT: number; /** * A constant representing a left-top alignment or position. */ - const LEFT_TOP: integer; + const LEFT_TOP: number; /** * A constant representing a left-center alignment or position. */ - const LEFT_CENTER: integer; + const LEFT_CENTER: number; /** * A constant representing a left-bottom alignment or position. */ - const LEFT_BOTTOM: integer; + const LEFT_BOTTOM: number; /** * A constant representing a center alignment or position. */ - const CENTER: integer; + const CENTER: number; /** * A constant representing a right-top alignment or position. */ - const RIGHT_TOP: integer; + const RIGHT_TOP: number; /** * A constant representing a right-center alignment or position. */ - const RIGHT_CENTER: integer; + const RIGHT_CENTER: number; /** * A constant representing a right-bottom alignment or position. */ - const RIGHT_BOTTOM: integer; + const RIGHT_BOTTOM: number; /** * A constant representing a bottom-left alignment or position. */ - const BOTTOM_LEFT: integer; + const BOTTOM_LEFT: number; /** * A constant representing a bottom-center alignment or position. */ - const BOTTOM_CENTER: integer; + const BOTTOM_CENTER: number; /** * A constant representing a bottom-right alignment or position. */ - const BOTTOM_RIGHT: integer; + const BOTTOM_RIGHT: number; namespace In { /** @@ -6715,7 +8015,7 @@ declare namespace Phaser { * @param offsetX Optional horizontal offset from the position. Default 0. * @param offsetY Optional vertical offset from the position. Default 0. */ - function QuickSet(child: G, alignIn: Phaser.GameObjects.GameObject, position: integer, offsetX?: number, offsetY?: number): G; + function QuickSet(child: G, alignIn: Phaser.GameObjects.GameObject, position: number, offsetX?: number, offsetY?: number): G; /** * Takes given Game Object and aligns it so that it is positioned in the right center of the other. @@ -6819,7 +8119,7 @@ declare namespace Phaser { * @param offsetX Optional horizontal offset from the position. Default 0. * @param offsetY Optional vertical offset from the position. Default 0. */ - function QuickSet(child: G, alignTo: Phaser.GameObjects.GameObject, position: integer, offsetX?: number, offsetY?: number): G; + function QuickSet(child: G, alignTo: Phaser.GameObjects.GameObject, position: number, offsetX?: number, offsetY?: number): G; /** * Takes given Game Object and aligns it so that it is positioned next to the right bottom position of the other. @@ -6894,6 +8194,13 @@ declare namespace Phaser { */ function GetBottom(gameObject: Phaser.GameObjects.GameObject): number; + /** + * Returns the unrotated bounds of the Game Object as a rectangle. + * @param gameObject The Game Object to get the bounds value from. + * @param output An object to store the values in. + */ + function GetBounds(gameObject: Phaser.GameObjects.GameObject, output?: Phaser.Geom.Rectangle | object): Phaser.Geom.Rectangle | object; + /** * Returns the center x coordinate from the bounds of the Game Object. * @param gameObject The Game Object to get the bounds value from. @@ -7017,7 +8324,7 @@ declare namespace Phaser { * @param canvasType The type of the Canvas. Either `Phaser.CANVAS` or `Phaser.WEBGL`. Default Phaser.CANVAS. * @param selfParent Use the generated Canvas element as the parent? Default false. */ - function create(parent: any, width?: integer, height?: integer, canvasType?: integer, selfParent?: boolean): HTMLCanvasElement; + function create(parent: any, width?: number, height?: number, canvasType?: number, selfParent?: boolean): HTMLCanvasElement; /** * Creates a new Canvas DOM element, or pulls one from the pool if free. @@ -7025,7 +8332,7 @@ declare namespace Phaser { * @param width The width of the Canvas. Default 1. * @param height The height of the Canvas. Default 1. */ - function create2D(parent: any, width?: integer, height?: integer): HTMLCanvasElement; + function create2D(parent: any, width?: number, height?: number): HTMLCanvasElement; /** * Creates a new Canvas DOM element, or pulls one from the pool if free. @@ -7033,13 +8340,13 @@ declare namespace Phaser { * @param width The width of the Canvas. Default 1. * @param height The height of the Canvas. Default 1. */ - function createWebGL(parent: any, width?: integer, height?: integer): HTMLCanvasElement; + function createWebGL(parent: any, width?: number, height?: number): HTMLCanvasElement; /** * Gets the first free canvas index from the pool. * @param canvasType The type of the Canvas. Either `Phaser.CANVAS` or `Phaser.WEBGL`. Default Phaser.CANVAS. */ - function first(canvasType?: integer): HTMLCanvasElement; + function first(canvasType?: number): HTMLCanvasElement; /** * Looks up a canvas based on its parent, and if found puts it back in the pool, freeing it up for re-use. @@ -7051,12 +8358,12 @@ declare namespace Phaser { /** * Gets the total number of used canvas elements in the pool. */ - function total(): integer; + function total(): number; /** * Gets the total number of free canvas elements in the pool. */ - function free(): integer; + function free(): number; /** * Disable context smoothing on any new Canvas element created. @@ -7172,7 +8479,7 @@ declare namespace Phaser { * @param blue The blue color value. A number between 0 and 255. Default 0. * @param alpha The alpha value. A number between 0 and 255. Default 255. */ - constructor(red?: integer, green?: integer, blue?: integer, alpha?: integer); + constructor(red?: number, green?: number, blue?: number, alpha?: number); /** * An array containing the calculated color values for WebGL use. @@ -7192,7 +8499,7 @@ declare namespace Phaser { * @param alpha The alpha value. A number between 0 and 255. Default 255. * @param updateHSV Update the HSV values after setting the RGB values? Default true. */ - setTo(red: integer, green: integer, blue: integer, alpha?: integer, updateHSV?: boolean): Phaser.Display.Color; + setTo(red: number, green: number, blue: number, alpha?: number, updateHSV?: boolean): Phaser.Display.Color; /** * Sets the red, green, blue and alpha GL values of this Color component. @@ -7226,53 +8533,53 @@ declare namespace Phaser { * Sets this Color object to be grayscaled based on the shade value given. * @param shade A value between 0 and 255. */ - gray(shade: integer): Phaser.Display.Color; + gray(shade: number): Phaser.Display.Color; /** * Sets this Color object to be a random color between the `min` and `max` values given. * @param min The minimum random color value. Between 0 and 255. Default 0. * @param max The maximum random color value. Between 0 and 255. Default 255. */ - random(min?: integer, max?: integer): Phaser.Display.Color; + random(min?: number, max?: number): Phaser.Display.Color; /** * Sets this Color object to be a random grayscale color between the `min` and `max` values given. * @param min The minimum random color value. Between 0 and 255. Default 0. * @param max The maximum random color value. Between 0 and 255. Default 255. */ - randomGray(min?: integer, max?: integer): Phaser.Display.Color; + randomGray(min?: number, max?: number): Phaser.Display.Color; /** * Increase the saturation of this Color by the percentage amount given. * The saturation is the amount of the base color in the hue. * @param amount The percentage amount to change this color by. A value between 0 and 100. */ - saturate(amount: integer): Phaser.Display.Color; + saturate(amount: number): Phaser.Display.Color; /** * Decrease the saturation of this Color by the percentage amount given. * The saturation is the amount of the base color in the hue. * @param amount The percentage amount to change this color by. A value between 0 and 100. */ - desaturate(amount: integer): Phaser.Display.Color; + desaturate(amount: number): Phaser.Display.Color; /** * Increase the lightness of this Color by the percentage amount given. * @param amount The percentage amount to change this color by. A value between 0 and 100. */ - lighten(amount: integer): Phaser.Display.Color; + lighten(amount: number): Phaser.Display.Color; /** * Decrease the lightness of this Color by the percentage amount given. * @param amount The percentage amount to change this color by. A value between 0 and 100. */ - darken(amount: integer): Phaser.Display.Color; + darken(amount: number): Phaser.Display.Color; /** * Brighten this Color by the percentage amount given. * @param amount The percentage amount to change this color by. A value between 0 and 100. */ - brighten(amount: integer): Phaser.Display.Color; + brighten(amount: number): Phaser.Display.Color; /** * The color of this Color component, not including the alpha channel. @@ -7347,6 +8654,18 @@ declare namespace Phaser { */ v: number; + /** + * Return an array of Colors in a Color Spectrum. + * + * The spectrum colors flow in the order: red, yellow, green, blue. + * + * By default this function will return an array with 1024 elements in. + * + * However, you can reduce this to a smaller quantity if needed, by specitying the `limit` parameter. + * @param limit How many colors should be returned? The maximum is 1024 but you can set a smaller quantity if required. Default 1024. + */ + static ColorSpectrum(limit?: number): Phaser.Types.Display.ColorObject[]; + /** * Converts the given color value into an Object containing r,g,b and a properties. * @param color A color value, optionally including the alpha value. @@ -7357,7 +8676,7 @@ declare namespace Phaser { * Returns a string containing a hex representation of the given color component. * @param color The color channel to get the hex value for, must be a value between 0 and 255. */ - static ComponentToHex(color: integer): string; + static ComponentToHex(color: number): string; /** * Given 3 separate color values this will return an integer representation of it. @@ -7365,7 +8684,7 @@ declare namespace Phaser { * @param green The green color value. A number between 0 and 255. * @param blue The blue color value. A number between 0 and 255. */ - static GetColor(red: integer, green: integer, blue: integer): number; + static GetColor(red: number, green: number, blue: number): number; /** * Given an alpha and 3 color values this will return an integer representation of it. @@ -7374,7 +8693,7 @@ declare namespace Phaser { * @param blue The blue color value. A number between 0 and 255. * @param alpha The alpha color value. A number between 0 and 255. */ - static GetColor32(red: integer, green: integer, blue: integer, alpha: integer): number; + static GetColor32(red: number, green: number, blue: number, alpha: number): number; /** * Converts a hex string into a Phaser Color object. @@ -7402,10 +8721,11 @@ declare namespace Phaser { static HSVColorWheel(s?: number, v?: number): Phaser.Types.Display.ColorObject[]; /** - * Converts an HSV (hue, saturation and value) color value to RGB. - * Conversion formula from http://en.wikipedia.org/wiki/HSL_color_space. + * Converts a HSV (hue, saturation and value) color set to RGB. + * + * Conversion formula from https://en.wikipedia.org/wiki/HSL_and_HSV + * * Assumes HSV values are contained in the set [0, 1]. - * Based on code by Michael Jackson (https://github.com/mjijackson) * @param h The hue, in the range 0 - 1. This is the base color. * @param s The saturation, in the range 0 - 1. This controls how much of the hue will be in the final color, where 1 is fully saturated and 0 will give you white. * @param v The value, in the range 0 - 1. This controls how dark the color is. Where 1 is as bright as possible and 0 is black. @@ -7423,7 +8743,7 @@ declare namespace Phaser { * Converts the given color value into an instance of a Color object. * @param input The color value to convert into a Color object. */ - static IntegerToColor(input: integer): Phaser.Display.Color; + static IntegerToColor(input: number): Phaser.Display.Color; /** * Return the component parts of a color as an Object with the properties alpha, red, green, blue. @@ -7431,7 +8751,7 @@ declare namespace Phaser { * Alpha will only be set if it exists in the given color (0xAARRGGBB) * @param input The color value to convert into a Color object. */ - static IntegerToRGB(input: integer): Phaser.Types.Display.ColorObject; + static IntegerToRGB(input: number): Phaser.Types.Display.ColorObject; /** * Converts an object containing `r`, `g`, `b` and `a` properties into a Color class instance. @@ -7445,7 +8765,7 @@ declare namespace Phaser { * @param min The minimum value to set the random range from (between 0 and 255) Default 0. * @param max The maximum value to set the random range from (between 0 and 255) Default 255. */ - static RandomRGB(min?: integer, max?: integer): Phaser.Display.Color; + static RandomRGB(min?: number, max?: number): Phaser.Display.Color; /** * Converts a CSS 'web' string into a Phaser Color object. @@ -7465,7 +8785,7 @@ declare namespace Phaser { * @param b The blue color value. A number between 0 and 255. * @param out An object to store the color values in. If not given an HSV Color Object will be created. */ - static RGBToHSV(r: integer, g: integer, b: integer, out?: Phaser.Types.Display.HSVColorObject | Phaser.Display.Color): Phaser.Types.Display.HSVColorObject | Phaser.Display.Color; + static RGBToHSV(r: number, g: number, b: number, out?: Phaser.Types.Display.HSVColorObject | Phaser.Display.Color): Phaser.Types.Display.HSVColorObject | Phaser.Display.Color; /** * Converts the color values into an HTML compatible color string, prefixed with either `#` or `0x`. @@ -7475,7 +8795,7 @@ declare namespace Phaser { * @param a The alpha value. A number between 0 and 255. Default 255. * @param prefix The prefix of the string. Either `#` or `0x`. Default #. */ - static RGBToString(r: integer, g: integer, b: integer, a?: integer, prefix?: string): string; + static RGBToString(r: number, g: number, b: number, a?: number, prefix?: string): string; /** * Converts the given source color value into an instance of a Color class. @@ -7486,6 +8806,160 @@ declare namespace Phaser { } + /** + * The ColorMatrix class creates a 5x4 matrix that can be used in shaders and graphics + * operations. It provides methods required to modify the color values, such as adjusting + * the brightness, setting a sepia tone, hue rotation and more. + * + * Use the method `getData` to return a Float32Array containing the current color values. + */ + class ColorMatrix { + /** + * The value that determines how much of the original color is used + * when mixing the colors. A value between 0 (all original) and 1 (all final) + */ + alpha: number; + + /** + * Sets this ColorMatrix from the given array of color values. + * @param value The ColorMatrix values to set. + */ + set(value: number[]): this; + + /** + * Resets the ColorMatrix. + */ + reset(): this; + + /** + * Gets the ColorMatrix as a Float32Array. + * + * Can be used directly as a 1fv shader uniform value. + */ + getData(): Float32Array; + + /** + * Changes the brightness of this ColorMatrix by the given amount. + * @param value The amount of brightness to apply to this ColorMatrix. Between 0 (black) and 1. Default 0. + * @param multiply Multiply the resulting ColorMatrix (`true`), or set it (`false`) ? Default false. + */ + brightness(value?: number, multiply?: boolean): this; + + /** + * Changes the saturation of this ColorMatrix by the given amount. + * @param value The amount of saturation to apply to this ColorMatrix. Default 0. + * @param multiply Multiply the resulting ColorMatrix (`true`), or set it (`false`) ? Default false. + */ + saturate(value?: number, multiply?: boolean): this; + + /** + * Desaturates this ColorMatrix (removes color from it). + * @param multiply Multiply the resulting ColorMatrix (`true`), or set it (`false`) ? Default false. + */ + saturation(multiply?: boolean): this; + + /** + * Rotates the hues of this ColorMatrix by the value given. + * @param rotation The amount of hue rotation to apply to this ColorMatrix, in degrees. Default 0. + * @param multiply Multiply the resulting ColorMatrix (`true`), or set it (`false`) ? Default false. + */ + hue(rotation?: number, multiply?: boolean): this; + + /** + * Sets this ColorMatrix to be grayscale. + * @param value The grayscale scale (0 is black). Default 1. + * @param multiply Multiply the resulting ColorMatrix (`true`), or set it (`false`) ? Default false. + */ + grayscale(value?: number, multiply?: boolean): this; + + /** + * Sets this ColorMatrix to be black and white. + * @param multiply Multiply the resulting ColorMatrix (`true`), or set it (`false`) ? Default false. + */ + blackWhite(multiply?: boolean): this; + + /** + * Change the contrast of this ColorMatrix by the amount given. + * @param value The amount of contrast to apply to this ColorMatrix. Default 0. + * @param multiply Multiply the resulting ColorMatrix (`true`), or set it (`false`) ? Default false. + */ + contrast(value?: number, multiply?: boolean): this; + + /** + * Converts this ColorMatrix to have negative values. + * @param multiply Multiply the resulting ColorMatrix (`true`), or set it (`false`) ? Default false. + */ + negative(multiply?: boolean): this; + + /** + * Apply a desaturated luminance to this ColorMatrix. + * @param multiply Multiply the resulting ColorMatrix (`true`), or set it (`false`) ? Default false. + */ + desaturateLuminance(multiply?: boolean): this; + + /** + * Applies a sepia tone to this ColorMatrix. + * @param multiply Multiply the resulting ColorMatrix (`true`), or set it (`false`) ? Default false. + */ + sepia(multiply?: boolean): this; + + /** + * Applies a night vision tone to this ColorMatrix. + * @param intensity The intensity of this effect. Default 0.1. + * @param multiply Multiply the resulting ColorMatrix (`true`), or set it (`false`) ? Default false. + */ + night(intensity?: number, multiply?: boolean): this; + + /** + * Applies a trippy color tone to this ColorMatrix. + * @param multiply Multiply the resulting ColorMatrix (`true`), or set it (`false`) ? Default false. + */ + lsd(multiply?: boolean): this; + + /** + * Applies a brown tone to this ColorMatrix. + * @param multiply Multiply the resulting ColorMatrix (`true`), or set it (`false`) ? Default false. + */ + brown(multiply?: boolean): this; + + /** + * Applies a vintage pinhole color effect to this ColorMatrix. + * @param multiply Multiply the resulting ColorMatrix (`true`), or set it (`false`) ? Default false. + */ + vintagePinhole(multiply?: boolean): this; + + /** + * Applies a kodachrome color effect to this ColorMatrix. + * @param multiply Multiply the resulting ColorMatrix (`true`), or set it (`false`) ? Default false. + */ + kodachrome(multiply?: boolean): this; + + /** + * Applies a technicolor color effect to this ColorMatrix. + * @param multiply Multiply the resulting ColorMatrix (`true`), or set it (`false`) ? Default false. + */ + technicolor(multiply?: boolean): this; + + /** + * Applies a polaroid color effect to this ColorMatrix. + * @param multiply Multiply the resulting ColorMatrix (`true`), or set it (`false`) ? Default false. + */ + polaroid(multiply?: boolean): this; + + /** + * Shifts the values of this ColorMatrix into BGR order. + * @param multiply Multiply the resulting ColorMatrix (`true`), or set it (`false`) ? Default false. + */ + shiftToBGR(multiply?: boolean): this; + + /** + * Multiplies the two given matrices. + * @param a The 5x4 array to multiply with ColorMatrix._matrix. + */ + multiply(a: number[]): this; + + } + namespace Masks { /** * A Bitmap Mask combines the alpha (opacity) of a masked pixel with the alpha of another pixel. @@ -7503,6 +8977,9 @@ declare namespace Phaser { * A pixel with an alpha of 1 in the masked Game Object will receive the same alpha as the * corresponding pixel in the mask. * + * Note: You cannot combine Bitmap Masks and Blend Modes on the same Game Object. You can, however, + * combine Geometry Masks and Blend Modes together. + * * The Bitmap Mask's location matches the location of its Game Object, not the location of the * masked objects. Moving or transforming the underlying Game Object will change the mask * (and affect the visibility of any masked objects), whereas moving or transforming a masked object @@ -7532,7 +9009,7 @@ declare namespace Phaser { bitmapMask: Phaser.GameObjects.GameObject; /** - * The texture used for the mask's framebuffer. + * The texture used for the masks framebuffer. */ maskTexture: WebGLTexture; @@ -7556,15 +9033,11 @@ declare namespace Phaser { */ maskFramebuffer: WebGLFramebuffer; - /** - * The previous framebuffer set in the renderer before this one was enabled. - */ - prevFramebuffer: WebGLFramebuffer; - /** * Whether to invert the masks alpha. * - * If `true`, the alpha of the masking pixel will be inverted before it's multiplied with the masked pixel. Essentially, this means that a masked area will be visible only if the corresponding area in the mask is invisible. + * If `true`, the alpha of the masking pixel will be inverted before it's multiplied with the masked pixel. + * Essentially, this means that a masked area will be visible only if the corresponding area in the mask is invisible. */ invertAlpha: boolean; @@ -7573,6 +9046,21 @@ declare namespace Phaser { */ readonly isStencil: boolean; + /** + * Creates the WebGL Texture2D objects and Framebuffers required for this + * mask. If this mask has already been created, then `clearMask` is called first. + */ + createMask(): void; + + /** + * Deletes the `mainTexture` and `maskTexture` WebGL Textures and deletes + * the `mainFramebuffer` and `maskFramebuffer` too, nulling all references. + * + * This is called when this mask is destroyed, or if you try to creat a new + * mask from this object when one is already set. + */ + clearMask(): void; + /** * Sets a new masking Game Object for the Bitmap Mask. * @param renderable A renderable Game Object that uses a texture, such as a Sprite. @@ -7654,6 +9142,8 @@ declare namespace Phaser { /** * Similar to the BitmapMasks invertAlpha setting this to true will then hide all pixels * drawn to the Geometry Mask. + * + * This is a WebGL only feature. */ invertAlpha: boolean; @@ -7670,7 +9160,10 @@ declare namespace Phaser { /** * Sets the `invertAlpha` property of this Geometry Mask. + * * Inverting the alpha essentially flips the way the mask works. + * + * This is a WebGL only feature. * @param value Invert the alpha of this mask? Default true. */ setInvertAlpha(value?: boolean): this; @@ -7723,6 +9216,87 @@ declare namespace Phaser { } + /** + * The RGB class holds a single color value and allows for easy modification and reading of it, + * with optional on-change callback notification and a dirty flag. + */ + class RGB { + /** + * + * @param red The red color value. A number between 0 and 1. Default 0. + * @param green The green color value. A number between 0 and 1. Default 0. + * @param blue The blue color value. A number between 0 and 1. Default 0. + */ + constructor(red?: number, green?: number, blue?: number); + + /** + * This callback will be invoked each time one of the RGB color values change. + * + * The callback is sent the new color values as the parameters. + */ + onChangeCallback: Function; + + /** + * Is this color dirty? + */ + dirty: boolean; + + /** + * Sets the red, green and blue values of this RGB object, flags it as being + * dirty and then invokes the `onChangeCallback`, if set. + * @param red The red color value. A number between 0 and 1. Default 0. + * @param green The green color value. A number between 0 and 1. Default 0. + * @param blue The blue color value. A number between 0 and 1. Default 0. + */ + set(red?: number, green?: number, blue?: number): this; + + /** + * Compares the given rgb parameters with those in this object and returns + * a boolean `true` value if they are equal, otherwise it returns `false`. + * @param red The red value to compare with this object. + * @param green The green value to compare with this object. + * @param blue The blue value to compare with this object. + */ + equals(red: number, green: number, blue: number): boolean; + + /** + * Internal on change handler. Sets this object as being dirty and + * then invokes the `onChangeCallback`, if set, passing in the + * new RGB values. + */ + onChange(): void; + + /** + * The red color value. Between 0 and 1. + * + * Changing this property will flag this RGB object as being dirty + * and invoke the `onChangeCallback` , if set. + */ + r: number; + + /** + * The green color value. Between 0 and 1. + * + * Changing this property will flag this RGB object as being dirty + * and invoke the `onChangeCallback` , if set. + */ + g: number; + + /** + * The blue color value. Between 0 and 1. + * + * Changing this property will flag this RGB object as being dirty + * and invoke the `onChangeCallback` , if set. + */ + b: number; + + /** + * Nulls any external references this object contains. + */ + destroy(): void; + + } + /** * A BaseShader is a small resource class that contains the data required for a WebGL Shader to be created. * @@ -7991,12 +9565,6 @@ declare namespace Phaser { } - /** - * Phaser Blend Modes to CSS Blend Modes Map. - */ - enum CSSBlendModes { - } - namespace GameObjects { /** * BitmapText objects work by taking a texture file and an XML or JSON file that describes the font structure. @@ -8018,12 +9586,12 @@ declare namespace Phaser { * * To create a BitmapText data files you need a 3rd party app such as: * - * BMFont (Windows, free): http://www.angelcode.com/products/bmfont/ - * Glyph Designer (OS X, commercial): http://www.71squared.com/en/glyphdesigner - * Littera (Web-based, free): http://kvazars.com/littera/ + * BMFont (Windows, free): {@link http://www.angelcode.com/products/bmfont/|http://www.angelcode.com/products/bmfont/} + * Glyph Designer (OS X, commercial): {@link http://www.71squared.com/en/glyphdesigner|http://www.71squared.com/en/glyphdesigner} + * Littera (Web-based, free): {@link http://kvazars.com/littera/|http://kvazars.com/littera/} * * For most use cases it is recommended to use XML. If you wish to use JSON, the formatting should be equal to the result of - * converting a valid XML file through the popular X2JS library. An online tool for conversion can be found here: http://codebeautify.org/xmltojson + * converting a valid XML file through the popular X2JS library. An online tool for conversion can be found here: {@link http://codebeautify.org/xmltojson|http://codebeautify.org/xmltojson} */ class DynamicBitmapText extends Phaser.GameObjects.BitmapText { /** @@ -8036,7 +9604,7 @@ declare namespace Phaser { * @param size The font size of this Bitmap Text. * @param align The alignment of the text in a multi-line BitmapText object. Default 0. */ - constructor(scene: Phaser.Scene, x: number, y: number, font: string, text?: string | string[], size?: number, align?: integer); + constructor(scene: Phaser.Scene, x: number, y: number, font: string, text?: string | string[], size?: number, align?: number); /** * The horizontal scroll position of the Bitmap Text. @@ -8078,7 +9646,7 @@ declare namespace Phaser { * @param width The width of the crop. * @param height The height of the crop. */ - setSize(width: number, height: number): Phaser.GameObjects.DynamicBitmapText; + setSize(width: number, height: number): this; /** * Set a callback that alters how each character of the Bitmap Text is rendered. @@ -8090,19 +9658,19 @@ declare namespace Phaser { * usual values when rendering. * @param callback The display callback to set. */ - setDisplayCallback(callback: Phaser.Types.GameObjects.BitmapText.DisplayCallback): Phaser.GameObjects.DynamicBitmapText; + setDisplayCallback(callback: Phaser.Types.GameObjects.BitmapText.DisplayCallback): this; /** * Set the horizontal scroll position of this Bitmap Text. * @param value The horizontal scroll position to set. */ - setScrollX(value: number): Phaser.GameObjects.DynamicBitmapText; + setScrollX(value: number): this; /** * Set the vertical scroll position of this Bitmap Text. * @param value The vertical scroll position to set. */ - setScrollY(value: number): Phaser.GameObjects.DynamicBitmapText; + setScrollY(value: number): this; /** * Clears all alpha values associated with this Game Object. @@ -8208,7 +9776,7 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. @@ -8221,13 +9789,13 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. * @param value The depth of this Game Object. */ - setDepth(value: integer): this; + setDepth(value: number): this; /** * The Mask this Game Object is using during render. @@ -8261,6 +9829,8 @@ declare namespace Phaser { * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, * including this one. * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * * To create the mask you need to pass in a reference to a renderable Game Object. * A renderable Game Object is one that uses a texture to render with, such as an * Image, Sprite, Render Texture or BitmapText. @@ -8338,14 +9908,10 @@ declare namespace Phaser { */ setDisplayOrigin(x?: number, y?: number): this; - /** - * Updates the Display Origin cached values internally stored on this Game Object. - * You don't usually call this directly, but it is exposed for edge-cases where you may. - */ - updateDisplayOrigin(): this; - /** * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. */ defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; @@ -8354,23 +9920,109 @@ declare namespace Phaser { */ pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + /** + * Does this Game Object have any Post Pipelines set? + */ + hasPostPipeline: boolean; + + /** + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. + */ + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; + + /** + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. + */ + pipelineData: object; + /** * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. */ - initPipeline(pipelineName?: string): boolean; + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. */ - setPipeline(pipelineName: string): this; + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; + + /** + * Sets one, or more, Post Pipelines on this Game Object. + * + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; + + /** + * Adds an entry to the `pipelineData` object belonging to this Game Object. + * + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. + */ + setPipelineData(key: string, value?: any): this; + + /** + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. + */ + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; /** * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; + + /** + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. */ - resetPipeline(): boolean; + resetPostPipeline(resetData?: boolean): void; + + /** + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. + */ + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; /** * Gets the name of the WebGL Pipeline this Game Object is currently using. @@ -8453,7 +10105,7 @@ declare namespace Phaser { * @param key The key of the texture to be used, as stored in the Texture Manager, or a Texture instance. * @param frame The name or index of the frame within the Texture. */ - setTexture(key: string | Phaser.Textures.Texture, frame?: string | integer): this; + setTexture(key: string | Phaser.Textures.Texture, frame?: string | number): this; /** * Sets the frame this Game Object will use to render with. @@ -8468,10 +10120,41 @@ declare namespace Phaser { * @param updateSize Should this call adjust the size of the Game Object? Default true. * @param updateOrigin Should this call adjust the origin of the Game Object? Default true. */ - setFrame(frame: string | integer, updateSize?: boolean, updateOrigin?: boolean): this; + setFrame(frame: string | number, updateSize?: boolean, updateOrigin?: boolean): this; /** - * Fill or additive? + * The tint value being applied to the top-left vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintTopLeft: number; + + /** + * The tint value being applied to the top-right vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintTopRight: number; + + /** + * The tint value being applied to the bottom-left vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintBottomLeft: number; + + /** + * The tint value being applied to the bottom-right vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintBottomRight: number; + + /** + * The tint fill mode. + * + * `false` = An additive tint (the default), where vertices colors are blended with the texture. + * `true` = A fill tint, where the vertices colors replace the texture, but respects texture alpha. */ tintFill: boolean; @@ -8503,7 +10186,7 @@ declare namespace Phaser { * @param bottomLeft The tint being applied to the bottom-left of the Game Object. * @param bottomRight The tint being applied to the bottom-right of the Game Object. */ - setTint(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; + setTint(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; /** * Sets a fill-based tint on this Game Object. @@ -8526,40 +10209,19 @@ declare namespace Phaser { * @param bottomLeft The tint being applied to the bottom-left of the Game Object. * @param bottomRight The tint being applied to the bottom-right of the Game Object. */ - setTintFill(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; - - /** - * The tint value being applied to the top-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintTopLeft: integer; - - /** - * The tint value being applied to the top-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintTopRight: integer; - - /** - * The tint value being applied to the bottom-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintBottomLeft: integer; - - /** - * The tint value being applied to the bottom-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintBottomRight: integer; + setTintFill(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; /** * The tint value being applied to the whole of the Game Object. * This property is a setter-only. Use the properties `tintTopLeft` etc to read the current tint value. */ - tint: integer; + tint: number; /** - * Does this Game Object have a tint applied to it or not? + * Does this Game Object have a tint applied? + * + * It checks to see if the 4 tint properties are set to the value 0xffffff + * and that the `tintFill` property is `false`. This indicates that a Game Object isn't tinted. */ readonly isTinted: boolean; @@ -8613,13 +10275,13 @@ declare namespace Phaser { * * If you prefer to work in radians, see the `rotation` property instead. */ - angle: integer; + angle: number; /** * The angle of this Game Object in radians. * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. * * If you prefer to work in degrees, see the `angle` property instead. */ @@ -8634,6 +10296,12 @@ declare namespace Phaser { */ setPosition(x?: number, y?: number, z?: number, w?: number): this; + /** + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; + /** * Sets the position of this Game Object to be a random position within the confines of * the given area. @@ -8708,6 +10376,22 @@ declare namespace Phaser { */ getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. + */ + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + /** * Gets the sum total rotation of all of this Game Objects parent Containers. * @@ -8830,7 +10514,7 @@ declare namespace Phaser { * @param size The font size of this Bitmap Text. * @param align The alignment of the text in a multi-line BitmapText object. Default 0. */ - constructor(scene: Phaser.Scene, x: number, y: number, font: string, text?: string | string[], size?: number, align?: integer); + constructor(scene: Phaser.Scene, x: number, y: number, font: string, text?: string | string[], size?: number, align?: number); /** * The key of the Bitmap Font used by this Bitmap Text. @@ -8849,6 +10533,34 @@ declare namespace Phaser { */ wordWrapCharCode: number; + /** + * The horizontal offset of the drop shadow. + * + * You can set this directly, or use `Phaser.GameObjects.BitmapText#setDropShadow`. + */ + dropShadowX: number; + + /** + * The vertical offset of the drop shadow. + * + * You can set this directly, or use `Phaser.GameObjects.BitmapText#setDropShadow`. + */ + dropShadowY: number; + + /** + * The color of the drop shadow. + * + * You can set this directly, or use `Phaser.GameObjects.BitmapText#setDropShadow`. + */ + dropShadowColor: number; + + /** + * The alpha value of the drop shadow. + * + * You can set this directly, or use `Phaser.GameObjects.BitmapText#setDropShadow`. + */ + dropShadowAlpha: number; + /** * Set the lines of text in this BitmapText to be left-aligned. * This only has any effect if this BitmapText contains more than one line of text. @@ -8889,6 +10601,95 @@ declare namespace Phaser { */ setText(value: string | string[]): this; + /** + * Sets a drop shadow effect on this Bitmap Text. + * + * This is a WebGL only feature and only works with Static Bitmap Text, not Dynamic. + * + * You can set the vertical and horizontal offset of the shadow, as well as the color and alpha. + * + * Once a shadow has been enabled you can modify the `dropShadowX` and `dropShadowY` properties of this + * Bitmap Text directly to adjust the position of the shadow in real-time. + * + * If you wish to clear the shadow, call this method with no parameters specified. + * @param x The horizontal offset of the drop shadow. Default 0. + * @param y The vertical offset of the drop shadow. Default 0. + * @param color The color of the drop shadow, given as a hex value, i.e. `0x000000` for black. Default 0x000000. + * @param alpha The alpha of the drop shadow, given as a float between 0 and 1. This is combined with the Bitmap Text alpha as well. Default 0.5. + */ + setDropShadow(x?: number, y?: number, color?: number, alpha?: number): this; + + /** + * Sets a tint on a range of characters in this Bitmap Text, starting from the `start` parameter index + * and running for `length` quantity of characters. + * + * The `start` parameter can be negative. In this case, it starts at the end of the text and counts + * backwards `start` places. + * + * You can also pass in -1 as the `length` and it will tint all characters from `start` + * up until the end of the string. + * Remember that spaces and punctuation count as characters. + * + * This is a WebGL only feature and only works with Static Bitmap Text, not Dynamic. + * + * The tint works by taking the pixel color values from the Bitmap Text texture, and then + * multiplying it by the color value of the tint. You can provide either one color value, + * in which case the whole character will be tinted in that color. Or you can provide a color + * per corner. The colors are blended together across the extent of the character range. + * + * To swap this from being an additive tint to a fill based tint, set the `tintFill` parameter to `true`. + * + * To modify the tint color once set, call this method again with new color values. + * + * Using `setWordTint` can override tints set by this function, and vice versa. + * + * To remove a tint call this method with just the `start`, and optionally, the `length` parameters defined. + * @param start The starting character to begin the tint at. If negative, it counts back from the end of the text. Default 0. + * @param length The number of characters to tint. Remember that spaces count as a character too. Pass -1 to tint all characters from `start` onwards. Default 1. + * @param tintFill Use a fill-based tint (true), or an additive tint (false) Default false. + * @param topLeft The tint being applied to the top-left of the character. If not other values are given this value is applied evenly, tinting the whole character. Default 0xffffff. + * @param topRight The tint being applied to the top-right of the character. + * @param bottomLeft The tint being applied to the bottom-left of the character. + * @param bottomRight The tint being applied to the bottom-right of the character. + */ + setCharacterTint(start?: number, length?: number, tintFill?: boolean, topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; + + /** + * Sets a tint on a matching word within this Bitmap Text. + * + * The `word` parameter can be either a string or a number. + * + * If a string, it will run a string comparison against the text contents, and if matching, + * it will tint the whole word. + * + * If a number, if till that word, based on its offset within the text contents. + * + * The `count` parameter controls how many words are replaced. Pass in -1 to replace them all. + * + * This parameter is ignored if you pass a number as the `word` to be searched for. + * + * This is a WebGL only feature and only works with Static Bitmap Text, not Dynamic. + * + * The tint works by taking the pixel color values from the Bitmap Text texture, and then + * multiplying it by the color value of the tint. You can provide either one color value, + * in which case the whole character will be tinted in that color. Or you can provide a color + * per corner. The colors are blended together across the extent of the character range. + * + * To swap this from being an additive tint to a fill based tint, set the `tintFill` parameter to `true`. + * + * To modify the tint color once set, call this method again with new color values. + * + * Using `setCharacterTint` can override tints set by this function, and vice versa. + * @param word The word to search for. Either a string, or an index of the word in the words array. + * @param count The number of matching words to tint. Pass -1 to tint all matching words. Default 1. + * @param tintFill Use a fill-based tint (true), or an additive tint (false) Default false. + * @param topLeft The tint being applied to the top-left of the word. If not other values are given this value is applied evenly, tinting the whole word. Default 0xffffff. + * @param topRight The tint being applied to the top-right of the word. + * @param bottomLeft The tint being applied to the bottom-left of the word. + * @param bottomRight The tint being applied to the bottom-right of the word. + */ + setWordTint(word: string | number, count?: number, tintFill?: boolean, topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; + /** * Calculate the bounds of this Bitmap Text. * @@ -8900,10 +10701,36 @@ declare namespace Phaser { * Global size takes into account the Game Object's scale, world position and display origin. * * Also in the object is data regarding the length of each line, should this be a multi-line BitmapText. - * @param round Whether to round the results to the nearest integer. + * @param round Whether to round the results up to the nearest integer. Default false. */ getTextBounds(round?: boolean): Phaser.Types.GameObjects.BitmapText.BitmapTextSize; + /** + * Gets the character located at the given x/y coordinate within this Bitmap Text. + * + * The coordinates you pass in are translated into the local space of the + * Bitmap Text, however, it is up to you to first translate the input coordinates to world space. + * + * If you wish to use this in combination with an input event, be sure + * to pass in `Pointer.worldX` and `worldY` so they are in world space. + * + * In some cases, based on kerning, characters can overlap. When this happens, + * the first character in the word is returned. + * + * Note that this does not work for DynamicBitmapText if you have changed the + * character positions during render. It will only scan characters in their un-translated state. + * @param x The x position to check. + * @param y The y position to check. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. + */ + getCharacterAt(x: number, y: number, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Types.GameObjects.BitmapText.BitmapTextCharacter; + + /** + * Updates the Display Origin cached values internally stored on this Game Object. + * You don't usually call this directly, but it is exposed for edge-cases where you may. + */ + updateDisplayOrigin(): this; + /** * Changes the font this BitmapText is using to render. * @@ -8913,7 +10740,7 @@ declare namespace Phaser { * @param size The font size of this Bitmap Text. If not specified the current size will be used. * @param align The alignment of the text in a multi-line BitmapText object. If not specified the current alignment will be used. Default 0. */ - setFont(font: string, size?: number, align?: integer): this; + setFont(font: string, size?: number, align?: number): this; /** * Sets the maximum display width of this BitmapText in pixels. @@ -8945,7 +10772,7 @@ declare namespace Phaser { * * The alignment position is based on the longest line of text. */ - align: integer; + align: number; /** * The text that this Bitmap Text object displays. @@ -8997,20 +10824,25 @@ declare namespace Phaser { */ toJSON(): Phaser.Types.GameObjects.BitmapText.JSONBitmapText; + /** + * Internal destroy handler, called as part of the destroy process. + */ + protected preDestroy(): void; + /** * Left align the text characters in a multi-line BitmapText object. */ - static ALIGN_LEFT: integer; + static ALIGN_LEFT: number; /** * Center align the text characters in a multi-line BitmapText object. */ - static ALIGN_CENTER: integer; + static ALIGN_CENTER: number; /** * Right align the text characters in a multi-line BitmapText object. */ - static ALIGN_RIGHT: integer; + static ALIGN_RIGHT: number; /** * Parse an XML Bitmap Font from an Atlas. @@ -9024,16 +10856,16 @@ declare namespace Phaser { * @param xSpacing The x-axis spacing to add between each letter. * @param ySpacing The y-axis spacing to add to the line height. */ - static ParseFromAtlas(scene: Phaser.Scene, fontName: string, textureKey: string, frameKey: string, xmlKey: string, xSpacing?: integer, ySpacing?: integer): boolean; + static ParseFromAtlas(scene: Phaser.Scene, fontName: string, textureKey: string, frameKey: string, xmlKey: string, xSpacing?: number, ySpacing?: number): boolean; /** * Parse an XML font to Bitmap Font data for the Bitmap Font cache. * @param xml The XML Document to parse the font from. + * @param frame The texture frame to take into account when creating the uv data. * @param xSpacing The x-axis spacing to add between each letter. Default 0. * @param ySpacing The y-axis spacing to add to the line height. Default 0. - * @param frame The texture frame to take into account while parsing. */ - static ParseXMLBitmapFont(xml: XMLDocument, xSpacing?: integer, ySpacing?: integer, frame?: Phaser.Textures.Frame): Phaser.Types.GameObjects.BitmapText.BitmapFontData; + static ParseXMLBitmapFont(xml: XMLDocument, frame: Phaser.Textures.Frame, xSpacing?: number, ySpacing?: number): Phaser.Types.GameObjects.BitmapText.BitmapFontData; /** * Clears all alpha values associated with this Game Object. @@ -9139,7 +10971,7 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. @@ -9152,13 +10984,13 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. * @param value The depth of this Game Object. */ - setDepth(value: integer): this; + setDepth(value: number): this; /** * The Mask this Game Object is using during render. @@ -9192,6 +11024,8 @@ declare namespace Phaser { * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, * including this one. * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * * To create the mask you need to pass in a reference to a renderable Game Object. * A renderable Game Object is one that uses a texture to render with, such as an * Image, Sprite, Render Texture or BitmapText. @@ -9269,14 +11103,10 @@ declare namespace Phaser { */ setDisplayOrigin(x?: number, y?: number): this; - /** - * Updates the Display Origin cached values internally stored on this Game Object. - * You don't usually call this directly, but it is exposed for edge-cases where you may. - */ - updateDisplayOrigin(): this; - /** * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. */ defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; @@ -9285,23 +11115,109 @@ declare namespace Phaser { */ pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + /** + * Does this Game Object have any Post Pipelines set? + */ + hasPostPipeline: boolean; + + /** + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. + */ + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; + + /** + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. + */ + pipelineData: object; + /** * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + */ + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; + + /** + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; + + /** + * Sets one, or more, Post Pipelines on this Game Object. + * + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; + + /** + * Adds an entry to the `pipelineData` object belonging to this Game Object. + * + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. */ - initPipeline(pipelineName?: string): boolean; + setPipelineData(key: string, value?: any): this; /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - setPipeline(pipelineName: string): this; + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; /** * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; + + /** + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPostPipeline(resetData?: boolean): void; + + /** + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - resetPipeline(): boolean; + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; /** * Gets the name of the WebGL Pipeline this Game Object is currently using. @@ -9384,7 +11300,7 @@ declare namespace Phaser { * @param key The key of the texture to be used, as stored in the Texture Manager, or a Texture instance. * @param frame The name or index of the frame within the Texture. */ - setTexture(key: string | Phaser.Textures.Texture, frame?: string | integer): this; + setTexture(key: string | Phaser.Textures.Texture, frame?: string | number): this; /** * Sets the frame this Game Object will use to render with. @@ -9399,10 +11315,41 @@ declare namespace Phaser { * @param updateSize Should this call adjust the size of the Game Object? Default true. * @param updateOrigin Should this call adjust the origin of the Game Object? Default true. */ - setFrame(frame: string | integer, updateSize?: boolean, updateOrigin?: boolean): this; + setFrame(frame: string | number, updateSize?: boolean, updateOrigin?: boolean): this; + + /** + * The tint value being applied to the top-left vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintTopLeft: number; + + /** + * The tint value being applied to the top-right vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintTopRight: number; + + /** + * The tint value being applied to the bottom-left vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintBottomLeft: number; /** - * Fill or additive? + * The tint value being applied to the bottom-right vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintBottomRight: number; + + /** + * The tint fill mode. + * + * `false` = An additive tint (the default), where vertices colors are blended with the texture. + * `true` = A fill tint, where the vertices colors replace the texture, but respects texture alpha. */ tintFill: boolean; @@ -9434,7 +11381,7 @@ declare namespace Phaser { * @param bottomLeft The tint being applied to the bottom-left of the Game Object. * @param bottomRight The tint being applied to the bottom-right of the Game Object. */ - setTint(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; + setTint(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; /** * Sets a fill-based tint on this Game Object. @@ -9457,40 +11404,19 @@ declare namespace Phaser { * @param bottomLeft The tint being applied to the bottom-left of the Game Object. * @param bottomRight The tint being applied to the bottom-right of the Game Object. */ - setTintFill(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; - - /** - * The tint value being applied to the top-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintTopLeft: integer; - - /** - * The tint value being applied to the top-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintTopRight: integer; - - /** - * The tint value being applied to the bottom-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintBottomLeft: integer; - - /** - * The tint value being applied to the bottom-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintBottomRight: integer; + setTintFill(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; /** * The tint value being applied to the whole of the Game Object. * This property is a setter-only. Use the properties `tintTopLeft` etc to read the current tint value. */ - tint: integer; + tint: number; /** - * Does this Game Object have a tint applied to it or not? + * Does this Game Object have a tint applied? + * + * It checks to see if the 4 tint properties are set to the value 0xffffff + * and that the `tintFill` property is `false`. This indicates that a Game Object isn't tinted. */ readonly isTinted: boolean; @@ -9544,13 +11470,13 @@ declare namespace Phaser { * * If you prefer to work in radians, see the `rotation` property instead. */ - angle: integer; + angle: number; /** * The angle of this Game Object in radians. * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. * * If you prefer to work in degrees, see the `angle` property instead. */ @@ -9565,6 +11491,12 @@ declare namespace Phaser { */ setPosition(x?: number, y?: number, z?: number, w?: number): this; + /** + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; + /** * Sets the position of this Game Object to be a random position within the confines of * the given area. @@ -9639,6 +11571,22 @@ declare namespace Phaser { */ getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. + */ + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + /** * Gets the sum total rotation of all of this Game Objects parent Containers. * @@ -9687,7 +11635,7 @@ declare namespace Phaser { * @param texture The key of the texture this Game Object will use for rendering. The Texture must already exist in the Texture Manager. Default '__DEFAULT'. * @param frame The Frame of the Texture that this Game Object will use. Only set if the Texture has multiple frames, such as a Texture Atlas or Sprite Sheet. Default 0. */ - constructor(scene: Phaser.Scene, x?: number, y?: number, texture?: string, frame?: string | integer); + constructor(scene: Phaser.Scene, x?: number, y?: number, texture?: string, frame?: string | number); /** * The children of this Blitter. @@ -9712,7 +11660,7 @@ declare namespace Phaser { * @param visible Should the created Bob render or not? Default true. * @param index The position in the Blitters Display List to add the new Bob at. Defaults to the top of the list. */ - create(x: number, y: number, frame?: string | integer | Phaser.Textures.Frame, visible?: boolean, index?: integer): Phaser.GameObjects.Bob; + create(x: number, y: number, frame?: string | number | Phaser.Textures.Frame, visible?: boolean, index?: number): Phaser.GameObjects.Bob; /** * Creates multiple Bob objects within this Blitter and then passes each of them to the specified callback. @@ -9721,7 +11669,7 @@ declare namespace Phaser { * @param frame The Frame the Bobs will use. It must be part of the Blitter Texture. * @param visible Should the created Bob render or not? Default true. */ - createFromCallback(callback: CreateCallback, quantity: integer, frame?: string | integer | Phaser.Textures.Frame | string[] | integer[] | Phaser.Textures.Frame[], visible?: boolean): Phaser.GameObjects.Bob[]; + createFromCallback(callback: CreateCallback, quantity: number, frame?: string | number | Phaser.Textures.Frame | string[] | number[] | Phaser.Textures.Frame[], visible?: boolean): Phaser.GameObjects.Bob[]; /** * Creates multiple Bobs in one call. @@ -9734,7 +11682,7 @@ declare namespace Phaser { * @param frame The Frame the Bobs will use. It must be part of the Blitter Texture. * @param visible Should the created Bob render or not? Default true. */ - createMultiple(quantity: integer, frame?: string | integer | Phaser.Textures.Frame | string[] | integer[] | Phaser.Textures.Frame[], visible?: boolean): Phaser.GameObjects.Bob[]; + createMultiple(quantity: number, frame?: string | number | Phaser.Textures.Frame | string[] | number[] | Phaser.Textures.Frame[], visible?: boolean): Phaser.GameObjects.Bob[]; /** * Checks if the given child can render or not, by checking its `visible` and `alpha` values. @@ -9862,7 +11810,7 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. @@ -9875,13 +11823,13 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. * @param value The depth of this Game Object. */ - setDepth(value: integer): this; + setDepth(value: number): this; /** * The Mask this Game Object is using during render. @@ -9915,6 +11863,8 @@ declare namespace Phaser { * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, * including this one. * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * * To create the mask you need to pass in a reference to a renderable Game Object. * A renderable Game Object is one that uses a texture to render with, such as an * Image, Sprite, Render Texture or BitmapText. @@ -9942,6 +11892,8 @@ declare namespace Phaser { /** * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. */ defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; @@ -9950,23 +11902,109 @@ declare namespace Phaser { */ pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + /** + * Does this Game Object have any Post Pipelines set? + */ + hasPostPipeline: boolean; + + /** + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. + */ + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; + + /** + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. + */ + pipelineData: object; + /** * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + */ + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; + + /** + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; + + /** + * Sets one, or more, Post Pipelines on this Game Object. + * + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; + + /** + * Adds an entry to the `pipelineData` object belonging to this Game Object. + * + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. */ - initPipeline(pipelineName?: string): boolean; + setPipelineData(key: string, value?: any): this; /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - setPipeline(pipelineName: string): this; + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; /** * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; + + /** + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPostPipeline(resetData?: boolean): void; + + /** + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - resetPipeline(): boolean; + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; /** * Gets the name of the WebGL Pipeline this Game Object is currently using. @@ -10123,7 +12161,7 @@ declare namespace Phaser { * @param key The key of the texture to be used, as stored in the Texture Manager, or a Texture instance. * @param frame The name or index of the frame within the Texture. */ - setTexture(key: string | Phaser.Textures.Texture, frame?: string | integer): this; + setTexture(key: string | Phaser.Textures.Texture, frame?: string | number): this; /** * Sets the frame this Game Object will use to render with. @@ -10138,7 +12176,7 @@ declare namespace Phaser { * @param updateSize Should this call adjust the size of the Game Object? Default true. * @param updateOrigin Should this call adjust the origin of the Game Object? Default true. */ - setFrame(frame: string | integer, updateSize?: boolean, updateOrigin?: boolean): this; + setFrame(frame: string | number, updateSize?: boolean, updateOrigin?: boolean): this; /** * The x position of this Game Object. @@ -10190,13 +12228,13 @@ declare namespace Phaser { * * If you prefer to work in radians, see the `rotation` property instead. */ - angle: integer; + angle: number; /** * The angle of this Game Object in radians. * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. * * If you prefer to work in degrees, see the `angle` property instead. */ @@ -10211,6 +12249,12 @@ declare namespace Phaser { */ setPosition(x?: number, y?: number, z?: number, w?: number): this; + /** + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; + /** * Sets the position of this Game Object to be a random position within the confines of * the given area. @@ -10285,6 +12329,22 @@ declare namespace Phaser { */ getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. + */ + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + /** * Gets the sum total rotation of all of this Game Objects parent Containers. * @@ -10333,7 +12393,7 @@ declare namespace Phaser { * @param frame The Frame this Bob will render with, as defined in the Texture the parent Blitter is using. * @param visible Should the Bob render visible or not to start with? */ - constructor(blitter: Phaser.GameObjects.Blitter, x: number, y: number, frame: string | integer, visible: boolean); + constructor(blitter: Phaser.GameObjects.Blitter, x: number, y: number, frame: string | number, visible: boolean); /** * The Blitter object that this Bob belongs to. @@ -10386,12 +12446,12 @@ declare namespace Phaser { * If no value is given it will use the default frame of the Blitter parent. * @param frame The frame to be used during rendering. */ - setFrame(frame?: string | integer | Phaser.Textures.Frame): Phaser.GameObjects.Bob; + setFrame(frame?: string | number | Phaser.Textures.Frame): this; /** * Resets the horizontal and vertical flipped state of this Bob back to their default un-flipped state. */ - resetFlip(): Phaser.GameObjects.Bob; + resetFlip(): this; /** * Resets this Bob. @@ -10403,33 +12463,33 @@ declare namespace Phaser { * @param y The y position of the Bob. Bob coordinate are relative to the position of the Blitter object. * @param frame The Frame the Bob will use. It _must_ be part of the Texture the parent Blitter object is using. */ - reset(x: number, y: number, frame?: string | integer | Phaser.Textures.Frame): Phaser.GameObjects.Bob; + reset(x: number, y: number, frame?: string | number | Phaser.Textures.Frame): this; /** * Changes the position of this Bob to the values given. * @param x The x position of the Bob. Bob coordinate are relative to the position of the Blitter object. * @param y The y position of the Bob. Bob coordinate are relative to the position of the Blitter object. */ - setPosition(x: number, y: number): Phaser.GameObjects.Bob; + setPosition(x: number, y: number): this; /** * Sets the horizontal flipped state of this Bob. * @param value The flipped state. `false` for no flip, or `true` to be flipped. */ - setFlipX(value: boolean): Phaser.GameObjects.Bob; + setFlipX(value: boolean): this; /** * Sets the vertical flipped state of this Bob. * @param value The flipped state. `false` for no flip, or `true` to be flipped. */ - setFlipY(value: boolean): Phaser.GameObjects.Bob; + setFlipY(value: boolean): this; /** * Sets the horizontal and vertical flipped state of this Bob. * @param x The horizontal flipped state. `false` for no flip, or `true` to be flipped. * @param y The horizontal flipped state. `false` for no flip, or `true` to be flipped. */ - setFlip(x: boolean, y: boolean): Phaser.GameObjects.Bob; + setFlip(x: boolean, y: boolean): this; /** * Sets the visibility of this Bob. @@ -10437,7 +12497,7 @@ declare namespace Phaser { * An invisible Bob will skip rendering. * @param value The visible state of the Game Object. */ - setVisible(value: boolean): Phaser.GameObjects.Bob; + setVisible(value: boolean): this; /** * Set the Alpha level of this Bob. The alpha controls the opacity of the Game Object as it renders. @@ -10446,13 +12506,13 @@ declare namespace Phaser { * A Bob with alpha 0 will skip rendering. * @param value The alpha value used for this Bob. Between 0 and 1. */ - setAlpha(value: number): Phaser.GameObjects.Bob; + setAlpha(value: number): this; /** * Sets the tint of this Bob. * @param value The tint value used for this Bob. Between 0 and 0xffffff. */ - setTint(value: number): Phaser.GameObjects.Bob; + setTint(value: number): this; /** * Destroys this Bob instance. @@ -10568,286 +12628,6 @@ declare namespace Phaser { alpha: number; } - interface Animation { - /** - * The Game Object to which this animation controller belongs. - */ - parent: Phaser.GameObjects.GameObject; - /** - * A reference to the global Animation Manager. - */ - animationManager: Phaser.Animations.AnimationManager; - /** - * Is an animation currently playing or not? - */ - isPlaying: boolean; - /** - * The current Animation loaded into this Animation Controller. - */ - currentAnim: Phaser.Animations.Animation; - /** - * The current AnimationFrame being displayed by this Animation Controller. - */ - currentFrame: Phaser.Animations.AnimationFrame; - /** - * The key of the next Animation to be loaded into this Animation Controller when the current animation completes. - */ - nextAnim: string; - /** - * The frame rate of playback in frames per second. - * The default is 24 if the `duration` property is `null`. - */ - frameRate: number; - /** - * How long the animation should play for, in milliseconds. - * If the `frameRate` property has been set then it overrides this value, - * otherwise the `frameRate` is derived from `duration`. - */ - duration: number; - /** - * ms per frame, not including frame specific modifiers that may be present in the Animation data. - */ - msPerFrame: number; - /** - * Skip frames if the time lags, or always advanced anyway? - */ - skipMissedFrames: boolean; - /** - * Will the playhead move forwards (`true`) or in reverse (`false`). - */ - forward: boolean; - /** - * Internal time overflow accumulator. - */ - accumulator: number; - /** - * The time point at which the next animation frame will change. - */ - nextTick: number; - /** - * An internal counter keeping track of how many repeats are left to play. - */ - repeatCounter: number; - /** - * An internal flag keeping track of pending repeats. - */ - pendingRepeat: boolean; - /** - * Sets an animation to be played immediately after the current one completes. - * - * The current animation must enter a 'completed' state for this to happen, i.e. finish all of its repeats, delays, etc, or have the `stop` method called directly on it. - * - * An animation set to repeat forever will never enter a completed state. - * - * You can chain a new animation at any point, including before the current one starts playing, during it, or when it ends (via its `animationcomplete` callback). - * Chained animations are specific to a Game Object, meaning different Game Objects can have different chained animations without impacting the global animation they're playing. - * - * Call this method with no arguments to reset the chained animation. - * @param key The string-based key of the animation to play next, as defined previously in the Animation Manager. Or an Animation instance. - */ - chain(key?: string | Phaser.Animations.Animation): Phaser.GameObjects.GameObject; - /** - * Sets the amount of time, in milliseconds, that the animation will be delayed before starting playback. - * @param value The amount of time, in milliseconds, to wait before starting playback. Default 0. - */ - setDelay(value?: integer): Phaser.GameObjects.GameObject; - /** - * Gets the amount of time, in milliseconds that the animation will be delayed before starting playback. - */ - getDelay(): integer; - /** - * Waits for the specified delay, in milliseconds, then starts playback of the requested animation. - * @param delay The delay, in milliseconds, to wait before starting the animation playing. - * @param key The key of the animation to play. - * @param startFrame The frame of the animation to start from. Default 0. - */ - delayedPlay(delay: integer, key: string, startFrame?: integer): Phaser.GameObjects.GameObject; - /** - * Returns the key of the animation currently loaded into this component. - */ - getCurrentKey(): string; - /** - * Internal method used to load an animation into this component. - * @param key The key of the animation to load. - * @param startFrame The start frame of the animation to load. Default 0. - */ - load(key: string, startFrame?: integer): Phaser.GameObjects.GameObject; - /** - * Pause the current animation and set the `isPlaying` property to `false`. - * You can optionally pause it at a specific frame. - * @param atFrame An optional frame to set after pausing the animation. - */ - pause(atFrame?: Phaser.Animations.AnimationFrame): Phaser.GameObjects.GameObject; - /** - * Resumes playback of a paused animation and sets the `isPlaying` property to `true`. - * You can optionally tell it to start playback from a specific frame. - * @param fromFrame An optional frame to set before restarting playback. - */ - resume(fromFrame?: Phaser.Animations.AnimationFrame): Phaser.GameObjects.GameObject; - /** - * `true` if the current animation is paused, otherwise `false`. - */ - readonly isPaused: boolean; - /** - * Plays an Animation on a Game Object that has the Animation component, such as a Sprite. - * - * Animations are stored in the global Animation Manager and are referenced by a unique string-based key. - * @param key The string-based key of the animation to play, as defined previously in the Animation Manager. Or an Animation instance. - * @param ignoreIfPlaying If this animation is already playing then ignore this call. Default false. - * @param startFrame Optionally start the animation playing from this frame index. Default 0. - */ - play(key: string | Phaser.Animations.Animation, ignoreIfPlaying?: boolean, startFrame?: integer): Phaser.GameObjects.GameObject; - /** - * Plays an Animation (in reverse mode) on the Game Object that owns this Animation Component. - * @param key The string-based key of the animation to play, as defined previously in the Animation Manager. Or an Animation instance. - * @param ignoreIfPlaying If an animation is already playing then ignore this call. Default false. - * @param startFrame Optionally start the animation playing from this frame index. Default 0. - */ - playReverse(key: string | Phaser.Animations.Animation, ignoreIfPlaying?: boolean, startFrame?: integer): Phaser.GameObjects.GameObject; - /** - * Load an Animation and fires 'onStartEvent' event, extracted from 'play' method. - * @param key The string-based key of the animation to play, as defined previously in the Animation Manager. - * @param startFrame Optionally start the animation playing from this frame index. Default 0. - */ - _startAnimation(key: string, startFrame?: integer): Phaser.GameObjects.GameObject; - /** - * Reverse the Animation that is already playing on the Game Object. - */ - reverse(): Phaser.GameObjects.GameObject; - /** - * Returns a value between 0 and 1 indicating how far this animation is through, ignoring repeats and yoyos. - * If the animation has a non-zero repeat defined, `getProgress` and `getTotalProgress` will be different - * because `getProgress` doesn't include any repeats or repeat delays, whereas `getTotalProgress` does. - */ - getProgress(): number; - /** - * Takes a value between 0 and 1 and uses it to set how far this animation is through playback. - * Does not factor in repeats or yoyos, but does handle playing forwards or backwards. - * @param value The progress value, between 0 and 1. Default 0. - */ - setProgress(value?: number): Phaser.GameObjects.GameObject; - /** - * Handle the removal of an animation from the Animation Manager. - * @param key The key of the removed Animation. - * @param animation The removed Animation. - */ - remove(key?: string, animation?: Phaser.Animations.Animation): void; - /** - * Gets the number of times that the animation will repeat - * after its first iteration. For example, if returns 1, the animation will - * play a total of twice (the initial play plus 1 repeat). - * A value of -1 means the animation will repeat indefinitely. - */ - getRepeat(): integer; - /** - * Sets the number of times that the animation should repeat - * after its first iteration. For example, if repeat is 1, the animation will - * play a total of twice (the initial play plus 1 repeat). - * To repeat indefinitely, use -1. repeat should always be an integer. - * @param value The number of times that the animation should repeat. - */ - setRepeat(value: integer): Phaser.GameObjects.GameObject; - /** - * Gets the amount of delay between repeats, if any. - */ - getRepeatDelay(): number; - /** - * Sets the amount of time in seconds between repeats. - * For example, if `repeat` is 2 and `repeatDelay` is 10, the animation will play initially, - * then wait for 10 seconds before repeating, then play again, then wait another 10 seconds - * before doing its final repeat. - * @param value The delay to wait between repeats, in seconds. - */ - setRepeatDelay(value: number): Phaser.GameObjects.GameObject; - /** - * Restarts the current animation from its beginning, optionally including its delay value. - * @param includeDelay Whether to include the delay value of the animation when restarting. Default false. - */ - restart(includeDelay?: boolean): Phaser.GameObjects.GameObject; - /** - * Immediately stops the current animation from playing and dispatches the `animationcomplete` event. - * - * If no animation is set, no event will be dispatched. - * - * If there is another animation queued (via the `chain` method) then it will start playing immediately. - */ - stop(): Phaser.GameObjects.GameObject; - /** - * Stops the current animation from playing after the specified time delay, given in milliseconds. - * @param delay The number of milliseconds to wait before stopping this animation. - */ - stopAfterDelay(delay: integer): Phaser.GameObjects.GameObject; - /** - * Stops the current animation from playing when it next repeats. - */ - stopOnRepeat(): Phaser.GameObjects.GameObject; - /** - * Stops the current animation from playing when it next sets the given frame. - * If this frame doesn't exist within the animation it will not stop it from playing. - * @param frame The frame to check before stopping this animation. - */ - stopOnFrame(frame: Phaser.Animations.AnimationFrame): Phaser.GameObjects.GameObject; - /** - * Sets the Time Scale factor, allowing you to make the animation go go faster or slower than default. - * Where 1 = normal speed (the default), 0.5 = half speed, 2 = double speed, etc. - * @param value The time scale factor, where 1 is no change, 0.5 is half speed, etc. Default 1. - */ - setTimeScale(value?: number): Phaser.GameObjects.GameObject; - /** - * Gets the Time Scale factor. - */ - getTimeScale(): number; - /** - * Returns the total number of frames in this animation. - */ - getTotalFrames(): integer; - /** - * The internal update loop for the Animation Component. - * @param time The current timestamp. - * @param delta The delta time, in ms, elapsed since the last frame. - */ - update(time: number, delta: number): void; - /** - * Sets the given Animation Frame as being the current frame - * and applies it to the parent Game Object, adjusting its size and origin as needed. - * @param animationFrame The Animation Frame to set as being current. - */ - setCurrentFrame(animationFrame: Phaser.Animations.AnimationFrame): Phaser.GameObjects.GameObject; - /** - * Advances the animation to the next frame, regardless of the time or animation state. - * If the animation is set to repeat, or yoyo, this will still take effect. - * - * Calling this does not change the direction of the animation. I.e. if it was currently - * playing in reverse, calling this method doesn't then change the direction to forwards. - */ - nextFrame(): Phaser.GameObjects.GameObject; - /** - * Advances the animation to the previous frame, regardless of the time or animation state. - * If the animation is set to repeat, or yoyo, this will still take effect. - * - * Calling this does not change the direction of the animation. I.e. if it was currently - * playing in forwards, calling this method doesn't then change the direction to backwards. - */ - previousFrame(): Phaser.GameObjects.GameObject; - /** - * Sets if the current Animation will yoyo when it reaches the end. - * A yoyo'ing animation will play through consecutively, and then reverse-play back to the start again. - * @param value `true` if the animation should yoyo, `false` to not. Default false. - */ - setYoyo(value?: boolean): Phaser.GameObjects.GameObject; - /** - * Gets if the current Animation will yoyo when it reaches the end. - * A yoyo'ing animation will play through consecutively, and then reverse-play back to the start again. - */ - getYoyo(): boolean; - /** - * Destroy this Animation component. - * - * Unregisters event listeners and cleans up its references. - */ - destroy(): void; - } - /** * Provides methods used for setting the blend mode of a Game Object. * Should be applied as a mixin and not used directly. @@ -11020,7 +12800,7 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. @@ -11032,13 +12812,13 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. * @param value The depth of this Game Object. */ - setDepth(value: integer): this; + setDepth(value: number): this; } /** @@ -11212,6 +12992,8 @@ declare namespace Phaser { * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, * including this one. * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * * To create the mask you need to pass in a reference to a renderable Game Object. * A renderable Game Object is one that uses a texture to render with, such as an * Image, Sprite, Render Texture or BitmapText. @@ -11316,13 +13098,13 @@ declare namespace Phaser { * @param path The Path this PathFollower is following. It can only follow one Path at a time. * @param config Settings for the PathFollower. */ - setPath(path: Phaser.Curves.Path, config?: number | Phaser.Types.GameObjects.PathFollower.PathConfig | Phaser.Types.Tweens.NumberTweenBuilderConfig): Phaser.GameObjects.PathFollower; + setPath(path: Phaser.Curves.Path, config?: number | Phaser.Types.GameObjects.PathFollower.PathConfig | Phaser.Types.Tweens.NumberTweenBuilderConfig): this; /** * Set whether the PathFollower should automatically rotate to point in the direction of the Path. * @param value Whether the PathFollower should automatically rotate to point in the direction of the Path. * @param offset Rotation offset in degrees. Default 0. */ - setRotateToPath(value: boolean, offset?: number): Phaser.GameObjects.PathFollower; + setRotateToPath(value: boolean, offset?: number): this; /** * Is this PathFollower actively following a Path or not? * @@ -11334,24 +13116,24 @@ declare namespace Phaser { * @param config The duration of the follow, or a PathFollower config object. Default {}. * @param startAt Optional start position of the follow, between 0 and 1. Default 0. */ - startFollow(config?: number | Phaser.Types.GameObjects.PathFollower.PathConfig | Phaser.Types.Tweens.NumberTweenBuilderConfig, startAt?: number): Phaser.GameObjects.PathFollower; + startFollow(config?: number | Phaser.Types.GameObjects.PathFollower.PathConfig | Phaser.Types.Tweens.NumberTweenBuilderConfig, startAt?: number): this; /** * Pauses this PathFollower. It will still continue to render, but it will remain motionless at the * point on the Path at which you paused it. */ - pauseFollow(): Phaser.GameObjects.PathFollower; + pauseFollow(): this; /** * Resumes a previously paused PathFollower. * * If the PathFollower was not paused this has no effect. */ - resumeFollow(): Phaser.GameObjects.PathFollower; + resumeFollow(): this; /** * Stops this PathFollower from following the path any longer. * * This will invoke any 'stop' conditions that may exist on the Path, or for the follower. */ - stopFollow(): Phaser.GameObjects.PathFollower; + stopFollow(): this; /** * Internal update handler that advances this PathFollower along the path. * @@ -11366,27 +13148,107 @@ declare namespace Phaser { interface Pipeline { /** * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. */ defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; /** * The current WebGL pipeline of this Game Object. */ pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + /** + * Does this Game Object have any Post Pipelines set? + */ + hasPostPipeline: boolean; + /** + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. + */ + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; + /** + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. + */ + pipelineData: object; /** * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + */ + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; + /** + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; + /** + * Sets one, or more, Post Pipelines on this Game Object. + * + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. */ - initPipeline(pipelineName?: string): boolean; + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. + * Adds an entry to the `pipelineData` object belonging to this Game Object. + * + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. */ - setPipeline(pipelineName: string): this; + setPipelineData(key: string, value?: any): this; + /** + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. + */ + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; /** * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; + /** + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. */ - resetPipeline(): boolean; + resetPostPipeline(resetData?: boolean): void; + /** + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. + */ + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; /** * Gets the name of the WebGL Pipeline this Game Object is currently using. */ @@ -11547,7 +13409,7 @@ declare namespace Phaser { * @param key The key of the texture to be used, as stored in the Texture Manager, or a Texture instance. * @param frame The name or index of the frame within the Texture. */ - setTexture(key: string | Phaser.Textures.Texture, frame?: string | integer): this; + setTexture(key: string | Phaser.Textures.Texture, frame?: string | number): this; /** * Sets the frame this Game Object will use to render with. * @@ -11561,7 +13423,7 @@ declare namespace Phaser { * @param updateSize Should this call adjust the size of the Game Object? Default true. * @param updateOrigin Should this call adjust the origin of the Game Object? Default true. */ - setFrame(frame: string | integer, updateSize?: boolean, updateOrigin?: boolean): this; + setFrame(frame: string | number, updateSize?: boolean, updateOrigin?: boolean): this; } /** @@ -11617,7 +13479,7 @@ declare namespace Phaser { * @param key The key of the texture to be used, as stored in the Texture Manager. * @param frame The name or index of the frame within the Texture. */ - setTexture(key: string, frame?: string | integer): this; + setTexture(key: string, frame?: string | number): this; /** * Sets the frame this Game Object will use to render with. * @@ -11631,7 +13493,7 @@ declare namespace Phaser { * @param updateSize Should this call adjust the size of the Game Object? Default true. * @param updateOrigin Should this call adjust the origin of the Game Object? Default true. */ - setFrame(frame: string | integer, updateSize?: boolean, updateOrigin?: boolean): this; + setFrame(frame: string | number, updateSize?: boolean, updateOrigin?: boolean): this; } /** @@ -11640,7 +13502,34 @@ declare namespace Phaser { */ interface Tint { /** - * Fill or additive? + * The tint value being applied to the top-left vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintTopLeft: number; + /** + * The tint value being applied to the top-right vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintTopRight: number; + /** + * The tint value being applied to the bottom-left vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintBottomLeft: number; + /** + * The tint value being applied to the bottom-right vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintBottomRight: number; + /** + * The tint fill mode. + * + * `false` = An additive tint (the default), where vertices colors are blended with the texture. + * `true` = A fill tint, where the vertices colors replace the texture, but respects texture alpha. */ tintFill: boolean; /** @@ -11670,7 +13559,7 @@ declare namespace Phaser { * @param bottomLeft The tint being applied to the bottom-left of the Game Object. * @param bottomRight The tint being applied to the bottom-right of the Game Object. */ - setTint(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; + setTint(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; /** * Sets a fill-based tint on this Game Object. * @@ -11692,34 +13581,17 @@ declare namespace Phaser { * @param bottomLeft The tint being applied to the bottom-left of the Game Object. * @param bottomRight The tint being applied to the bottom-right of the Game Object. */ - setTintFill(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; - /** - * The tint value being applied to the top-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintTopLeft: integer; - /** - * The tint value being applied to the top-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintTopRight: integer; - /** - * The tint value being applied to the bottom-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintBottomLeft: integer; - /** - * The tint value being applied to the bottom-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintBottomRight: integer; + setTintFill(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; /** * The tint value being applied to the whole of the Game Object. * This property is a setter-only. Use the properties `tintTopLeft` etc to read the current tint value. */ - tint: integer; + tint: number; /** - * Does this Game Object have a tint applied to it or not? + * Does this Game Object have a tint applied? + * + * It checks to see if the 4 tint properties are set to the value 0xffffff + * and that the `tintFill` property is `false`. This indicates that a Game Object isn't tinted. */ readonly isTinted: boolean; } @@ -11779,12 +13651,12 @@ declare namespace Phaser { * * If you prefer to work in radians, see the `rotation` property instead. */ - angle: integer; + angle: number; /** * The angle of this Game Object in radians. * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. * * If you prefer to work in degrees, see the `angle` property instead. */ @@ -11797,6 +13669,11 @@ declare namespace Phaser { * @param w The w position of this Game Object. Default 0. */ setPosition(x?: number, y?: number, z?: number, w?: number): this; + /** + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; /** * Sets the position of this Game Object to be a random position within the confines of * the given area. @@ -11861,6 +13738,21 @@ declare namespace Phaser { * @param parentMatrix A temporary matrix to hold parent values during the calculations. */ getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. + */ + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; /** * Gets the sum total rotation of all of this Game Objects parent Containers. * @@ -11997,7 +13889,7 @@ declare namespace Phaser { * @param rhs The Matrix to multiply by. * @param out An optional Matrix to store the results in. */ - multiply(rhs: Phaser.GameObjects.Components.TransformMatrix, out?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + multiply(rhs: Phaser.GameObjects.Components.TransformMatrix, out?: Phaser.GameObjects.Components.TransformMatrix): this | Phaser.GameObjects.Components.TransformMatrix; /** * Multiply this Matrix by the matrix given, including the offset. @@ -12126,6 +14018,26 @@ declare namespace Phaser { */ getY(x: number, y: number): number; + /** + * Returns the X component of this matrix multiplied by the given values. + * + * This is the same as `x * a + y * c + e`, optionally passing via `Math.round`. + * @param x The x value. + * @param y The y value. + * @param round Math.round the resulting value? Default false. + */ + getXRound(x: number, y: number, round?: boolean): number; + + /** + * Returns the Y component of this matrix multiplied by the given values. + * + * This is the same as `x * b + y * d + f`, optionally passing via `Math.round`. + * @param x The x value. + * @param y The y value. + * @param round Math.round the resulting value? Default false. + */ + getYRound(x: number, y: number, round?: boolean): number; + /** * Returns a string that can be used in a CSS Transform call as a `matrix` property. */ @@ -12169,6 +14081,10 @@ declare namespace Phaser { * * The position of the Game Object automatically becomes relative to the position of the Container. * + * The origin of a Container is 0x0 (in local space) and that cannot be changed. The children you add to the + * Container should be positioned with this value in mind. I.e. you should treat 0x0 as being the center of + * the Container, and position children positively and negative around it as required. + * * When the Container is rendered, all of its children are rendered as well, in the order in which they exist * within the Container. Container children can be repositioned using methods such as `MoveUp`, `MoveDown` and `SendToBack`. * @@ -12183,6 +14099,9 @@ declare namespace Phaser { * Containers can be enabled for input. Because they do not have a texture you need to provide a shape for them * to use as their hit area. Container children can also be enabled for input, independent of the Container. * + * If input enabling a _child_ you should not set both the `origin` and a **negative** scale factor on the child, + * or the input area will become misaligned. + * * Containers can be given a physics body for either Arcade Physics, Impact Physics or Matter Physics. However, * if Container _children_ are enabled for physics you may get unexpected results, such as offset bodies, * if the Container itself, or any of its ancestors, is positioned anywhere other than at 0 x 0. Container children @@ -12195,7 +14114,7 @@ declare namespace Phaser { * flexible manner as those not within them. In short, don't use them for the sake of it. You pay a small cost * every time you create one, try to structure your game around avoiding that where possible. */ - class Container extends Phaser.GameObjects.GameObject implements Phaser.GameObjects.Components.AlphaSingle, Phaser.GameObjects.Components.BlendMode, Phaser.GameObjects.Components.ComputedSize, Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.Mask, Phaser.GameObjects.Components.Transform, Phaser.GameObjects.Components.Visible { + class Container extends Phaser.GameObjects.GameObject implements Phaser.GameObjects.Components.AlphaSingle, Phaser.GameObjects.Components.BlendMode, Phaser.GameObjects.Components.ComputedSize, Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.Mask, Phaser.GameObjects.Components.Pipeline, Phaser.GameObjects.Components.Transform, Phaser.GameObjects.Components.Visible { /** * * @param scene The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. @@ -12230,12 +14149,12 @@ declare namespace Phaser { * will constrict the addition of new Game Objects into the Container, capping off * the maximum limit the Container can grow in size to. */ - maxSize: integer; + maxSize: number; /** * The cursor position. */ - position: integer; + position: number; /** * Internal Transform Matrix used for local space conversion. @@ -12324,7 +14243,7 @@ declare namespace Phaser { * display list, but are being replicated where-ever this Container is. * @param value The exclusive state of this Container. Default true. */ - setExclusive(value?: boolean): Phaser.GameObjects.Container; + setExclusive(value?: boolean): this; /** * Gets the bounds of this Container. It works by iterating all children of the Container, @@ -12363,7 +14282,7 @@ declare namespace Phaser { * Each Game Object must be unique within the Container. * @param child The Game Object, or array of Game Objects, to add to the Container. */ - add(child: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[]): Phaser.GameObjects.Container; + add(child: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[]): this; /** * Adds the given Game Object, or array of Game Objects, to this Container at the specified position. @@ -12374,19 +14293,19 @@ declare namespace Phaser { * @param child The Game Object, or array of Game Objects, to add to the Container. * @param index The position to insert the Game Object/s at. Default 0. */ - addAt(child: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[], index?: integer): Phaser.GameObjects.Container; + addAt(child: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[], index?: number): this; /** * Returns the Game Object at the given position in this Container. * @param index The position to get the Game Object from. */ - getAt(index: integer): Phaser.GameObjects.GameObject; + getAt(index: number): Phaser.GameObjects.GameObject; /** * Returns the index of the given Game Object in this Container. * @param child The Game Object to search for in this Container. */ - getIndex(child: Phaser.GameObjects.GameObject): integer; + getIndex(child: Phaser.GameObjects.GameObject): number; /** * Sort the contents of this Container so the items are in order based on the given property. @@ -12394,7 +14313,7 @@ declare namespace Phaser { * @param property The property to lexically sort by. * @param handler Provide your own custom handler function. Will receive 2 children which it should compare and return a boolean. */ - sort(property: string, handler?: Function): Phaser.GameObjects.Container; + sort(property: string, handler?: Function): this; /** * Searches for the first instance of a child with its `name` property matching the given argument. @@ -12408,7 +14327,7 @@ declare namespace Phaser { * @param startIndex An optional start index. Default 0. * @param length An optional length, the total number of elements (from the startIndex) to choose from. */ - getRandom(startIndex?: integer, length?: integer): Phaser.GameObjects.GameObject; + getRandom(startIndex?: number, length?: number): Phaser.GameObjects.GameObject; /** * Gets the first Game Object in this Container. @@ -12424,7 +14343,7 @@ declare namespace Phaser { * @param startIndex An optional start index to search from. Default 0. * @param endIndex An optional end index to search up to (but not included) Default Container.length. */ - getFirst(property: string, value: any, startIndex?: integer, endIndex?: integer): Phaser.GameObjects.GameObject; + getFirst(property: string, value: any, startIndex?: number, endIndex?: number): Phaser.GameObjects.GameObject; /** * Returns all Game Objects in this Container. @@ -12445,7 +14364,7 @@ declare namespace Phaser { * @param startIndex An optional start index to search from. Default 0. * @param endIndex An optional end index to search up to (but not included) Default Container.length. */ - getAll(property?: string, value?: any, startIndex?: integer, endIndex?: integer): Phaser.GameObjects.GameObject[]; + getAll(property?: string, value?: any, startIndex?: number, endIndex?: number): Phaser.GameObjects.GameObject[]; /** * Returns the total number of Game Objects in this Container that have a property @@ -12459,7 +14378,7 @@ declare namespace Phaser { * @param startIndex An optional start index to search from. Default 0. * @param endIndex An optional end index to search up to (but not included) Default Container.length. */ - count(property: string, value: any, startIndex?: integer, endIndex?: integer): integer; + count(property: string, value: any, startIndex?: number, endIndex?: number): number; /** * Swaps the position of two Game Objects in this Container. @@ -12467,7 +14386,7 @@ declare namespace Phaser { * @param child1 The first Game Object to swap. * @param child2 The second Game Object to swap. */ - swap(child1: Phaser.GameObjects.GameObject, child2: Phaser.GameObjects.GameObject): Phaser.GameObjects.Container; + swap(child1: Phaser.GameObjects.GameObject, child2: Phaser.GameObjects.GameObject): this; /** * Moves a Game Object to a new position within this Container. @@ -12479,7 +14398,7 @@ declare namespace Phaser { * @param child The Game Object to move. * @param index The new position of the Game Object in this Container. */ - moveTo(child: Phaser.GameObjects.GameObject, index: integer): Phaser.GameObjects.Container; + moveTo(child: Phaser.GameObjects.GameObject, index: number): this; /** * Removes the given Game Object, or array of Game Objects, from this Container. @@ -12490,7 +14409,7 @@ declare namespace Phaser { * @param child The Game Object, or array of Game Objects, to be removed from the Container. * @param destroyChild Optionally call `destroy` on each child successfully removed from this Container. Default false. */ - remove(child: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[], destroyChild?: boolean): Phaser.GameObjects.Container; + remove(child: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[], destroyChild?: boolean): this; /** * Removes the Game Object at the given position in this Container. @@ -12499,7 +14418,7 @@ declare namespace Phaser { * @param index The index of the Game Object to be removed. * @param destroyChild Optionally call `destroy` on the Game Object if successfully removed from this Container. Default false. */ - removeAt(index: integer, destroyChild?: boolean): Phaser.GameObjects.Container; + removeAt(index: number, destroyChild?: boolean): this; /** * Removes the Game Objects between the given positions in this Container. @@ -12509,7 +14428,7 @@ declare namespace Phaser { * @param endIndex An optional end index to search up to (but not included) Default Container.length. * @param destroyChild Optionally call `destroy` on each Game Object successfully removed from this Container. Default false. */ - removeBetween(startIndex?: integer, endIndex?: integer, destroyChild?: boolean): Phaser.GameObjects.Container; + removeBetween(startIndex?: number, endIndex?: number, destroyChild?: boolean): this; /** * Removes all Game Objects from this Container. @@ -12517,43 +14436,43 @@ declare namespace Phaser { * You can also optionally call `destroy` on each Game Object that is removed from the Container. * @param destroyChild Optionally call `destroy` on each Game Object successfully removed from this Container. Default false. */ - removeAll(destroyChild?: boolean): Phaser.GameObjects.Container; + removeAll(destroyChild?: boolean): this; /** * Brings the given Game Object to the top of this Container. * This will cause it to render on-top of any other objects in the Container. * @param child The Game Object to bring to the top of the Container. */ - bringToTop(child: Phaser.GameObjects.GameObject): Phaser.GameObjects.Container; + bringToTop(child: Phaser.GameObjects.GameObject): this; /** * Sends the given Game Object to the bottom of this Container. * This will cause it to render below any other objects in the Container. * @param child The Game Object to send to the bottom of the Container. */ - sendToBack(child: Phaser.GameObjects.GameObject): Phaser.GameObjects.Container; + sendToBack(child: Phaser.GameObjects.GameObject): this; /** * Moves the given Game Object up one place in this Container, unless it's already at the top. * @param child The Game Object to be moved in the Container. */ - moveUp(child: Phaser.GameObjects.GameObject): Phaser.GameObjects.Container; + moveUp(child: Phaser.GameObjects.GameObject): this; /** * Moves the given Game Object down one place in this Container, unless it's already at the bottom. * @param child The Game Object to be moved in the Container. */ - moveDown(child: Phaser.GameObjects.GameObject): Phaser.GameObjects.Container; + moveDown(child: Phaser.GameObjects.GameObject): this; /** * Reverses the order of all Game Objects in this Container. */ - reverse(): Phaser.GameObjects.Container; + reverse(): this; /** * Shuffles the all Game Objects in this Container using the Fisher-Yates implementation. */ - shuffle(): Phaser.GameObjects.Container; + shuffle(): this; /** * Replaces a Game Object in this Container with the new Game Object. @@ -12562,7 +14481,7 @@ declare namespace Phaser { * @param newChild The Game Object to be added to this Container. * @param destroyChild Optionally call `destroy` on the Game Object if successfully removed from this Container. Default false. */ - replace(oldChild: Phaser.GameObjects.GameObject, newChild: Phaser.GameObjects.GameObject, destroyChild?: boolean): Phaser.GameObjects.Container; + replace(oldChild: Phaser.GameObjects.GameObject, newChild: Phaser.GameObjects.GameObject, destroyChild?: boolean): this; /** * Returns `true` if the given Game Object is a direct child of this Container. @@ -12583,7 +14502,7 @@ declare namespace Phaser { * @param startIndex An optional start index to search from. Default 0. * @param endIndex An optional end index to search up to (but not included) Default Container.length. */ - setAll(property: string, value: any, startIndex?: integer, endIndex?: integer): Phaser.GameObjects.Container; + setAll(property: string, value: any, startIndex?: number, endIndex?: number): this; /** * Passes all Game Objects in this Container to the given callback. @@ -12597,7 +14516,7 @@ declare namespace Phaser { * @param context Value to use as `this` when executing callback. * @param args Additional arguments that will be passed to the callback, after the child. */ - each(callback: Function, context?: object, ...args: any[]): Phaser.GameObjects.Container; + each(callback: Function, context?: object, ...args: any[]): this; /** * Passes all Game Objects in this Container to the given callback. @@ -12608,7 +14527,7 @@ declare namespace Phaser { * @param context Value to use as `this` when executing callback. * @param args Additional arguments that will be passed to the callback, after the child. */ - iterate(callback: Function, context?: object, ...args: any[]): Phaser.GameObjects.Container; + iterate(callback: Function, context?: object, ...args: any[]): this; /** * Sets the scroll factor of this Container and optionally all of its children. @@ -12635,7 +14554,7 @@ declare namespace Phaser { /** * The number of Game Objects inside this Container. */ - readonly length: integer; + readonly length: number; /** * Returns the first Game Object within the Container, or `null` if it is empty. @@ -12804,7 +14723,7 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. @@ -12817,13 +14736,13 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. * @param value The depth of this Game Object. */ - setDepth(value: integer): this; + setDepth(value: number): this; /** * The Mask this Game Object is using during render. @@ -12857,6 +14776,8 @@ declare namespace Phaser { * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, * including this one. * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * * To create the mask you need to pass in a reference to a renderable Game Object. * A renderable Game Object is one that uses a texture to render with, such as an * Image, Sprite, Render Texture or BitmapText. @@ -12882,6 +14803,127 @@ declare namespace Phaser { */ createGeometryMask(graphics?: Phaser.GameObjects.Graphics): Phaser.Display.Masks.GeometryMask; + /** + * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. + */ + defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; + + /** + * The current WebGL pipeline of this Game Object. + */ + pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + + /** + * Does this Game Object have any Post Pipelines set? + */ + hasPostPipeline: boolean; + + /** + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. + */ + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; + + /** + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. + */ + pipelineData: object; + + /** + * Sets the initial WebGL Pipeline of this Game Object. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + */ + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; + + /** + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; + + /** + * Sets one, or more, Post Pipelines on this Game Object. + * + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; + + /** + * Adds an entry to the `pipelineData` object belonging to this Game Object. + * + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. + */ + setPipelineData(key: string, value?: any): this; + + /** + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. + */ + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; + + /** + * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; + + /** + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPostPipeline(resetData?: boolean): void; + + /** + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. + */ + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; + + /** + * Gets the name of the WebGL Pipeline this Game Object is currently using. + */ + getPipelineName(): string; + /** * The x position of this Game Object. */ @@ -12932,13 +14974,13 @@ declare namespace Phaser { * * If you prefer to work in radians, see the `rotation` property instead. */ - angle: integer; + angle: number; /** * The angle of this Game Object in radians. * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. * * If you prefer to work in degrees, see the `angle` property instead. */ @@ -12953,6 +14995,12 @@ declare namespace Phaser { */ setPosition(x?: number, y?: number, z?: number, w?: number): this; + /** + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; + /** * Sets the position of this Game Object to be a random position within the confines of * the given area. @@ -13027,6 +15075,22 @@ declare namespace Phaser { */ getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. + */ + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + /** * Gets the sum total rotation of all of this Game Objects parent Containers. * @@ -13080,6 +15144,11 @@ declare namespace Phaser { */ systems: Phaser.Scenes.Systems; + /** + * The Scene's Event Emitter. + */ + events: Phaser.Events.EventEmitter; + /** * Force a sort of the display list on the next call to depthSort. */ @@ -13095,7 +15164,7 @@ declare namespace Phaser { * @param childA The first Game Object. * @param childB The second Game Object. */ - sortByDepth(childA: Phaser.GameObjects.GameObject, childB: Phaser.GameObjects.GameObject): integer; + sortByDepth(childA: Phaser.GameObjects.GameObject, childB: Phaser.GameObjects.GameObject): number; /** * Returns an array which contains all objects currently on the Display List. @@ -13121,6 +15190,9 @@ declare namespace Phaser { * of the game canvas. This div is sized to match the canvas, and if the canvas size changes, as a result of * settings within the Scale Manager, the dom container is resized accordingly. * + * If you have not already done so, you have to provide a `parent` in the Game Configuration, or the DOM + * Container will fail to be created. + * * You can create a DOM Element by either passing in DOMStrings, or by passing in a reference to an existing * Element that you wish to be placed under the control of Phaser. For example: * @@ -13152,6 +15224,9 @@ declare namespace Phaser { * * Also, all DOM Elements are inserted into the same DOM Container, regardless of which Scene they are created in. * + * Note that you should only have DOM Elements in a Scene with a _single_ Camera. If you require multiple cameras, + * use parallel scenes to achieve this. + * * DOM Elements are a powerful way to align native HTML with your Phaser Game Objects. For example, you can insert * a login form for a multiplayer game directly into your title screen. Or a text input box for a highscore table. * Or a banner ad from a 3rd party service. Or perhaps you'd like to use them for high resolution text display and @@ -13608,7 +15683,7 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. @@ -13621,13 +15696,13 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. * @param value The depth of this Game Object. */ - setDepth(value: integer): this; + setDepth(value: number): this; /** * The horizontal origin of this Game Object. @@ -13796,13 +15871,13 @@ declare namespace Phaser { * * If you prefer to work in radians, see the `rotation` property instead. */ - angle: integer; + angle: number; /** * The angle of this Game Object in radians. * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. * * If you prefer to work in degrees, see the `angle` property instead. */ @@ -13817,6 +15892,12 @@ declare namespace Phaser { */ setPosition(x?: number, y?: number, z?: number, w?: number): this; + /** + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; + /** * Sets the position of this Game Object to be a random position within the confines of * the given area. @@ -13891,6 +15972,22 @@ declare namespace Phaser { */ getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. + */ + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + /** * Gets the sum total rotation of all of this Game Objects parent Containers. * @@ -13916,6 +16013,15 @@ declare namespace Phaser { } namespace Events { + /** + * The Game Object Added to Scene Event. + * + * This event is dispatched when a Game Object is added to a Scene. + * + * Listen for it on a Game Object instance using `GameObject.on('addedtoscene', listener)`. + */ + const ADDED_TO_SCENE: any; + /** * The Game Object Destroy Event. * @@ -13925,6 +16031,15 @@ declare namespace Phaser { */ const DESTROY: any; + /** + * The Game Object Removed from Scene Event. + * + * This event is dispatched when a Game Object is removed from a Scene. + * + * Listen for it on a Game Object instance using `GameObject.on('removedfromscene', listener)`. + */ + const REMOVED_FROM_SCENE: any; + /** * The Video Game Object Complete Event. * @@ -14051,7 +16166,7 @@ declare namespace Phaser { * * The WebGL context is then left is a 'clean' state, ready for you to bind your own shaders, * or draw to it, whatever you wish to do. Once you've finished, you should free-up any - * of your resources. The Extern will then rebind the Phaser pipeline and carry on + * of your resources. The Extern will then rebind the Phaser pipeline and carry on * rendering the display list. * * Although this object has lots of properties such as Alpha, Blend Mode and Tint, none of @@ -14168,7 +16283,7 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. @@ -14181,13 +16296,13 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. * @param value The depth of this Game Object. */ - setDepth(value: integer): this; + setDepth(value: number): this; /** * The horizontally flipped state of the Game Object. @@ -14461,7 +16576,7 @@ declare namespace Phaser { * @param key The key of the texture to be used, as stored in the Texture Manager, or a Texture instance. * @param frame The name or index of the frame within the Texture. */ - setTexture(key: string | Phaser.Textures.Texture, frame?: string | integer): this; + setTexture(key: string | Phaser.Textures.Texture, frame?: string | number): this; /** * Sets the frame this Game Object will use to render with. @@ -14476,10 +16591,41 @@ declare namespace Phaser { * @param updateSize Should this call adjust the size of the Game Object? Default true. * @param updateOrigin Should this call adjust the origin of the Game Object? Default true. */ - setFrame(frame: string | integer, updateSize?: boolean, updateOrigin?: boolean): this; + setFrame(frame: string | number, updateSize?: boolean, updateOrigin?: boolean): this; + + /** + * The tint value being applied to the top-left vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintTopLeft: number; + + /** + * The tint value being applied to the top-right vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintTopRight: number; /** - * Fill or additive? + * The tint value being applied to the bottom-left vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintBottomLeft: number; + + /** + * The tint value being applied to the bottom-right vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintBottomRight: number; + + /** + * The tint fill mode. + * + * `false` = An additive tint (the default), where vertices colors are blended with the texture. + * `true` = A fill tint, where the vertices colors replace the texture, but respects texture alpha. */ tintFill: boolean; @@ -14511,7 +16657,7 @@ declare namespace Phaser { * @param bottomLeft The tint being applied to the bottom-left of the Game Object. * @param bottomRight The tint being applied to the bottom-right of the Game Object. */ - setTint(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; + setTint(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; /** * Sets a fill-based tint on this Game Object. @@ -14534,40 +16680,19 @@ declare namespace Phaser { * @param bottomLeft The tint being applied to the bottom-left of the Game Object. * @param bottomRight The tint being applied to the bottom-right of the Game Object. */ - setTintFill(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; - - /** - * The tint value being applied to the top-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintTopLeft: integer; - - /** - * The tint value being applied to the top-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintTopRight: integer; - - /** - * The tint value being applied to the bottom-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintBottomLeft: integer; - - /** - * The tint value being applied to the bottom-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintBottomRight: integer; + setTintFill(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; /** * The tint value being applied to the whole of the Game Object. * This property is a setter-only. Use the properties `tintTopLeft` etc to read the current tint value. */ - tint: integer; + tint: number; /** - * Does this Game Object have a tint applied to it or not? + * Does this Game Object have a tint applied? + * + * It checks to see if the 4 tint properties are set to the value 0xffffff + * and that the `tintFill` property is `false`. This indicates that a Game Object isn't tinted. */ readonly isTinted: boolean; @@ -14621,13 +16746,13 @@ declare namespace Phaser { * * If you prefer to work in radians, see the `rotation` property instead. */ - angle: integer; + angle: number; /** * The angle of this Game Object in radians. * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. * * If you prefer to work in degrees, see the `angle` property instead. */ @@ -14642,6 +16767,12 @@ declare namespace Phaser { */ setPosition(x?: number, y?: number, z?: number, w?: number): this; + /** + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; + /** * Sets the position of this Game Object to be a random position within the confines of * the given area. @@ -14716,6 +16847,22 @@ declare namespace Phaser { */ getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. + */ + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + /** * Gets the sum total rotation of all of this Game Objects parent Containers. * @@ -14754,10 +16901,23 @@ declare namespace Phaser { constructor(scene: Phaser.Scene, type: string); /** - * The Scene to which this Game Object belongs. + * A reference to the Scene to which this Game Object belongs. + * * Game Objects can only belong to one Scene. + * + * You should consider this property as being read-only. You cannot move a + * Game Object to another Scene by simply changing it. */ - protected scene: Phaser.Scene; + scene: Phaser.Scene; + + /** + * Holds a reference to the Display List that contains this Game Object. + * + * This is set automatically when this Game Object is added to a Scene or Layer. + * + * You should treat this property as being read-only. + */ + displayList: Phaser.GameObjects.DisplayList | Phaser.GameObjects.Layer; /** * A textual representation of this Game Object, i.e. `sprite`. @@ -14775,7 +16935,7 @@ declare namespace Phaser { * in your game code), or a string. These are recommended to keep it light and simple, with fast comparisons. * If you need to store complex data about your Game Object, look at using the Data Component instead. */ - state: integer | string; + state: number | string; /** * The parent Container of this Game Object, if it has one. @@ -14799,7 +16959,7 @@ declare namespace Phaser { * The Tab Index of the Game Object. * Reserved for future use by plugins and the Input Manager. */ - tabIndex: integer; + tabIndex: number; /** * A Data Manager. @@ -14813,7 +16973,7 @@ declare namespace Phaser { * The bits are 0001 | 0010 | 0100 | 1000 set by the components Visible, Alpha, Transform and Texture respectively. * If those components are not used by your custom class then you can use this bitmask as you wish. */ - renderFlags: integer; + renderFlags: number; /** * A bitmask that controls if this Game Object is drawn by a Camera or not. @@ -14829,9 +16989,9 @@ declare namespace Phaser { input: Phaser.Types.Input.InteractiveObject; /** - * If this Game Object is enabled for physics then this property will contain a reference to a Physics Body. + * If this Game Object is enabled for Arcade or Matter Physics then this property will contain a reference to a Physics Body. */ - body: object | Phaser.Physics.Arcade.Body | Phaser.Physics.Impact.Body; + body: Phaser.Physics.Arcade.Body | Phaser.Physics.Arcade.StaticBody | MatterJS.BodyType; /** * This Game Object will ignore all calls made to its destroy method if this flag is set to `true`. @@ -14866,7 +17026,7 @@ declare namespace Phaser { * If you need to store complex data about your Game Object, look at using the Data Component instead. * @param value The state of the Game Object. */ - setState(value: integer | string): this; + setState(value: number | string): this; /** * Adds a Data Manager component to this Game Object. @@ -14916,6 +17076,33 @@ declare namespace Phaser { */ setData(key: string | object, data?: any): this; + /** + * Increase a value for the given key within this Game Objects Data Manager. If the key doesn't already exist in the Data Manager then it is increased from 0. + * + * If the Game Object has not been enabled for data (via `setDataEnabled`) then it will be enabled + * before setting the value. + * + * If the key doesn't already exist in the Data Manager then it is created. + * + * When the value is first set, a `setdata` event is emitted from this Game Object. + * @param key The key to increase the value for. + * @param data The value to increase for the given key. + */ + incData(key: string | object, data?: any): this; + + /** + * Toggle a boolean value for the given key within this Game Objects Data Manager. If the key doesn't already exist in the Data Manager then it is toggled from false. + * + * If the Game Object has not been enabled for data (via `setDataEnabled`) then it will be enabled + * before setting the value. + * + * If the key doesn't already exist in the Data Manager then it is created. + * + * When the value is first set, a `setdata` event is emitted from this Game Object. + * @param key The key to toggle the value for. + */ + toggleData(key: string | object): this; + /** * Retrieves the value for the given key in this Game Objects Data Manager, or undefined if it doesn't exist. * @@ -14954,11 +17141,11 @@ declare namespace Phaser { * shape for it to use. * * You can also provide an Input Configuration Object as the only argument to this method. - * @param shape 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. - * @param callback A callback to be invoked when the Game Object is interacted with. If you provide a shape you must also provide a callback. + * @param hitArea Either an input configuration object, or a geometric shape that defines the hit area for the Game Object. If not given it will try to create a Rectangle based on the texture frame. + * @param callback The callback that determines if the pointer is within the Hit Area shape or not. If you provide a shape you must also provide a callback. * @param dropZone Should this Game Object be treated as a drop zone target? Default false. */ - setInteractive(shape?: Phaser.Types.Input.InputConfiguration | any, callback?: Phaser.Types.Input.HitAreaCallback, dropZone?: boolean): this; + setInteractive(hitArea?: Phaser.Types.Input.InputConfiguration | any, callback?: Phaser.Types.Input.HitAreaCallback, dropZone?: boolean): this; /** * If this Game Object has previously been enabled for input, this will disable it. @@ -14993,6 +17180,26 @@ declare namespace Phaser { */ removeInteractive(): this; + /** + * This callback is invoked when this Game Object is added to a Scene. + * + * Can be overriden by custom Game Objects, but be aware of some Game Objects that + * will use this, such as Sprites, to add themselves into the Update List. + * + * You can also listen for the `ADDED_TO_SCENE` event from this Game Object. + */ + addedToScene(): void; + + /** + * This callback is invoked when this Game Object is removed from a Scene. + * + * Can be overriden by custom Game Objects, but be aware of some Game Objects that + * will use this, such as Sprites, to removed themselves from the Update List. + * + * You can also listen for the `REMOVED_FROM_SCENE` event from this Game Object. + */ + removedFromScene(): void; + /** * To be overridden by custom GameObjects. Allows base objects to be used in a Pool. * @param args args @@ -15019,7 +17226,7 @@ declare namespace Phaser { * Used internally by the InputPlugin but also useful if you wish to find out the display depth of * this Game Object and all of its ancestors. */ - getIndexList(): integer[]; + getIndexList(): number[]; /** * Destroys this Game Object removing it from the Display List and Update List and @@ -15033,14 +17240,13 @@ declare namespace Phaser { * * If you just want to temporarily disable an object then look at using the * Game Object Pool instead of destroying it, as destroyed objects cannot be resurrected. - * @param fromScene Is this Game Object being destroyed as the result of a Scene shutdown? Default false. */ - destroy(fromScene?: boolean): void; + destroy(): void; /** * The bitmask that `GameObject.renderFlags` is compared against to determine if the Game Object will render or not. */ - static readonly RENDER_MASK: integer; + static readonly RENDER_MASK: number; } @@ -15105,6 +17311,11 @@ declare namespace Phaser { */ protected systems: Phaser.Scenes.Systems; + /** + * A reference to the Scene Event Emitter. + */ + protected events: Phaser.Events.EventEmitter; + /** * A reference to the Scene Display List. */ @@ -15141,6 +17352,15 @@ declare namespace Phaser { */ image(config: object, addToScene?: boolean): Phaser.GameObjects.Image; + /** + * Creates a new Layer Game Object and returns it. + * + * Note: This method will only be available if the Layer Game Object has been built into Phaser. + * @param config The configuration object this Game Object will use to create itself. + * @param addToScene Add this Game Object to the Scene after creating it? If set this argument overrides the `add` property in the config object. + */ + layer(config: object, addToScene?: boolean): Phaser.GameObjects.Layer; + /** * Creates a new Mesh Game Object and returns it. * @@ -15160,13 +17380,13 @@ declare namespace Phaser { particles(config: object, addToScene?: boolean): Phaser.GameObjects.Particles.ParticleEmitterManager; /** - * Creates a new Quad Game Object and returns it. + * Creates a new Point Light Game Object and returns it. * - * Note: This method will only be available if the Quad Game Object and WebGL support have been built into Phaser. + * Note: This method will only be available if the Point Light Game Object has been built into Phaser. * @param config The configuration object this Game Object will use to create itself. * @param addToScene Add this Game Object to the Scene after creating it? If set this argument overrides the `add` property in the config object. */ - quad(config: object, addToScene?: boolean): Phaser.GameObjects.Quad; + pointlight(config: object, addToScene?: boolean): Phaser.GameObjects.PointLight; /** * Creates a new Render Texture Game Object and returns it. @@ -15177,6 +17397,15 @@ declare namespace Phaser { */ renderTexture(config: Phaser.Types.GameObjects.RenderTexture.RenderTextureConfig, addToScene?: boolean): Phaser.GameObjects.RenderTexture; + /** + * Creates a new Rope Game Object and returns it. + * + * Note: This method will only be available if the Rope Game Object and WebGL support have been built into Phaser. + * @param config The configuration object this Game Object will use to create itself. + * @param addToScene Add this Game Object to the Scene after creating it? If set this argument overrides the `add` property in the config object. + */ + rope(config: object, addToScene?: boolean): Phaser.GameObjects.Rope; + /** * Creates a new Shader Game Object and returns it. * @@ -15202,7 +17431,7 @@ declare namespace Phaser { * @param config The configuration object this Game Object will use to create itself. * @param addToScene Add this Game Object to the Scene after creating it? If set this argument overrides the `add` property in the config object. */ - text(config: object, addToScene?: boolean): Phaser.GameObjects.Text; + text(config: Phaser.Types.GameObjects.Text.TextConfig, addToScene?: boolean): Phaser.GameObjects.Text; /** * Creates a new TileSprite Game Object and returns it. @@ -15339,7 +17568,7 @@ declare namespace Phaser { * @param size The font size to set. * @param align The alignment of the text in a multi-line BitmapText object. Default 0. */ - bitmapText(x: number, y: number, font: string, text?: string | string[], size?: number, align?: integer): Phaser.GameObjects.BitmapText; + bitmapText(x: number, y: number, font: string, text?: string | string[], size?: number, align?: number): Phaser.GameObjects.BitmapText; /** * Creates a new Blitter Game Object and adds it to the Scene. @@ -15350,17 +17579,17 @@ declare namespace Phaser { * @param key The key of the Texture the Blitter object will use. * @param frame The default Frame children of the Blitter will use. */ - blitter(x: number, y: number, key: string, frame?: string | integer): Phaser.GameObjects.Blitter; + blitter(x: number, y: number, key: string, frame?: string | number): Phaser.GameObjects.Blitter; /** * Creates a new Container Game Object and adds it to the Scene. * * Note: This method will only be available if the Container Game Object has been built into Phaser. - * @param x The horizontal position of this Game Object in the world. - * @param y The vertical position of this Game Object in the world. + * @param x The horizontal position of this Game Object in the world. Default 0. + * @param y The vertical position of this Game Object in the world. Default 0. * @param children An optional array of Game Objects to add to this Container. */ - container(x: number, y: number, children?: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[]): Phaser.GameObjects.Container; + container(x?: number, y?: number, children?: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[]): Phaser.GameObjects.Container; /** * DOM Element Game Objects are a way to control and manipulate HTML Elements over the top of your game. @@ -15441,6 +17670,11 @@ declare namespace Phaser { */ protected systems: Phaser.Scenes.Systems; + /** + * A reference to the Scene Event Emitter. + */ + protected events: Phaser.Events.EventEmitter; + /** * A reference to the Scene Display List. */ @@ -15458,7 +17692,7 @@ declare namespace Phaser { * If it has a `preUpdate` method, it will be added to the Update List. * @param child The child to be added to this Scene. */ - existing(child: Phaser.GameObjects.GameObject | Phaser.GameObjects.Group): Phaser.GameObjects.GameObject; + existing(child: G): G; /** * Static method called directly by the Game Object factory functions. @@ -15501,10 +17735,18 @@ declare namespace Phaser { * Note: This method will only be available if the Image Game Object has been built into Phaser. * @param x The horizontal position of this Game Object in the world. * @param y The vertical position of this Game Object in the world. - * @param texture The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. + * @param texture The key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager. * @param frame An optional frame from the Texture this Game Object is rendering with. */ - image(x: number, y: number, texture: string, frame?: string | integer): Phaser.GameObjects.Image; + image(x: number, y: number, texture: string | Phaser.Textures.Texture, frame?: string | number): Phaser.GameObjects.Image; + + /** + * Creates a new Layer Game Object and adds it to the Scene. + * + * Note: This method will only be available if the Layer Game Object has been built into Phaser. + * @param children An optional array of Game Objects to add to this Layer. + */ + layer(children?: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[]): Phaser.GameObjects.Layer; /** * Creates a new Mesh Game Object and adds it to the Scene. @@ -15512,24 +17754,27 @@ declare namespace Phaser { * Note: This method will only be available if the Mesh Game Object and WebGL support have been built into Phaser. * @param x The horizontal position of this Game Object in the world. * @param y The vertical position of this Game Object in the world. - * @param vertices An array containing the vertices data for this Mesh. - * @param uv An array containing the uv data for this Mesh. - * @param colors An array containing the color data for this Mesh. - * @param alphas An array containing the alpha data for this Mesh. - * @param texture The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. + * @param texture The key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager. * @param frame An optional frame from the Texture this Game Object is rendering with. + * @param vertices The vertices array. Either `xy` pairs, or `xyz` if the `containsZ` parameter is `true`. + * @param uvs The UVs pairs array. + * @param indicies Optional vertex indicies array. If you don't have one, pass `null` or an empty array. + * @param containsZ Does the vertices data include a `z` component? Default false. + * @param normals Optional vertex normals array. If you don't have one, pass `null` or an empty array. + * @param colors An array of colors, one per vertex, or a single color value applied to all vertices. Default 0xffffff. + * @param alphas An array of alpha values, one per vertex, or a single alpha value applied to all vertices. Default 1. */ - mesh(x: number, y: number, vertices: number[], uv: number[], colors: number[], alphas: number[], texture: string, frame?: string | integer): Phaser.GameObjects.Mesh; + mesh(x?: number, y?: number, texture?: string | Phaser.Textures.Texture, frame?: string | number, vertices?: number[], uvs?: number[], indicies?: number[], containsZ?: boolean, normals?: number[], colors?: number | number[], alphas?: number | number[]): Phaser.GameObjects.Mesh; /** * Creates a new Particle Emitter Manager Game Object and adds it to the Scene. * * Note: This method will only be available if the Particles Game Object has been built into Phaser. - * @param texture The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. + * @param texture The key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager. * @param frame An optional frame from the Texture this Game Object is rendering with. * @param emitters Configuration settings for one or more emitters to create. */ - particles(texture: string, frame?: string | integer | object, emitters?: Phaser.Types.GameObjects.Particles.ParticleEmitterConfig | Phaser.Types.GameObjects.Particles.ParticleEmitterConfig[]): Phaser.GameObjects.Particles.ParticleEmitterManager; + particles(texture: string | Phaser.Textures.Texture, frame?: string | number | object, emitters?: Phaser.Types.GameObjects.Particles.ParticleEmitterConfig | Phaser.Types.GameObjects.Particles.ParticleEmitterConfig[]): Phaser.GameObjects.Particles.ParticleEmitterManager; /** * Creates a new PathFollower Game Object and adds it to the Scene. @@ -15538,21 +17783,47 @@ declare namespace Phaser { * @param path The Path this PathFollower is connected to. * @param x The horizontal position of this Game Object in the world. * @param y The vertical position of this Game Object in the world. - * @param texture The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. + * @param texture The key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager. * @param frame An optional frame from the Texture this Game Object is rendering with. */ - follower(path: Phaser.Curves.Path, x: number, y: number, texture: string, frame?: string | integer): Phaser.GameObjects.PathFollower; + follower(path: Phaser.Curves.Path, x: number, y: number, texture: string | Phaser.Textures.Texture, frame?: string | number): Phaser.GameObjects.PathFollower; /** - * Creates a new Quad Game Object and adds it to the Scene. + * Creates a new Point Light Game Object and adds it to the Scene. * - * Note: This method will only be available if the Quad Game Object and WebGL support have been built into Phaser. - * @param x The horizontal position of this Game Object in the world. - * @param y The vertical position of this Game Object in the world. - * @param texture The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. - * @param frame An optional frame from the Texture this Game Object is rendering with. + * Note: This method will only be available if the Point Light Game Object has been built into Phaser. + * + * The Point Light Game Object provides a way to add a point light effect into your game, + * without the expensive shader processing requirements of the traditional Light Game Object. + * + * The difference is that the Point Light renders using a custom shader, designed to give the + * impression of a point light source, of variable radius, intensity and color, in your game. + * However, unlike the Light Game Object, it does not impact any other Game Objects, or use their + * normal maps for calcuations. This makes them extremely fast to render compared to Lights + * and perfect for special effects, such as flickering torches or muzzle flashes. + * + * For maximum performance you should batch Point Light Game Objects together. This means + * ensuring they follow each other consecutively on the display list. Ideally, use a Layer + * Game Object and then add just Point Lights to it, so that it can batch together the rendering + * of the lights. You don't _have_ to do this, and if you've only a handful of Point Lights in + * your game then it's perfectly safe to mix them into the dislay list as normal. However, if + * you're using a large number of them, please consider how they are mixed into the display list. + * + * The renderer will automatically cull Point Lights. Those with a radius that does not intersect + * with the Camera will be skipped in the rendering list. This happens automatically and the + * culled state is refreshed every frame, for every camera. + * + * The origin of a Point Light is always 0.5 and it cannot be changed. + * + * Point Lights are a WebGL only feature and do not have a Canvas counterpart. + * @param x The horizontal position of this Point Light in the world. + * @param y The vertical position of this Point Light in the world. + * @param color The color of the Point Light, given as a hex value. Default 0xffffff. + * @param radius The radius of the Point Light. Default 128. + * @param intensity The intensity, or colr blend, of the Point Light. Default 1. + * @param attenuation The attenuation of the Point Light. This is the reduction of light from the center point. Default 0.1. */ - quad(x: number, y: number, texture: string, frame?: string | integer): Phaser.GameObjects.Quad; + pointlight(x: number, y: number, color?: number, radius?: number, intensity?: number, attenuation?: number): Phaser.GameObjects.PointLight; /** * Creates a new Render Texture Game Object and adds it to the Scene. @@ -15567,7 +17838,22 @@ declare namespace Phaser { * @param width The width of the Render Texture. Default 32. * @param height The height of the Render Texture. Default 32. */ - renderTexture(x: number, y: number, width?: integer, height?: integer): Phaser.GameObjects.RenderTexture; + renderTexture(x: number, y: number, width?: number, height?: number): Phaser.GameObjects.RenderTexture; + + /** + * Creates a new Rope Game Object and adds it to the Scene. + * + * Note: This method will only be available if the Rope Game Object and WebGL support have been built into Phaser. + * @param x The horizontal position of this Game Object in the world. + * @param y The vertical position of this Game Object in the world. + * @param texture The key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager. + * @param frame An optional frame from the Texture this Game Object is rendering with. + * @param points An array containing the vertices data for this Rope. If none is provided a simple quad is created. See `setPoints` to set this post-creation. + * @param horizontal Should the vertices of this Rope be aligned horizontally (`true`), or vertically (`false`)? Default true. + * @param colors An optional array containing the color data for this Rope. You should provide one color value per pair of vertices. + * @param alphas An optional array containing the alpha data for this Rope. You should provide one alpha value per pair of vertices. + */ + rope(x: number, y: number, texture: string | Phaser.Textures.Texture, frame?: string | number, points?: Phaser.Types.Math.Vector2Like[], horizontal?: boolean, colors?: number[], alphas?: number[]): Phaser.GameObjects.Rope; /** * Creates a new Shader Game Object and adds it to the Scene. @@ -15608,7 +17894,7 @@ declare namespace Phaser { * @param fillColor The color the arc will be filled with, i.e. 0xff0000 for red. * @param fillAlpha The alpha the arc will be filled with. You can also set the alpha of the overall Shape using its `alpha` property. */ - arc(x?: number, y?: number, radius?: number, startAngle?: integer, endAngle?: integer, anticlockwise?: boolean, fillColor?: number, fillAlpha?: number): Phaser.GameObjects.Arc; + arc(x?: number, y?: number, radius?: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean, fillColor?: number, fillAlpha?: number): Phaser.GameObjects.Arc; /** * Creates a new Circle Shape Game Object and adds it to the Scene. @@ -15913,10 +18199,10 @@ declare namespace Phaser { * Note: This method will only be available if the Sprite Game Object has been built into Phaser. * @param x The horizontal position of this Game Object in the world. * @param y The vertical position of this Game Object in the world. - * @param texture The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. + * @param texture The key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager. * @param frame An optional frame from the Texture this Game Object is rendering with. */ - sprite(x: number, y: number, texture: string, frame?: string | integer): Phaser.GameObjects.Sprite; + sprite(x: number, y: number, texture: string | Phaser.Textures.Texture, frame?: string | number): Phaser.GameObjects.Sprite; /** * Creates a new Text Game Object and adds it to the Scene. @@ -15950,7 +18236,7 @@ declare namespace Phaser { * @param text The text this Text object will display. * @param style The Text style configuration object. */ - text(x: number, y: number, text: string | string[], style?: object): Phaser.GameObjects.Text; + text(x: number, y: number, text: string | string[], style?: Phaser.Types.GameObjects.Text.TextStyle): Phaser.GameObjects.Text; /** * Creates a new TileSprite Game Object and adds it to the Scene. @@ -15960,21 +18246,20 @@ declare namespace Phaser { * @param y The vertical position of this Game Object in the world. * @param width The width of the Game Object. If zero it will use the size of the texture frame. * @param height The height of the Game Object. If zero it will use the size of the texture frame. - * @param texture The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. + * @param texture The key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager. * @param frame An optional frame from the Texture this Game Object is rendering with. */ - tileSprite(x: number, y: number, width: integer, height: integer, texture: string, frame?: string | integer): Phaser.GameObjects.TileSprite; + tileSprite(x: number, y: number, width: number, height: number, texture: string | Phaser.Textures.Texture, frame?: string | number): Phaser.GameObjects.TileSprite; /** - * Creates a new Image Game Object and adds it to the Scene. + * Creates a new Video Game Object and adds it to the Scene. * - * Note: This method will only be available if the Image Game Object has been built into Phaser. + * Note: This method will only be available if the Video Game Object has been built into Phaser. * @param x The horizontal position of this Game Object in the world. * @param y The vertical position of this Game Object in the world. - * @param texture The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. - * @param frame An optional frame from the Texture this Game Object is rendering with. + * @param key Optional key of the Video this Game Object will play, as stored in the Video Cache. */ - video(x: number, y: number, texture: string, frame?: string | integer): Phaser.GameObjects.Image; + video(x: number, y: number, key?: string): Phaser.GameObjects.Video; /** * Creates a new Zone Game Object and adds it to the Scene. @@ -16010,7 +18295,7 @@ declare namespace Phaser { * consumption. However if your map is small or you need to update the tiles dynamically, then leave * the default value set. Default false. */ - tilemap(key?: string, tileWidth?: integer, tileHeight?: integer, width?: integer, height?: integer, data?: integer[][], insertNull?: boolean): Phaser.Tilemaps.Tilemap; + tilemap(key?: string, tileWidth?: number, tileHeight?: number, width?: number, height?: number, data?: number[][], insertNull?: boolean): Phaser.Tilemaps.Tilemap; /** * Creates a new Tween object. @@ -16022,6 +18307,20 @@ declare namespace Phaser { } + /** + * Calculates the Transform Matrix of the given Game Object and Camera, factoring in + * the parent matrix if provided. + * + * Note that the object this results contains _references_ to the Transform Matrices, + * not new instances of them. Therefore, you should use their values immediately, or + * copy them to your own matrix, as they will be replaced as soon as another Game + * Object is rendered. + * @param src The Game Object to calculate the transform matrix for. + * @param camera The camera being used to render the Game Object. + * @param parentMatrix The transform matrix of the parent container, if any. + */ + function GetCalcMatrix(src: Phaser.GameObjects.GameObject, camera: Phaser.Cameras.Scene2D.Camera, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.Types.GameObjects.GetCalcMatrixResults; + /** * A Graphics object is a way to draw primitive shapes to your game. Primitives include forms of geometry, such as * Rectangles, Circles, and Polygons. They also include lines, arcs and curves. When you initially create a Graphics @@ -16114,7 +18413,7 @@ declare namespace Phaser { * Set the default style settings for this Graphics object. * @param options The styles to set as defaults. */ - setDefaultStyles(options: Phaser.Types.GameObjects.Graphics.Styles): Phaser.GameObjects.Graphics; + setDefaultStyles(options: Phaser.Types.GameObjects.Graphics.Styles): this; /** * Set the current line style. @@ -16122,14 +18421,14 @@ declare namespace Phaser { * @param color The stroke color. * @param alpha The stroke alpha. Default 1. */ - lineStyle(lineWidth: number, color: number, alpha?: number): Phaser.GameObjects.Graphics; + lineStyle(lineWidth: number, color: number, alpha?: number): this; /** * Set the current fill style. * @param color The fill color. * @param alpha The fill alpha. Default 1. */ - fillStyle(color: number, alpha?: number): Phaser.GameObjects.Graphics; + fillStyle(color: number, alpha?: number): this; /** * Sets a gradient fill style. This is a WebGL only feature. @@ -16145,13 +18444,16 @@ declare namespace Phaser { * Note that for objects such as arcs or ellipses, or anything which is made out of triangles, each triangle used * will be filled with a gradient on its own. There is no ability to gradient fill a shape or path as a single * entity at this time. - * @param topLeft The tint being applied to the top-left of the Game Object. - * @param topRight The tint being applied to the top-right of the Game Object. - * @param bottomLeft The tint being applied to the bottom-left of the Game Object. - * @param bottomRight The tint being applied to the bottom-right of the Game Object. - * @param alpha The fill alpha. Default 1. + * @param topLeft The top left fill color. + * @param topRight The top right fill color. + * @param bottomLeft The bottom left fill color. + * @param bottomRight The bottom right fill color. Not used when filling triangles. + * @param alphaTopLeft The top left alpha value. If you give only this value, it's used for all corners. Default 1. + * @param alphaTopRight The top right alpha value. Default 1. + * @param alphaBottomLeft The bottom left alpha value. Default 1. + * @param alphaBottomRight The bottom right alpha value. Default 1. */ - fillGradientStyle(topLeft: integer, topRight: integer, bottomLeft: integer, bottomRight: integer, alpha?: number): Phaser.GameObjects.Graphics; + fillGradientStyle(topLeft: number, topRight: number, bottomLeft: number, bottomRight: number, alphaTopLeft?: number, alphaTopRight?: number, alphaBottomLeft?: number, alphaBottomRight?: number): this; /** * Sets a gradient line style. This is a WebGL only feature. @@ -16172,41 +18474,22 @@ declare namespace Phaser { * @param bottomRight The tint being applied to the bottom-right of the Game Object. * @param alpha The fill alpha. Default 1. */ - lineGradientStyle(lineWidth: number, topLeft: integer, topRight: integer, bottomLeft: integer, bottomRight: integer, alpha?: number): Phaser.GameObjects.Graphics; - - /** - * Sets the texture frame this Graphics Object will use when drawing all shapes defined after calling this. - * - * Textures are referenced by their string-based keys, as stored in the Texture Manager. - * - * Once set, all shapes will use this texture. Call this method with no arguments to clear it. - * - * The textures are not tiled. They are stretched to the dimensions of the shapes being rendered. For this reason, - * it works best with seamless / tileable textures. - * - * The mode argument controls how the textures are combined with the fill colors. The default value (0) will - * multiply the texture by the fill color. A value of 1 will use just the fill color, but the alpha data from the texture, - * and a value of 2 will use just the texture and no fill color at all. - * @param key The key of the texture to be used, as stored in the Texture Manager. Leave blank to clear a previously set texture. - * @param frame The name or index of the frame within the Texture. - * @param mode The texture tint mode. 0 is multiply, 1 is alpha only and 2 is texture only. Default 0. - */ - setTexture(key?: string, frame?: string | integer, mode?: number): this; + lineGradientStyle(lineWidth: number, topLeft: number, topRight: number, bottomLeft: number, bottomRight: number, alpha?: number): this; /** * Start a new shape path. */ - beginPath(): Phaser.GameObjects.Graphics; + beginPath(): this; /** * Close the current path. */ - closePath(): Phaser.GameObjects.Graphics; + closePath(): this; /** * Fill the current path. */ - fillPath(): Phaser.GameObjects.Graphics; + fillPath(): this; /** * Fill the current path. @@ -16214,12 +18497,12 @@ declare namespace Phaser { * This is an alias for `Graphics.fillPath` and does the same thing. * It was added to match the CanvasRenderingContext 2D API. */ - fill(): Phaser.GameObjects.Graphics; + fill(): this; /** * Stroke the current path. */ - strokePath(): Phaser.GameObjects.Graphics; + strokePath(): this; /** * Stroke the current path. @@ -16227,19 +18510,19 @@ declare namespace Phaser { * This is an alias for `Graphics.strokePath` and does the same thing. * It was added to match the CanvasRenderingContext 2D API. */ - stroke(): Phaser.GameObjects.Graphics; + stroke(): this; /** * Fill the given circle. * @param circle The circle to fill. */ - fillCircleShape(circle: Phaser.Geom.Circle): Phaser.GameObjects.Graphics; + fillCircleShape(circle: Phaser.Geom.Circle): this; /** * Stroke the given circle. * @param circle The circle to stroke. */ - strokeCircleShape(circle: Phaser.Geom.Circle): Phaser.GameObjects.Graphics; + strokeCircleShape(circle: Phaser.Geom.Circle): this; /** * Fill a circle with the given position and radius. @@ -16247,7 +18530,7 @@ declare namespace Phaser { * @param y The y coordinate of the center of the circle. * @param radius The radius of the circle. */ - fillCircle(x: number, y: number, radius: number): Phaser.GameObjects.Graphics; + fillCircle(x: number, y: number, radius: number): this; /** * Stroke a circle with the given position and radius. @@ -16255,19 +18538,19 @@ declare namespace Phaser { * @param y The y coordinate of the center of the circle. * @param radius The radius of the circle. */ - strokeCircle(x: number, y: number, radius: number): Phaser.GameObjects.Graphics; + strokeCircle(x: number, y: number, radius: number): this; /** * Fill the given rectangle. * @param rect The rectangle to fill. */ - fillRectShape(rect: Phaser.Geom.Rectangle): Phaser.GameObjects.Graphics; + fillRectShape(rect: Phaser.Geom.Rectangle): this; /** * Stroke the given rectangle. * @param rect The rectangle to stroke. */ - strokeRectShape(rect: Phaser.Geom.Rectangle): Phaser.GameObjects.Graphics; + strokeRectShape(rect: Phaser.Geom.Rectangle): this; /** * Fill a rectangle with the given position and size. @@ -16276,7 +18559,7 @@ declare namespace Phaser { * @param width The width of the rectangle. * @param height The height of the rectangle. */ - fillRect(x: number, y: number, width: number, height: number): Phaser.GameObjects.Graphics; + fillRect(x: number, y: number, width: number, height: number): this; /** * Stroke a rectangle with the given position and size. @@ -16285,7 +18568,7 @@ declare namespace Phaser { * @param width The width of the rectangle. * @param height The height of the rectangle. */ - strokeRect(x: number, y: number, width: number, height: number): Phaser.GameObjects.Graphics; + strokeRect(x: number, y: number, width: number, height: number): this; /** * Fill a rounded rectangle with the given position, size and radius. @@ -16295,7 +18578,7 @@ declare namespace Phaser { * @param height The height of the rectangle. * @param radius The corner radius; It can also be an object to specify different radii for corners. Default 20. */ - fillRoundedRect(x: number, y: number, width: number, height: number, radius?: Phaser.Types.GameObjects.Graphics.RoundedRectRadius | number): Phaser.GameObjects.Graphics; + fillRoundedRect(x: number, y: number, width: number, height: number, radius?: Phaser.Types.GameObjects.Graphics.RoundedRectRadius | number): this; /** * Stroke a rounded rectangle with the given position, size and radius. @@ -16305,7 +18588,7 @@ declare namespace Phaser { * @param height The height of the rectangle. * @param radius The corner radius; It can also be an object to specify different radii for corners. Default 20. */ - strokeRoundedRect(x: number, y: number, width: number, height: number, radius?: Phaser.Types.GameObjects.Graphics.RoundedRectRadius | number): Phaser.GameObjects.Graphics; + strokeRoundedRect(x: number, y: number, width: number, height: number, radius?: Phaser.Types.GameObjects.Graphics.RoundedRectRadius | number): this; /** * Fill the given point. @@ -16314,7 +18597,7 @@ declare namespace Phaser { * @param point The point to fill. * @param size The size of the square to draw. Default 1. */ - fillPointShape(point: Phaser.Geom.Point | Phaser.Math.Vector2 | object, size?: number): Phaser.GameObjects.Graphics; + fillPointShape(point: Phaser.Geom.Point | Phaser.Math.Vector2 | object, size?: number): this; /** * Fill a point at the given position. @@ -16324,19 +18607,19 @@ declare namespace Phaser { * @param y The y coordinate of the point. * @param size The size of the square to draw. Default 1. */ - fillPoint(x: number, y: number, size?: number): Phaser.GameObjects.Graphics; + fillPoint(x: number, y: number, size?: number): this; /** * Fill the given triangle. * @param triangle The triangle to fill. */ - fillTriangleShape(triangle: Phaser.Geom.Triangle): Phaser.GameObjects.Graphics; + fillTriangleShape(triangle: Phaser.Geom.Triangle): this; /** * Stroke the given triangle. * @param triangle The triangle to stroke. */ - strokeTriangleShape(triangle: Phaser.Geom.Triangle): Phaser.GameObjects.Graphics; + strokeTriangleShape(triangle: Phaser.Geom.Triangle): this; /** * Fill a triangle with the given points. @@ -16347,7 +18630,7 @@ declare namespace Phaser { * @param x2 The x coordinate of the third point. * @param y2 The y coordinate of the third point. */ - fillTriangle(x0: number, y0: number, x1: number, y1: number, x2: number, y2: number): Phaser.GameObjects.Graphics; + fillTriangle(x0: number, y0: number, x1: number, y1: number, x2: number, y2: number): this; /** * Stroke a triangle with the given points. @@ -16358,13 +18641,13 @@ declare namespace Phaser { * @param x2 The x coordinate of the third point. * @param y2 The y coordinate of the third point. */ - strokeTriangle(x0: number, y0: number, x1: number, y1: number, x2: number, y2: number): Phaser.GameObjects.Graphics; + strokeTriangle(x0: number, y0: number, x1: number, y1: number, x2: number, y2: number): this; /** * Draw the given line. * @param line The line to stroke. */ - strokeLineShape(line: Phaser.Geom.Line): Phaser.GameObjects.Graphics; + strokeLineShape(line: Phaser.Geom.Line): this; /** * Draw a line between the given points. @@ -16373,7 +18656,7 @@ declare namespace Phaser { * @param x2 The x coordinate of the end point of the line. * @param y2 The y coordinate of the end point of the line. */ - lineBetween(x1: number, y1: number, x2: number, y2: number): Phaser.GameObjects.Graphics; + lineBetween(x1: number, y1: number, x2: number, y2: number): this; /** * Draw a line from the current drawing position to the given position. @@ -16382,14 +18665,14 @@ declare namespace Phaser { * @param x The x coordinate to draw the line to. * @param y The y coordinate to draw the line to. */ - lineTo(x: number, y: number): Phaser.GameObjects.Graphics; + lineTo(x: number, y: number): this; /** * Move the current drawing position to the given position. * @param x The x coordinate to move to. * @param y The y coordinate to move to. */ - moveTo(x: number, y: number): Phaser.GameObjects.Graphics; + moveTo(x: number, y: number): this; /** * Stroke the shape represented by the given array of points. @@ -16402,7 +18685,7 @@ declare namespace Phaser { * @param closePath When `true`, the path is closed before being stroked. Default false. * @param endIndex The index of `points` to stop drawing at. Defaults to `points.length`. */ - strokePoints(points: any[] | Phaser.Geom.Point[], closeShape?: boolean, closePath?: boolean, endIndex?: integer): Phaser.GameObjects.Graphics; + strokePoints(points: any[] | Phaser.Geom.Point[], closeShape?: boolean, closePath?: boolean, endIndex?: number): this; /** * Fill the shape represented by the given array of points. @@ -16415,14 +18698,14 @@ declare namespace Phaser { * @param closePath When `true`, the path is closed before being stroked. Default false. * @param endIndex The index of `points` to stop at. Defaults to `points.length`. */ - fillPoints(points: any[] | Phaser.Geom.Point[], closeShape?: boolean, closePath?: boolean, endIndex?: integer): Phaser.GameObjects.Graphics; + fillPoints(points: any[] | Phaser.Geom.Point[], closeShape?: boolean, closePath?: boolean, endIndex?: number): this; /** * Stroke the given ellipse. * @param ellipse The ellipse to stroke. * @param smoothness The number of points to draw the ellipse with. Default 32. */ - strokeEllipseShape(ellipse: Phaser.Geom.Ellipse, smoothness?: integer): Phaser.GameObjects.Graphics; + strokeEllipseShape(ellipse: Phaser.Geom.Ellipse, smoothness?: number): this; /** * Stroke an ellipse with the given position and size. @@ -16432,14 +18715,14 @@ declare namespace Phaser { * @param height The height of the ellipse. * @param smoothness The number of points to draw the ellipse with. Default 32. */ - strokeEllipse(x: number, y: number, width: number, height: number, smoothness?: integer): Phaser.GameObjects.Graphics; + strokeEllipse(x: number, y: number, width: number, height: number, smoothness?: number): this; /** * Fill the given ellipse. * @param ellipse The ellipse to fill. * @param smoothness The number of points to draw the ellipse with. Default 32. */ - fillEllipseShape(ellipse: Phaser.Geom.Ellipse, smoothness?: integer): Phaser.GameObjects.Graphics; + fillEllipseShape(ellipse: Phaser.Geom.Ellipse, smoothness?: number): this; /** * Fill an ellipse with the given position and size. @@ -16449,7 +18732,7 @@ declare namespace Phaser { * @param height The height of the ellipse. * @param smoothness The number of points to draw the ellipse with. Default 32. */ - fillEllipse(x: number, y: number, width: number, height: number, smoothness?: integer): Phaser.GameObjects.Graphics; + fillEllipse(x: number, y: number, width: number, height: number, smoothness?: number): this; /** * Draw an arc. @@ -16473,7 +18756,7 @@ declare namespace Phaser { * @param anticlockwise Whether the drawing should be anticlockwise or clockwise. Default false. * @param overshoot This value allows you to increase the segment iterations in WebGL rendering. Useful if the arc has a thick stroke and needs to overshoot to join-up cleanly. Use small numbers such as 0.01 to start with and increase as needed. Default 0. */ - arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean, overshoot?: number): Phaser.GameObjects.Graphics; + arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean, overshoot?: number): this; /** * Creates a pie-chart slice shape centered at `x`, `y` with the given radius. @@ -16492,14 +18775,14 @@ declare namespace Phaser { * @param anticlockwise Whether the drawing should be anticlockwise or clockwise. Default false. * @param overshoot This value allows you to overshoot the endAngle by this amount. Useful if the arc has a thick stroke and needs to overshoot to join-up cleanly. Default 0. */ - slice(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean, overshoot?: number): Phaser.GameObjects.Graphics; + slice(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean, overshoot?: number): this; /** * Saves the state of the Graphics by pushing the current state onto a stack. * * The most recently saved state can then be restored with {@link Phaser.GameObjects.Graphics#restore}. */ - save(): Phaser.GameObjects.Graphics; + save(): this; /** * Restores the most recently saved state of the Graphics by popping from the state stack. @@ -16508,7 +18791,7 @@ declare namespace Phaser { * * If there is no saved state, this command does nothing. */ - restore(): Phaser.GameObjects.Graphics; + restore(): this; /** * Inserts a translation command into this Graphics objects command buffer. @@ -16521,7 +18804,7 @@ declare namespace Phaser { * @param x The horizontal translation to apply. * @param y The vertical translation to apply. */ - translateCanvas(x: number, y: number): Phaser.GameObjects.Graphics; + translateCanvas(x: number, y: number): this; /** * Inserts a scale command into this Graphics objects command buffer. @@ -16534,7 +18817,7 @@ declare namespace Phaser { * @param x The horizontal scale to apply. * @param y The vertical scale to apply. */ - scaleCanvas(x: number, y: number): Phaser.GameObjects.Graphics; + scaleCanvas(x: number, y: number): this; /** * Inserts a rotation command into this Graphics objects command buffer. @@ -16546,12 +18829,12 @@ declare namespace Phaser { * only of the objects drawn by it after calling this method. * @param radians The rotation angle, in radians. */ - rotateCanvas(radians: number): Phaser.GameObjects.Graphics; + rotateCanvas(radians: number): this; /** * Clear the command buffer and reset the fill style and line style to their defaults. */ - clear(): Phaser.GameObjects.Graphics; + clear(): this; /** * Generate a texture from this Graphics object. @@ -16561,11 +18844,15 @@ declare namespace Phaser { * * If `key` is a Canvas it will draw the texture to that canvas context. Note that it will NOT * automatically upload it to the GPU in WebGL mode. + * + * Please understand that the texture is created via the Canvas API of the browser, therefore some + * Graphics features, such as `fillGradientStyle`, will not appear on the resulting texture, + * as they're unsupported by the Canvas API. * @param key The key to store the texture with in the Texture Manager, or a Canvas to draw to. * @param width The width of the graphics to generate. * @param height The height of the graphics to generate. */ - generateTexture(key: string | HTMLCanvasElement, width?: integer, height?: integer): Phaser.GameObjects.Graphics; + generateTexture(key: string | HTMLCanvasElement, width?: number, height?: number): this; /** * Internal destroy handler, called as part of the destroy process. @@ -16651,7 +18938,7 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. @@ -16664,13 +18951,13 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. * @param value The depth of this Game Object. */ - setDepth(value: integer): this; + setDepth(value: number): this; /** * The Mask this Game Object is using during render. @@ -16704,6 +18991,8 @@ declare namespace Phaser { * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, * including this one. * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * * To create the mask you need to pass in a reference to a renderable Game Object. * A renderable Game Object is one that uses a texture to render with, such as an * Image, Sprite, Render Texture or BitmapText. @@ -16731,6 +19020,8 @@ declare namespace Phaser { /** * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. */ defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; @@ -16739,23 +19030,109 @@ declare namespace Phaser { */ pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + /** + * Does this Game Object have any Post Pipelines set? + */ + hasPostPipeline: boolean; + + /** + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. + */ + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; + + /** + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. + */ + pipelineData: object; + /** * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + */ + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; + + /** + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; + + /** + * Sets one, or more, Post Pipelines on this Game Object. + * + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; + + /** + * Adds an entry to the `pipelineData` object belonging to this Game Object. + * + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. */ - initPipeline(pipelineName?: string): boolean; + setPipelineData(key: string, value?: any): this; /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - setPipeline(pipelineName: string): this; + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; /** * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. */ - resetPipeline(): boolean; + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; + + /** + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPostPipeline(resetData?: boolean): void; + + /** + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. + */ + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; /** * Gets the name of the WebGL Pipeline this Game Object is currently using. @@ -16812,13 +19189,13 @@ declare namespace Phaser { * * If you prefer to work in radians, see the `rotation` property instead. */ - angle: integer; + angle: number; /** * The angle of this Game Object in radians. * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. * * If you prefer to work in degrees, see the `angle` property instead. */ @@ -16833,6 +19210,12 @@ declare namespace Phaser { */ setPosition(x?: number, y?: number, z?: number, w?: number): this; + /** + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; + /** * Sets the position of this Game Object to be a random position within the confines of * the given area. @@ -16907,6 +19290,22 @@ declare namespace Phaser { */ getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. + */ + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + /** * Gets the sum total rotation of all of this Game Objects parent Containers. * @@ -16997,7 +19396,7 @@ declare namespace Phaser { * * Groups themselves aren't displayable, and can't be positioned, rotated, scaled, or hidden. */ - class Group { + class Group extends Phaser.Events.EventEmitter { /** * * @param scene The scene this group belongs to. @@ -17039,15 +19438,14 @@ declare namespace Phaser { name: string; /** - * Whether this group runs its {@link Phaser.GameObjects.Group#preUpdate} method - * (which may update any members). + * Whether this group runs its {@link Phaser.GameObjects.Group#preUpdate} method (which may update any members). */ active: boolean; /** * The maximum size of this group, if used as a pool. -1 is no limit. */ - maxSize: integer; + maxSize: number; /** * A default texture key to use when creating new group members. @@ -17060,7 +19458,7 @@ declare namespace Phaser { /** * A default texture frame to use when creating new group members. */ - defaultFrame: string | integer; + defaultFrame: string | number; /** * Whether to call the update method of any members. @@ -17093,7 +19491,7 @@ declare namespace Phaser { * @param visible The {@link Phaser.GameObjects.Components.Visible#visible} state of the new Game Object. Default true. * @param active The {@link Phaser.GameObjects.GameObject#active} state of the new Game Object. Default true. */ - create(x?: number, y?: number, key?: string, frame?: string | integer, visible?: boolean, active?: boolean): any; + create(x?: number, y?: number, key?: string, frame?: string | number, visible?: boolean, active?: boolean): any; /** * Creates several Game Objects and adds them to this group. @@ -17125,7 +19523,7 @@ declare namespace Phaser { * @param child The Game Object to add. * @param addToScene Also add the Game Object to the scene. Default false. */ - add(child: Phaser.GameObjects.GameObject, addToScene?: boolean): Phaser.GameObjects.Group; + add(child: Phaser.GameObjects.GameObject, addToScene?: boolean): this; /** * Adds several Game Objects to this group. @@ -17134,7 +19532,7 @@ declare namespace Phaser { * @param children The Game Objects to add. * @param addToScene Also add the Game Objects to the scene. Default false. */ - addMultiple(children: Phaser.GameObjects.GameObject[], addToScene?: boolean): Phaser.GameObjects.Group; + addMultiple(children: Phaser.GameObjects.GameObject[], addToScene?: boolean): this; /** * Removes a member of this Group and optionally removes it from the Scene and / or destroys it. @@ -17144,7 +19542,7 @@ declare namespace Phaser { * @param removeFromScene Optionally remove the Group member from the Scene it belongs to. Default false. * @param destroyChild Optionally call destroy on the removed Group member. Default false. */ - remove(child: Phaser.GameObjects.GameObject, removeFromScene?: boolean, destroyChild?: boolean): Phaser.GameObjects.Group; + remove(child: Phaser.GameObjects.GameObject, removeFromScene?: boolean, destroyChild?: boolean): this; /** * Removes all members of this Group and optionally removes them from the Scene and / or destroys them. @@ -17153,7 +19551,7 @@ declare namespace Phaser { * @param removeFromScene Optionally remove each Group member from the Scene. Default false. * @param destroyChild Optionally call destroy on the removed Group members. Default false. */ - clear(removeFromScene?: boolean, destroyChild?: boolean): Phaser.GameObjects.Group; + clear(removeFromScene?: boolean, destroyChild?: boolean): this; /** * Tests if a Game Object is a member of this group. @@ -17169,7 +19567,22 @@ declare namespace Phaser { /** * The number of members of the group. */ - getLength(): integer; + getLength(): number; + + /** + * Returns all children in this Group that match the given criteria based on the `property` and `value` arguments. + * + * For example: `getAll('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. + * @param property The property to test on each array element. + * @param value The value to test the property against. Must pass a strict (`===`) comparison check. + * @param startIndex An optional start index to search from. + * @param endIndex An optional end index to search to. + */ + getMatching(property?: string, value?: any, startIndex?: number, endIndex?: number): any[]; /** * Scans the Group, from top to bottom, for the first member that has an {@link Phaser.GameObjects.GameObject#active} state matching the argument, @@ -17185,7 +19598,7 @@ declare namespace Phaser { * @param frame A texture frame assigned to a new Game Object (if one is created). Default defaultFrame. * @param visible The {@link Phaser.GameObjects.Components.Visible#visible} state of a new Game Object (if one is created). Default true. */ - getFirst(state?: boolean, createIfNull?: boolean, x?: number, y?: number, key?: string, frame?: string | integer, visible?: boolean): any; + getFirst(state?: boolean, createIfNull?: boolean, x?: number, y?: number, key?: string, frame?: string | number, visible?: boolean): any; /** * Scans the Group, from top to bottom, for the nth member that has an {@link Phaser.GameObjects.GameObject#active} state matching the argument, @@ -17202,7 +19615,7 @@ declare namespace Phaser { * @param frame A texture frame assigned to a new Game Object (if one is created). Default defaultFrame. * @param visible The {@link Phaser.GameObjects.Components.Visible#visible} state of a new Game Object (if one is created). Default true. */ - getFirstNth(nth: integer, state?: boolean, createIfNull?: boolean, x?: number, y?: number, key?: string, frame?: string | integer, visible?: boolean): any; + getFirstNth(nth: number, state?: boolean, createIfNull?: boolean, x?: number, y?: number, key?: string, frame?: string | number, visible?: boolean): any; /** * Scans the Group for the last member that has an {@link Phaser.GameObjects.GameObject#active} state matching the argument, @@ -17218,7 +19631,7 @@ declare namespace Phaser { * @param frame A texture frame assigned to a new Game Object (if one is created). Default defaultFrame. * @param visible The {@link Phaser.GameObjects.Components.Visible#visible} state of a new Game Object (if one is created). Default true. */ - getLast(state?: boolean, createIfNull?: boolean, x?: number, y?: number, key?: string, frame?: string | integer, visible?: boolean): any; + getLast(state?: boolean, createIfNull?: boolean, x?: number, y?: number, key?: string, frame?: string | number, visible?: boolean): any; /** * Scans the Group for the last nth member that has an {@link Phaser.GameObjects.GameObject#active} state matching the argument, @@ -17235,7 +19648,7 @@ declare namespace Phaser { * @param frame A texture frame assigned to a new Game Object (if one is created). Default defaultFrame. * @param visible The {@link Phaser.GameObjects.Components.Visible#visible} state of a new Game Object (if one is created). Default true. */ - getLastNth(nth: integer, state?: boolean, createIfNull?: boolean, x?: number, y?: number, key?: string, frame?: string | integer, visible?: boolean): any; + getLastNth(nth: number, state?: boolean, createIfNull?: boolean, x?: number, y?: number, key?: string, frame?: string | number, visible?: boolean): any; /** * Scans the group for the first member that has an {@link Phaser.GameObjects.GameObject#active} state set to `false`, @@ -17250,7 +19663,7 @@ declare namespace Phaser { * @param frame A texture frame assigned to a new Game Object (if one is created). Default defaultFrame. * @param visible The {@link Phaser.GameObjects.Components.Visible#visible} state of a new Game Object (if one is created). Default true. */ - get(x?: number, y?: number, key?: string, frame?: string | integer, visible?: boolean): any; + get(x?: number, y?: number, key?: string, frame?: string | number, visible?: boolean): any; /** * Scans the group for the first member that has an {@link Phaser.GameObjects.GameObject#active} state set to `true`, @@ -17265,7 +19678,7 @@ declare namespace Phaser { * @param frame A texture frame assigned to a new Game Object (if one is created). Default defaultFrame. * @param visible The {@link Phaser.GameObjects.Components.Visible#visible} state of a new Game Object (if one is created). Default true. */ - getFirstAlive(createIfNull?: boolean, x?: number, y?: number, key?: string, frame?: string | integer, visible?: boolean): any; + getFirstAlive(createIfNull?: boolean, x?: number, y?: number, key?: string, frame?: string | number, visible?: boolean): any; /** * Scans the group for the first member that has an {@link Phaser.GameObjects.GameObject#active} state set to `false`, @@ -17281,14 +19694,14 @@ declare namespace Phaser { * @param frame A texture frame assigned to a new Game Object (if one is created). Default defaultFrame. * @param visible The {@link Phaser.GameObjects.Components.Visible#visible} state of a new Game Object (if one is created). Default true. */ - getFirstDead(createIfNull?: boolean, x?: number, y?: number, key?: string, frame?: string | integer, visible?: boolean): any; + getFirstDead(createIfNull?: boolean, x?: number, y?: number, key?: string, frame?: string | number, visible?: boolean): any; /** * {@link Phaser.GameObjects.Components.Animation#play Plays} an animation for all members of this group. * @param key The string-based key of the animation to play. * @param startFrame Optionally start the animation playing from this frame index. Default 0. */ - playAnimation(key: string, startFrame?: string): Phaser.GameObjects.Group; + playAnimation(key: string, startFrame?: string): this; /** * Whether this group's size at its {@link Phaser.GameObjects.Group#maxSize maximum}. @@ -17299,19 +19712,33 @@ declare namespace Phaser { * Counts the number of active (or inactive) group members. * @param value Count active (true) or inactive (false) group members. Default true. */ - countActive(value?: boolean): integer; + countActive(value?: boolean): number; /** * Counts the number of in-use (active) group members. */ - getTotalUsed(): integer; + getTotalUsed(): number; /** * The difference of {@link Phaser.GameObjects.Group#maxSize} and the number of active group members. * * This represents the number of group members that could be created or reactivated before reaching the size limit. */ - getTotalFree(): integer; + getTotalFree(): number; + + /** + * Sets the `active` property of this Group. + * When active, this Group runs its `preUpdate` method. + * @param value True if this Group should be set as active, false if not. + */ + setActive(value: boolean): this; + + /** + * Sets the `name` property of this Group. + * The `name` property is not populated by Phaser and is presented for your own use. + * @param value The name to be given to this Group. + */ + setName(value: string): this; /** * Sets the property as defined in `key` of each group member to the given value. @@ -17321,7 +19748,7 @@ declare namespace Phaser { * @param index An optional offset to start searching from within the items array. Default 0. * @param direction The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1. */ - propertyValueSet(key: string, value: number, step?: number, index?: integer, direction?: integer): Phaser.GameObjects.Group; + propertyValueSet(key: string, value: number, step?: number, index?: number, direction?: number): this; /** * Adds the given value to the property as defined in `key` of each group member. @@ -17331,21 +19758,21 @@ declare namespace Phaser { * @param index An optional offset to start searching from within the items array. Default 0. * @param direction The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1. */ - propertyValueInc(key: string, value: number, step?: number, index?: integer, direction?: integer): Phaser.GameObjects.Group; + propertyValueInc(key: string, value: number, step?: number, index?: number, direction?: number): this; /** * Sets the x of each group member. * @param value The amount to set the property to. * @param step This is added to the `value` amount, multiplied by the iteration counter. Default 0. */ - setX(value: number, step?: number): Phaser.GameObjects.Group; + setX(value: number, step?: number): this; /** * Sets the y of each group member. * @param value The amount to set the property to. * @param step This is added to the `value` amount, multiplied by the iteration counter. Default 0. */ - setY(value: number, step?: number): Phaser.GameObjects.Group; + setY(value: number, step?: number): this; /** * Sets the x, y of each group member. @@ -17354,21 +19781,21 @@ declare namespace Phaser { * @param stepX This is added to the `x` amount, multiplied by the iteration counter. Default 0. * @param stepY This is added to the `y` amount, multiplied by the iteration counter. Default 0. */ - setXY(x: number, y?: number, stepX?: number, stepY?: number): Phaser.GameObjects.Group; + setXY(x: number, y?: number, stepX?: number, stepY?: number): this; /** * Adds the given value to the x of each group member. * @param value The amount to be added to the `x` property. * @param step This is added to the `value` amount, multiplied by the iteration counter. Default 0. */ - incX(value: number, step?: number): Phaser.GameObjects.Group; + incX(value: number, step?: number): this; /** * Adds the given value to the y of each group member. * @param value The amount to be added to the `y` property. * @param step This is added to the `value` amount, multiplied by the iteration counter. Default 0. */ - incY(value: number, step?: number): Phaser.GameObjects.Group; + incY(value: number, step?: number): this; /** * Adds the given value to the x, y of each group member. @@ -17377,7 +19804,7 @@ declare namespace Phaser { * @param stepX This is added to the `x` amount, multiplied by the iteration counter. Default 0. * @param stepY This is added to the `y` amount, multiplied by the iteration counter. Default 0. */ - incXY(x: number, y?: number, stepX?: number, stepY?: number): Phaser.GameObjects.Group; + incXY(x: number, y?: number, stepX?: number, stepY?: number): this; /** * Iterate through the group members changing the position of each element to be that of the element that came before @@ -17388,28 +19815,28 @@ declare namespace Phaser { * @param y The y coordinate to place the first item in the array at. * @param direction The iteration direction. 0 = first to last and 1 = last to first. Default 0. */ - shiftPosition(x: number, y: number, direction?: integer): Phaser.GameObjects.Group; + shiftPosition(x: number, y: number, direction?: number): this; /** * Sets the angle of each group member. * @param value The amount to set the angle to, in degrees. * @param step This is added to the `value` amount, multiplied by the iteration counter. Default 0. */ - angle(value: number, step?: number): Phaser.GameObjects.Group; + angle(value: number, step?: number): this; /** * Sets the rotation of each group member. * @param value The amount to set the rotation to, in radians. * @param step This is added to the `value` amount, multiplied by the iteration counter. Default 0. */ - rotate(value: number, step?: number): Phaser.GameObjects.Group; + rotate(value: number, step?: number): this; /** * Rotates each group member around the given point by the given angle. * @param point Any object with public `x` and `y` properties. * @param angle The angle to rotate by, in radians. */ - rotateAround(point: Phaser.Types.Math.Vector2Like, angle: number): Phaser.GameObjects.Group; + rotateAround(point: Phaser.Types.Math.Vector2Like, angle: number): this; /** * Rotates each group member around the given point by the given angle and distance. @@ -17417,14 +19844,14 @@ declare namespace Phaser { * @param angle The angle to rotate by, in radians. * @param distance The distance from the point of rotation in pixels. */ - rotateAroundDistance(point: Phaser.Types.Math.Vector2Like, angle: number, distance: number): Phaser.GameObjects.Group; + rotateAroundDistance(point: Phaser.Types.Math.Vector2Like, angle: number, distance: number): this; /** * Sets the alpha of each group member. * @param value The amount to set the alpha to. * @param step This is added to the `value` amount, multiplied by the iteration counter. Default 0. */ - setAlpha(value: number, step?: number): Phaser.GameObjects.Group; + setAlpha(value: number, step?: number): this; /** * Sets the tint of each group member. @@ -17433,7 +19860,7 @@ declare namespace Phaser { * @param bottomLeft The tint to be applied to the bottom-left corner of item. * @param bottomRight The tint to be applied to the bottom-right corner of item. */ - setTint(topLeft: number, topRight?: number, bottomLeft?: number, bottomRight?: number): Phaser.GameObjects.Group; + setTint(topLeft: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; /** * Sets the originX, originY of each group member. @@ -17442,21 +19869,21 @@ declare namespace Phaser { * @param stepX This is added to the `originX` amount, multiplied by the iteration counter. Default 0. * @param stepY This is added to the `originY` amount, multiplied by the iteration counter. Default 0. */ - setOrigin(originX: number, originY?: number, stepX?: number, stepY?: number): Phaser.GameObjects.Group; + setOrigin(originX: number, originY?: number, stepX?: number, stepY?: number): this; /** * Sets the scaleX of each group member. * @param value The amount to set the property to. * @param step This is added to the `value` amount, multiplied by the iteration counter. Default 0. */ - scaleX(value: number, step?: number): Phaser.GameObjects.Group; + scaleX(value: number, step?: number): this; /** * Sets the scaleY of each group member. * @param value The amount to set the property to. * @param step This is added to the `value` amount, multiplied by the iteration counter. Default 0. */ - scaleY(value: number, step?: number): Phaser.GameObjects.Group; + scaleY(value: number, step?: number): this; /** * Sets the scaleX, scaleY of each group member. @@ -17465,32 +19892,32 @@ declare namespace Phaser { * @param stepX This is added to the `scaleX` amount, multiplied by the iteration counter. Default 0. * @param stepY This is added to the `scaleY` amount, multiplied by the iteration counter. Default 0. */ - scaleXY(scaleX: number, scaleY?: number, stepX?: number, stepY?: number): Phaser.GameObjects.Group; + scaleXY(scaleX: number, scaleY?: number, stepX?: number, stepY?: number): this; /** * Sets the depth of each group member. * @param value The amount to set the property to. * @param step This is added to the `value` amount, multiplied by the iteration counter. Default 0. */ - setDepth(value: number, step?: number): Phaser.GameObjects.Group; + setDepth(value: number, step?: number): this; /** * Sets the blendMode of each group member. * @param value The amount to set the property to. */ - setBlendMode(value: number): Phaser.GameObjects.Group; + setBlendMode(value: number): this; /** * Passes all group members to the Input Manager to enable them for input with identical areas and callbacks. * @param hitArea 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. * @param hitAreaCallback A callback to be invoked when the Game Object is interacted with. If you provide a shape you must also provide a callback. */ - setHitArea(hitArea: any, hitAreaCallback: Phaser.Types.Input.HitAreaCallback): Phaser.GameObjects.Group; + setHitArea(hitArea: any, hitAreaCallback: Phaser.Types.Input.HitAreaCallback): this; /** * Shuffles the group members in place. */ - shuffle(): Phaser.GameObjects.Group; + shuffle(): this; /** * Deactivates a member of this group. @@ -17510,12 +19937,12 @@ declare namespace Phaser { * @param index An optional offset to start searching from within the items array. Default 0. * @param direction The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1. */ - setVisible(value: boolean, index?: integer, direction?: integer): Phaser.GameObjects.Group; + setVisible(value: boolean, index?: number, direction?: number): this; /** * Toggles (flips) the visible state of each member of this group. */ - toggleVisible(): Phaser.GameObjects.Group; + toggleVisible(): this; /** * Empties this group and removes it from the Scene. @@ -17541,10 +19968,10 @@ declare namespace Phaser { * @param scene The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. * @param x The horizontal position of this Game Object in the world. * @param y The vertical position of this Game Object in the world. - * @param texture The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. + * @param texture The key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager. * @param frame An optional frame from the Texture this Game Object is rendering with. */ - constructor(scene: Phaser.Scene, x: number, y: number, texture: string, frame?: string | integer); + constructor(scene: Phaser.Scene, x: number, y: number, texture: string | Phaser.Textures.Texture, frame?: string | number); /** * Clears all alpha values associated with this Game Object. @@ -17650,7 +20077,7 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. @@ -17663,13 +20090,13 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. * @param value The depth of this Game Object. */ - setDepth(value: integer): this; + setDepth(value: number): this; /** * The horizontally flipped state of the Game Object. @@ -17845,6 +20272,8 @@ declare namespace Phaser { * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, * including this one. * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * * To create the mask you need to pass in a reference to a renderable Game Object. * A renderable Game Object is one that uses a texture to render with, such as an * Image, Sprite, Render Texture or BitmapText. @@ -17930,6 +20359,8 @@ declare namespace Phaser { /** * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. */ defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; @@ -17938,23 +20369,109 @@ declare namespace Phaser { */ pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + /** + * Does this Game Object have any Post Pipelines set? + */ + hasPostPipeline: boolean; + + /** + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. + */ + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; + + /** + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. + */ + pipelineData: object; + /** * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + */ + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; + + /** + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; + + /** + * Sets one, or more, Post Pipelines on this Game Object. + * + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; + + /** + * Adds an entry to the `pipelineData` object belonging to this Game Object. + * + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. */ - initPipeline(pipelineName?: string): boolean; + setPipelineData(key: string, value?: any): this; /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - setPipeline(pipelineName: string): this; + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; /** * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. */ - resetPipeline(): boolean; + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; + + /** + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPostPipeline(resetData?: boolean): void; + + /** + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. + */ + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; /** * Gets the name of the WebGL Pipeline this Game Object is currently using. @@ -18147,7 +20664,7 @@ declare namespace Phaser { * @param key The key of the texture to be used, as stored in the Texture Manager. * @param frame The name or index of the frame within the Texture. */ - setTexture(key: string, frame?: string | integer): this; + setTexture(key: string, frame?: string | number): this; /** * Sets the frame this Game Object will use to render with. @@ -18162,10 +20679,41 @@ declare namespace Phaser { * @param updateSize Should this call adjust the size of the Game Object? Default true. * @param updateOrigin Should this call adjust the origin of the Game Object? Default true. */ - setFrame(frame: string | integer, updateSize?: boolean, updateOrigin?: boolean): this; + setFrame(frame: string | number, updateSize?: boolean, updateOrigin?: boolean): this; + + /** + * The tint value being applied to the top-left vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintTopLeft: number; + + /** + * The tint value being applied to the top-right vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintTopRight: number; + + /** + * The tint value being applied to the bottom-left vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintBottomLeft: number; + + /** + * The tint value being applied to the bottom-right vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintBottomRight: number; /** - * Fill or additive? + * The tint fill mode. + * + * `false` = An additive tint (the default), where vertices colors are blended with the texture. + * `true` = A fill tint, where the vertices colors replace the texture, but respects texture alpha. */ tintFill: boolean; @@ -18197,7 +20745,7 @@ declare namespace Phaser { * @param bottomLeft The tint being applied to the bottom-left of the Game Object. * @param bottomRight The tint being applied to the bottom-right of the Game Object. */ - setTint(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; + setTint(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; /** * Sets a fill-based tint on this Game Object. @@ -18220,40 +20768,19 @@ declare namespace Phaser { * @param bottomLeft The tint being applied to the bottom-left of the Game Object. * @param bottomRight The tint being applied to the bottom-right of the Game Object. */ - setTintFill(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; - - /** - * The tint value being applied to the top-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintTopLeft: integer; - - /** - * The tint value being applied to the top-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintTopRight: integer; - - /** - * The tint value being applied to the bottom-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintBottomLeft: integer; - - /** - * The tint value being applied to the bottom-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintBottomRight: integer; + setTintFill(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; /** * The tint value being applied to the whole of the Game Object. * This property is a setter-only. Use the properties `tintTopLeft` etc to read the current tint value. */ - tint: integer; + tint: number; /** - * Does this Game Object have a tint applied to it or not? + * Does this Game Object have a tint applied? + * + * It checks to see if the 4 tint properties are set to the value 0xffffff + * and that the `tintFill` property is `false`. This indicates that a Game Object isn't tinted. */ readonly isTinted: boolean; @@ -18307,13 +20834,13 @@ declare namespace Phaser { * * If you prefer to work in radians, see the `rotation` property instead. */ - angle: integer; + angle: number; /** * The angle of this Game Object in radians. * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. * * If you prefer to work in degrees, see the `angle` property instead. */ @@ -18328,6 +20855,12 @@ declare namespace Phaser { */ setPosition(x?: number, y?: number, z?: number, w?: number): this; + /** + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; + /** * Sets the position of this Game Object to be a random position within the confines of * the given area. @@ -18402,6 +20935,22 @@ declare namespace Phaser { */ getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. + */ + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + /** * Gets the sum total rotation of all of this Game Objects parent Containers. * @@ -18427,335 +20976,373 @@ declare namespace Phaser { } /** - * A 2D point light. + * A Layer Game Object. * - * These are typically created by a {@link Phaser.GameObjects.LightsManager}, available from within a scene via `this.lights`. + * A Layer is a special type of Game Object that acts as a Display List. You can add any type of Game Object + * to a Layer, just as you would to a Scene. Layers can be used to visually group together 'layers' of Game + * Objects: + * + * ```javascript + * const spaceman = this.add.sprite(150, 300, 'spaceman'); + * const bunny = this.add.sprite(400, 300, 'bunny'); + * const elephant = this.add.sprite(650, 300, 'elephant'); * - * Any Game Objects using the Light2D pipeline will then be affected by these Lights. + * const layer = this.add.layer(); * - * They can also simply be used to represent a point light for your own purposes. + * layer.add([ spaceman, bunny, elephant ]); + * ``` + * + * The 3 sprites in the example above will now be managed by the Layer they were added to. Therefore, + * if you then set `layer.setVisible(false)` they would all vanish from the display. + * + * You can also control the depth of the Game Objects within the Layer. For example, calling the + * `setDepth` method of a child of a Layer will allow you to adjust the depth of that child _within the + * Layer itself_, rather than the whole Scene. The Layer, too, can have its depth set as well. + * + * The Layer class also offers many different methods for manipulating the list, such as the + * methods `moveUp`, `moveDown`, `sendToBack`, `bringToTop` and so on. These allow you to change the + * display list position of the Layers children, causing it to adjust the order in which they are + * rendered. Using `setDepth` on a child allows you to override this. + * + * Layers can have Post FX Pipelines set, which allows you to easily enable a post pipeline across + * a whole range of children, which, depending on the effect, can often be far more efficient that doing so + * on a per-child basis. + * + * Layers have no position or size within the Scene. This means you cannot enable a Layer for + * physics or input, or change the position, rotation or scale of a Layer. They also have no scroll + * factor, texture, tint, origin, crop or bounds. + * + * If you need those kind of features then you should use a Container instead. Containers can be added + * to Layers, but Layers cannot be added to Containers. + * + * However, you can set the Alpha, Blend Mode, Depth, Mask and Visible state of a Layer. These settings + * will impact all children being rendered by the Layer. */ - class Light { + class Layer extends Phaser.Structs.List implements Phaser.GameObjects.Components.AlphaSingle, Phaser.GameObjects.Components.BlendMode, Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.Mask, Phaser.GameObjects.Components.Pipeline, Phaser.GameObjects.Components.Visible { /** * - * @param x The horizontal position of the light. - * @param y The vertical position of the light. - * @param radius The radius of the light. - * @param r The red color of the light. A value between 0 and 1. - * @param g The green color of the light. A value between 0 and 1. - * @param b The blue color of the light. A value between 0 and 1. - * @param intensity The intensity of the light. + * @param scene The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. + * @param children An optional array of Game Objects to add to this Layer. */ - constructor(x: number, y: number, radius: number, r: number, g: number, b: number, intensity: number); + constructor(scene: Phaser.Scene, children?: Phaser.GameObjects.GameObject[]); /** - * The horizontal position of the light. + * A reference to the Scene to which this Game Object belongs. + * + * Game Objects can only belong to one Scene. + * + * You should consider this property as being read-only. You cannot move a + * Game Object to another Scene by simply changing it. */ - x: number; + scene: Phaser.Scene; /** - * The vertical position of the light. + * Holds a reference to the Display List that contains this Game Object. + * + * This is set automatically when this Game Object is added to a Scene or Layer. + * + * You should treat this property as being read-only. */ - y: number; + displayList: Phaser.GameObjects.DisplayList | Phaser.GameObjects.Layer; /** - * The radius of the light. + * A textual representation of this Game Object, i.e. `sprite`. + * Used internally by Phaser but is available for your own custom classes to populate. */ - radius: number; + type: string; /** - * The red color of the light. A value between 0 and 1. + * The current state of this Game Object. + * + * Phaser itself will never modify this value, although plugins may do so. + * + * Use this property to track the state of a Game Object during its lifetime. For example, it could change from + * a state of 'moving', to 'attacking', to 'dead'. The state value should be an integer (ideally mapped to a constant + * in your game code), or a string. These are recommended to keep it light and simple, with fast comparisons. + * If you need to store complex data about your Game Object, look at using the Data Component instead. */ - r: number; + state: number | string; /** - * The green color of the light. A value between 0 and 1. + * The name of this Game Object. + * Empty by default and never populated by Phaser, this is left for developers to use. */ - g: number; + name: string; /** - * The blue color of the light. A value between 0 and 1. + * The active state of this Game Object. + * A Game Object with an active state of `true` is processed by the Scenes UpdateList, if added to it. + * An active object is one which is having its logic and internal systems updated. */ - b: number; + active: boolean; /** - * The intensity of the light. + * A Data Manager. + * It allows you to store, query and get key/value paired information specific to this Game Object. + * `null` by default. Automatically created if you use `getData` or `setData` or `setDataEnabled`. */ - intensity: number; + data: Phaser.Data.DataManager; /** - * The horizontal scroll factor of the light. + * The flags that are compared against `RENDER_MASK` to determine if this Game Object will render or not. + * The bits are 0001 | 0010 | 0100 | 1000 set by the components Visible, Alpha, Transform and Texture respectively. + * If those components are not used by your custom class then you can use this bitmask as you wish. */ - scrollFactorX: number; + renderFlags: number; /** - * The vertical scroll factor of the light. + * A bitmask that controls if this Game Object is drawn by a Camera or not. + * Not usually set directly, instead call `Camera.ignore`, however you can + * set this property directly using the Camera.id property: */ - scrollFactorY: number; + cameraFilter: number; /** - * Set the properties of the light. - * - * Sets both horizontal and vertical scroll factor to 1. Use {@link Phaser.GameObjects.Light#setScrollFactor} to set - * the scroll factor. - * @param x The horizontal position of the light. - * @param y The vertical position of the light. - * @param radius The radius of the light. - * @param r The red color. A value between 0 and 1. - * @param g The green color. A value between 0 and 1. - * @param b The blue color. A value between 0 and 1. - * @param intensity The intensity of the light. + * This Game Object will ignore all calls made to its destroy method if this flag is set to `true`. + * This includes calls that may come from a Group, Container or the Scene itself. + * While it allows you to persist a Game Object across Scenes, please understand you are entirely + * responsible for managing references to and from this Game Object. */ - set(x: number, y: number, radius: number, r: number, g: number, b: number, intensity: number): Phaser.GameObjects.Light; + ignoreDestroy: boolean; /** - * Set the scroll factor of the light. - * @param x The horizontal scroll factor of the light. - * @param y The vertical scroll factor of the light. + * A reference to the Scene Systems. */ - setScrollFactor(x: number, y: number): Phaser.GameObjects.Light; + systems: Phaser.Scenes.Systems; /** - * Set the color of the light from a single integer RGB value. - * @param rgb The integer RGB color of the light. + * A reference to the Scene Event Emitter. */ - setColor(rgb: number): Phaser.GameObjects.Light; + events: Phaser.Events.EventEmitter; /** - * Set the intensity of the light. - * @param intensity The intensity of the light. + * The flag the determines whether Game Objects should be sorted when `depthSort()` is called. */ - setIntensity(intensity: number): Phaser.GameObjects.Light; + sortChildrenFlag: boolean; /** - * Set the position of the light. - * @param x The horizontal position of the light. - * @param y The vertical position of the light. + * Sets the `active` property of this Game Object and returns this Game Object for further chaining. + * A Game Object with its `active` property set to `true` will be updated by the Scenes UpdateList. + * @param value True if this Game Object should be set as active, false if not. */ - setPosition(x: number, y: number): Phaser.GameObjects.Light; + setActive(value: boolean): this; /** - * Set the radius of the light. - * @param radius The radius of the light. + * Sets the `name` property of this Game Object and returns this Game Object for further chaining. + * The `name` property is not populated by Phaser and is presented for your own use. + * @param value The name to be given to this Game Object. */ - setRadius(radius: number): Phaser.GameObjects.Light; - - } + setName(value: string): this; - /** - * Manages Lights for a Scene. - * - * Affects the rendering of Game Objects using the `Light2D` pipeline. - */ - class LightsManager { /** - * The pool of Lights. + * Sets the current state of this Game Object. * - * Used to recycle removed Lights for a more efficient use of memory. + * Phaser itself will never modify the State of a Game Object, although plugins may do so. + * + * For example, a Game Object could change from a state of 'moving', to 'attacking', to 'dead'. + * The state value should typically be an integer (ideally mapped to a constant + * in your game code), but could also be a string. It is recommended to keep it light and simple. + * If you need to store complex data about your Game Object, look at using the Data Component instead. + * @param value The state of the Game Object. */ - lightPool: Phaser.GameObjects.Light[]; + setState(value: number | string): this; /** - * The Lights in the Scene. + * Adds a Data Manager component to this Game Object. */ - lights: Phaser.GameObjects.Light[]; + setDataEnabled(): this; /** - * Lights that have been culled from a Camera's viewport. + * Allows you to store a key value pair within this Game Objects Data Manager. + * + * If the Game Object has not been enabled for data (via `setDataEnabled`) then it will be enabled + * before setting the value. + * + * If the key doesn't already exist in the Data Manager then it is created. + * + * ```javascript + * sprite.setData('name', 'Red Gem Stone'); + * ``` + * + * You can also pass in an object of key value pairs as the first argument: + * + * ```javascript + * sprite.setData({ name: 'Red Gem Stone', level: 2, owner: 'Link', gold: 50 }); + * ``` + * + * To get a value back again you can call `getData`: + * + * ```javascript + * sprite.getData('gold'); + * ``` + * + * Or you can access the value directly via the `values` property, where it works like any other variable: + * + * ```javascript + * sprite.data.values.gold += 50; + * ``` + * + * When the value is first set, a `setdata` event is emitted from this Game Object. + * + * If the key already exists, a `changedata` event is emitted instead, along an event named after the key. + * For example, if you updated an existing key called `PlayerLives` then it would emit the event `changedata-PlayerLives`. + * These events will be emitted regardless if you use this method to set the value, or the direct `values` setter. * - * Lights in this list will not be rendered. + * Please note that the data keys are case-sensitive and must be valid JavaScript Object property strings. + * This means the keys `gold` and `Gold` are treated as two unique values within the Data Manager. + * @param key The key to set the value for. Or an object of key value pairs. If an object the `data` argument is ignored. + * @param data The value to set for the given key. If an object is provided as the key this argument is ignored. */ - culledLights: Phaser.GameObjects.Light[]; + setData(key: string | object, data?: any): this; /** - * The ambient color. + * Increase a value for the given key within this Game Objects Data Manager. If the key doesn't already exist in the Data Manager then it is increased from 0. + * + * If the Game Object has not been enabled for data (via `setDataEnabled`) then it will be enabled + * before setting the value. + * + * If the key doesn't already exist in the Data Manager then it is created. + * + * When the value is first set, a `setdata` event is emitted from this Game Object. + * @param key The key to increase the value for. + * @param data The value to increase for the given key. */ - ambientColor: Object; + incData(key: string | object, data?: any): this; /** - * Whether the Lights Manager is enabled. + * Toggle a boolean value for the given key within this Game Objects Data Manager. If the key doesn't already exist in the Data Manager then it is toggled from false. + * + * If the Game Object has not been enabled for data (via `setDataEnabled`) then it will be enabled + * before setting the value. + * + * If the key doesn't already exist in the Data Manager then it is created. + * + * When the value is first set, a `setdata` event is emitted from this Game Object. + * @param key The key to toggle the value for. */ - active: boolean; + toggleData(key: string | object): this; /** - * The maximum number of lights that a single Camera and the lights shader can process. - * Change this via the `maxLights` property in your game config, as it cannot be changed at runtime. + * Retrieves the value for the given key in this Game Objects Data Manager, or undefined if it doesn't exist. + * + * You can also access values via the `values` object. For example, if you had a key called `gold` you can do either: + * + * ```javascript + * sprite.getData('gold'); + * ``` + * + * Or access the value directly: + * + * ```javascript + * sprite.data.values.gold; + * ``` + * + * You can also pass in an array of keys, in which case an array of values will be returned: + * + * ```javascript + * sprite.getData([ 'gold', 'armor', 'health' ]); + * ``` + * + * This approach is useful for destructuring arrays in ES6. + * @param key The key of the value to retrieve, or an array of keys. */ - readonly maxLights: integer; + getData(key: string | string[]): any; /** - * Enable the Lights Manager. + * This callback is invoked when this Game Object is added to a Scene. + * + * Can be overriden by custom Game Objects, but be aware of some Game Objects that + * will use this, such as Sprites, to add themselves into the Update List. + * + * You can also listen for the `ADDED_TO_SCENE` event from this Game Object. */ - enable(): Phaser.GameObjects.LightsManager; + addedToScene(): void; /** - * Disable the Lights Manager. + * This callback is invoked when this Game Object is removed from a Scene. + * + * Can be overriden by custom Game Objects, but be aware of some Game Objects that + * will use this, such as Sprites, to removed themselves from the Update List. + * + * You can also listen for the `REMOVED_FROM_SCENE` event from this Game Object. */ - disable(): Phaser.GameObjects.LightsManager; + removedFromScene(): void; /** - * Cull any Lights that aren't visible to the given Camera. - * - * Culling Lights improves performance by ensuring that only Lights within a Camera's viewport are rendered. - * @param camera The Camera to cull Lights for. + * To be overridden by custom GameObjects. Allows base objects to be used in a Pool. + * @param args args */ - cull(camera: Phaser.Cameras.Scene2D.Camera): Phaser.GameObjects.Light[]; + update(...args: any[]): void; /** - * Iterate over each Light with a callback. - * @param callback The callback that is called with each Light. + * Returns a JSON representation of the Game Object. */ - forEachLight(callback: LightForEach): Phaser.GameObjects.LightsManager; + toJSON(): Phaser.Types.GameObjects.JSONGameObject; /** - * Set the ambient light color. - * @param rgb The integer RGB color of the ambient light. + * Compares the renderMask with the renderFlags to see if this Game Object will render or not. + * Also checks the Game Object against the given Cameras exclusion list. + * @param camera The Camera to check against this Game Object. */ - setAmbientColor(rgb: number): Phaser.GameObjects.LightsManager; + willRender(camera: Phaser.Cameras.Scene2D.Camera): boolean; /** - * Returns the maximum number of Lights allowed to appear at once. + * Force a sort of the display list on the next call to depthSort. */ - getMaxVisibleLights(): integer; + queueDepthSort(): void; /** - * Get the number of Lights managed by this Lights Manager. + * Immediately sorts the display list if the flag is set. */ - getLightCount(): integer; + depthSort(): void; /** - * Add a Light. - * @param x The horizontal position of the Light. Default 0. - * @param y The vertical position of the Light. Default 0. - * @param radius The radius of the Light. Default 100. - * @param rgb The integer RGB color of the light. Default 0xffffff. - * @param intensity The intensity of the Light. Default 1. + * Compare the depth of two Game Objects. + * @param childA The first Game Object. + * @param childB The second Game Object. */ - addLight(x?: number, y?: number, radius?: number, rgb?: number, intensity?: number): Phaser.GameObjects.Light; + sortByDepth(childA: Phaser.GameObjects.GameObject, childB: Phaser.GameObjects.GameObject): number; /** - * Remove a Light. - * @param light The Light to remove. + * Returns an array which contains all Game Objects within this Layer. + * + * This is a reference to the main list array, not a copy of it, so be careful not to modify it. */ - removeLight(light: Phaser.GameObjects.Light): Phaser.GameObjects.LightsManager; + getChildren(): Phaser.GameObjects.GameObject[]; /** - * Shut down the Lights Manager. + * Destroys this Game Object removing it from the Display List and Update List and + * severing all ties to parent resources. * - * Recycles all active Lights into the Light pool, resets ambient light color and clears the lists of Lights and - * culled Lights. + * Use this to remove a Game Object from your game if you don't ever plan to use it again. + * As long as no reference to it exists within your own code it should become free for + * garbage collection by the browser. + * + * If you just want to temporarily disable an object then look at using the + * Game Object Pool instead of destroying it, as destroyed objects cannot be resurrected. */ - shutdown(): void; + destroy(): void; /** - * Destroy the Lights Manager. + * Clears all alpha values associated with this Game Object. * - * Cleans up all references by calling {@link Phaser.GameObjects.LightsManager#shutdown}. + * Immediately sets the alpha levels back to 1 (fully opaque). */ - destroy(): void; + clearAlpha(): this; - } - - /** - * A Scene plugin that provides a {@link Phaser.GameObjects.LightsManager} for the Light2D pipeline. - * - * Available from within a Scene via `this.lights`. - * - * Add Lights using the {@link Phaser.GameObjects.LightsManager#addLight} method: - * - * ```javascript - * // Enable the Lights Manager because it is disabled by default - * this.lights.enable(); - * - * // Create a Light at [400, 300] with a radius of 200 - * this.lights.addLight(400, 300, 200); - * ``` - * - * For Game Objects to be affected by the Lights when rendered, you will need to set them to use the `Light2D` pipeline like so: - * - * ```javascript - * sprite.setPipeline('Light2D'); - * ``` - */ - class LightsPlugin extends Phaser.GameObjects.LightsManager { - /** - * - * @param scene The Scene that this Lights Plugin belongs to. - */ - constructor(scene: Phaser.Scene); - - /** - * A reference to the Scene that this Lights Plugin belongs to. - */ - scene: Phaser.Scene; - - /** - * A reference to the Scene's systems. - */ - systems: Phaser.Scenes.Systems; + /** + * Set the Alpha level of this Game Object. The alpha controls the opacity of the Game Object as it renders. + * Alpha values are provided as a float between 0, fully transparent, and 1, fully opaque. + * @param value The alpha value applied across the whole Game Object. Default 1. + */ + setAlpha(value?: number): this; /** - * Boot the Lights Plugin. - */ - boot(): void; - - /** - * Destroy the Lights Plugin. - * - * Cleans up all references. - */ - destroy(): void; - - } - - /** - * A Mesh Game Object. - */ - class Mesh extends Phaser.GameObjects.GameObject implements Phaser.GameObjects.Components.BlendMode, Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.Mask, Phaser.GameObjects.Components.Pipeline, Phaser.GameObjects.Components.Size, Phaser.GameObjects.Components.Texture, Phaser.GameObjects.Components.Transform, Phaser.GameObjects.Components.Visible, Phaser.GameObjects.Components.ScrollFactor { - /** + * The alpha value of the Game Object. * - * @param scene The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. - * @param x The horizontal position of this Game Object in the world. - * @param y The vertical position of this Game Object in the world. - * @param vertices An array containing the vertices data for this Mesh. - * @param uv An array containing the uv data for this Mesh. - * @param colors An array containing the color data for this Mesh. - * @param alphas An array containing the alpha data for this Mesh. - * @param texture The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. - * @param frame An optional frame from the Texture this Game Object is rendering with. - */ - constructor(scene: Phaser.Scene, x: number, y: number, vertices: number[], uv: number[], colors: number[], alphas: number[], texture: string, frame?: string | integer); - - /** - * An array containing the vertices data for this Mesh. - */ - vertices: Float32Array; - - /** - * An array containing the uv data for this Mesh. - */ - uv: Float32Array; - - /** - * An array containing the color data for this Mesh. - */ - colors: Uint32Array; - - /** - * An array containing the alpha data for this Mesh. - */ - alphas: Float32Array; - - /** - * Fill or additive mode used when blending the color values? - */ - tintFill: boolean; - - /** - * This method is left intentionally empty and does not do anything. - * It is retained to allow a Mesh or Quad to be added to a Container. + * This is a global value, impacting the entire Game Object, not just a region of it. */ - setAlpha(): void; + alpha: number; /** * Sets the Blend Mode being used by this Game Object. @@ -18810,7 +21397,7 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. @@ -18823,13 +21410,13 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. * @param value The depth of this Game Object. */ - setDepth(value: integer): this; + setDepth(value: number): this; /** * The Mask this Game Object is using during render. @@ -18863,6 +21450,8 @@ declare namespace Phaser { * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, * including this one. * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * * To create the mask you need to pass in a reference to a renderable Game Object. * A renderable Game Object is one that uses a texture to render with, such as an * Image, Sprite, Render Texture or BitmapText. @@ -18890,6 +21479,8 @@ declare namespace Phaser { /** * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. */ defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; @@ -18899,302 +21490,192 @@ declare namespace Phaser { pipeline: Phaser.Renderer.WebGL.WebGLPipeline; /** - * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. - */ - initPipeline(pipelineName?: string): boolean; - - /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. - */ - setPipeline(pipelineName: string): this; - - /** - * Resets the WebGL Pipeline of this Game Object back to the default it was created with. - */ - resetPipeline(): boolean; - - /** - * Gets the name of the WebGL Pipeline this Game Object is currently using. + * Does this Game Object have any Post Pipelines set? */ - getPipelineName(): string; + hasPostPipeline: boolean; /** - * The native (un-scaled) width of this Game Object. + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayWidth` property. - */ - width: number; - - /** - * The native (un-scaled) height of this Game Object. + * The pipelines are processed in the order in which they appear in this array. * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayHeight` property. + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. */ - height: number; + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; /** - * The displayed width of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. */ - displayWidth: number; + pipelineData: object; /** - * The displayed height of this Game Object. - * - * This value takes into account the scale factor. + * Sets the initial WebGL Pipeline of this Game Object. * - * Setting this value will adjust the Game Object's scale property. + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. */ - displayHeight: number; + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; /** - * Sets the size of this Game Object to be that of the given Frame. + * Sets the main WebGL Pipeline of this Game Object. * - * This will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or call the - * `setDisplaySize` method, which is the same thing as changing the scale but allows you - * to do so by giving pixel values. + * Also sets the `pipelineData` property, if the parameter is given. * - * If you have enabled this Game Object for input, changing the size will _not_ change the - * size of the hit area. To do this you should adjust the `input.hitArea` object directly. - * @param frame The frame to base the size of this Game Object on. + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. */ - setSizeToFrame(frame: Phaser.Textures.Frame): this; + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; /** - * Sets the internal size of this Game Object, as used for frame or physics body creation. + * Sets one, or more, Post Pipelines on this Game Object. * - * This will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or call the - * `setDisplaySize` method, which is the same thing as changing the scale but allows you - * to do so by giving pixel values. + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. * - * If you have enabled this Game Object for input, changing the size will _not_ change the - * size of the hit area. To do this you should adjust the `input.hitArea` object directly. - * @param width The width of this Game Object. - * @param height The height of this Game Object. - */ - setSize(width: number, height: number): this; - - /** - * Sets the display size of this Game Object. + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. * - * Calling this will adjust the scale. - * @param width The width of this Game Object. - * @param height The height of this Game Object. - */ - setDisplaySize(width: number, height: number): this; - - /** - * The Texture this Game Object is using to render with. - */ - texture: Phaser.Textures.Texture | Phaser.Textures.CanvasTexture; - - /** - * The Texture Frame this Game Object is using to render with. - */ - frame: Phaser.Textures.Frame; - - /** - * Sets the texture and frame this Game Object will use to render with. + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. * - * Textures are referenced by their string-based keys, as stored in the Texture Manager. - * @param key The key of the texture to be used, as stored in the Texture Manager, or a Texture instance. - * @param frame The name or index of the frame within the Texture. + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. */ - setTexture(key: string | Phaser.Textures.Texture, frame?: string | integer): this; + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; /** - * Sets the frame this Game Object will use to render with. + * Adds an entry to the `pipelineData` object belonging to this Game Object. * - * The Frame has to belong to the current Texture being used. + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. * - * It can be either a string or an index. + * If `value` is undefined, and `key` exists, `key` is removed from the data object. * - * Calling `setFrame` will modify the `width` and `height` properties of your Game Object. - * It will also change the `origin` if the Frame has a custom pivot point, as exported from packages like Texture Packer. - * @param frame The name or index of the frame within the Texture. - * @param updateSize Should this call adjust the size of the Game Object? Default true. - * @param updateOrigin Should this call adjust the origin of the Game Object? Default true. - */ - setFrame(frame: string | integer, updateSize?: boolean, updateOrigin?: boolean): this; - - /** - * The x position of this Game Object. + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. */ - x: number; + setPipelineData(key: string, value?: any): this; /** - * The y position of this Game Object. + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - y: number; + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; /** - * The z position of this Game Object. - * - * Note: The z position does not control the rendering order of 2D Game Objects. Use - * {@link Phaser.GameObjects.Components.Depth#depth} instead. + * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. */ - z: number; + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; /** - * The w position of this Game Object. + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. */ - w: number; + resetPostPipeline(resetData?: boolean): void; /** - * This is a special setter that allows you to set both the horizontal and vertical scale of this Game Object - * to the same value, at the same time. When reading this value the result returned is `(scaleX + scaleY) / 2`. + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. * - * Use of this property implies you wish the horizontal and vertical scales to be equal to each other. If this - * isn't the case, use the `scaleX` or `scaleY` properties instead. + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - scale: number; - - /** - * The horizontal scale of this Game Object. - */ - scaleX: number; + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; /** - * The vertical scale of this Game Object. + * Gets the name of the WebGL Pipeline this Game Object is currently using. */ - scaleY: number; + getPipelineName(): string; /** - * The angle of this Game Object as expressed in degrees. - * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * The visible state of the Game Object. * - * If you prefer to work in radians, see the `rotation` property instead. + * An invisible Game Object will skip rendering, but will still process update logic. */ - angle: integer; + visible: boolean; /** - * The angle of this Game Object in radians. - * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Sets the visibility of this Game Object. * - * If you prefer to work in degrees, see the `angle` property instead. + * An invisible Game Object will skip rendering, but will still process update logic. + * @param value The visible state of the Game Object. */ - rotation: number; + setVisible(value: boolean): this; - /** - * Sets the position of this Game Object. - * @param x The x position of this Game Object. Default 0. - * @param y The y position of this Game Object. If not set it will use the `x` value. Default x. - * @param z The z position of this Game Object. Default 0. - * @param w The w position of this Game Object. Default 0. - */ - setPosition(x?: number, y?: number, z?: number, w?: number): this; + } + /** + * A 2D point light. + * + * These are typically created by a {@link Phaser.GameObjects.LightsManager}, available from within a scene via `this.lights`. + * + * Any Game Objects using the Light2D pipeline will then be affected by these Lights as long as they have a normal map. + * + * They can also simply be used to represent a point light for your own purposes. + */ + class Light extends Phaser.Geom.Circle implements Phaser.GameObjects.Components.ScrollFactor, Phaser.GameObjects.Components.Visible { /** - * Sets the position of this Game Object to be a random position within the confines of - * the given area. - * - * If no area is specified a random position between 0 x 0 and the game width x height is used instead. * - * The position does not factor in the size of this Game Object, meaning that only the origin is - * guaranteed to be within the area. - * @param x The x position of the top-left of the random area. Default 0. - * @param y The y position of the top-left of the random area. Default 0. - * @param width The width of the random area. - * @param height The height of the random area. - */ - setRandomPosition(x?: number, y?: number, width?: number, height?: number): this; - - /** - * Sets the rotation of this Game Object. - * @param radians The rotation of this Game Object, in radians. Default 0. - */ - setRotation(radians?: number): this; - - /** - * Sets the angle of this Game Object. - * @param degrees The rotation of this Game Object, in degrees. Default 0. - */ - setAngle(degrees?: number): this; - - /** - * Sets the scale of this Game Object. - * @param x The horizontal scale of this Game Object. - * @param y The vertical scale of this Game Object. If not set it will use the `x` value. Default x. - */ - setScale(x: number, y?: number): this; - - /** - * Sets the x position of this Game Object. - * @param value The x position of this Game Object. Default 0. - */ - setX(value?: number): this; - - /** - * Sets the y position of this Game Object. - * @param value The y position of this Game Object. Default 0. + * @param x The horizontal position of the light. + * @param y The vertical position of the light. + * @param radius The radius of the light. + * @param r The red color of the light. A value between 0 and 1. + * @param g The green color of the light. A value between 0 and 1. + * @param b The blue color of the light. A value between 0 and 1. + * @param intensity The intensity of the light. */ - setY(value?: number): this; + constructor(x: number, y: number, radius: number, r: number, g: number, b: number, intensity: number); /** - * Sets the z position of this Game Object. - * - * Note: The z position does not control the rendering order of 2D Game Objects. Use - * {@link Phaser.GameObjects.Components.Depth#setDepth} instead. - * @param value The z position of this Game Object. Default 0. + * The color of the light. */ - setZ(value?: number): this; + color: Phaser.Display.RGB; /** - * Sets the w position of this Game Object. - * @param value The w position of this Game Object. Default 0. + * The intensity of the light. */ - setW(value?: number): this; + intensity: number; /** - * Gets the local transform matrix for this Game Object. - * @param tempMatrix The matrix to populate with the values from this Game Object. + * Compares the renderMask with the renderFlags to see if this Game Object will render or not. + * Also checks the Game Object against the given Cameras exclusion list. + * @param camera The Camera to check against this Game Object. */ - getLocalTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + willRender(camera: Phaser.Cameras.Scene2D.Camera): boolean; /** - * Gets the world transform matrix for this Game Object, factoring in any parent Containers. - * @param tempMatrix The matrix to populate with the values from this Game Object. - * @param parentMatrix A temporary matrix to hold parent values during the calculations. + * Set the color of the light from a single integer RGB value. + * @param rgb The integer RGB color of the light. */ - getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + setColor(rgb: number): this; /** - * Gets the sum total rotation of all of this Game Objects parent Containers. - * - * The returned value is in radians and will be zero if this Game Object has no parent container. + * Set the intensity of the light. + * @param intensity The intensity of the light. */ - getParentRotation(): number; + setIntensity(intensity: number): this; /** - * The visible state of the Game Object. - * - * An invisible Game Object will skip rendering, but will still process update logic. + * Set the radius of the light. + * @param radius The radius of the light. */ - visible: boolean; + setRadius(radius: number): this; /** - * Sets the visibility of this Game Object. - * - * An invisible Game Object will skip rendering, but will still process update logic. - * @param value The visible state of the Game Object. + * The bitmask that `GameObject.renderFlags` is compared against to determine if the Game Object will render or not. */ - setVisible(value: boolean): this; + static readonly RENDER_MASK: number; /** * The horizontal scroll factor of this Game Object. @@ -19255,2948 +21736,3296 @@ declare namespace Phaser { */ setScrollFactor(x: number, y?: number): this; - } + /** + * The visible state of the Game Object. + * + * An invisible Game Object will skip rendering, but will still process update logic. + */ + visible: boolean; - namespace Particles { /** - * A Particle Emitter property. + * Sets the visibility of this Game Object. * - * Facilitates changing Particle properties as they are emitted and throughout their lifetime. + * An invisible Game Object will skip rendering, but will still process update logic. + * @param value The visible state of the Game Object. */ - class EmitterOp { - /** - * - * @param config Settings for the Particle Emitter that owns this property. - * @param key The name of the property. - * @param defaultValue The default value of the property. - * @param emitOnly Whether the property can only be modified when a Particle is emitted. Default false. - */ - constructor(config: Phaser.Types.GameObjects.Particles.ParticleEmitterConfig, key: string, defaultValue: number, emitOnly?: boolean); + setVisible(value: boolean): this; - /** - * The name of this property. - */ - propertyKey: string; + } - /** - * The value of this property. - */ - propertyValue: number; + /** + * Manages Lights for a Scene. + * + * Affects the rendering of Game Objects using the `Light2D` pipeline. + */ + class LightsManager { + /** + * The Lights in the Scene. + */ + lights: Phaser.GameObjects.Light[]; - /** - * The default value of this property. - */ - defaultValue: number; + /** + * The ambient color. + */ + ambientColor: Phaser.Display.RGB; - /** - * The number of steps for stepped easing between {@link Phaser.GameObjects.Particles.EmitterOp#start} and - * {@link Phaser.GameObjects.Particles.EmitterOp#end} values, per emit. - */ - steps: number; + /** + * Whether the Lights Manager is enabled. + */ + active: boolean; - /** - * The step counter for stepped easing, per emit. - */ - counter: number; + /** + * The maximum number of lights that a single Camera and the lights shader can process. + * Change this via the `maxLights` property in your game config, as it cannot be changed at runtime. + */ + readonly maxLights: number; - /** - * The start value for this property to ease between. - */ - start: number; + /** + * The number of lights that the LightPipeline processed in the _previous_ frame. + */ + readonly visibleLights: number; - /** - * The end value for this property to ease between. - */ - end: number; + /** + * Enable the Lights Manager. + */ + enable(): Phaser.GameObjects.LightsManager; - /** - * The easing function to use for updating this property. - */ - ease: Function; + /** + * Disable the Lights Manager. + */ + disable(): Phaser.GameObjects.LightsManager; - /** - * Whether this property can only be modified when a Particle is emitted. - * - * Set to `true` to allow only {@link Phaser.GameObjects.Particles.EmitterOp#onEmit} callbacks to be set and - * affect this property. - * - * Set to `false` to allow both {@link Phaser.GameObjects.Particles.EmitterOp#onEmit} and - * {@link Phaser.GameObjects.Particles.EmitterOp#onUpdate} callbacks to be set and affect this property. - */ - emitOnly: boolean; + /** + * Get all lights that can be seen by the given Camera. + * + * It will automatically cull lights that are outside the world view of the Camera. + * + * If more lights are returned than supported by the pipeline, the lights are then culled + * based on the distance from the center of the camera. Only those closest are rendered. + * @param camera The Camera to cull Lights for. + */ + getLights(camera: Phaser.Cameras.Scene2D.Camera): Phaser.GameObjects.Light[]; - /** - * The callback to run for Particles when they are emitted from the Particle Emitter. - */ - onEmit: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitCallback; + /** + * Set the ambient light color. + * @param rgb The integer RGB color of the ambient light. + */ + setAmbientColor(rgb: number): Phaser.GameObjects.LightsManager; - /** - * The callback to run for Particles when they are updated. - */ - onUpdate: Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateCallback; + /** + * Returns the maximum number of Lights allowed to appear at once. + */ + getMaxVisibleLights(): number; - /** - * Load the property from a Particle Emitter configuration object. - * - * Optionally accepts a new property key to use, replacing the current one. - * @param config Settings for the Particle Emitter that owns this property. - * @param newKey The new key to use for this property, if any. - */ - loadConfig(config?: Phaser.Types.GameObjects.Particles.ParticleEmitterConfig, newKey?: string): void; + /** + * Get the number of Lights managed by this Lights Manager. + */ + getLightCount(): number; - /** - * Build a JSON representation of this Particle Emitter property. - */ - toJSON(): object; + /** + * Add a Light. + * @param x The horizontal position of the Light. Default 0. + * @param y The vertical position of the Light. Default 0. + * @param radius The radius of the Light. Default 100. + * @param rgb The integer RGB color of the light. Default 0xffffff. + * @param intensity The intensity of the Light. Default 1. + */ + addLight(x?: number, y?: number, radius?: number, rgb?: number, intensity?: number): Phaser.GameObjects.Light; - /** - * Change the current value of the property and update its callback methods. - * @param value The value of the property. - */ - onChange(value: number): Phaser.GameObjects.Particles.EmitterOp; + /** + * Remove a Light. + * @param light The Light to remove. + */ + removeLight(light: Phaser.GameObjects.Light): Phaser.GameObjects.LightsManager; - /** - * Update the {@link Phaser.GameObjects.Particles.EmitterOp#onEmit} and - * {@link Phaser.GameObjects.Particles.EmitterOp#onUpdate} callbacks based on the type of the current - * {@link Phaser.GameObjects.Particles.EmitterOp#propertyValue}. - */ - setMethods(): Phaser.GameObjects.Particles.EmitterOp; + /** + * Shut down the Lights Manager. + * + * Recycles all active Lights into the Light pool, resets ambient light color and clears the lists of Lights and + * culled Lights. + */ + shutdown(): void; - /** - * Check whether an object has the given property. - * @param object The object to check. - * @param key The key of the property to look for in the object. - */ - has(object: object, key: string): boolean; + /** + * Destroy the Lights Manager. + * + * Cleans up all references by calling {@link Phaser.GameObjects.LightsManager#shutdown}. + */ + destroy(): void; - /** - * Check whether an object has both of the given properties. - * @param object The object to check. - * @param key1 The key of the first property to check the object for. - * @param key2 The key of the second property to check the object for. - */ - hasBoth(object: object, key1: string, key2: string): boolean; - - /** - * Check whether an object has at least one of the given properties. - * @param object The object to check. - * @param key1 The key of the first property to check the object for. - * @param key2 The key of the second property to check the object for. - */ - hasEither(object: object, key1: string, key2: string): boolean; - - /** - * The returned value sets what the property will be at the START of the particles life, on emit. - * @param particle The particle. - * @param key The name of the property. - * @param value The current value of the property. - */ - defaultEmit(particle: Phaser.GameObjects.Particles.Particle, key: string, value?: number): number; - - /** - * The returned value updates the property for the duration of the particles life. - * @param particle The particle. - * @param key The name of the property. - * @param t The T value (between 0 and 1) - * @param value The current value of the property. - */ - defaultUpdate(particle: Phaser.GameObjects.Particles.Particle, key: string, t: number, value: number): number; - - /** - * An `onEmit` callback that returns the current value of the property. - */ - staticValueEmit(): number; + } - /** - * An `onUpdate` callback that returns the current value of the property. - */ - staticValueUpdate(): number; + /** + * A Scene plugin that provides a {@link Phaser.GameObjects.LightsManager} for the Light2D pipeline. + * + * Available from within a Scene via `this.lights`. + * + * Add Lights using the {@link Phaser.GameObjects.LightsManager#addLight} method: + * + * ```javascript + * // Enable the Lights Manager because it is disabled by default + * this.lights.enable(); + * + * // Create a Light at [400, 300] with a radius of 200 + * this.lights.addLight(400, 300, 200); + * ``` + * + * For Game Objects to be affected by the Lights when rendered, you will need to set them to use the `Light2D` pipeline like so: + * + * ```javascript + * sprite.setPipeline('Light2D'); + * ``` + * + * Note that you cannot use this pipeline on Graphics Game Objects or Shape Game Objects. + */ + class LightsPlugin extends Phaser.GameObjects.LightsManager { + /** + * + * @param scene The Scene that this Lights Plugin belongs to. + */ + constructor(scene: Phaser.Scene); - /** - * An `onEmit` callback that returns a random value from the current value array. - */ - randomStaticValueEmit(): number; + /** + * A reference to the Scene that this Lights Plugin belongs to. + */ + scene: Phaser.Scene; - /** - * An `onEmit` callback that returns a value between the {@link Phaser.GameObjects.Particles.EmitterOp#start} and - * {@link Phaser.GameObjects.Particles.EmitterOp#end} range. - * @param particle The particle. - * @param key The key of the property. - */ - randomRangedValueEmit(particle: Phaser.GameObjects.Particles.Particle, key: string): number; + /** + * A reference to the Scene's systems. + */ + systems: Phaser.Scenes.Systems; - /** - * An `onEmit` callback that returns a stepped value between the - * {@link Phaser.GameObjects.Particles.EmitterOp#start} and {@link Phaser.GameObjects.Particles.EmitterOp#end} - * range. - */ - steppedEmit(): number; + /** + * Boot the Lights Plugin. + */ + boot(): void; - /** - * An `onEmit` callback for an eased property. - * - * It prepares the particle for easing by {@link Phaser.GameObjects.Particles.EmitterOp#easeValueUpdate}. - * @param particle The particle. - * @param key The name of the property. - */ - easedValueEmit(particle: Phaser.GameObjects.Particles.Particle, key: string): number; + /** + * Destroy the Lights Plugin. + * + * Cleans up all references. + */ + destroy(): void; - /** - * An `onUpdate` callback that returns an eased value between the - * {@link Phaser.GameObjects.Particles.EmitterOp#start} and {@link Phaser.GameObjects.Particles.EmitterOp#end} - * range. - * @param particle The particle. - * @param key The name of the property. - * @param t The T value (between 0 and 1) - */ - easeValueUpdate(particle: Phaser.GameObjects.Particles.Particle, key: string, t: number): number; + } - } + /** + * A Mesh Game Object. + * + * The Mesh Game Object allows you to render a group of textured vertices and manipulate + * the view of those vertices, such as rotation, translation or scaling. + * + * Support for generating mesh data from grids, model data or Wavefront OBJ Files is included. + * + * Although you can use this to render 3D objects, its primary use is for displaying more complex + * Sprites, or Sprites where you need fine-grained control over the vertice positions in order to + * achieve special effects in your games. Note that rendering still takes place using Phasers + * orthographic camera. As a result, all depth and face tests are done in orthographic space. + * + * The rendering process will iterate through the faces of this Mesh and render out each face + * that is considered as being in view of the camera. No depth buffer is used, and because of this, + * you should be careful not to use model data with too many vertices, or overlapping geometry, + * or you'll probably encounter z-depth fighting. The Mesh was designed to allow for more advanced + * 2D layouts, rather than displaying 3D objects, even though it can do this to a degree. + * + * In short, if you want to remake Crysis, use a 3D engine, not a Mesh. However, if you want + * to easily add some small fun 3D elements into your game, or create some special effects involving + * vertex warping, this is the right object for you. Mesh data becomes part of the WebGL batch, + * just like standard Sprites, so doesn't introduce any additional shader overhead. Because + * the Mesh just generates vertices into the WebGL batch, like any other Sprite, you can use all of + * the common Game Object components on a Mesh too, such as a custom pipeline, mask, blend mode + * or texture. + * + * Note that the Mesh object is WebGL only and does not have a Canvas counterpart. + * + * The Mesh origin is always 0.5 x 0.5 and cannot be changed. + */ + class Mesh extends Phaser.GameObjects.GameObject implements Phaser.GameObjects.Components.AlphaSingle, Phaser.GameObjects.Components.BlendMode, Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.Mask, Phaser.GameObjects.Components.Pipeline, Phaser.GameObjects.Components.Size, Phaser.GameObjects.Components.Texture, Phaser.GameObjects.Components.Transform, Phaser.GameObjects.Components.Visible, Phaser.GameObjects.Components.ScrollFactor { + /** + * + * @param scene The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. + * @param x The horizontal position of this Game Object in the world. + * @param y The vertical position of this Game Object in the world. + * @param texture The key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager. + * @param frame An optional frame from the Texture this Game Object is rendering with. + * @param vertices The vertices array. Either `xy` pairs, or `xyz` if the `containsZ` parameter is `true`. + * @param uvs The UVs pairs array. + * @param indicies Optional vertex indicies array. If you don't have one, pass `null` or an empty array. + * @param containsZ Does the vertices data include a `z` component? Default false. + * @param normals Optional vertex normals array. If you don't have one, pass `null` or an empty array. + * @param colors An array of colors, one per vertex, or a single color value applied to all vertices. Default 0xffffff. + * @param alphas An array of alpha values, one per vertex, or a single alpha value applied to all vertices. Default 1. + */ + constructor(scene: Phaser.Scene, x?: number, y?: number, texture?: string | Phaser.Textures.Texture, frame?: string | number, vertices?: number[], uvs?: number[], indicies?: number[], containsZ?: boolean, normals?: number[], colors?: number | number[], alphas?: number | number[]); /** - * The GravityWell action applies a force on the particle to draw it towards, or repel it from, a single point. + * An array containing the Face instances belonging to this Mesh. * - * The force applied is inversely proportional to the square of the distance from the particle to the point, in accordance with Newton's law of gravity. + * A Face consists of 3 Vertex objects. * - * This simulates the effect of gravity over large distances (as between planets, for example). + * This array is populated during calls such as `addVertices` or `addOBJ`. */ - class GravityWell { - /** - * - * @param x The x coordinate of the Gravity Well, in world space. Default 0. - * @param y The y coordinate of the Gravity Well, in world space. Default 0. - * @param power The strength of the gravity force - larger numbers produce a stronger force. Default 0. - * @param epsilon The minimum distance for which the gravity force is calculated. Default 100. - * @param gravity The gravitational force of this Gravity Well. Default 50. - */ - constructor(x?: number | Phaser.Types.GameObjects.Particles.GravityWellConfig, y?: number, power?: number, epsilon?: number, gravity?: number); - - /** - * The x coordinate of the Gravity Well, in world space. - */ - x: number; + faces: Phaser.Geom.Mesh.Face[]; - /** - * The y coordinate of the Gravity Well, in world space. - */ - y: number; - - /** - * The active state of the Gravity Well. An inactive Gravity Well will not influence any particles. - */ - active: boolean; + /** + * An array containing Vertex instances. One instance per vertex in this Mesh. + * + * This array is populated during calls such as `addVertex` or `addOBJ`. + */ + vertices: Phaser.Geom.Mesh.Vertex[]; - /** - * The strength of the gravity force - larger numbers produce a stronger force. - */ - power: number; + /** + * The tint fill mode. + * + * `false` = An additive tint (the default), where vertices colors are blended with the texture. + * `true` = A fill tint, where the vertex colors replace the texture, but respects texture alpha. + */ + tintFill: boolean; - /** - * The minimum distance for which the gravity force is calculated. - */ - epsilon: number; + /** + * You can optionally choose to render the vertices of this Mesh to a Graphics instance. + * + * Achieve this by setting the `debugCallback` and the `debugGraphic` properties. + * + * You can do this in a single call via the `Mesh.setDebug` method, which will use the + * built-in debug function. You can also set it to your own callback. The callback + * will be invoked _once per render_ and sent the following parameters: + * + * `debugCallback(src, meshLength, verts)` + * + * `src` is the Mesh instance being debugged. + * `meshLength` is the number of mesh vertices in total. + * `verts` is an array of the translated vertex coordinates. + * + * To disable rendering, set this property back to `null`. + * + * Please note that high vertex count Meshes will struggle to debug properly. + */ + debugCallback: Function; - /** - * Takes a Particle and updates it based on the properties of this Gravity Well. - * @param particle The Particle to update. - * @param delta The delta time in ms. - * @param step The delta value divided by 1000. - */ - update(particle: Phaser.GameObjects.Particles.Particle, delta: number, step: number): void; + /** + * The Graphics instance that the debug vertices will be drawn to, if `setDebug` has + * been called. + */ + debugGraphic: Phaser.GameObjects.Graphics; - } + /** + * When rendering, skip any Face that isn't counter clockwise? + * + * Enable this to hide backward-facing Faces during rendering. + * + * Disable it to render all Faces. + */ + hideCCW: boolean; /** - * A Particle is a simple Game Object controlled by a Particle Emitter and Manager, and rendered by the Manager. - * It uses its own lightweight physics system, and can interact only with its Emitter's bounds and zones. + * A Vector3 containing the 3D position of the vertices in this Mesh. + * + * Modifying the components of this property will allow you to reposition where + * the vertices are rendered within the Mesh. This happens in the `preUpdate` phase, + * where each vertex is transformed using the view and projection matrices. + * + * Changing this property will impact all vertices being rendered by this Mesh. + * + * You can also adjust the 'view' by using the `pan` methods. */ - class Particle { - /** - * - * @param emitter The Emitter to which this Particle belongs. - */ - constructor(emitter: Phaser.GameObjects.Particles.ParticleEmitter); + modelPosition: Phaser.Math.Vector3; - /** - * The Emitter to which this Particle belongs. - * - * A Particle can only belong to a single Emitter and is created, updated and destroyed via it. - */ - emitter: Phaser.GameObjects.Particles.ParticleEmitter; + /** + * A Vector3 containing the 3D scale of the vertices in this Mesh. + * + * Modifying the components of this property will allow you to scale + * the vertices within the Mesh. This happens in the `preUpdate` phase, + * where each vertex is transformed using the view and projection matrices. + * + * Changing this property will impact all vertices being rendered by this Mesh. + */ + modelScale: Phaser.Math.Vector3; - /** - * The texture frame used to render this Particle. - */ - frame: Phaser.Textures.Frame; + /** + * A Vector3 containing the 3D rotation of the vertices in this Mesh. + * + * The values should be given in radians, i.e. to rotate the vertices by 90 + * degrees you can use `modelRotation.x = Phaser.Math.DegToRad(90)`. + * + * Modifying the components of this property will allow you to rotate + * the vertices within the Mesh. This happens in the `preUpdate` phase, + * where each vertex is transformed using the view and projection matrices. + * + * Changing this property will impact all vertices being rendered by this Mesh. + */ + modelRotation: Phaser.Math.Vector3; - /** - * The x coordinate of this Particle. - */ - x: number; + /** + * The transformation matrix for this Mesh. + */ + transformMatrix: Phaser.Math.Matrix4; - /** - * The y coordinate of this Particle. - */ - y: number; + /** + * The view position for this Mesh. + * + * Use the methods`panX`, `panY` and `panZ` to adjust the view. + */ + viewPosition: Phaser.Math.Vector3; - /** - * The x velocity of this Particle. - */ - velocityX: number; + /** + * The view matrix for this Mesh. + */ + viewMatrix: Phaser.Math.Matrix4; - /** - * The y velocity of this Particle. - */ - velocityY: number; + /** + * The projection matrix for this Mesh. + * + * Update it with the `setPerspective` or `setOrtho` methods. + */ + projectionMatrix: Phaser.Math.Matrix4; - /** - * The x acceleration of this Particle. - */ - accelerationX: number; + /** + * How many faces were rendered by this Mesh Game Object in the last + * draw? This is reset in the `preUpdate` method and then incremented + * each time a face is drawn. Note that in multi-camera Scenes this + * value may exceed that found in `Mesh.getFaceCount` due to + * cameras drawing the same faces more than once. + */ + readonly totalRendered: number; - /** - * The y acceleration of this Particle. - */ - accelerationY: number; + /** + * By default, the Mesh will check to see if its model or view transform has + * changed each frame and only recalculate the vertex positions if they have. + * + * This avoids lots of additional math in the `preUpdate` step when not required. + * + * However, if you are performing per-Face or per-Vertex manipulation on this Mesh, + * such as tweening a Face, or moving it without moving the rest of the Mesh, + * then you may need to disable the dirty cache in order for the Mesh to re-render + * correctly. You can toggle this property to do that. Please note that leaving + * this set to `true` will cause the Mesh to recalculate the position of every single + * vertex in it, every single frame. So only really do this if you know you + * need it. + */ + ignoreDirtyCache: boolean; - /** - * The maximum horizontal velocity this Particle can travel at. - */ - maxVelocityX: number; + /** + * Translates the view position of this Mesh on the x axis by the given amount. + * @param v The amount to pan by. + */ + panX(v: number): void; - /** - * The maximum vertical velocity this Particle can travel at. - */ - maxVelocityY: number; + /** + * Translates the view position of this Mesh on the y axis by the given amount. + * @param v The amount to pan by. + */ + panY(v: number): void; - /** - * The bounciness, or restitution, of this Particle. - */ - bounce: number; + /** + * Translates the view position of this Mesh on the z axis by the given amount. + * @param v The amount to pan by. + */ + panZ(v: number): void; - /** - * The horizontal scale of this Particle. - */ - scaleX: number; + /** + * Builds a new perspective projection matrix from the given values. + * + * See also `setOrtho`. + * @param width The width of the projection matrix. Typically the same as the Mesh and/or Renderer. + * @param height The height of the projection matrix. Typically the same as the Mesh and/or Renderer. + * @param fov The field of view, in degrees. Default 45. + * @param near The near value of the view. Default 0.01. + * @param far The far value of the view. Default 1000. + */ + setPerspective(width: number, height: number, fov?: number, near?: number, far?: number): void; - /** - * The vertical scale of this Particle. - */ - scaleY: number; + /** + * Builds a new orthographic projection matrix from the given values. + * + * If using this mode you will often need to set `Mesh.hideCCW` to `false` as well. + * + * By default, calling this method with no parameters will set the scaleX value to + * match the renderers aspect ratio. + * + * See also `setPerspective`. + * @param scaleX The default horizontal scale in relation to the Mesh / Renderer dimensions. Default 1. + * @param scaleY The default vertical scale in relation to the Mesh / Renderer dimensions. Default 1. + * @param near The near value of the view. Default -1000. + * @param far The far value of the view. Default 1000. + */ + setOrtho(scaleX?: number, scaleY?: number, near?: number, far?: number): void; - /** - * The alpha value of this Particle. - */ - alpha: number; + /** + * Iterates and destroys all current Faces in this Mesh, then resets the + * `faces` and `vertices` arrays. + */ + clear(): this; - /** - * The angle of this Particle in degrees. - */ - angle: number; + /** + * This method will add the data from a triangulated Wavefront OBJ model file to this Mesh. + * + * The data should have been loaded via the OBJFile: + * + * ```javascript + * this.load.obj(key, url); + * ``` + * + * Then use the same `key` as the first parameter to this method. + * + * Multiple Mesh Game Objects can use the same model data without impacting on each other. + * + * Make sure your 3D package has triangulated the model data prior to exporting it. + * + * You can add multiple models to a single Mesh, although they will act as one when + * moved or rotated. You can scale the model data, should it be too small, or too large, to see. + * You can also offset the vertices of the model via the `x`, `y` and `z` parameters. + * @param key The key of the model data in the OBJ Cache to add to this Mesh. + * @param scale An amount to scale the model data by. Use this if the model has exported too small, or large, to see. Default 1. + * @param x Translate the model x position by this amount. Default 0. + * @param y Translate the model y position by this amount. Default 0. + * @param z Translate the model z position by this amount. Default 0. + * @param rotateX Rotate the model on the x axis by this amount, in radians. Default 0. + * @param rotateY Rotate the model on the y axis by this amount, in radians. Default 0. + * @param rotateZ Rotate the model on the z axis by this amount, in radians. Default 0. + * @param zIsUp Is the z axis up (true), or is y axis up (false)? Default true. + */ + addVerticesFromObj(key: string, scale?: number, x?: number, y?: number, z?: number, rotateX?: number, rotateY?: number, rotateZ?: number, zIsUp?: boolean): this; - /** - * The angle of this Particle in radians. - */ - rotation: number; + /** + * Compare the depth of two Faces. + * @param faceA The first Face. + * @param faceB The second Face. + */ + sortByDepth(faceA: Phaser.Geom.Mesh.Face, faceB: Phaser.Geom.Mesh.Face): number; - /** - * The tint applied to this Particle. - */ - tint: integer; + /** + * Runs a depth sort across all Faces in this Mesh, comparing their averaged depth. + * + * This is called automatically if you use any of the `rotate` methods, but you can + * also invoke it to sort the Faces should you manually position them. + */ + depthSort(): this; - /** - * The lifespan of this Particle in ms. - */ - life: number; + /** + * Adds a new Vertex into the vertices array of this Mesh. + * + * Just adding a vertex isn't enough to render it. You need to also + * make it part of a Face, with 3 Vertex instances per Face. + * @param x The x position of the vertex. + * @param y The y position of the vertex. + * @param z The z position of the vertex. + * @param u The UV u coordinate of the vertex. + * @param v The UV v coordinate of the vertex. + * @param color The color value of the vertex. Default 0xffffff. + * @param alpha The alpha value of the vertex. Default 1. + */ + addVertex(x: number, y: number, z: number, u: number, v: number, color?: number, alpha?: number): this; - /** - * The current life of this Particle in ms. - */ - lifeCurrent: number; + /** + * Adds a new Face into the faces array of this Mesh. + * + * A Face consists of references to 3 Vertex instances, which must be provided. + * @param vertex1 The first vertex of the Face. + * @param vertex2 The second vertex of the Face. + * @param vertex3 The third vertex of the Face. + */ + addFace(vertex1: Phaser.Geom.Mesh.Vertex, vertex2: Phaser.Geom.Mesh.Vertex, vertex3: Phaser.Geom.Mesh.Vertex): this; - /** - * The delay applied to this Particle upon emission, in ms. - */ - delayCurrent: number; + /** + * Adds new vertices to this Mesh by parsing the given data. + * + * This method will take vertex data in one of two formats, based on the `containsZ` parameter. + * + * If your vertex data are `x`, `y` pairs, then `containsZ` should be `false` (this is the default) + * + * If your vertex data is groups of `x`, `y` and `z` values, then the `containsZ` parameter must be true. + * + * The `uvs` parameter is a numeric array consisting of `u` and `v` pairs. + * + * The `normals` parameter is a numeric array consisting of `x`, `y` vertex normal values and, if `containsZ` is true, `z` values as well. + * + * The `indicies` parameter is an optional array that, if given, is an indexed list of vertices to be added. + * + * The `colors` parameter is an optional array, or single value, that if given sets the color of each vertex created. + * + * The `alphas` parameter is an optional array, or single value, that if given sets the alpha of each vertex created. + * + * When providing indexed data it is assumed that _all_ of the arrays are indexed, not just the vertices. + * + * The following example will create a 256 x 256 sized quad using an index array: + * + * ```javascript + * const vertices = [ + * -128, 128, + * 128, 128, + * -128, -128, + * 128, -128 + * ]; + * + * const uvs = [ + * 0, 1, + * 1, 1, + * 0, 0, + * 1, 0 + * ]; + * + * const indices = [ 0, 2, 1, 2, 3, 1 ]; + * + * mesh.addVertices(vertices, uvs, indicies); + * ``` + * + * If the data is not indexed, it's assumed that the arrays all contain sequential data. + * @param vertices The vertices array. Either `xy` pairs, or `xyz` if the `containsZ` parameter is `true`. + * @param uvs The UVs pairs array. + * @param indicies Optional vertex indicies array. If you don't have one, pass `null` or an empty array. + * @param containsZ Does the vertices data include a `z` component? Default false. + * @param normals Optional vertex normals array. If you don't have one, pass `null` or an empty array. + * @param colors An array of colors, one per vertex, or a single color value applied to all vertices. Default 0xffffff. + * @param alphas An array of alpha values, one per vertex, or a single alpha value applied to all vertices. Default 1. + */ + addVertices(vertices: number[], uvs: number[], indicies?: number[], containsZ?: boolean, normals?: number[], colors?: number | number[], alphas?: number | number[]): this; - /** - * The normalized lifespan T value, where 0 is the start and 1 is the end. - */ - lifeT: number; + /** + * Returns the total number of Faces in this Mesh Game Object. + */ + getFaceCount(): number; - /** - * The data used by the ease equation. - */ - data: object; + /** + * Returns the total number of Vertices in this Mesh Game Object. + */ + getVertexCount(): number; - /** - * Checks to see if this Particle is alive and updating. - */ - isAlive(): boolean; + /** + * Returns the Face at the given index in this Mesh Game Object. + * @param index The index of the Face to get. + */ + getFace(index: number): Phaser.Geom.Mesh.Face; - /** - * Resets the position of this particle back to zero. - */ - resetPosition(): void; + /** + * Return an array of Face objects from this Mesh that intersect with the given coordinates. + * + * The given position is translated through the matrix of this Mesh and the given Camera, + * before being compared against the vertices. + * + * If more than one Face intersects, they will all be returned in the array, but the array will + * be depth sorted first, so the first element will always be that closest to the camera. + * @param x The x position to check against. + * @param y The y position to check against. + * @param camera The camera to pass the coordinates through. If not give, the default Scene Camera is used. + */ + getFaceAt(x: number, y: number, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Geom.Mesh.Face[]; - /** - * Starts this Particle from the given coordinates. - * @param x The x coordinate to launch this Particle from. - * @param y The y coordinate to launch this Particle from. - */ - fire(x: number, y: number): void; + /** + * This method enables rendering of the Mesh vertices to the given Graphics instance. + * + * If you enable this feature, you **must** call `Graphics.clear()` in your Scene `update`, + * otherwise the Graphics instance you provide to debug will fill-up with draw calls, + * eventually crashing the browser. This is not done automatically to allow you to debug + * draw multiple Mesh objects to a single Graphics instance. + * + * The Mesh class has a built-in debug rendering callback `Mesh.renderDebug`, however + * you can also provide your own callback to be used instead. Do this by setting the `callback` parameter. + * + * The callback is invoked _once per render_ and sent the following parameters: + * + * `callback(src, faces)` + * + * `src` is the Mesh instance being debugged. + * `faces` is an array of the Faces that were rendered. + * + * You can get the final drawn vertex position from a Face object like this: + * + * ```javascript + * let face = faces[i]; + * + * let x0 = face.vertex1.tx; + * let y0 = face.vertex1.ty; + * let x1 = face.vertex2.tx; + * let y1 = face.vertex2.ty; + * let x2 = face.vertex3.tx; + * let y2 = face.vertex3.ty; + * + * graphic.strokeTriangle(x0, y0, x1, y1, x2, y2); + * ``` + * + * If using your own callback you do not have to provide a Graphics instance to this method. + * + * To disable debug rendering, to either your own callback or the built-in one, call this method + * with no arguments. + * @param graphic The Graphic instance to render to if using the built-in callback. + * @param callback The callback to invoke during debug render. Leave as undefined to use the built-in callback. + */ + setDebug(graphic?: Phaser.GameObjects.Graphics, callback?: Function): this; - /** - * An internal method that calculates the velocity of the Particle. - * @param emitter The Emitter that is updating this Particle. - * @param delta The delta time in ms. - * @param step The delta value divided by 1000. - * @param processors Particle processors (gravity wells). - */ - computeVelocity(emitter: Phaser.GameObjects.Particles.ParticleEmitter, delta: number, step: number, processors: any[]): void; + /** + * Checks if the transformation data in this mesh is dirty. + * + * This is used internally by the `preUpdate` step to determine if the vertices should + * be recalculated or not. + */ + isDirty(): boolean; - /** - * Checks if this Particle is still within the bounds defined by the given Emitter. - * - * If not, and depending on the Emitter collision flags, the Particle may either stop or rebound. - * @param emitter The Emitter to check the bounds against. - */ - checkBounds(emitter: Phaser.GameObjects.Particles.ParticleEmitter): void; + /** + * The Mesh update loop. The following takes place in this method: + * + * First, the `totalRendered` and `totalFrame` properties are set. + * + * If the view matrix of this Mesh isn't dirty, and the model position, rotate or scale properties are + * all clean, then the method returns at this point. + * + * Otherwise, if the viewPosition is dirty (i.e. from calling a method like `panZ`), then it will + * refresh the viewMatrix. + * + * After this, a new transformMatrix is built and it then iterates through all Faces in this + * Mesh, calling `transformCoordinatesLocal` on all of them. Internally, this updates every + * vertex, calculating its new transformed position, based on the new transform matrix. + * + * Finally, the faces are depth sorted. + * @param time The current timestamp. + * @param delta The delta time, in ms, elapsed since the last frame. + */ + protected preUpdate(time: number, delta: number): void; - /** - * The main update method for this Particle. - * - * Updates its life values, computes the velocity and repositions the Particle. - * @param delta The delta time in ms. - * @param step The delta value divided by 1000. - * @param processors An optional array of update processors. - */ - update(delta: number, step: number, processors: any[]): boolean; + /** + * The built-in Mesh debug rendering method. + * + * See `Mesh.setDebug` for more details. + * @param src The Mesh object being rendered. + * @param faces An array of Faces. + */ + renderDebug(src: Phaser.GameObjects.Mesh, faces: Phaser.Geom.Mesh.Face[]): void; - } + /** + * Clears all alpha values associated with this Game Object. + * + * Immediately sets the alpha levels back to 1 (fully opaque). + */ + clearAlpha(): this; /** - * A particle emitter represents a single particle stream. - * It controls a pool of {@link Phaser.GameObjects.Particles.Particle Particles} and is controlled by a {@link Phaser.GameObjects.Particles.ParticleEmitterManager Particle Emitter Manager}. + * Set the Alpha level of this Game Object. The alpha controls the opacity of the Game Object as it renders. + * Alpha values are provided as a float between 0, fully transparent, and 1, fully opaque. + * @param value The alpha value applied across the whole Game Object. Default 1. */ - class ParticleEmitter implements Phaser.GameObjects.Components.BlendMode, Phaser.GameObjects.Components.Mask, Phaser.GameObjects.Components.ScrollFactor, Phaser.GameObjects.Components.Visible { - /** - * - * @param manager The Emitter Manager this Emitter belongs to. - * @param config Settings for this emitter. - */ - constructor(manager: Phaser.GameObjects.Particles.ParticleEmitterManager, config: Phaser.Types.GameObjects.Particles.ParticleEmitterConfig); + setAlpha(value?: number): this; - /** - * The Emitter Manager this Emitter belongs to. - */ - manager: Phaser.GameObjects.Particles.ParticleEmitterManager; + /** + * The alpha value of the Game Object. + * + * This is a global value, impacting the entire Game Object, not just a region of it. + */ + alpha: number; - /** - * The texture assigned to particles. - */ - texture: Phaser.Textures.Texture; + /** + * Sets the Blend Mode being used by this Game Object. + * + * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) + * + * Under WebGL only the following Blend Modes are available: + * + * * ADD + * * MULTIPLY + * * SCREEN + * * ERASE + * + * Canvas has more available depending on browser support. + * + * You can also create your own custom Blend Modes in WebGL. + * + * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending + * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these + * reasons try to be careful about the construction of your Scene and the frequency of which blend modes + * are used. + */ + blendMode: Phaser.BlendModes | string; - /** - * The texture frames assigned to particles. - */ - frames: Phaser.Textures.Frame[]; + /** + * Sets the Blend Mode being used by this Game Object. + * + * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) + * + * Under WebGL only the following Blend Modes are available: + * + * * ADD + * * MULTIPLY + * * SCREEN + * * ERASE (only works when rendering to a framebuffer, like a Render Texture) + * + * Canvas has more available depending on browser support. + * + * You can also create your own custom Blend Modes in WebGL. + * + * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending + * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these + * reasons try to be careful about the construction of your Scene and the frequency in which blend modes + * are used. + * @param value The BlendMode value. Either a string or a CONST. + */ + setBlendMode(value: string | Phaser.BlendModes): this; - /** - * The default texture frame assigned to particles. - */ - defaultFrame: Phaser.Textures.Frame; + /** + * The depth of this Game Object within the Scene. + * + * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order + * of Game Objects, without actually moving their position in the display list. + * + * The default depth is zero. A Game Object with a higher depth + * value will always render in front of one with a lower value. + * + * Setting the depth will queue a depth sort event within the Scene. + */ + depth: number; - /** - * Names of simple configuration properties. - */ - configFastMap: object; + /** + * The depth of this Game Object within the Scene. + * + * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order + * of Game Objects, without actually moving their position in the display list. + * + * The default depth is zero. A Game Object with a higher depth + * value will always render in front of one with a lower value. + * + * Setting the depth will queue a depth sort event within the Scene. + * @param value The depth of this Game Object. + */ + setDepth(value: number): this; - /** - * Names of complex configuration properties. - */ - configOpMap: object; + /** + * The Mask this Game Object is using during render. + */ + mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask; - /** - * The name of this Particle Emitter. - * - * Empty by default and never populated by Phaser, this is left for developers to use. - */ - name: string; + /** + * Sets the mask that this Game Object will use to render with. + * + * The mask must have been previously created and can be either a GeometryMask or a BitmapMask. + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * + * If a mask is already set on this Game Object it will be immediately replaced. + * + * Masks are positioned in global space and are not relative to the Game Object to which they + * are applied. The reason for this is that multiple Game Objects can all share the same mask. + * + * Masks have no impact on physics or input detection. They are purely a rendering component + * that allows you to limit what is visible during the render pass. + * @param mask The mask this Game Object will use when rendering. + */ + setMask(mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask): this; - /** - * The Particle Class which will be emitted by this Emitter. - */ - particleClass: Phaser.GameObjects.Particles.Particle; + /** + * Clears the mask that this Game Object was using. + * @param destroyMask Destroy the mask before clearing it? Default false. + */ + clearMask(destroyMask?: boolean): this; - /** - * The x-coordinate of the particle origin (where particles will be emitted). - */ - x: Phaser.GameObjects.Particles.EmitterOp; + /** + * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, + * including this one. + * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * + * To create the mask you need to pass in a reference to a renderable Game Object. + * A renderable Game Object is one that uses a texture to render with, such as an + * Image, Sprite, Render Texture or BitmapText. + * + * If you do not provide a renderable object, and this Game Object has a texture, + * it will use itself as the object. This means you can call this method to create + * a Bitmap Mask from any renderable Game Object. + * @param renderable A renderable Game Object that uses a texture, such as a Sprite. + */ + createBitmapMask(renderable?: Phaser.GameObjects.GameObject): Phaser.Display.Masks.BitmapMask; - /** - * The y-coordinate of the particle origin (where particles will be emitted). - */ - y: Phaser.GameObjects.Particles.EmitterOp; + /** + * Creates and returns a Geometry Mask. This mask can be used by any Game Object, + * including this one. + * + * To create the mask you need to pass in a reference to a Graphics Game Object. + * + * If you do not provide a graphics object, and this Game Object is an instance + * of a Graphics object, then it will use itself to create the mask. + * + * This means you can call this method to create a Geometry Mask from any Graphics Game Object. + * @param graphics A Graphics Game Object. The geometry within it will be used as the mask. + */ + createGeometryMask(graphics?: Phaser.GameObjects.Graphics): Phaser.Display.Masks.GeometryMask; - /** - * A radial emitter will emit particles in all directions between angle min and max, - * using {@link Phaser.GameObjects.Particles.ParticleEmitter#speed} as the value. If set to false then this acts as a point Emitter. - * A point emitter will emit particles only in the direction derived from the speedX and speedY values. - */ - radial: boolean; + /** + * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. + */ + defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; - /** - * Horizontal acceleration applied to emitted particles, in pixels per second squared. - */ - gravityX: number; + /** + * The current WebGL pipeline of this Game Object. + */ + pipeline: Phaser.Renderer.WebGL.WebGLPipeline; - /** - * Vertical acceleration applied to emitted particles, in pixels per second squared. - */ - gravityY: number; + /** + * Does this Game Object have any Post Pipelines set? + */ + hasPostPipeline: boolean; - /** - * Whether accelerationX and accelerationY are non-zero. Set automatically during configuration. - */ - acceleration: boolean; + /** + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. + */ + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; - /** - * Horizontal acceleration applied to emitted particles, in pixels per second squared. - */ - accelerationX: Phaser.GameObjects.Particles.EmitterOp; + /** + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. + */ + pipelineData: object; - /** - * Vertical acceleration applied to emitted particles, in pixels per second squared. - */ - accelerationY: Phaser.GameObjects.Particles.EmitterOp; + /** + * Sets the initial WebGL Pipeline of this Game Object. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + */ + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; - /** - * The maximum horizontal velocity of emitted particles, in pixels per second squared. - */ - maxVelocityX: Phaser.GameObjects.Particles.EmitterOp; + /** + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; - /** - * The maximum vertical velocity of emitted particles, in pixels per second squared. - */ - maxVelocityY: Phaser.GameObjects.Particles.EmitterOp; + /** + * Sets one, or more, Post Pipelines on this Game Object. + * + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; - /** - * The initial horizontal speed of emitted particles, in pixels per second. - */ - speedX: Phaser.GameObjects.Particles.EmitterOp; + /** + * Adds an entry to the `pipelineData` object belonging to this Game Object. + * + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. + */ + setPipelineData(key: string, value?: any): this; - /** - * The initial vertical speed of emitted particles, in pixels per second. - */ - speedY: Phaser.GameObjects.Particles.EmitterOp; + /** + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. + */ + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; - /** - * Whether moveToX and moveToY are nonzero. Set automatically during configuration. - */ - moveTo: boolean; + /** + * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; - /** - * The x-coordinate emitted particles move toward, when {@link Phaser.GameObjects.Particles.ParticleEmitter#moveTo} is true. - */ - moveToX: Phaser.GameObjects.Particles.EmitterOp; + /** + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPostPipeline(resetData?: boolean): void; - /** - * The y-coordinate emitted particles move toward, when {@link Phaser.GameObjects.Particles.ParticleEmitter#moveTo} is true. - */ - moveToY: Phaser.GameObjects.Particles.EmitterOp; + /** + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. + */ + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; - /** - * Whether particles will rebound when they meet the emitter bounds. - */ - bounce: Phaser.GameObjects.Particles.EmitterOp; + /** + * Gets the name of the WebGL Pipeline this Game Object is currently using. + */ + getPipelineName(): string; - /** - * The horizontal scale of emitted particles. - */ - scaleX: Phaser.GameObjects.Particles.EmitterOp; + /** + * The native (un-scaled) width of this Game Object. + * + * Changing this value will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or use + * the `displayWidth` property. + */ + width: number; - /** - * The vertical scale of emitted particles. - */ - scaleY: Phaser.GameObjects.Particles.EmitterOp; + /** + * The native (un-scaled) height of this Game Object. + * + * Changing this value will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or use + * the `displayHeight` property. + */ + height: number; - /** - * Color tint applied to emitted particles. Any alpha component (0xAA000000) is ignored. - */ - tint: Phaser.GameObjects.Particles.EmitterOp; + /** + * The displayed width of this Game Object. + * + * This value takes into account the scale factor. + * + * Setting this value will adjust the Game Object's scale property. + */ + displayWidth: number; - /** - * The alpha (transparency) of emitted particles. - */ - alpha: Phaser.GameObjects.Particles.EmitterOp; + /** + * The displayed height of this Game Object. + * + * This value takes into account the scale factor. + * + * Setting this value will adjust the Game Object's scale property. + */ + displayHeight: number; - /** - * The lifespan of emitted particles, in ms. - */ - lifespan: Phaser.GameObjects.Particles.EmitterOp; + /** + * Sets the size of this Game Object to be that of the given Frame. + * + * This will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or call the + * `setDisplaySize` method, which is the same thing as changing the scale but allows you + * to do so by giving pixel values. + * + * If you have enabled this Game Object for input, changing the size will _not_ change the + * size of the hit area. To do this you should adjust the `input.hitArea` object directly. + * @param frame The frame to base the size of this Game Object on. + */ + setSizeToFrame(frame: Phaser.Textures.Frame): this; - /** - * The angle of the initial velocity of emitted particles, in degrees. - */ - angle: Phaser.GameObjects.Particles.EmitterOp; + /** + * Sets the internal size of this Game Object, as used for frame or physics body creation. + * + * This will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or call the + * `setDisplaySize` method, which is the same thing as changing the scale but allows you + * to do so by giving pixel values. + * + * If you have enabled this Game Object for input, changing the size will _not_ change the + * size of the hit area. To do this you should adjust the `input.hitArea` object directly. + * @param width The width of this Game Object. + * @param height The height of this Game Object. + */ + setSize(width: number, height: number): this; - /** - * The rotation of emitted particles, in degrees. - */ - rotate: Phaser.GameObjects.Particles.EmitterOp; + /** + * Sets the display size of this Game Object. + * + * Calling this will adjust the scale. + * @param width The width of this Game Object. + * @param height The height of this Game Object. + */ + setDisplaySize(width: number, height: number): this; - /** - * A function to call when a particle is emitted. - */ - emitCallback: Phaser.Types.GameObjects.Particles.ParticleEmitterCallback; + /** + * The Texture this Game Object is using to render with. + */ + texture: Phaser.Textures.Texture | Phaser.Textures.CanvasTexture; - /** - * The calling context for {@link Phaser.GameObjects.Particles.ParticleEmitter#emitCallback}. - */ - emitCallbackScope: any; + /** + * The Texture Frame this Game Object is using to render with. + */ + frame: Phaser.Textures.Frame; - /** - * A function to call when a particle dies. - */ - deathCallback: Phaser.Types.GameObjects.Particles.ParticleDeathCallback; + /** + * Sets the texture and frame this Game Object will use to render with. + * + * Textures are referenced by their string-based keys, as stored in the Texture Manager. + * @param key The key of the texture to be used, as stored in the Texture Manager, or a Texture instance. + * @param frame The name or index of the frame within the Texture. + */ + setTexture(key: string | Phaser.Textures.Texture, frame?: string | number): this; - /** - * The calling context for {@link Phaser.GameObjects.Particles.ParticleEmitter#deathCallback}. - */ - deathCallbackScope: any; + /** + * Sets the frame this Game Object will use to render with. + * + * The Frame has to belong to the current Texture being used. + * + * It can be either a string or an index. + * + * Calling `setFrame` will modify the `width` and `height` properties of your Game Object. + * It will also change the `origin` if the Frame has a custom pivot point, as exported from packages like Texture Packer. + * @param frame The name or index of the frame within the Texture. + * @param updateSize Should this call adjust the size of the Game Object? Default true. + * @param updateOrigin Should this call adjust the origin of the Game Object? Default true. + */ + setFrame(frame: string | number, updateSize?: boolean, updateOrigin?: boolean): this; - /** - * Set to hard limit the amount of particle objects this emitter is allowed to create. - * 0 means unlimited. - */ - maxParticles: integer; + /** + * The x position of this Game Object. + */ + x: number; - /** - * How many particles are emitted each time particles are emitted (one explosion or one flow cycle). - */ - quantity: Phaser.GameObjects.Particles.EmitterOp; + /** + * The y position of this Game Object. + */ + y: number; - /** - * How many ms to wait after emission before the particles start updating. - */ - delay: Phaser.GameObjects.Particles.EmitterOp; + /** + * The z position of this Game Object. + * + * Note: The z position does not control the rendering order of 2D Game Objects. Use + * {@link Phaser.GameObjects.Components.Depth#depth} instead. + */ + z: number; - /** - * For a flow emitter, the time interval (>= 0) between particle flow cycles in ms. - * A value of 0 means there is one particle flow cycle for each logic update (the maximum flow frequency). This is the default setting. - * For an exploding emitter, this value will be -1. - * Calling {@link Phaser.GameObjects.Particles.ParticleEmitter#flow} also puts the emitter in flow mode (frequency >= 0). - * Calling {@link Phaser.GameObjects.Particles.ParticleEmitter#explode} also puts the emitter in explode mode (frequency = -1). - */ - frequency: number; + /** + * The w position of this Game Object. + */ + w: number; - /** - * Controls if the emitter is currently emitting a particle flow (when frequency >= 0). - * Already alive particles will continue to update until they expire. - * Controlled by {@link Phaser.GameObjects.Particles.ParticleEmitter#start} and {@link Phaser.GameObjects.Particles.ParticleEmitter#stop}. - */ - on: boolean; + /** + * This is a special setter that allows you to set both the horizontal and vertical scale of this Game Object + * to the same value, at the same time. When reading this value the result returned is `(scaleX + scaleY) / 2`. + * + * Use of this property implies you wish the horizontal and vertical scales to be equal to each other. If this + * isn't the case, use the `scaleX` or `scaleY` properties instead. + */ + scale: number; - /** - * Newly emitted particles are added to the top of the particle list, i.e. rendered above those already alive. - * Set to false to send them to the back. - */ - particleBringToTop: boolean; + /** + * The horizontal scale of this Game Object. + */ + scaleX: number; - /** - * The time rate applied to active particles, affecting lifespan, movement, and tweens. Values larger than 1 are faster than normal. - */ - timeScale: number; + /** + * The vertical scale of this Game Object. + */ + scaleY: number; - /** - * An object describing a shape to emit particles from. - */ - emitZone: Phaser.GameObjects.Particles.Zones.EdgeZone | Phaser.GameObjects.Particles.Zones.RandomZone; + /** + * The angle of this Game Object as expressed in degrees. + * + * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left + * and -90 is up. + * + * If you prefer to work in radians, see the `rotation` property instead. + */ + angle: number; - /** - * An object describing a shape that deactivates particles when they interact with it. - */ - deathZone: Phaser.GameObjects.Particles.Zones.DeathZone; + /** + * The angle of this Game Object in radians. + * + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. + * + * If you prefer to work in degrees, see the `angle` property instead. + */ + rotation: number; - /** - * A rectangular boundary constraining particle movement. - */ - bounds: Phaser.Geom.Rectangle; + /** + * Sets the position of this Game Object. + * @param x The x position of this Game Object. Default 0. + * @param y The y position of this Game Object. If not set it will use the `x` value. Default x. + * @param z The z position of this Game Object. Default 0. + * @param w The w position of this Game Object. Default 0. + */ + setPosition(x?: number, y?: number, z?: number, w?: number): this; - /** - * Whether particles interact with the left edge of the emitter {@link Phaser.GameObjects.Particles.ParticleEmitter#bounds}. - */ - collideLeft: boolean; + /** + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; - /** - * Whether particles interact with the right edge of the emitter {@link Phaser.GameObjects.Particles.ParticleEmitter#bounds}. - */ - collideRight: boolean; + /** + * Sets the position of this Game Object to be a random position within the confines of + * the given area. + * + * If no area is specified a random position between 0 x 0 and the game width x height is used instead. + * + * The position does not factor in the size of this Game Object, meaning that only the origin is + * guaranteed to be within the area. + * @param x The x position of the top-left of the random area. Default 0. + * @param y The y position of the top-left of the random area. Default 0. + * @param width The width of the random area. + * @param height The height of the random area. + */ + setRandomPosition(x?: number, y?: number, width?: number, height?: number): this; - /** - * Whether particles interact with the top edge of the emitter {@link Phaser.GameObjects.Particles.ParticleEmitter#bounds}. - */ - collideTop: boolean; + /** + * Sets the rotation of this Game Object. + * @param radians The rotation of this Game Object, in radians. Default 0. + */ + setRotation(radians?: number): this; + + /** + * Sets the angle of this Game Object. + * @param degrees The rotation of this Game Object, in degrees. Default 0. + */ + setAngle(degrees?: number): this; + + /** + * Sets the scale of this Game Object. + * @param x The horizontal scale of this Game Object. + * @param y The vertical scale of this Game Object. If not set it will use the `x` value. Default x. + */ + setScale(x: number, y?: number): this; + + /** + * Sets the x position of this Game Object. + * @param value The x position of this Game Object. Default 0. + */ + setX(value?: number): this; + + /** + * Sets the y position of this Game Object. + * @param value The y position of this Game Object. Default 0. + */ + setY(value?: number): this; + + /** + * Sets the z position of this Game Object. + * + * Note: The z position does not control the rendering order of 2D Game Objects. Use + * {@link Phaser.GameObjects.Components.Depth#setDepth} instead. + * @param value The z position of this Game Object. Default 0. + */ + setZ(value?: number): this; + + /** + * Sets the w position of this Game Object. + * @param value The w position of this Game Object. Default 0. + */ + setW(value?: number): this; + + /** + * Gets the local transform matrix for this Game Object. + * @param tempMatrix The matrix to populate with the values from this Game Object. + */ + getLocalTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + + /** + * Gets the world transform matrix for this Game Object, factoring in any parent Containers. + * @param tempMatrix The matrix to populate with the values from this Game Object. + * @param parentMatrix A temporary matrix to hold parent values during the calculations. + */ + getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. + */ + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + + /** + * Gets the sum total rotation of all of this Game Objects parent Containers. + * + * The returned value is in radians and will be zero if this Game Object has no parent container. + */ + getParentRotation(): number; + + /** + * The visible state of the Game Object. + * + * An invisible Game Object will skip rendering, but will still process update logic. + */ + visible: boolean; + + /** + * Sets the visibility of this Game Object. + * + * An invisible Game Object will skip rendering, but will still process update logic. + * @param value The visible state of the Game Object. + */ + setVisible(value: boolean): this; + + /** + * The horizontal scroll factor of this Game Object. + * + * The scroll factor controls the influence of the movement of a Camera upon this Game Object. + * + * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. + * It does not change the Game Objects actual position values. + * + * A value of 1 means it will move exactly in sync with a camera. + * A value of 0 means it will not move at all, even if the camera moves. + * Other values control the degree to which the camera movement is mapped to this Game Object. + * + * Please be aware that scroll factor values other than 1 are not taken in to consideration when + * calculating physics collisions. Bodies always collide based on their world position, but changing + * the scroll factor is a visual adjustment to where the textures are rendered, which can offset + * them from physics bodies if not accounted for in your code. + */ + scrollFactorX: number; + + /** + * The vertical scroll factor of this Game Object. + * + * The scroll factor controls the influence of the movement of a Camera upon this Game Object. + * + * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. + * It does not change the Game Objects actual position values. + * + * A value of 1 means it will move exactly in sync with a camera. + * A value of 0 means it will not move at all, even if the camera moves. + * Other values control the degree to which the camera movement is mapped to this Game Object. + * + * Please be aware that scroll factor values other than 1 are not taken in to consideration when + * calculating physics collisions. Bodies always collide based on their world position, but changing + * the scroll factor is a visual adjustment to where the textures are rendered, which can offset + * them from physics bodies if not accounted for in your code. + */ + scrollFactorY: number; + + /** + * Sets the scroll factor of this Game Object. + * + * The scroll factor controls the influence of the movement of a Camera upon this Game Object. + * + * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. + * It does not change the Game Objects actual position values. + * + * A value of 1 means it will move exactly in sync with a camera. + * A value of 0 means it will not move at all, even if the camera moves. + * Other values control the degree to which the camera movement is mapped to this Game Object. + * + * Please be aware that scroll factor values other than 1 are not taken in to consideration when + * calculating physics collisions. Bodies always collide based on their world position, but changing + * the scroll factor is a visual adjustment to where the textures are rendered, which can offset + * them from physics bodies if not accounted for in your code. + * @param x The horizontal scroll factor of this Game Object. + * @param y The vertical scroll factor of this Game Object. If not set it will use the `x` value. Default x. + */ + setScrollFactor(x: number, y?: number): this; + + } + namespace Particles { + /** + * A Particle Emitter property. + * + * Facilitates changing Particle properties as they are emitted and throughout their lifetime. + */ + class EmitterOp { /** - * Whether particles interact with the bottom edge of the emitter {@link Phaser.GameObjects.Particles.ParticleEmitter#bounds}. + * + * @param config Settings for the Particle Emitter that owns this property. + * @param key The name of the property. + * @param defaultValue The default value of the property. + * @param emitOnly Whether the property can only be modified when a Particle is emitted. Default false. */ - collideBottom: boolean; + constructor(config: Phaser.Types.GameObjects.Particles.ParticleEmitterConfig, key: string, defaultValue: number, emitOnly?: boolean); /** - * Whether this emitter updates itself and its particles. - * - * Controlled by {@link Phaser.GameObjects.Particles.ParticleEmitter#pause} - * and {@link Phaser.GameObjects.Particles.ParticleEmitter#resume}. + * The name of this property. */ - active: boolean; + propertyKey: string; /** - * Set this to false to hide any active particles. + * The value of this property. */ - visible: boolean; + propertyValue: number; /** - * The blend mode of this emitter's particles. + * The default value of this property. */ - blendMode: integer; + defaultValue: number; /** - * A Game Object whose position is used as the particle origin. + * The number of steps for stepped easing between {@link Phaser.GameObjects.Particles.EmitterOp#start} and + * {@link Phaser.GameObjects.Particles.EmitterOp#end} values, per emit. */ - follow: Phaser.GameObjects.GameObject; + steps: number; /** - * The offset of the particle origin from the {@link Phaser.GameObjects.Particles.ParticleEmitter#follow} target. + * The step counter for stepped easing, per emit. */ - followOffset: Phaser.Math.Vector2; + counter: number; /** - * Whether the emitter's {@link Phaser.GameObjects.Particles.ParticleEmitter#visible} state will track - * the {@link Phaser.GameObjects.Particles.ParticleEmitter#follow} target's visibility state. + * The start value for this property to ease between. */ - trackVisible: boolean; + start: number; /** - * The current texture frame, as an index of {@link Phaser.GameObjects.Particles.ParticleEmitter#frames}. + * The end value for this property to ease between. */ - currentFrame: integer; + end: number; /** - * Whether texture {@link Phaser.GameObjects.Particles.ParticleEmitter#frames} are selected at random. + * The easing function to use for updating this property. */ - randomFrame: boolean; + ease: Function; /** - * The number of consecutive particles that receive a single texture frame (per frame cycle). + * Whether this property can only be modified when a Particle is emitted. + * + * Set to `true` to allow only {@link Phaser.GameObjects.Particles.EmitterOp#onEmit} callbacks to be set and + * affect this property. + * + * Set to `false` to allow both {@link Phaser.GameObjects.Particles.EmitterOp#onEmit} and + * {@link Phaser.GameObjects.Particles.EmitterOp#onUpdate} callbacks to be set and affect this property. */ - frameQuantity: integer; + emitOnly: boolean; /** - * Merges configuration settings into the emitter's current settings. - * @param config Settings for this emitter. + * The callback to run for Particles when they are emitted from the Particle Emitter. */ - fromJSON(config: Phaser.Types.GameObjects.Particles.ParticleEmitterConfig): Phaser.GameObjects.Particles.ParticleEmitter; + onEmit: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitCallback; /** - * Creates a description of this emitter suitable for JSON serialization. - * @param output An object to copy output into. + * The callback to run for Particles when they are updated. */ - toJSON(output?: object): object; + onUpdate: Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateCallback; /** - * Continuously moves the particle origin to follow a Game Object's position. - * @param target The Game Object to follow. - * @param offsetX Horizontal offset of the particle origin from the Game Object. Default 0. - * @param offsetY Vertical offset of the particle origin from the Game Object. Default 0. - * @param trackVisible Whether the emitter's visible state will track the target's visible state. Default false. + * Load the property from a Particle Emitter configuration object. + * + * Optionally accepts a new property key to use, replacing the current one. + * @param config Settings for the Particle Emitter that owns this property. + * @param newKey The new key to use for this property, if any. */ - startFollow(target: Phaser.GameObjects.GameObject, offsetX?: number, offsetY?: number, trackVisible?: boolean): Phaser.GameObjects.Particles.ParticleEmitter; + loadConfig(config?: Phaser.Types.GameObjects.Particles.ParticleEmitterConfig, newKey?: string): void; /** - * Stops following a Game Object. + * Build a JSON representation of this Particle Emitter property. */ - stopFollow(): Phaser.GameObjects.Particles.ParticleEmitter; + toJSON(): object; /** - * Chooses a texture frame from {@link Phaser.GameObjects.Particles.ParticleEmitter#frames}. + * Change the current value of the property and update its callback methods. + * @param value The value of the property. */ - getFrame(): Phaser.Textures.Frame; + onChange(value: number): this; /** - * Sets a pattern for assigning texture frames to emitted particles. - * @param frames One or more texture frames, or a configuration object. - * @param pickRandom Whether frames should be assigned at random from `frames`. Default true. - * @param quantity The number of consecutive particles that will receive each frame. Default 1. + * Update the {@link Phaser.GameObjects.Particles.EmitterOp#onEmit} and + * {@link Phaser.GameObjects.Particles.EmitterOp#onUpdate} callbacks based on the type of the current + * {@link Phaser.GameObjects.Particles.EmitterOp#propertyValue}. */ - setFrame(frames: any[] | string | integer | Phaser.Types.GameObjects.Particles.ParticleEmitterFrameConfig, pickRandom?: boolean, quantity?: integer): Phaser.GameObjects.Particles.ParticleEmitter; + setMethods(): this; /** - * Turns {@link Phaser.GameObjects.Particles.ParticleEmitter#radial} particle movement on or off. - * @param value Radial mode (true) or point mode (true). Default true. + * Check whether an object has the given property. + * @param object The object to check. + * @param key The key of the property to look for in the object. */ - setRadial(value?: boolean): Phaser.GameObjects.Particles.ParticleEmitter; + has(object: object, key: string): boolean; /** - * Sets the position of the emitter's particle origin. - * New particles will be emitted here. - * @param x The x-coordinate of the particle origin. - * @param y The y-coordinate of the particle origin. + * Check whether an object has both of the given properties. + * @param object The object to check. + * @param key1 The key of the first property to check the object for. + * @param key2 The key of the second property to check the object for. */ - setPosition(x: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType, y: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType): Phaser.GameObjects.Particles.ParticleEmitter; + hasBoth(object: object, key1: string, key2: string): boolean; /** - * Sets or modifies a rectangular boundary constraining the particles. - * - * To remove the boundary, set {@link Phaser.GameObjects.Particles.ParticleEmitter#bounds} to null. - * @param x The x-coordinate of the left edge of the boundary, or an object representing a rectangle. - * @param y The y-coordinate of the top edge of the boundary. - * @param width The width of the boundary. - * @param height The height of the boundary. + * Check whether an object has at least one of the given properties. + * @param object The object to check. + * @param key1 The key of the first property to check the object for. + * @param key2 The key of the second property to check the object for. */ - setBounds(x: number | Phaser.Types.GameObjects.Particles.ParticleEmitterBounds | Phaser.Types.GameObjects.Particles.ParticleEmitterBoundsAlt, y: number, width: number, height: number): Phaser.GameObjects.Particles.ParticleEmitter; + hasEither(object: object, key1: string, key2: string): boolean; /** - * Sets the initial horizontal speed of emitted particles. - * Changes the emitter to point mode. - * @param value The speed, in pixels per second. + * The returned value sets what the property will be at the START of the particles life, on emit. + * @param particle The particle. + * @param key The name of the property. + * @param value The current value of the property. */ - setSpeedX(value: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType): Phaser.GameObjects.Particles.ParticleEmitter; + defaultEmit(particle: Phaser.GameObjects.Particles.Particle, key: string, value?: number): number; /** - * Sets the initial vertical speed of emitted particles. - * Changes the emitter to point mode. - * @param value The speed, in pixels per second. + * The returned value updates the property for the duration of the particles life. + * @param particle The particle. + * @param key The name of the property. + * @param t The T value (between 0 and 1) + * @param value The current value of the property. */ - setSpeedY(value: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType): Phaser.GameObjects.Particles.ParticleEmitter; + defaultUpdate(particle: Phaser.GameObjects.Particles.Particle, key: string, t: number, value: number): number; /** - * Sets the initial radial speed of emitted particles. - * Changes the emitter to radial mode. - * @param value The speed, in pixels per second. + * An `onEmit` callback that returns the current value of the property. */ - setSpeed(value: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType): Phaser.GameObjects.Particles.ParticleEmitter; + staticValueEmit(): number; /** - * Sets the horizontal scale of emitted particles. - * @param value The scale, relative to 1. + * An `onUpdate` callback that returns the current value of the property. */ - setScaleX(value: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType | Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateType): Phaser.GameObjects.Particles.ParticleEmitter; + staticValueUpdate(): number; /** - * Sets the vertical scale of emitted particles. - * @param value The scale, relative to 1. + * An `onEmit` callback that returns a random value from the current value array. */ - setScaleY(value: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType | Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateType): Phaser.GameObjects.Particles.ParticleEmitter; + randomStaticValueEmit(): number; /** - * Sets the scale of emitted particles. - * @param value The scale, relative to 1. + * An `onEmit` callback that returns a value between the {@link Phaser.GameObjects.Particles.EmitterOp#start} and + * {@link Phaser.GameObjects.Particles.EmitterOp#end} range. + * @param particle The particle. + * @param key The key of the property. */ - setScale(value: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType | Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateType): Phaser.GameObjects.Particles.ParticleEmitter; + randomRangedValueEmit(particle: Phaser.GameObjects.Particles.Particle, key: string): number; /** - * Sets the horizontal gravity applied to emitted particles. - * @param value Acceleration due to gravity, in pixels per second squared. + * An `onEmit` callback that returns a stepped value between the + * {@link Phaser.GameObjects.Particles.EmitterOp#start} and {@link Phaser.GameObjects.Particles.EmitterOp#end} + * range. */ - setGravityX(value: number): Phaser.GameObjects.Particles.ParticleEmitter; + steppedEmit(): number; /** - * Sets the vertical gravity applied to emitted particles. - * @param value Acceleration due to gravity, in pixels per second squared. + * An `onEmit` callback for an eased property. + * + * It prepares the particle for easing by {@link Phaser.GameObjects.Particles.EmitterOp#easeValueUpdate}. + * @param particle The particle. + * @param key The name of the property. */ - setGravityY(value: number): Phaser.GameObjects.Particles.ParticleEmitter; + easedValueEmit(particle: Phaser.GameObjects.Particles.Particle, key: string): number; /** - * Sets the gravity applied to emitted particles. - * @param x Horizontal acceleration due to gravity, in pixels per second squared. - * @param y Vertical acceleration due to gravity, in pixels per second squared. + * An `onUpdate` callback that returns an eased value between the + * {@link Phaser.GameObjects.Particles.EmitterOp#start} and {@link Phaser.GameObjects.Particles.EmitterOp#end} + * range. + * @param particle The particle. + * @param key The name of the property. + * @param t The T value (between 0 and 1) */ - setGravity(x: number, y: number): Phaser.GameObjects.Particles.ParticleEmitter; + easeValueUpdate(particle: Phaser.GameObjects.Particles.Particle, key: string, t: number): number; + + } + /** + * The GravityWell action applies a force on the particle to draw it towards, or repel it from, a single point. + * + * The force applied is inversely proportional to the square of the distance from the particle to the point, in accordance with Newton's law of gravity. + * + * This simulates the effect of gravity over large distances (as between planets, for example). + */ + class GravityWell { /** - * Sets the opacity of emitted particles. - * @param value A value between 0 (transparent) and 1 (opaque). + * + * @param x The x coordinate of the Gravity Well, in world space. Default 0. + * @param y The y coordinate of the Gravity Well, in world space. Default 0. + * @param power The strength of the gravity force - larger numbers produce a stronger force. Default 0. + * @param epsilon The minimum distance for which the gravity force is calculated. Default 100. + * @param gravity The gravitational force of this Gravity Well. Default 50. */ - setAlpha(value: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType | Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateType): Phaser.GameObjects.Particles.ParticleEmitter; + constructor(x?: number | Phaser.Types.GameObjects.Particles.GravityWellConfig, y?: number, power?: number, epsilon?: number, gravity?: number); /** - * Sets the color tint of emitted particles. - * @param value A value between 0 and 0xffffff. + * The x coordinate of the Gravity Well, in world space. */ - setTint(value: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType | Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateType): Phaser.GameObjects.Particles.ParticleEmitter; + x: number; /** - * Sets the angle of a {@link Phaser.GameObjects.Particles.ParticleEmitter#radial} particle stream. - * @param value The angle of the initial velocity of emitted particles. + * The y coordinate of the Gravity Well, in world space. */ - setEmitterAngle(value: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType): Phaser.GameObjects.Particles.ParticleEmitter; + y: number; /** - * Sets the angle of a {@link Phaser.GameObjects.Particles.ParticleEmitter#radial} particle stream. - * @param value The angle of the initial velocity of emitted particles. + * The active state of the Gravity Well. An inactive Gravity Well will not influence any particles. */ - setAngle(value: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType): Phaser.GameObjects.Particles.ParticleEmitter; + active: boolean; /** - * Sets the lifespan of newly emitted particles. - * @param value The particle lifespan, in ms. + * The strength of the gravity force - larger numbers produce a stronger force. */ - setLifespan(value: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType): Phaser.GameObjects.Particles.ParticleEmitter; + power: number; /** - * Sets the number of particles released at each flow cycle or explosion. - * @param quantity The number of particles to release at each flow cycle or explosion. + * The minimum distance for which the gravity force is calculated. */ - setQuantity(quantity: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType): Phaser.GameObjects.Particles.ParticleEmitter; + epsilon: number; /** - * Sets the emitter's {@link Phaser.GameObjects.Particles.ParticleEmitter#frequency} - * and {@link Phaser.GameObjects.Particles.ParticleEmitter#quantity}. - * @param frequency The time interval (>= 0) of each flow cycle, in ms; or -1 to put the emitter in explosion mode. - * @param quantity The number of particles to release at each flow cycle or explosion. + * Takes a Particle and updates it based on the properties of this Gravity Well. + * @param particle The Particle to update. + * @param delta The delta time in ms. + * @param step The delta value divided by 1000. */ - setFrequency(frequency: number, quantity?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType): Phaser.GameObjects.Particles.ParticleEmitter; + update(particle: Phaser.GameObjects.Particles.Particle, delta: number, step: number): void; + + } + /** + * A Particle is a simple Game Object controlled by a Particle Emitter and Manager, and rendered by the Manager. + * It uses its own lightweight physics system, and can interact only with its Emitter's bounds and zones. + */ + class Particle { /** - * Sets or removes the {@link Phaser.GameObjects.Particles.ParticleEmitter#emitZone}. * - * An {@link Phaser.Types.GameObjects.Particles.ParticleEmitterEdgeZoneConfig EdgeZone} places particles on its edges. Its {@link Phaser.Types.GameObjects.Particles.EdgeZoneSource source} can be a Curve, Path, Circle, Ellipse, Line, Polygon, Rectangle, or Triangle; or any object with a suitable {@link Phaser.Types.GameObjects.Particles.EdgeZoneSourceCallback getPoints} method. + * @param emitter The Emitter to which this Particle belongs. + */ + constructor(emitter: Phaser.GameObjects.Particles.ParticleEmitter); + + /** + * The Emitter to which this Particle belongs. * - * A {@link Phaser.Types.GameObjects.Particles.ParticleEmitterRandomZoneConfig RandomZone} places randomly within its interior. Its {@link RandomZoneSource source} can be a Circle, Ellipse, Line, Polygon, Rectangle, or Triangle; or any object with a suitable {@link Phaser.Types.GameObjects.Particles.RandomZoneSourceCallback getRandomPoint} method. - * @param zoneConfig An object describing the zone, or `undefined` to remove any current emit zone. + * A Particle can only belong to a single Emitter and is created, updated and destroyed via it. */ - setEmitZone(zoneConfig?: Phaser.Types.GameObjects.Particles.ParticleEmitterEdgeZoneConfig | Phaser.Types.GameObjects.Particles.ParticleEmitterRandomZoneConfig): Phaser.GameObjects.Particles.ParticleEmitter; + emitter: Phaser.GameObjects.Particles.ParticleEmitter; /** - * Sets or removes the {@link Phaser.GameObjects.Particles.ParticleEmitter#deathZone}. - * @param zoneConfig An object describing the zone, or `undefined` to remove any current death zone. + * The texture frame used to render this Particle. */ - setDeathZone(zoneConfig?: Phaser.Types.GameObjects.Particles.ParticleEmitterDeathZoneConfig): Phaser.GameObjects.Particles.ParticleEmitter; + frame: Phaser.Textures.Frame; /** - * Creates inactive particles and adds them to this emitter's pool. - * @param particleCount The number of particles to create. + * The x coordinate of this Particle. */ - reserve(particleCount: integer): Phaser.GameObjects.Particles.ParticleEmitter; + x: number; /** - * Gets the number of active (in-use) particles in this emitter. + * The y coordinate of this Particle. */ - getAliveParticleCount(): integer; + y: number; /** - * Gets the number of inactive (available) particles in this emitter. + * The x velocity of this Particle. */ - getDeadParticleCount(): integer; + velocityX: number; /** - * Gets the total number of particles in this emitter. + * The y velocity of this Particle. */ - getParticleCount(): integer; + velocityY: number; /** - * Whether this emitter is at its limit (if set). + * The x acceleration of this Particle. */ - atLimit(): boolean; + accelerationX: number; /** - * Sets a function to call for each newly emitted particle. - * @param callback The function. - * @param context The calling context. + * The y acceleration of this Particle. */ - onParticleEmit(callback: Phaser.Types.GameObjects.Particles.ParticleEmitterCallback, context?: any): Phaser.GameObjects.Particles.ParticleEmitter; + accelerationY: number; /** - * Sets a function to call for each particle death. - * @param callback The function. - * @param context The function's calling context. + * The maximum horizontal velocity this Particle can travel at. */ - onParticleDeath(callback: Phaser.Types.GameObjects.Particles.ParticleDeathCallback, context?: any): Phaser.GameObjects.Particles.ParticleEmitter; + maxVelocityX: number; /** - * Deactivates every particle in this emitter. + * The maximum vertical velocity this Particle can travel at. */ - killAll(): Phaser.GameObjects.Particles.ParticleEmitter; + maxVelocityY: number; /** - * Calls a function for each active particle in this emitter. - * @param callback The function. - * @param context The function's calling context. + * The bounciness, or restitution, of this Particle. */ - forEachAlive(callback: Phaser.Types.GameObjects.Particles.ParticleEmitterCallback, context: any): Phaser.GameObjects.Particles.ParticleEmitter; + bounce: number; /** - * Calls a function for each inactive particle in this emitter. - * @param callback The function. - * @param context The function's calling context. + * The horizontal scale of this Particle. */ - forEachDead(callback: Phaser.Types.GameObjects.Particles.ParticleEmitterCallback, context: any): Phaser.GameObjects.Particles.ParticleEmitter; + scaleX: number; /** - * Turns {@link Phaser.GameObjects.Particles.ParticleEmitter#on} the emitter and resets the flow counter. - * - * If this emitter is in flow mode (frequency >= 0; the default), the particle flow will start (or restart). - * - * If this emitter is in explode mode (frequency = -1), nothing will happen. - * Use {@link Phaser.GameObjects.Particles.ParticleEmitter#explode} or {@link Phaser.GameObjects.Particles.ParticleEmitter#flow} instead. + * The vertical scale of this Particle. */ - start(): Phaser.GameObjects.Particles.ParticleEmitter; + scaleY: number; /** - * Turns {@link Phaser.GameObjects.Particles.ParticleEmitter#on off} the emitter. + * The alpha value of this Particle. */ - stop(): Phaser.GameObjects.Particles.ParticleEmitter; + alpha: number; /** - * {@link Phaser.GameObjects.Particles.ParticleEmitter#active Deactivates} the emitter. + * The angle of this Particle in degrees. */ - pause(): Phaser.GameObjects.Particles.ParticleEmitter; + angle: number; /** - * {@link Phaser.GameObjects.Particles.ParticleEmitter#active Activates} the emitter. + * The angle of this Particle in radians. */ - resume(): Phaser.GameObjects.Particles.ParticleEmitter; + rotation: number; /** - * Removes the emitter from its manager and the scene. + * The tint applied to this Particle. */ - remove(): Phaser.GameObjects.Particles.ParticleEmitter; + tint: number; /** - * Sorts active particles with {@link Phaser.GameObjects.Particles.ParticleEmitter#depthSortCallback}. + * The lifespan of this Particle in ms. */ - depthSort(): Phaser.GameObjects.Particles.ParticleEmitter; + life: number; /** - * Puts the emitter in flow mode (frequency >= 0) and starts (or restarts) a particle flow. - * - * To resume a flow at the current frequency and quantity, use {@link Phaser.GameObjects.Particles.ParticleEmitter#start} instead. - * @param frequency The time interval (>= 0) of each flow cycle, in ms. - * @param count The number of particles to emit at each flow cycle. Default 1. + * The current life of this Particle in ms. */ - flow(frequency: number, count?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType): Phaser.GameObjects.Particles.ParticleEmitter; + lifeCurrent: number; /** - * Puts the emitter in explode mode (frequency = -1), stopping any current particle flow, and emits several particles all at once. - * @param count The amount of Particles to emit. - * @param x The x coordinate to emit the Particles from. - * @param y The y coordinate to emit the Particles from. + * The delay applied to this Particle upon emission, in ms. */ - explode(count: integer, x: number, y: number): Phaser.GameObjects.Particles.Particle; + delayCurrent: number; /** - * Emits particles at a given position (or the emitter's current position). - * @param x The x coordinate to emit the Particles from. Default this.x. - * @param y The y coordinate to emit the Particles from. Default this.x. - * @param count The number of Particles to emit. Default this.quantity. + * The normalized lifespan T value, where 0 is the start and 1 is the end. */ - emitParticleAt(x?: number, y?: number, count?: integer): Phaser.GameObjects.Particles.Particle; + lifeT: number; /** - * Emits particles at a given position (or the emitter's current position). - * @param count The number of Particles to emit. Default this.quantity. - * @param x The x coordinate to emit the Particles from. Default this.x. - * @param y The y coordinate to emit the Particles from. Default this.x. + * The data used by the ease equation. */ - emitParticle(count?: integer, x?: number, y?: number): Phaser.GameObjects.Particles.Particle; + data: object; /** - * Updates this emitter and its particles. - * @param time The current timestamp as generated by the Request Animation Frame or SetTimeout. - * @param delta The delta time, in ms, elapsed since the last frame. + * Checks to see if this Particle is alive and updating. */ - preUpdate(time: integer, delta: number): void; + isAlive(): boolean; /** - * Calculates the difference of two particles, for sorting them by depth. - * @param a The first particle. - * @param b The second particle. + * Resets the position of this particle back to zero. */ - depthSortCallback(a: object, b: object): integer; + resetPosition(): void; /** - * Sets the Blend Mode being used by this Game Object. - * - * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) - * - * Under WebGL only the following Blend Modes are available: - * - * * ADD - * * MULTIPLY - * * SCREEN - * * ERASE (only works when rendering to a framebuffer, like a Render Texture) - * - * Canvas has more available depending on browser support. - * - * You can also create your own custom Blend Modes in WebGL. - * - * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending - * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these - * reasons try to be careful about the construction of your Scene and the frequency in which blend modes - * are used. - * @param value The BlendMode value. Either a string or a CONST. + * Starts this Particle from the given coordinates. + * @param x The x coordinate to launch this Particle from. + * @param y The y coordinate to launch this Particle from. */ - setBlendMode(value: string | Phaser.BlendModes): this; + fire(x: number, y: number): void; /** - * The Mask this Game Object is using during render. + * An internal method that calculates the velocity of the Particle. + * @param emitter The Emitter that is updating this Particle. + * @param delta The delta time in ms. + * @param step The delta value divided by 1000. + * @param processors Particle processors (gravity wells). */ - mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask; + computeVelocity(emitter: Phaser.GameObjects.Particles.ParticleEmitter, delta: number, step: number, processors: any[]): void; /** - * Sets the mask that this Game Object will use to render with. - * - * The mask must have been previously created and can be either a GeometryMask or a BitmapMask. - * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. - * - * If a mask is already set on this Game Object it will be immediately replaced. - * - * Masks are positioned in global space and are not relative to the Game Object to which they - * are applied. The reason for this is that multiple Game Objects can all share the same mask. + * Checks if this Particle is still within the bounds defined by the given Emitter. * - * Masks have no impact on physics or input detection. They are purely a rendering component - * that allows you to limit what is visible during the render pass. - * @param mask The mask this Game Object will use when rendering. + * If not, and depending on the Emitter collision flags, the Particle may either stop or rebound. + * @param emitter The Emitter to check the bounds against. */ - setMask(mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask): this; + checkBounds(emitter: Phaser.GameObjects.Particles.ParticleEmitter): void; /** - * Clears the mask that this Game Object was using. - * @param destroyMask Destroy the mask before clearing it? Default false. + * The main update method for this Particle. + * + * Updates its life values, computes the velocity and repositions the Particle. + * @param delta The delta time in ms. + * @param step The delta value divided by 1000. + * @param processors An optional array of update processors. */ - clearMask(destroyMask?: boolean): this; + update(delta: number, step: number, processors: any[]): boolean; + + } + /** + * A particle emitter represents a single particle stream. + * It controls a pool of {@link Phaser.GameObjects.Particles.Particle Particles} and is controlled by a {@link Phaser.GameObjects.Particles.ParticleEmitterManager Particle Emitter Manager}. + */ + class ParticleEmitter implements Phaser.GameObjects.Components.BlendMode, Phaser.GameObjects.Components.Mask, Phaser.GameObjects.Components.ScrollFactor, Phaser.GameObjects.Components.Visible { /** - * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, - * including this one. - * - * To create the mask you need to pass in a reference to a renderable Game Object. - * A renderable Game Object is one that uses a texture to render with, such as an - * Image, Sprite, Render Texture or BitmapText. * - * If you do not provide a renderable object, and this Game Object has a texture, - * it will use itself as the object. This means you can call this method to create - * a Bitmap Mask from any renderable Game Object. - * @param renderable A renderable Game Object that uses a texture, such as a Sprite. + * @param manager The Emitter Manager this Emitter belongs to. + * @param config Settings for this emitter. */ - createBitmapMask(renderable?: Phaser.GameObjects.GameObject): Phaser.Display.Masks.BitmapMask; + constructor(manager: Phaser.GameObjects.Particles.ParticleEmitterManager, config: Phaser.Types.GameObjects.Particles.ParticleEmitterConfig); /** - * Creates and returns a Geometry Mask. This mask can be used by any Game Object, - * including this one. - * - * To create the mask you need to pass in a reference to a Graphics Game Object. - * - * If you do not provide a graphics object, and this Game Object is an instance - * of a Graphics object, then it will use itself to create the mask. - * - * This means you can call this method to create a Geometry Mask from any Graphics Game Object. - * @param graphics A Graphics Game Object. The geometry within it will be used as the mask. + * The Emitter Manager this Emitter belongs to. */ - createGeometryMask(graphics?: Phaser.GameObjects.Graphics): Phaser.Display.Masks.GeometryMask; + manager: Phaser.GameObjects.Particles.ParticleEmitterManager; /** - * The horizontal scroll factor of this Game Object. - * - * The scroll factor controls the influence of the movement of a Camera upon this Game Object. - * - * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. - * It does not change the Game Objects actual position values. - * - * A value of 1 means it will move exactly in sync with a camera. - * A value of 0 means it will not move at all, even if the camera moves. - * Other values control the degree to which the camera movement is mapped to this Game Object. - * - * Please be aware that scroll factor values other than 1 are not taken in to consideration when - * calculating physics collisions. Bodies always collide based on their world position, but changing - * the scroll factor is a visual adjustment to where the textures are rendered, which can offset - * them from physics bodies if not accounted for in your code. + * The texture assigned to particles. */ - scrollFactorX: number; + texture: Phaser.Textures.Texture; /** - * The vertical scroll factor of this Game Object. - * - * The scroll factor controls the influence of the movement of a Camera upon this Game Object. - * - * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. - * It does not change the Game Objects actual position values. - * - * A value of 1 means it will move exactly in sync with a camera. - * A value of 0 means it will not move at all, even if the camera moves. - * Other values control the degree to which the camera movement is mapped to this Game Object. - * - * Please be aware that scroll factor values other than 1 are not taken in to consideration when - * calculating physics collisions. Bodies always collide based on their world position, but changing - * the scroll factor is a visual adjustment to where the textures are rendered, which can offset - * them from physics bodies if not accounted for in your code. + * The texture frames assigned to particles. */ - scrollFactorY: number; + frames: Phaser.Textures.Frame[]; /** - * Sets the scroll factor of this Game Object. - * - * The scroll factor controls the influence of the movement of a Camera upon this Game Object. - * - * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. - * It does not change the Game Objects actual position values. - * - * A value of 1 means it will move exactly in sync with a camera. - * A value of 0 means it will not move at all, even if the camera moves. - * Other values control the degree to which the camera movement is mapped to this Game Object. - * - * Please be aware that scroll factor values other than 1 are not taken in to consideration when - * calculating physics collisions. Bodies always collide based on their world position, but changing - * the scroll factor is a visual adjustment to where the textures are rendered, which can offset - * them from physics bodies if not accounted for in your code. - * @param x The horizontal scroll factor of this Game Object. - * @param y The vertical scroll factor of this Game Object. If not set it will use the `x` value. Default x. + * The default texture frame assigned to particles. */ - setScrollFactor(x: number, y?: number): this; + defaultFrame: Phaser.Textures.Frame; /** - * Sets the visibility of this Game Object. - * - * An invisible Game Object will skip rendering, but will still process update logic. - * @param value The visible state of the Game Object. + * Names of simple configuration properties. */ - setVisible(value: boolean): this; - - } + configFastMap: object; - /** - * A Particle Emitter Manager creates and controls {@link Phaser.GameObjects.Particles.ParticleEmitter Particle Emitters} and {@link Phaser.GameObjects.Particles.GravityWell Gravity Wells}. - */ - class ParticleEmitterManager extends Phaser.GameObjects.GameObject implements Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.Mask, Phaser.GameObjects.Components.Pipeline, Phaser.GameObjects.Components.Transform, Phaser.GameObjects.Components.Visible { /** - * - * @param scene The Scene to which this Emitter Manager belongs. - * @param texture The key of the Texture this Emitter Manager will use to render particles, as stored in the Texture Manager. - * @param frame An optional frame from the Texture this Emitter Manager will use to render particles. - * @param emitters Configuration settings for one or more emitters to create. + * Names of complex configuration properties. */ - constructor(scene: Phaser.Scene, texture: string, frame?: string | integer, emitters?: Phaser.Types.GameObjects.Particles.ParticleEmitterConfig | Phaser.Types.GameObjects.Particles.ParticleEmitterConfig[]); + configOpMap: object; /** - * The time scale applied to all emitters and particles, affecting flow rate, lifespan, and movement. - * Values larger than 1 are faster than normal. - * This is multiplied with any timeScale set on each individual emitter. + * The name of this Particle Emitter. + * + * Empty by default and never populated by Phaser, this is left for developers to use. */ - timeScale: number; + name: string; /** - * The texture used to render this Emitter Manager's particles. + * The Particle Class which will be emitted by this Emitter. */ - texture: Phaser.Textures.Texture; + particleClass: Phaser.GameObjects.Particles.Particle; /** - * The texture frame used to render this Emitter Manager's particles. + * The x-coordinate of the particle origin (where particles will be emitted). */ - frame: Phaser.Textures.Frame; + x: Phaser.GameObjects.Particles.EmitterOp; /** - * Names of this Emitter Manager's texture frames. + * The y-coordinate of the particle origin (where particles will be emitted). */ - frameNames: string[]; + y: Phaser.GameObjects.Particles.EmitterOp; /** - * A list of Emitters being managed by this Emitter Manager. + * A radial emitter will emit particles in all directions between angle min and max, + * using {@link Phaser.GameObjects.Particles.ParticleEmitter#speed} as the value. If set to false then this acts as a point Emitter. + * A point emitter will emit particles only in the direction derived from the speedX and speedY values. */ - emitters: Phaser.Structs.List; + radial: boolean; /** - * A list of Gravity Wells being managed by this Emitter Manager. + * Horizontal acceleration applied to emitted particles, in pixels per second squared. */ - wells: Phaser.Structs.List; + gravityX: number; /** - * Sets the texture and frame this Emitter Manager will use to render with. - * - * Textures are referenced by their string-based keys, as stored in the Texture Manager. - * @param key The key of the texture to be used, as stored in the Texture Manager. - * @param frame The name or index of the frame within the Texture. + * Vertical acceleration applied to emitted particles, in pixels per second squared. */ - setTexture(key: string, frame?: string | integer): Phaser.GameObjects.Particles.ParticleEmitterManager; + gravityY: number; /** - * Sets the frame this Emitter Manager will use to render with. - * - * The Frame has to belong to the current Texture being used. - * - * It can be either a string or an index. - * @param frame The name or index of the frame within the Texture. + * Whether accelerationX and accelerationY are non-zero. Set automatically during configuration. */ - setFrame(frame?: string | integer): Phaser.GameObjects.Particles.ParticleEmitterManager; + acceleration: boolean; /** - * Assigns texture frames to an emitter. - * @param frames The texture frames. - * @param emitter The particle emitter to modify. + * Horizontal acceleration applied to emitted particles, in pixels per second squared. */ - setEmitterFrames(frames: Phaser.Textures.Frame | Phaser.Textures.Frame[], emitter: Phaser.GameObjects.Particles.ParticleEmitter): Phaser.GameObjects.Particles.ParticleEmitterManager; + accelerationX: Phaser.GameObjects.Particles.EmitterOp; /** - * Adds an existing Particle Emitter to this Emitter Manager. - * @param emitter The Particle Emitter to add to this Emitter Manager. + * Vertical acceleration applied to emitted particles, in pixels per second squared. */ - addEmitter(emitter: Phaser.GameObjects.Particles.ParticleEmitter): Phaser.GameObjects.Particles.ParticleEmitter; + accelerationY: Phaser.GameObjects.Particles.EmitterOp; /** - * Creates a new Particle Emitter object, adds it to this Emitter Manager and returns a reference to it. - * @param config Configuration settings for the Particle Emitter to create. + * The maximum horizontal velocity of emitted particles, in pixels per second squared. */ - createEmitter(config: Phaser.Types.GameObjects.Particles.ParticleEmitterConfig): Phaser.GameObjects.Particles.ParticleEmitter; + maxVelocityX: Phaser.GameObjects.Particles.EmitterOp; /** - * Removes a Particle Emitter from this Emitter Manager, if the Emitter belongs to this Manager. + * The maximum vertical velocity of emitted particles, in pixels per second squared. */ - removeEmitter(emitter: Phaser.GameObjects.Particles.ParticleEmitter): Phaser.GameObjects.Particles.ParticleEmitter; + maxVelocityY: Phaser.GameObjects.Particles.EmitterOp; /** - * Adds an existing Gravity Well object to this Emitter Manager. - * @param well The Gravity Well to add to this Emitter Manager. + * The initial horizontal speed of emitted particles, in pixels per second. */ - addGravityWell(well: Phaser.GameObjects.Particles.GravityWell): Phaser.GameObjects.Particles.GravityWell; + speedX: Phaser.GameObjects.Particles.EmitterOp; /** - * Creates a new Gravity Well, adds it to this Emitter Manager and returns a reference to it. - * @param config Configuration settings for the Gravity Well to create. + * The initial vertical speed of emitted particles, in pixels per second. */ - createGravityWell(config: Phaser.Types.GameObjects.Particles.GravityWellConfig): Phaser.GameObjects.Particles.GravityWell; + speedY: Phaser.GameObjects.Particles.EmitterOp; /** - * Emits particles from each active emitter. - * @param count The number of particles to release from each emitter. The default is the emitter's own {@link Phaser.GameObjects.Particles.ParticleEmitter#quantity}. - * @param x The x-coordinate to to emit particles from. The default is the x-coordinate of the emitter's current location. - * @param y The y-coordinate to to emit particles from. The default is the y-coordinate of the emitter's current location. + * Whether moveToX and moveToY are nonzero. Set automatically during configuration. */ - emitParticle(count?: integer, x?: number, y?: number): Phaser.GameObjects.Particles.ParticleEmitterManager; + moveTo: boolean; /** - * Emits particles from each active emitter. - * @param x The x-coordinate to to emit particles from. The default is the x-coordinate of the emitter's current location. - * @param y The y-coordinate to to emit particles from. The default is the y-coordinate of the emitter's current location. - * @param count The number of particles to release from each emitter. The default is the emitter's own {@link Phaser.GameObjects.Particles.ParticleEmitter#quantity}. + * The x-coordinate emitted particles move toward, when {@link Phaser.GameObjects.Particles.ParticleEmitter#moveTo} is true. */ - emitParticleAt(x?: number, y?: number, count?: integer): Phaser.GameObjects.Particles.ParticleEmitterManager; + moveToX: Phaser.GameObjects.Particles.EmitterOp; /** - * Pauses this Emitter Manager. - * - * This has the effect of pausing all emitters, and all particles of those emitters, currently under its control. - * - * The particles will still render, but they will not have any of their logic updated. + * The y-coordinate emitted particles move toward, when {@link Phaser.GameObjects.Particles.ParticleEmitter#moveTo} is true. */ - pause(): Phaser.GameObjects.Particles.ParticleEmitterManager; + moveToY: Phaser.GameObjects.Particles.EmitterOp; /** - * Resumes this Emitter Manager, should it have been previously paused. + * Whether particles will rebound when they meet the emitter bounds. */ - resume(): Phaser.GameObjects.Particles.ParticleEmitterManager; + bounce: Phaser.GameObjects.Particles.EmitterOp; /** - * Gets all active particle processors (gravity wells). + * The horizontal scale of emitted particles. */ - getProcessors(): Phaser.GameObjects.Particles.GravityWell[]; + scaleX: Phaser.GameObjects.Particles.EmitterOp; /** - * Updates all active emitters. - * @param time The current timestamp as generated by the Request Animation Frame or SetTimeout. - * @param delta The delta time, in ms, elapsed since the last frame. + * The vertical scale of emitted particles. */ - preUpdate(time: integer, delta: number): void; + scaleY: Phaser.GameObjects.Particles.EmitterOp; /** - * The depth of this Game Object within the Scene. - * - * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order - * of Game Objects, without actually moving their position in the display list. - * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth - * value will always render in front of one with a lower value. - * - * Setting the depth will queue a depth sort event within the Scene. + * Color tint applied to emitted particles. Value must not include the alpha channel. */ - depth: number; + tint: Phaser.GameObjects.Particles.EmitterOp; /** - * The depth of this Game Object within the Scene. - * - * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order - * of Game Objects, without actually moving their position in the display list. - * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth - * value will always render in front of one with a lower value. - * - * Setting the depth will queue a depth sort event within the Scene. - * @param value The depth of this Game Object. + * The alpha (transparency) of emitted particles. */ - setDepth(value: integer): this; + alpha: Phaser.GameObjects.Particles.EmitterOp; /** - * The Mask this Game Object is using during render. + * The lifespan of emitted particles, in ms. */ - mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask; + lifespan: Phaser.GameObjects.Particles.EmitterOp; /** - * Sets the mask that this Game Object will use to render with. - * - * The mask must have been previously created and can be either a GeometryMask or a BitmapMask. - * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. - * - * If a mask is already set on this Game Object it will be immediately replaced. - * - * Masks are positioned in global space and are not relative to the Game Object to which they - * are applied. The reason for this is that multiple Game Objects can all share the same mask. - * - * Masks have no impact on physics or input detection. They are purely a rendering component - * that allows you to limit what is visible during the render pass. - * @param mask The mask this Game Object will use when rendering. + * The angle of the initial velocity of emitted particles, in degrees. */ - setMask(mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask): this; + angle: Phaser.GameObjects.Particles.EmitterOp; /** - * Clears the mask that this Game Object was using. - * @param destroyMask Destroy the mask before clearing it? Default false. + * The rotation of emitted particles, in degrees. */ - clearMask(destroyMask?: boolean): this; + rotate: Phaser.GameObjects.Particles.EmitterOp; /** - * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, - * including this one. - * - * To create the mask you need to pass in a reference to a renderable Game Object. - * A renderable Game Object is one that uses a texture to render with, such as an - * Image, Sprite, Render Texture or BitmapText. - * - * If you do not provide a renderable object, and this Game Object has a texture, - * it will use itself as the object. This means you can call this method to create - * a Bitmap Mask from any renderable Game Object. - * @param renderable A renderable Game Object that uses a texture, such as a Sprite. + * A function to call when a particle is emitted. */ - createBitmapMask(renderable?: Phaser.GameObjects.GameObject): Phaser.Display.Masks.BitmapMask; + emitCallback: Phaser.Types.GameObjects.Particles.ParticleEmitterCallback; /** - * Creates and returns a Geometry Mask. This mask can be used by any Game Object, - * including this one. - * - * To create the mask you need to pass in a reference to a Graphics Game Object. - * - * If you do not provide a graphics object, and this Game Object is an instance - * of a Graphics object, then it will use itself to create the mask. - * - * This means you can call this method to create a Geometry Mask from any Graphics Game Object. - * @param graphics A Graphics Game Object. The geometry within it will be used as the mask. + * The calling context for {@link Phaser.GameObjects.Particles.ParticleEmitter#emitCallback}. */ - createGeometryMask(graphics?: Phaser.GameObjects.Graphics): Phaser.Display.Masks.GeometryMask; + emitCallbackScope: any; /** - * The initial WebGL pipeline of this Game Object. + * A function to call when a particle dies. */ - defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; + deathCallback: Phaser.Types.GameObjects.Particles.ParticleDeathCallback; /** - * The current WebGL pipeline of this Game Object. + * The calling context for {@link Phaser.GameObjects.Particles.ParticleEmitter#deathCallback}. */ - pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + deathCallbackScope: any; /** - * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. + * Set to hard limit the amount of particle objects this emitter is allowed to create. + * 0 means unlimited. */ - initPipeline(pipelineName?: string): boolean; + maxParticles: number; /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. + * How many particles are emitted each time particles are emitted (one explosion or one flow cycle). */ - setPipeline(pipelineName: string): this; + quantity: Phaser.GameObjects.Particles.EmitterOp; /** - * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * How many ms to wait after emission before the particles start updating. */ - resetPipeline(): boolean; + delay: Phaser.GameObjects.Particles.EmitterOp; /** - * Gets the name of the WebGL Pipeline this Game Object is currently using. + * For a flow emitter, the time interval (>= 0) between particle flow cycles in ms. + * A value of 0 means there is one particle flow cycle for each logic update (the maximum flow frequency). This is the default setting. + * For an exploding emitter, this value will be -1. + * Calling {@link Phaser.GameObjects.Particles.ParticleEmitter#flow} also puts the emitter in flow mode (frequency >= 0). + * Calling {@link Phaser.GameObjects.Particles.ParticleEmitter#explode} also puts the emitter in explode mode (frequency = -1). */ - getPipelineName(): string; + frequency: number; /** - * The x position of this Game Object. + * Controls if the emitter is currently emitting a particle flow (when frequency >= 0). + * Already alive particles will continue to update until they expire. + * Controlled by {@link Phaser.GameObjects.Particles.ParticleEmitter#start} and {@link Phaser.GameObjects.Particles.ParticleEmitter#stop}. */ - x: number; + on: boolean; /** - * The y position of this Game Object. + * Newly emitted particles are added to the top of the particle list, i.e. rendered above those already alive. + * Set to false to send them to the back. */ - y: number; + particleBringToTop: boolean; /** - * The z position of this Game Object. - * - * Note: The z position does not control the rendering order of 2D Game Objects. Use - * {@link Phaser.GameObjects.Components.Depth#depth} instead. + * The time rate applied to active particles, affecting lifespan, movement, and tweens. Values larger than 1 are faster than normal. */ - z: number; + timeScale: number; /** - * The w position of this Game Object. + * An object describing a shape to emit particles from. */ - w: number; + emitZone: Phaser.GameObjects.Particles.Zones.EdgeZone | Phaser.GameObjects.Particles.Zones.RandomZone; /** - * This is a special setter that allows you to set both the horizontal and vertical scale of this Game Object - * to the same value, at the same time. When reading this value the result returned is `(scaleX + scaleY) / 2`. - * - * Use of this property implies you wish the horizontal and vertical scales to be equal to each other. If this - * isn't the case, use the `scaleX` or `scaleY` properties instead. + * An object describing a shape that deactivates particles when they interact with it. */ - scale: number; + deathZone: Phaser.GameObjects.Particles.Zones.DeathZone; /** - * The horizontal scale of this Game Object. + * A rectangular boundary constraining particle movement. */ - scaleX: number; + bounds: Phaser.Geom.Rectangle; /** - * The vertical scale of this Game Object. + * Whether particles interact with the left edge of the emitter {@link Phaser.GameObjects.Particles.ParticleEmitter#bounds}. */ - scaleY: number; + collideLeft: boolean; /** - * The angle of this Game Object as expressed in degrees. - * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. - * - * If you prefer to work in radians, see the `rotation` property instead. + * Whether particles interact with the right edge of the emitter {@link Phaser.GameObjects.Particles.ParticleEmitter#bounds}. */ - angle: integer; + collideRight: boolean; /** - * The angle of this Game Object in radians. - * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. - * - * If you prefer to work in degrees, see the `angle` property instead. + * Whether particles interact with the top edge of the emitter {@link Phaser.GameObjects.Particles.ParticleEmitter#bounds}. */ - rotation: number; + collideTop: boolean; /** - * Sets the position of this Game Object. - * @param x The x position of this Game Object. Default 0. - * @param y The y position of this Game Object. If not set it will use the `x` value. Default x. - * @param z The z position of this Game Object. Default 0. - * @param w The w position of this Game Object. Default 0. + * Whether particles interact with the bottom edge of the emitter {@link Phaser.GameObjects.Particles.ParticleEmitter#bounds}. */ - setPosition(x?: number, y?: number, z?: number, w?: number): this; + collideBottom: boolean; /** - * Sets the position of this Game Object to be a random position within the confines of - * the given area. - * - * If no area is specified a random position between 0 x 0 and the game width x height is used instead. + * Whether this emitter updates itself and its particles. * - * The position does not factor in the size of this Game Object, meaning that only the origin is - * guaranteed to be within the area. - * @param x The x position of the top-left of the random area. Default 0. - * @param y The y position of the top-left of the random area. Default 0. - * @param width The width of the random area. - * @param height The height of the random area. + * Controlled by {@link Phaser.GameObjects.Particles.ParticleEmitter#pause} + * and {@link Phaser.GameObjects.Particles.ParticleEmitter#resume}. */ - setRandomPosition(x?: number, y?: number, width?: number, height?: number): this; + active: boolean; /** - * Sets the rotation of this Game Object. - * @param radians The rotation of this Game Object, in radians. Default 0. + * Set this to false to hide any active particles. */ - setRotation(radians?: number): this; + visible: boolean; /** - * Sets the angle of this Game Object. - * @param degrees The rotation of this Game Object, in degrees. Default 0. + * The blend mode of this emitter's particles. */ - setAngle(degrees?: number): this; + blendMode: number; /** - * Sets the scale of this Game Object. - * @param x The horizontal scale of this Game Object. - * @param y The vertical scale of this Game Object. If not set it will use the `x` value. Default x. + * A Game Object whose position is used as the particle origin. */ - setScale(x: number, y?: number): this; + follow: Phaser.GameObjects.GameObject; /** - * Sets the x position of this Game Object. - * @param value The x position of this Game Object. Default 0. + * The offset of the particle origin from the {@link Phaser.GameObjects.Particles.ParticleEmitter#follow} target. */ - setX(value?: number): this; + followOffset: Phaser.Math.Vector2; /** - * Sets the y position of this Game Object. - * @param value The y position of this Game Object. Default 0. + * Whether the emitter's {@link Phaser.GameObjects.Particles.ParticleEmitter#visible} state will track + * the {@link Phaser.GameObjects.Particles.ParticleEmitter#follow} target's visibility state. */ - setY(value?: number): this; + trackVisible: boolean; /** - * Sets the z position of this Game Object. - * - * Note: The z position does not control the rendering order of 2D Game Objects. Use - * {@link Phaser.GameObjects.Components.Depth#setDepth} instead. - * @param value The z position of this Game Object. Default 0. + * The current texture frame, as an index of {@link Phaser.GameObjects.Particles.ParticleEmitter#frames}. */ - setZ(value?: number): this; + currentFrame: number; /** - * Sets the w position of this Game Object. - * @param value The w position of this Game Object. Default 0. + * Whether texture {@link Phaser.GameObjects.Particles.ParticleEmitter#frames} are selected at random. */ - setW(value?: number): this; + randomFrame: boolean; /** - * Gets the local transform matrix for this Game Object. - * @param tempMatrix The matrix to populate with the values from this Game Object. + * The number of consecutive particles that receive a single texture frame (per frame cycle). */ - getLocalTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + frameQuantity: number; /** - * Gets the world transform matrix for this Game Object, factoring in any parent Containers. - * @param tempMatrix The matrix to populate with the values from this Game Object. - * @param parentMatrix A temporary matrix to hold parent values during the calculations. + * Merges configuration settings into the emitter's current settings. + * @param config Settings for this emitter. */ - getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + fromJSON(config: Phaser.Types.GameObjects.Particles.ParticleEmitterConfig): this; /** - * Gets the sum total rotation of all of this Game Objects parent Containers. - * - * The returned value is in radians and will be zero if this Game Object has no parent container. + * Creates a description of this emitter suitable for JSON serialization. + * @param output An object to copy output into. */ - getParentRotation(): number; + toJSON(output?: object): object; /** - * The visible state of the Game Object. - * - * An invisible Game Object will skip rendering, but will still process update logic. + * Continuously moves the particle origin to follow a Game Object's position. + * @param target The Game Object to follow. + * @param offsetX Horizontal offset of the particle origin from the Game Object. Default 0. + * @param offsetY Vertical offset of the particle origin from the Game Object. Default 0. + * @param trackVisible Whether the emitter's visible state will track the target's visible state. Default false. */ - visible: boolean; + startFollow(target: Phaser.GameObjects.GameObject, offsetX?: number, offsetY?: number, trackVisible?: boolean): this; /** - * Sets the visibility of this Game Object. - * - * An invisible Game Object will skip rendering, but will still process update logic. - * @param value The visible state of the Game Object. + * Stops following a Game Object. */ - setVisible(value: boolean): this; + stopFollow(): this; - } + /** + * Chooses a texture frame from {@link Phaser.GameObjects.Particles.ParticleEmitter#frames}. + */ + getFrame(): Phaser.Textures.Frame; - namespace Zones { /** - * A Death Zone. - * - * A Death Zone is a special type of zone that will kill a Particle as soon as it either enters, or leaves, the zone. - * - * The zone consists of a `source` which could be a Geometric shape, such as a Rectangle or Ellipse, or your own - * object as long as it includes a `contains` method for which the Particles can be tested against. + * Sets a pattern for assigning texture frames to emitted particles. + * @param frames One or more texture frames, or a configuration object. + * @param pickRandom Whether frames should be assigned at random from `frames`. Default true. + * @param quantity The number of consecutive particles that will receive each frame. Default 1. */ - class DeathZone { - /** - * - * @param source An object instance that has a `contains` method that returns a boolean when given `x` and `y` arguments. - * @param killOnEnter Should the Particle be killed when it enters the zone? `true` or leaves it? `false` - */ - constructor(source: Phaser.Types.GameObjects.Particles.DeathZoneSource, killOnEnter: boolean); - - /** - * An object instance that has a `contains` method that returns a boolean when given `x` and `y` arguments. - * This could be a Geometry shape, such as `Phaser.Geom.Circle`, or your own custom object. - */ - source: Phaser.Types.GameObjects.Particles.DeathZoneSource; - - /** - * Set to `true` if the Particle should be killed if it enters this zone. - * Set to `false` to kill the Particle if it leaves this zone. - */ - killOnEnter: boolean; - - /** - * Checks if the given Particle will be killed or not by this zone. - * @param particle The Particle to be checked against this zone. - */ - willKill(particle: Phaser.GameObjects.Particles.Particle): boolean; + setFrame(frames: any[] | string | number | Phaser.Types.GameObjects.Particles.ParticleEmitterFrameConfig, pickRandom?: boolean, quantity?: number): this; - } + /** + * Turns {@link Phaser.GameObjects.Particles.ParticleEmitter#radial} particle movement on or off. + * @param value Radial mode (true) or point mode (true). Default true. + */ + setRadial(value?: boolean): this; /** - * A zone that places particles on a shape's edges. + * Sets the position of the emitter's particle origin. + * New particles will be emitted here. + * @param x The x-coordinate of the particle origin. + * @param y The y-coordinate of the particle origin. */ - class EdgeZone { - /** - * - * @param source An object instance with a `getPoints(quantity, stepRate)` method returning an array of points. - * @param quantity The number of particles to place on the source edge. Set to 0 to use `stepRate` instead. - * @param stepRate The distance between each particle. When set, `quantity` is implied and should be set to 0. - * @param yoyo Whether particles are placed from start to end and then end to start. Default false. - * @param seamless Whether one endpoint will be removed if it's identical to the other. Default true. - */ - constructor(source: Phaser.Types.GameObjects.Particles.EdgeZoneSource, quantity: integer, stepRate: number, yoyo?: boolean, seamless?: boolean); + setPosition(x: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType, y: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType): this; - /** - * An object instance with a `getPoints(quantity, stepRate)` method returning an array of points. - */ - source: Phaser.Types.GameObjects.Particles.EdgeZoneSource | Phaser.Types.GameObjects.Particles.RandomZoneSource; + /** + * Sets or modifies a rectangular boundary constraining the particles. + * + * To remove the boundary, set {@link Phaser.GameObjects.Particles.ParticleEmitter#bounds} to null. + * @param x The x-coordinate of the left edge of the boundary, or an object representing a rectangle. + * @param y The y-coordinate of the top edge of the boundary. + * @param width The width of the boundary. + * @param height The height of the boundary. + */ + setBounds(x: number | Phaser.Types.GameObjects.Particles.ParticleEmitterBounds | Phaser.Types.GameObjects.Particles.ParticleEmitterBoundsAlt, y: number, width: number, height: number): this; - /** - * The points placed on the source edge. - */ - points: Phaser.Geom.Point[]; + /** + * Sets the initial horizontal speed of emitted particles. + * Changes the emitter to point mode. + * @param value The speed, in pixels per second. + */ + setSpeedX(value: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType): this; - /** - * The number of particles to place on the source edge. Set to 0 to use `stepRate` instead. - */ - quantity: integer; + /** + * Sets the initial vertical speed of emitted particles. + * Changes the emitter to point mode. + * @param value The speed, in pixels per second. + */ + setSpeedY(value: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType): this; - /** - * The distance between each particle. When set, `quantity` is implied and should be set to 0. - */ - stepRate: number; + /** + * Sets the initial radial speed of emitted particles. + * Changes the emitter to radial mode. + * @param value The speed, in pixels per second. + */ + setSpeed(value: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType): this; - /** - * Whether particles are placed from start to end and then end to start. - */ - yoyo: boolean; + /** + * Sets the horizontal scale of emitted particles. + * @param value The scale, relative to 1. + */ + setScaleX(value: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType | Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateType): this; - /** - * The counter used for iterating the EdgeZone's points. - */ - counter: number; + /** + * Sets the vertical scale of emitted particles. + * @param value The scale, relative to 1. + */ + setScaleY(value: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType | Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateType): this; - /** - * Whether one endpoint will be removed if it's identical to the other. - */ - seamless: boolean; + /** + * Sets the scale of emitted particles. + * @param value The scale, relative to 1. + */ + setScale(value: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType | Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateType): this; - /** - * Update the {@link Phaser.GameObjects.Particles.Zones.EdgeZone#points} from the EdgeZone's - * {@link Phaser.GameObjects.Particles.Zones.EdgeZone#source}. - * - * Also updates internal properties. - */ - updateSource(): Phaser.GameObjects.Particles.Zones.EdgeZone; + /** + * Sets the horizontal gravity applied to emitted particles. + * @param value Acceleration due to gravity, in pixels per second squared. + */ + setGravityX(value: number): this; - /** - * Change the source of the EdgeZone. - * @param source An object instance with a `getPoints(quantity, stepRate)` method returning an array of points. - */ - changeSource(source: Phaser.Types.GameObjects.Particles.EdgeZoneSource): Phaser.GameObjects.Particles.Zones.EdgeZone; + /** + * Sets the vertical gravity applied to emitted particles. + * @param value Acceleration due to gravity, in pixels per second squared. + */ + setGravityY(value: number): this; - /** - * Get the next point in the Zone and set its coordinates on the given Particle. - * @param particle The Particle. - */ - getPoint(particle: Phaser.GameObjects.Particles.Particle): void; + /** + * Sets the gravity applied to emitted particles. + * @param x Horizontal acceleration due to gravity, in pixels per second squared. + * @param y Vertical acceleration due to gravity, in pixels per second squared. + */ + setGravity(x: number, y: number): this; - } + /** + * Sets the opacity of emitted particles. + * @param value A value between 0 (transparent) and 1 (opaque). + */ + setAlpha(value: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType | Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateType): this; /** - * A zone that places particles randomly within a shape's area. + * Sets the color tint of emitted particles. + * @param value A value between 0 and 0xffffff. */ - class RandomZone { - /** - * - * @param source An object instance with a `getRandomPoint(point)` method. - */ - constructor(source: Phaser.Types.GameObjects.Particles.RandomZoneSource); + setTint(value: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType | Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateType): this; - /** - * An object instance with a `getRandomPoint(point)` method. - */ - source: Phaser.Types.GameObjects.Particles.RandomZoneSource; + /** + * Sets the angle of a {@link Phaser.GameObjects.Particles.ParticleEmitter#radial} particle stream. + * @param value The angle of the initial velocity of emitted particles. + */ + setEmitterAngle(value: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType): this; - /** - * Get the next point in the Zone and set its coordinates on the given Particle. - * @param particle The Particle. - */ - getPoint(particle: Phaser.GameObjects.Particles.Particle): void; + /** + * Sets the angle of a {@link Phaser.GameObjects.Particles.ParticleEmitter#radial} particle stream. + * @param value The angle of the initial velocity of emitted particles. + */ + setAngle(value: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType): this; - } + /** + * Sets the lifespan of newly emitted particles. + * @param value The particle lifespan, in ms. + */ + setLifespan(value: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType): this; - } + /** + * Sets the number of particles released at each flow cycle or explosion. + * @param quantity The number of particles to release at each flow cycle or explosion. + */ + setQuantity(quantity: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType): this; - } + /** + * Sets the emitter's {@link Phaser.GameObjects.Particles.ParticleEmitter#frequency} + * and {@link Phaser.GameObjects.Particles.ParticleEmitter#quantity}. + * @param frequency The time interval (>= 0) of each flow cycle, in ms; or -1 to put the emitter in explosion mode. + * @param quantity The number of particles to release at each flow cycle or explosion. + */ + setFrequency(frequency: number, quantity?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType): this; - /** - * A PathFollower Game Object. - * - * A PathFollower is a Sprite Game Object with some extra helpers to allow it to follow a Path automatically. - * - * Anything you can do with a standard Sprite can be done with this PathFollower, such as animate it, tint it, - * scale it and so on. - * - * PathFollowers are bound to a single Path at any one time and can traverse the length of the Path, from start - * to finish, forwards or backwards, or from any given point on the Path to its end. They can optionally rotate - * to face the direction of the path, be offset from the path coordinates or rotate independently of the Path. - */ - class PathFollower extends Phaser.GameObjects.Sprite implements Phaser.GameObjects.Components.PathFollower { - /** - * - * @param scene The Scene to which this PathFollower belongs. - * @param path The Path this PathFollower is following. It can only follow one Path at a time. - * @param x The horizontal position of this Game Object in the world. - * @param y The vertical position of this Game Object in the world. - * @param texture The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. - * @param frame An optional frame from the Texture this Game Object is rendering with. - */ - constructor(scene: Phaser.Scene, path: Phaser.Curves.Path, x: number, y: number, texture: string, frame?: string | integer); + /** + * Sets or removes the {@link Phaser.GameObjects.Particles.ParticleEmitter#emitZone}. + * + * An {@link Phaser.Types.GameObjects.Particles.ParticleEmitterEdgeZoneConfig EdgeZone} places particles on its edges. Its {@link Phaser.Types.GameObjects.Particles.EdgeZoneSource source} can be a Curve, Path, Circle, Ellipse, Line, Polygon, Rectangle, or Triangle; or any object with a suitable {@link Phaser.Types.GameObjects.Particles.EdgeZoneSourceCallback getPoints} method. + * + * A {@link Phaser.Types.GameObjects.Particles.ParticleEmitterRandomZoneConfig RandomZone} places randomly within its interior. Its {@link RandomZoneSource source} can be a Circle, Ellipse, Line, Polygon, Rectangle, or Triangle; or any object with a suitable {@link Phaser.Types.GameObjects.Particles.RandomZoneSourceCallback getRandomPoint} method. + * @param zoneConfig An object describing the zone, or `undefined` to remove any current emit zone. + */ + setEmitZone(zoneConfig?: Phaser.Types.GameObjects.Particles.ParticleEmitterEdgeZoneConfig | Phaser.Types.GameObjects.Particles.ParticleEmitterRandomZoneConfig): this; - /** - * If the PathFollower is rotating to match the Path (@see Phaser.GameObjects.PathFollower#rotateToPath) - * this value is added to the rotation value. This allows you to rotate objects to a path but control - * the angle of the rotation as well. - */ - pathRotationOffset: number; + /** + * Sets or removes the {@link Phaser.GameObjects.Particles.ParticleEmitter#deathZone}. + * @param zoneConfig An object describing the zone, or `undefined` to remove any current death zone. + */ + setDeathZone(zoneConfig?: Phaser.Types.GameObjects.Particles.ParticleEmitterDeathZoneConfig): this; - /** - * An additional vector to add to the PathFollowers position, allowing you to offset it from the - * Path coordinates. - */ - pathOffset: Phaser.Math.Vector2; + /** + * Creates inactive particles and adds them to this emitter's pool. + * @param particleCount The number of particles to create. + */ + reserve(particleCount: number): this; - /** - * A Vector2 that stores the current point of the path the follower is on. - */ - pathVector: Phaser.Math.Vector2; + /** + * Gets the number of active (in-use) particles in this emitter. + */ + getAliveParticleCount(): number; - /** - * The Tween used for following the Path. - */ - pathTween: Phaser.Tweens.Tween; + /** + * Gets the number of inactive (available) particles in this emitter. + */ + getDeadParticleCount(): number; - /** - * Settings for the PathFollower. - */ - pathConfig: Phaser.Types.GameObjects.PathFollower.PathConfig; + /** + * Gets the total number of particles in this emitter. + */ + getParticleCount(): number; - /** - * Internal update handler that advances this PathFollower along the path. - * - * Called automatically by the Scene step, should not typically be called directly. - * @param time The current timestamp as generated by the Request Animation Frame or SetTimeout. - * @param delta The delta time, in ms, elapsed since the last frame. - */ - protected preUpdate(time: integer, delta: number): void; + /** + * Whether this emitter is at its limit (if set). + */ + atLimit(): boolean; - /** - * Clears all alpha values associated with this Game Object. - * - * Immediately sets the alpha levels back to 1 (fully opaque). - */ - clearAlpha(): this; + /** + * Sets a function to call for each newly emitted particle. + * @param callback The function. + * @param context The calling context. + */ + onParticleEmit(callback: Phaser.Types.GameObjects.Particles.ParticleEmitterCallback, context?: any): this; - /** - * Set the Alpha level of this Game Object. The alpha controls the opacity of the Game Object as it renders. - * Alpha values are provided as a float between 0, fully transparent, and 1, fully opaque. - * - * If your game is running under WebGL you can optionally specify four different alpha values, each of which - * correspond to the four corners of the Game Object. Under Canvas only the `topLeft` value given is used. - * @param topLeft The alpha value used for the top-left of the Game Object. If this is the only value given it's applied across the whole Game Object. Default 1. - * @param topRight The alpha value used for the top-right of the Game Object. WebGL only. - * @param bottomLeft The alpha value used for the bottom-left of the Game Object. WebGL only. - * @param bottomRight The alpha value used for the bottom-right of the Game Object. WebGL only. - */ - setAlpha(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; + /** + * Sets a function to call for each particle death. + * @param callback The function. + * @param context The function's calling context. + */ + onParticleDeath(callback: Phaser.Types.GameObjects.Particles.ParticleDeathCallback, context?: any): this; - /** - * The alpha value of the Game Object. - * - * This is a global value, impacting the entire Game Object, not just a region of it. - */ - alpha: number; + /** + * Deactivates every particle in this emitter. + */ + killAll(): this; - /** - * The alpha value starting from the top-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - alphaTopLeft: number; + /** + * Calls a function for each active particle in this emitter. + * @param callback The function. + * @param context The function's calling context. + */ + forEachAlive(callback: Phaser.Types.GameObjects.Particles.ParticleEmitterCallback, context: any): this; - /** - * The alpha value starting from the top-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - alphaTopRight: number; + /** + * Calls a function for each inactive particle in this emitter. + * @param callback The function. + * @param context The function's calling context. + */ + forEachDead(callback: Phaser.Types.GameObjects.Particles.ParticleEmitterCallback, context: any): this; - /** - * The alpha value starting from the bottom-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - alphaBottomLeft: number; + /** + * Turns {@link Phaser.GameObjects.Particles.ParticleEmitter#on} the emitter and resets the flow counter. + * + * If this emitter is in flow mode (frequency >= 0; the default), the particle flow will start (or restart). + * + * If this emitter is in explode mode (frequency = -1), nothing will happen. + * Use {@link Phaser.GameObjects.Particles.ParticleEmitter#explode} or {@link Phaser.GameObjects.Particles.ParticleEmitter#flow} instead. + */ + start(): this; - /** - * The alpha value starting from the bottom-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - alphaBottomRight: number; + /** + * Turns {@link Phaser.GameObjects.Particles.ParticleEmitter#on off} the emitter. + */ + stop(): this; - /** - * Sets the Blend Mode being used by this Game Object. - * - * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) - * - * Under WebGL only the following Blend Modes are available: - * - * * ADD - * * MULTIPLY - * * SCREEN - * * ERASE - * - * Canvas has more available depending on browser support. - * - * You can also create your own custom Blend Modes in WebGL. - * - * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending - * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these - * reasons try to be careful about the construction of your Scene and the frequency of which blend modes - * are used. - */ - blendMode: Phaser.BlendModes | string; + /** + * {@link Phaser.GameObjects.Particles.ParticleEmitter#active Deactivates} the emitter. + */ + pause(): this; - /** - * Sets the Blend Mode being used by this Game Object. - * - * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) - * - * Under WebGL only the following Blend Modes are available: - * - * * ADD - * * MULTIPLY - * * SCREEN - * * ERASE (only works when rendering to a framebuffer, like a Render Texture) - * - * Canvas has more available depending on browser support. - * - * You can also create your own custom Blend Modes in WebGL. - * - * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending - * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these - * reasons try to be careful about the construction of your Scene and the frequency in which blend modes - * are used. - * @param value The BlendMode value. Either a string or a CONST. - */ - setBlendMode(value: string | Phaser.BlendModes): this; + /** + * {@link Phaser.GameObjects.Particles.ParticleEmitter#active Activates} the emitter. + */ + resume(): this; - /** - * The depth of this Game Object within the Scene. - * - * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order - * of Game Objects, without actually moving their position in the display list. - * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth - * value will always render in front of one with a lower value. - * - * Setting the depth will queue a depth sort event within the Scene. - */ - depth: number; + /** + * Removes the emitter from its manager and the scene. + */ + remove(): this; - /** - * The depth of this Game Object within the Scene. - * - * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order - * of Game Objects, without actually moving their position in the display list. - * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth - * value will always render in front of one with a lower value. - * - * Setting the depth will queue a depth sort event within the Scene. - * @param value The depth of this Game Object. - */ - setDepth(value: integer): this; + /** + * Sorts active particles with {@link Phaser.GameObjects.Particles.ParticleEmitter#depthSortCallback}. + */ + depthSort(): this; - /** - * The horizontally flipped state of the Game Object. - * - * A Game Object that is flipped horizontally will render inversed on the horizontal axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. - */ - flipX: boolean; + /** + * Puts the emitter in flow mode (frequency >= 0) and starts (or restarts) a particle flow. + * + * To resume a flow at the current frequency and quantity, use {@link Phaser.GameObjects.Particles.ParticleEmitter#start} instead. + * @param frequency The time interval (>= 0) of each flow cycle, in ms. + * @param count The number of particles to emit at each flow cycle. Default 1. + */ + flow(frequency: number, count?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType): this; - /** - * The vertically flipped state of the Game Object. - * - * A Game Object that is flipped vertically will render inversed on the vertical axis (i.e. upside down) - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. - */ - flipY: boolean; + /** + * Puts the emitter in explode mode (frequency = -1), stopping any current particle flow, and emits several particles all at once. + * @param count The amount of Particles to emit. + * @param x The x coordinate to emit the Particles from. + * @param y The y coordinate to emit the Particles from. + */ + explode(count: number, x: number, y: number): Phaser.GameObjects.Particles.Particle; - /** - * Toggles the horizontal flipped state of this Game Object. - * - * A Game Object that is flipped horizontally will render inversed on the horizontal axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. - */ - toggleFlipX(): this; + /** + * Emits particles at a given position (or the emitter's current position). + * @param x The x coordinate to emit the Particles from. Default this.x. + * @param y The y coordinate to emit the Particles from. Default this.x. + * @param count The number of Particles to emit. Default this.quantity. + */ + emitParticleAt(x?: number, y?: number, count?: number): Phaser.GameObjects.Particles.Particle; - /** - * Toggles the vertical flipped state of this Game Object. - */ - toggleFlipY(): this; + /** + * Emits particles at a given position (or the emitter's current position). + * @param count The number of Particles to emit. Default this.quantity. + * @param x The x coordinate to emit the Particles from. Default this.x. + * @param y The y coordinate to emit the Particles from. Default this.x. + */ + emitParticle(count?: number, x?: number, y?: number): Phaser.GameObjects.Particles.Particle; - /** - * Sets the horizontal flipped state of this Game Object. - * - * A Game Object that is flipped horizontally will render inversed on the horizontal axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. - * @param value The flipped state. `false` for no flip, or `true` to be flipped. - */ - setFlipX(value: boolean): this; + /** + * Updates this emitter and its particles. + * @param time The current timestamp as generated by the Request Animation Frame or SetTimeout. + * @param delta The delta time, in ms, elapsed since the last frame. + */ + preUpdate(time: number, delta: number): void; - /** - * Sets the vertical flipped state of this Game Object. - * @param value The flipped state. `false` for no flip, or `true` to be flipped. - */ - setFlipY(value: boolean): this; + /** + * Calculates the difference of two particles, for sorting them by depth. + * @param a The first particle. + * @param b The second particle. + */ + depthSortCallback(a: object, b: object): number; - /** - * Sets the horizontal and vertical flipped state of this Game Object. - * - * A Game Object that is flipped will render inversed on the flipped axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. - * @param x The horizontal flipped state. `false` for no flip, or `true` to be flipped. - * @param y The horizontal flipped state. `false` for no flip, or `true` to be flipped. - */ - setFlip(x: boolean, y: boolean): this; + /** + * Sets the Blend Mode being used by this Game Object. + * + * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) + * + * Under WebGL only the following Blend Modes are available: + * + * * ADD + * * MULTIPLY + * * SCREEN + * * ERASE (only works when rendering to a framebuffer, like a Render Texture) + * + * Canvas has more available depending on browser support. + * + * You can also create your own custom Blend Modes in WebGL. + * + * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending + * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these + * reasons try to be careful about the construction of your Scene and the frequency in which blend modes + * are used. + * @param value The BlendMode value. Either a string or a CONST. + */ + setBlendMode(value: string | Phaser.BlendModes): this; - /** - * Resets the horizontal and vertical flipped state of this Game Object back to their default un-flipped state. - */ - resetFlip(): this; + /** + * The Mask this Game Object is using during render. + */ + mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask; - /** - * Gets the center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - */ - getCenter(output?: O): O; + /** + * Sets the mask that this Game Object will use to render with. + * + * The mask must have been previously created and can be either a GeometryMask or a BitmapMask. + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * + * If a mask is already set on this Game Object it will be immediately replaced. + * + * Masks are positioned in global space and are not relative to the Game Object to which they + * are applied. The reason for this is that multiple Game Objects can all share the same mask. + * + * Masks have no impact on physics or input detection. They are purely a rendering component + * that allows you to limit what is visible during the render pass. + * @param mask The mask this Game Object will use when rendering. + */ + setMask(mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask): this; - /** - * Gets the top-left corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. - */ - getTopLeft(output?: O, includeParent?: boolean): O; + /** + * Clears the mask that this Game Object was using. + * @param destroyMask Destroy the mask before clearing it? Default false. + */ + clearMask(destroyMask?: boolean): this; - /** - * Gets the top-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. - */ - getTopCenter(output?: O, includeParent?: boolean): O; + /** + * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, + * including this one. + * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * + * To create the mask you need to pass in a reference to a renderable Game Object. + * A renderable Game Object is one that uses a texture to render with, such as an + * Image, Sprite, Render Texture or BitmapText. + * + * If you do not provide a renderable object, and this Game Object has a texture, + * it will use itself as the object. This means you can call this method to create + * a Bitmap Mask from any renderable Game Object. + * @param renderable A renderable Game Object that uses a texture, such as a Sprite. + */ + createBitmapMask(renderable?: Phaser.GameObjects.GameObject): Phaser.Display.Masks.BitmapMask; - /** - * Gets the top-right corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. - */ - getTopRight(output?: O, includeParent?: boolean): O; + /** + * Creates and returns a Geometry Mask. This mask can be used by any Game Object, + * including this one. + * + * To create the mask you need to pass in a reference to a Graphics Game Object. + * + * If you do not provide a graphics object, and this Game Object is an instance + * of a Graphics object, then it will use itself to create the mask. + * + * This means you can call this method to create a Geometry Mask from any Graphics Game Object. + * @param graphics A Graphics Game Object. The geometry within it will be used as the mask. + */ + createGeometryMask(graphics?: Phaser.GameObjects.Graphics): Phaser.Display.Masks.GeometryMask; - /** - * Gets the left-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. - */ - getLeftCenter(output?: O, includeParent?: boolean): O; + /** + * The horizontal scroll factor of this Game Object. + * + * The scroll factor controls the influence of the movement of a Camera upon this Game Object. + * + * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. + * It does not change the Game Objects actual position values. + * + * A value of 1 means it will move exactly in sync with a camera. + * A value of 0 means it will not move at all, even if the camera moves. + * Other values control the degree to which the camera movement is mapped to this Game Object. + * + * Please be aware that scroll factor values other than 1 are not taken in to consideration when + * calculating physics collisions. Bodies always collide based on their world position, but changing + * the scroll factor is a visual adjustment to where the textures are rendered, which can offset + * them from physics bodies if not accounted for in your code. + */ + scrollFactorX: number; - /** - * Gets the right-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. - */ - getRightCenter(output?: O, includeParent?: boolean): O; + /** + * The vertical scroll factor of this Game Object. + * + * The scroll factor controls the influence of the movement of a Camera upon this Game Object. + * + * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. + * It does not change the Game Objects actual position values. + * + * A value of 1 means it will move exactly in sync with a camera. + * A value of 0 means it will not move at all, even if the camera moves. + * Other values control the degree to which the camera movement is mapped to this Game Object. + * + * Please be aware that scroll factor values other than 1 are not taken in to consideration when + * calculating physics collisions. Bodies always collide based on their world position, but changing + * the scroll factor is a visual adjustment to where the textures are rendered, which can offset + * them from physics bodies if not accounted for in your code. + */ + scrollFactorY: number; - /** - * Gets the bottom-left corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. - */ - getBottomLeft(output?: O, includeParent?: boolean): O; + /** + * Sets the scroll factor of this Game Object. + * + * The scroll factor controls the influence of the movement of a Camera upon this Game Object. + * + * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. + * It does not change the Game Objects actual position values. + * + * A value of 1 means it will move exactly in sync with a camera. + * A value of 0 means it will not move at all, even if the camera moves. + * Other values control the degree to which the camera movement is mapped to this Game Object. + * + * Please be aware that scroll factor values other than 1 are not taken in to consideration when + * calculating physics collisions. Bodies always collide based on their world position, but changing + * the scroll factor is a visual adjustment to where the textures are rendered, which can offset + * them from physics bodies if not accounted for in your code. + * @param x The horizontal scroll factor of this Game Object. + * @param y The vertical scroll factor of this Game Object. If not set it will use the `x` value. Default x. + */ + setScrollFactor(x: number, y?: number): this; - /** - * Gets the bottom-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. - */ - getBottomCenter(output?: O, includeParent?: boolean): O; + /** + * Sets the visibility of this Game Object. + * + * An invisible Game Object will skip rendering, but will still process update logic. + * @param value The visible state of the Game Object. + */ + setVisible(value: boolean): this; - /** - * Gets the bottom-right corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. - */ - getBottomRight(output?: O, includeParent?: boolean): O; + } /** - * Gets the bounds of this Game Object, regardless of origin. - * The values are stored and returned in a Rectangle, or Rectangle-like, object. - * @param output An object to store the values in. If not provided a new Rectangle will be created. + * A Particle Emitter Manager creates and controls {@link Phaser.GameObjects.Particles.ParticleEmitter Particle Emitters} and {@link Phaser.GameObjects.Particles.GravityWell Gravity Wells}. */ - getBounds(output?: O): O; + class ParticleEmitterManager extends Phaser.GameObjects.GameObject implements Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.Mask, Phaser.GameObjects.Components.Pipeline, Phaser.GameObjects.Components.Transform, Phaser.GameObjects.Components.Visible { + /** + * + * @param scene The Scene to which this Emitter Manager belongs. + * @param texture The key of the Texture this Emitter Manager will use to render particles, as stored in the Texture Manager. + * @param frame An optional frame from the Texture this Emitter Manager will use to render particles. + * @param emitters Configuration settings for one or more emitters to create. + */ + constructor(scene: Phaser.Scene, texture: string, frame?: string | number, emitters?: Phaser.Types.GameObjects.Particles.ParticleEmitterConfig | Phaser.Types.GameObjects.Particles.ParticleEmitterConfig[]); - /** - * The Mask this Game Object is using during render. - */ - mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask; + /** + * The time scale applied to all emitters and particles, affecting flow rate, lifespan, and movement. + * Values larger than 1 are faster than normal. + * This is multiplied with any timeScale set on each individual emitter. + */ + timeScale: number; - /** - * Sets the mask that this Game Object will use to render with. - * - * The mask must have been previously created and can be either a GeometryMask or a BitmapMask. - * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. - * - * If a mask is already set on this Game Object it will be immediately replaced. - * - * Masks are positioned in global space and are not relative to the Game Object to which they - * are applied. The reason for this is that multiple Game Objects can all share the same mask. - * - * Masks have no impact on physics or input detection. They are purely a rendering component - * that allows you to limit what is visible during the render pass. - * @param mask The mask this Game Object will use when rendering. - */ - setMask(mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask): this; + /** + * The texture used to render this Emitter Manager's particles. + */ + texture: Phaser.Textures.Texture; - /** - * Clears the mask that this Game Object was using. - * @param destroyMask Destroy the mask before clearing it? Default false. - */ - clearMask(destroyMask?: boolean): this; + /** + * The texture frame used to render this Emitter Manager's particles. + */ + frame: Phaser.Textures.Frame; - /** - * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, - * including this one. - * - * To create the mask you need to pass in a reference to a renderable Game Object. - * A renderable Game Object is one that uses a texture to render with, such as an - * Image, Sprite, Render Texture or BitmapText. - * - * If you do not provide a renderable object, and this Game Object has a texture, - * it will use itself as the object. This means you can call this method to create - * a Bitmap Mask from any renderable Game Object. - * @param renderable A renderable Game Object that uses a texture, such as a Sprite. - */ - createBitmapMask(renderable?: Phaser.GameObjects.GameObject): Phaser.Display.Masks.BitmapMask; + /** + * Names of this Emitter Manager's texture frames. + */ + frameNames: string[]; - /** - * Creates and returns a Geometry Mask. This mask can be used by any Game Object, - * including this one. - * - * To create the mask you need to pass in a reference to a Graphics Game Object. - * - * If you do not provide a graphics object, and this Game Object is an instance - * of a Graphics object, then it will use itself to create the mask. - * - * This means you can call this method to create a Geometry Mask from any Graphics Game Object. - * @param graphics A Graphics Game Object. The geometry within it will be used as the mask. - */ - createGeometryMask(graphics?: Phaser.GameObjects.Graphics): Phaser.Display.Masks.GeometryMask; + /** + * A list of Emitters being managed by this Emitter Manager. + */ + emitters: Phaser.Structs.List; - /** - * The horizontal origin of this Game Object. - * The origin maps the relationship between the size and position of the Game Object. - * The default value is 0.5, meaning all Game Objects are positioned based on their center. - * Setting the value to 0 means the position now relates to the left of the Game Object. - */ - originX: number; + /** + * A list of Gravity Wells being managed by this Emitter Manager. + */ + wells: Phaser.Structs.List; - /** - * The vertical origin of this Game Object. - * The origin maps the relationship between the size and position of the Game Object. - * The default value is 0.5, meaning all Game Objects are positioned based on their center. - * Setting the value to 0 means the position now relates to the top of the Game Object. - */ - originY: number; + /** + * Sets the texture and frame this Emitter Manager will use to render with. + * + * Textures are referenced by their string-based keys, as stored in the Texture Manager. + * @param key The key of the texture to be used, as stored in the Texture Manager. + * @param frame The name or index of the frame within the Texture. + */ + setTexture(key: string, frame?: string | number): this; - /** - * The horizontal display origin of this Game Object. - * The origin is a normalized value between 0 and 1. - * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. - */ - displayOriginX: number; + /** + * Sets the frame this Emitter Manager will use to render with. + * + * The Frame has to belong to the current Texture being used. + * + * It can be either a string or an index. + * @param frame The name or index of the frame within the Texture. + */ + setFrame(frame?: string | number): this; - /** - * The vertical display origin of this Game Object. - * The origin is a normalized value between 0 and 1. - * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. - */ - displayOriginY: number; + /** + * Assigns texture frames to an emitter. + * @param frames The texture frames. + * @param emitter The particle emitter to modify. + */ + setEmitterFrames(frames: Phaser.Textures.Frame | Phaser.Textures.Frame[], emitter: Phaser.GameObjects.Particles.ParticleEmitter): this; - /** - * Sets the origin of this Game Object. - * - * The values are given in the range 0 to 1. - * @param x The horizontal origin value. Default 0.5. - * @param y The vertical origin value. If not defined it will be set to the value of `x`. Default x. - */ - setOrigin(x?: number, y?: number): this; + /** + * Adds an existing Particle Emitter to this Emitter Manager. + * @param emitter The Particle Emitter to add to this Emitter Manager. + */ + addEmitter(emitter: Phaser.GameObjects.Particles.ParticleEmitter): Phaser.GameObjects.Particles.ParticleEmitter; - /** - * Sets the origin of this Game Object based on the Pivot values in its Frame. - */ - setOriginFromFrame(): this; + /** + * Creates a new Particle Emitter object, adds it to this Emitter Manager and returns a reference to it. + * @param config Configuration settings for the Particle Emitter to create. + */ + createEmitter(config: Phaser.Types.GameObjects.Particles.ParticleEmitterConfig): Phaser.GameObjects.Particles.ParticleEmitter; - /** - * Sets the display origin of this Game Object. - * The difference between this and setting the origin is that you can use pixel values for setting the display origin. - * @param x The horizontal display origin value. Default 0. - * @param y The vertical display origin value. If not defined it will be set to the value of `x`. Default x. - */ - setDisplayOrigin(x?: number, y?: number): this; + /** + * Removes a Particle Emitter from this Emitter Manager, if the Emitter belongs to this Manager. + */ + removeEmitter(emitter: Phaser.GameObjects.Particles.ParticleEmitter): Phaser.GameObjects.Particles.ParticleEmitter; - /** - * Updates the Display Origin cached values internally stored on this Game Object. - * You don't usually call this directly, but it is exposed for edge-cases where you may. - */ - updateDisplayOrigin(): this; + /** + * Adds an existing Gravity Well object to this Emitter Manager. + * @param well The Gravity Well to add to this Emitter Manager. + */ + addGravityWell(well: Phaser.GameObjects.Particles.GravityWell): Phaser.GameObjects.Particles.GravityWell; - /** - * The initial WebGL pipeline of this Game Object. - */ - defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; + /** + * Creates a new Gravity Well, adds it to this Emitter Manager and returns a reference to it. + * @param config Configuration settings for the Gravity Well to create. + */ + createGravityWell(config: Phaser.Types.GameObjects.Particles.GravityWellConfig): Phaser.GameObjects.Particles.GravityWell; - /** - * The current WebGL pipeline of this Game Object. - */ - pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + /** + * Emits particles from each active emitter. + * @param count The number of particles to release from each emitter. The default is the emitter's own {@link Phaser.GameObjects.Particles.ParticleEmitter#quantity}. + * @param x The x-coordinate to to emit particles from. The default is the x-coordinate of the emitter's current location. + * @param y The y-coordinate to to emit particles from. The default is the y-coordinate of the emitter's current location. + */ + emitParticle(count?: number, x?: number, y?: number): this; - /** - * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. - */ - initPipeline(pipelineName?: string): boolean; + /** + * Emits particles from each active emitter. + * @param x The x-coordinate to to emit particles from. The default is the x-coordinate of the emitter's current location. + * @param y The y-coordinate to to emit particles from. The default is the y-coordinate of the emitter's current location. + * @param count The number of particles to release from each emitter. The default is the emitter's own {@link Phaser.GameObjects.Particles.ParticleEmitter#quantity}. + */ + emitParticleAt(x?: number, y?: number, count?: number): this; - /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. - */ - setPipeline(pipelineName: string): this; + /** + * Pauses this Emitter Manager. + * + * This has the effect of pausing all emitters, and all particles of those emitters, currently under its control. + * + * The particles will still render, but they will not have any of their logic updated. + */ + pause(): this; - /** - * Resets the WebGL Pipeline of this Game Object back to the default it was created with. - */ - resetPipeline(): boolean; + /** + * Resumes this Emitter Manager, should it have been previously paused. + */ + resume(): this; - /** - * Gets the name of the WebGL Pipeline this Game Object is currently using. - */ - getPipelineName(): string; + /** + * Gets all active particle processors (gravity wells). + */ + getProcessors(): Phaser.GameObjects.Particles.GravityWell[]; - /** - * The horizontal scroll factor of this Game Object. - * - * The scroll factor controls the influence of the movement of a Camera upon this Game Object. - * - * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. - * It does not change the Game Objects actual position values. - * - * A value of 1 means it will move exactly in sync with a camera. - * A value of 0 means it will not move at all, even if the camera moves. - * Other values control the degree to which the camera movement is mapped to this Game Object. - * - * Please be aware that scroll factor values other than 1 are not taken in to consideration when - * calculating physics collisions. Bodies always collide based on their world position, but changing - * the scroll factor is a visual adjustment to where the textures are rendered, which can offset - * them from physics bodies if not accounted for in your code. - */ - scrollFactorX: number; + /** + * Updates all active emitters. + * @param time The current timestamp as generated by the Request Animation Frame or SetTimeout. + * @param delta The delta time, in ms, elapsed since the last frame. + */ + preUpdate(time: number, delta: number): void; - /** - * The vertical scroll factor of this Game Object. - * - * The scroll factor controls the influence of the movement of a Camera upon this Game Object. - * - * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. - * It does not change the Game Objects actual position values. - * - * A value of 1 means it will move exactly in sync with a camera. - * A value of 0 means it will not move at all, even if the camera moves. - * Other values control the degree to which the camera movement is mapped to this Game Object. - * - * Please be aware that scroll factor values other than 1 are not taken in to consideration when - * calculating physics collisions. Bodies always collide based on their world position, but changing - * the scroll factor is a visual adjustment to where the textures are rendered, which can offset - * them from physics bodies if not accounted for in your code. - */ - scrollFactorY: number; + /** + * The depth of this Game Object within the Scene. + * + * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order + * of Game Objects, without actually moving their position in the display list. + * + * The default depth is zero. A Game Object with a higher depth + * value will always render in front of one with a lower value. + * + * Setting the depth will queue a depth sort event within the Scene. + */ + depth: number; - /** - * Sets the scroll factor of this Game Object. - * - * The scroll factor controls the influence of the movement of a Camera upon this Game Object. - * - * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. - * It does not change the Game Objects actual position values. - * - * A value of 1 means it will move exactly in sync with a camera. - * A value of 0 means it will not move at all, even if the camera moves. - * Other values control the degree to which the camera movement is mapped to this Game Object. - * - * Please be aware that scroll factor values other than 1 are not taken in to consideration when - * calculating physics collisions. Bodies always collide based on their world position, but changing - * the scroll factor is a visual adjustment to where the textures are rendered, which can offset - * them from physics bodies if not accounted for in your code. - * @param x The horizontal scroll factor of this Game Object. - * @param y The vertical scroll factor of this Game Object. If not set it will use the `x` value. Default x. - */ - setScrollFactor(x: number, y?: number): this; - - /** - * The native (un-scaled) width of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayWidth` property. - */ - width: number; + /** + * The depth of this Game Object within the Scene. + * + * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order + * of Game Objects, without actually moving their position in the display list. + * + * The default depth is zero. A Game Object with a higher depth + * value will always render in front of one with a lower value. + * + * Setting the depth will queue a depth sort event within the Scene. + * @param value The depth of this Game Object. + */ + setDepth(value: number): this; - /** - * The native (un-scaled) height of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayHeight` property. - */ - height: number; + /** + * The Mask this Game Object is using during render. + */ + mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask; - /** - * The displayed width of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. - */ - displayWidth: number; + /** + * Sets the mask that this Game Object will use to render with. + * + * The mask must have been previously created and can be either a GeometryMask or a BitmapMask. + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * + * If a mask is already set on this Game Object it will be immediately replaced. + * + * Masks are positioned in global space and are not relative to the Game Object to which they + * are applied. The reason for this is that multiple Game Objects can all share the same mask. + * + * Masks have no impact on physics or input detection. They are purely a rendering component + * that allows you to limit what is visible during the render pass. + * @param mask The mask this Game Object will use when rendering. + */ + setMask(mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask): this; - /** - * The displayed height of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. - */ - displayHeight: number; + /** + * Clears the mask that this Game Object was using. + * @param destroyMask Destroy the mask before clearing it? Default false. + */ + clearMask(destroyMask?: boolean): this; - /** - * Sets the size of this Game Object to be that of the given Frame. - * - * This will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or call the - * `setDisplaySize` method, which is the same thing as changing the scale but allows you - * to do so by giving pixel values. - * - * If you have enabled this Game Object for input, changing the size will _not_ change the - * size of the hit area. To do this you should adjust the `input.hitArea` object directly. - * @param frame The frame to base the size of this Game Object on. - */ - setSizeToFrame(frame: Phaser.Textures.Frame): this; + /** + * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, + * including this one. + * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * + * To create the mask you need to pass in a reference to a renderable Game Object. + * A renderable Game Object is one that uses a texture to render with, such as an + * Image, Sprite, Render Texture or BitmapText. + * + * If you do not provide a renderable object, and this Game Object has a texture, + * it will use itself as the object. This means you can call this method to create + * a Bitmap Mask from any renderable Game Object. + * @param renderable A renderable Game Object that uses a texture, such as a Sprite. + */ + createBitmapMask(renderable?: Phaser.GameObjects.GameObject): Phaser.Display.Masks.BitmapMask; - /** - * Sets the internal size of this Game Object, as used for frame or physics body creation. - * - * This will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or call the - * `setDisplaySize` method, which is the same thing as changing the scale but allows you - * to do so by giving pixel values. - * - * If you have enabled this Game Object for input, changing the size will _not_ change the - * size of the hit area. To do this you should adjust the `input.hitArea` object directly. - * @param width The width of this Game Object. - * @param height The height of this Game Object. - */ - setSize(width: number, height: number): this; + /** + * Creates and returns a Geometry Mask. This mask can be used by any Game Object, + * including this one. + * + * To create the mask you need to pass in a reference to a Graphics Game Object. + * + * If you do not provide a graphics object, and this Game Object is an instance + * of a Graphics object, then it will use itself to create the mask. + * + * This means you can call this method to create a Geometry Mask from any Graphics Game Object. + * @param graphics A Graphics Game Object. The geometry within it will be used as the mask. + */ + createGeometryMask(graphics?: Phaser.GameObjects.Graphics): Phaser.Display.Masks.GeometryMask; - /** - * Sets the display size of this Game Object. - * - * Calling this will adjust the scale. - * @param width The width of this Game Object. - * @param height The height of this Game Object. - */ - setDisplaySize(width: number, height: number): this; + /** + * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. + */ + defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; - /** - * The Texture this Game Object is using to render with. - */ - texture: Phaser.Textures.Texture | Phaser.Textures.CanvasTexture; + /** + * The current WebGL pipeline of this Game Object. + */ + pipeline: Phaser.Renderer.WebGL.WebGLPipeline; - /** - * The Texture Frame this Game Object is using to render with. - */ - frame: Phaser.Textures.Frame; + /** + * Does this Game Object have any Post Pipelines set? + */ + hasPostPipeline: boolean; - /** - * A boolean flag indicating if this Game Object is being cropped or not. - * You can toggle this at any time after `setCrop` has been called, to turn cropping on or off. - * Equally, calling `setCrop` with no arguments will reset the crop and disable it. - */ - isCropped: boolean; + /** + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. + */ + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; - /** - * Applies a crop to a texture based Game Object, such as a Sprite or Image. - * - * The crop is a rectangle that limits the area of the texture frame that is visible during rendering. - * - * Cropping a Game Object does not change its size, dimensions, physics body or hit area, it just - * changes what is shown when rendered. - * - * The crop coordinates are relative to the texture frame, not the Game Object, meaning 0 x 0 is the top-left. - * - * Therefore, if you had a Game Object that had an 800x600 sized texture, and you wanted to show only the left - * half of it, you could call `setCrop(0, 0, 400, 600)`. - * - * It is also scaled to match the Game Object scale automatically. Therefore a crop rect of 100x50 would crop - * an area of 200x100 when applied to a Game Object that had a scale factor of 2. - * - * You can either pass in numeric values directly, or you can provide a single Rectangle object as the first argument. - * - * Call this method with no arguments at all to reset the crop, or toggle the property `isCropped` to `false`. - * - * You should do this if the crop rectangle becomes the same size as the frame itself, as it will allow - * the renderer to skip several internal calculations. - * @param x The x coordinate to start the crop from. Or a Phaser.Geom.Rectangle object, in which case the rest of the arguments are ignored. - * @param y The y coordinate to start the crop from. - * @param width The width of the crop rectangle in pixels. - * @param height The height of the crop rectangle in pixels. - */ - setCrop(x?: number | Phaser.Geom.Rectangle, y?: number, width?: number, height?: number): this; + /** + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. + */ + pipelineData: object; - /** - * Sets the texture and frame this Game Object will use to render with. - * - * Textures are referenced by their string-based keys, as stored in the Texture Manager. - * @param key The key of the texture to be used, as stored in the Texture Manager. - * @param frame The name or index of the frame within the Texture. - */ - setTexture(key: string, frame?: string | integer): this; + /** + * Sets the initial WebGL Pipeline of this Game Object. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + */ + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; - /** - * Sets the frame this Game Object will use to render with. - * - * The Frame has to belong to the current Texture being used. - * - * It can be either a string or an index. - * - * Calling `setFrame` will modify the `width` and `height` properties of your Game Object. - * It will also change the `origin` if the Frame has a custom pivot point, as exported from packages like Texture Packer. - * @param frame The name or index of the frame within the Texture. - * @param updateSize Should this call adjust the size of the Game Object? Default true. - * @param updateOrigin Should this call adjust the origin of the Game Object? Default true. - */ - setFrame(frame: string | integer, updateSize?: boolean, updateOrigin?: boolean): this; + /** + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; - /** - * Fill or additive? - */ - tintFill: boolean; + /** + * Sets one, or more, Post Pipelines on this Game Object. + * + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; - /** - * Clears all tint values associated with this Game Object. - * - * Immediately sets the color values back to 0xffffff and the tint type to 'additive', - * which results in no visible change to the texture. - */ - clearTint(): this; + /** + * Adds an entry to the `pipelineData` object belonging to this Game Object. + * + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. + */ + setPipelineData(key: string, value?: any): this; - /** - * Sets an additive tint on this Game Object. - * - * The tint works by taking the pixel color values from the Game Objects texture, and then - * multiplying it by the color value of the tint. You can provide either one color value, - * in which case the whole Game Object will be tinted in that color. Or you can provide a color - * per corner. The colors are blended together across the extent of the Game Object. - * - * To modify the tint color once set, either call this method again with new values or use the - * `tint` property to set all colors at once. Or, use the properties `tintTopLeft`, `tintTopRight, - * `tintBottomLeft` and `tintBottomRight` to set the corner color values independently. - * - * To remove a tint call `clearTint`. - * - * To swap this from being an additive tint to a fill based tint set the property `tintFill` to `true`. - * @param topLeft The tint being applied to the top-left of the Game Object. If no other values are given this value is applied evenly, tinting the whole Game Object. Default 0xffffff. - * @param topRight The tint being applied to the top-right of the Game Object. - * @param bottomLeft The tint being applied to the bottom-left of the Game Object. - * @param bottomRight The tint being applied to the bottom-right of the Game Object. - */ - setTint(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; + /** + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. + */ + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; - /** - * Sets a fill-based tint on this Game Object. - * - * Unlike an additive tint, a fill-tint literally replaces the pixel colors from the texture - * with those in the tint. You can use this for effects such as making a player flash 'white' - * if hit by something. You can provide either one color value, in which case the whole - * Game Object will be rendered in that color. Or you can provide a color per corner. The colors - * are blended together across the extent of the Game Object. - * - * To modify the tint color once set, either call this method again with new values or use the - * `tint` property to set all colors at once. Or, use the properties `tintTopLeft`, `tintTopRight, - * `tintBottomLeft` and `tintBottomRight` to set the corner color values independently. - * - * To remove a tint call `clearTint`. - * - * To swap this from being a fill-tint to an additive tint set the property `tintFill` to `false`. - * @param topLeft The tint being applied to the top-left of the Game Object. If not other values are given this value is applied evenly, tinting the whole Game Object. Default 0xffffff. - * @param topRight The tint being applied to the top-right of the Game Object. - * @param bottomLeft The tint being applied to the bottom-left of the Game Object. - * @param bottomRight The tint being applied to the bottom-right of the Game Object. - */ - setTintFill(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; + /** + * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; - /** - * The tint value being applied to the top-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintTopLeft: integer; + /** + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPostPipeline(resetData?: boolean): void; - /** - * The tint value being applied to the top-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintTopRight: integer; + /** + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. + */ + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; - /** - * The tint value being applied to the bottom-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintBottomLeft: integer; + /** + * Gets the name of the WebGL Pipeline this Game Object is currently using. + */ + getPipelineName(): string; - /** - * The tint value being applied to the bottom-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintBottomRight: integer; + /** + * The x position of this Game Object. + */ + x: number; - /** - * The tint value being applied to the whole of the Game Object. - * This property is a setter-only. Use the properties `tintTopLeft` etc to read the current tint value. - */ - tint: integer; + /** + * The y position of this Game Object. + */ + y: number; - /** - * Does this Game Object have a tint applied to it or not? - */ - readonly isTinted: boolean; + /** + * The z position of this Game Object. + * + * Note: The z position does not control the rendering order of 2D Game Objects. Use + * {@link Phaser.GameObjects.Components.Depth#depth} instead. + */ + z: number; - /** - * The x position of this Game Object. - */ - x: number; + /** + * The w position of this Game Object. + */ + w: number; - /** - * The y position of this Game Object. - */ - y: number; + /** + * This is a special setter that allows you to set both the horizontal and vertical scale of this Game Object + * to the same value, at the same time. When reading this value the result returned is `(scaleX + scaleY) / 2`. + * + * Use of this property implies you wish the horizontal and vertical scales to be equal to each other. If this + * isn't the case, use the `scaleX` or `scaleY` properties instead. + */ + scale: number; - /** - * The z position of this Game Object. - * - * Note: The z position does not control the rendering order of 2D Game Objects. Use - * {@link Phaser.GameObjects.Components.Depth#depth} instead. - */ - z: number; + /** + * The horizontal scale of this Game Object. + */ + scaleX: number; - /** - * The w position of this Game Object. - */ - w: number; + /** + * The vertical scale of this Game Object. + */ + scaleY: number; - /** - * This is a special setter that allows you to set both the horizontal and vertical scale of this Game Object - * to the same value, at the same time. When reading this value the result returned is `(scaleX + scaleY) / 2`. - * - * Use of this property implies you wish the horizontal and vertical scales to be equal to each other. If this - * isn't the case, use the `scaleX` or `scaleY` properties instead. - */ - scale: number; + /** + * The angle of this Game Object as expressed in degrees. + * + * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left + * and -90 is up. + * + * If you prefer to work in radians, see the `rotation` property instead. + */ + angle: number; - /** - * The horizontal scale of this Game Object. - */ - scaleX: number; + /** + * The angle of this Game Object in radians. + * + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. + * + * If you prefer to work in degrees, see the `angle` property instead. + */ + rotation: number; - /** - * The vertical scale of this Game Object. - */ - scaleY: number; + /** + * Sets the position of this Game Object. + * @param x The x position of this Game Object. Default 0. + * @param y The y position of this Game Object. If not set it will use the `x` value. Default x. + * @param z The z position of this Game Object. Default 0. + * @param w The w position of this Game Object. Default 0. + */ + setPosition(x?: number, y?: number, z?: number, w?: number): this; - /** - * The angle of this Game Object as expressed in degrees. - * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. - * - * If you prefer to work in radians, see the `rotation` property instead. - */ - angle: integer; + /** + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; - /** - * The angle of this Game Object in radians. - * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. - * - * If you prefer to work in degrees, see the `angle` property instead. - */ - rotation: number; + /** + * Sets the position of this Game Object to be a random position within the confines of + * the given area. + * + * If no area is specified a random position between 0 x 0 and the game width x height is used instead. + * + * The position does not factor in the size of this Game Object, meaning that only the origin is + * guaranteed to be within the area. + * @param x The x position of the top-left of the random area. Default 0. + * @param y The y position of the top-left of the random area. Default 0. + * @param width The width of the random area. + * @param height The height of the random area. + */ + setRandomPosition(x?: number, y?: number, width?: number, height?: number): this; - /** - * Sets the position of this Game Object. - * @param x The x position of this Game Object. Default 0. - * @param y The y position of this Game Object. If not set it will use the `x` value. Default x. - * @param z The z position of this Game Object. Default 0. - * @param w The w position of this Game Object. Default 0. - */ - setPosition(x?: number, y?: number, z?: number, w?: number): this; + /** + * Sets the rotation of this Game Object. + * @param radians The rotation of this Game Object, in radians. Default 0. + */ + setRotation(radians?: number): this; - /** - * Sets the position of this Game Object to be a random position within the confines of - * the given area. - * - * If no area is specified a random position between 0 x 0 and the game width x height is used instead. - * - * The position does not factor in the size of this Game Object, meaning that only the origin is - * guaranteed to be within the area. - * @param x The x position of the top-left of the random area. Default 0. - * @param y The y position of the top-left of the random area. Default 0. - * @param width The width of the random area. - * @param height The height of the random area. - */ - setRandomPosition(x?: number, y?: number, width?: number, height?: number): this; + /** + * Sets the angle of this Game Object. + * @param degrees The rotation of this Game Object, in degrees. Default 0. + */ + setAngle(degrees?: number): this; - /** - * Sets the rotation of this Game Object. - * @param radians The rotation of this Game Object, in radians. Default 0. - */ - setRotation(radians?: number): this; + /** + * Sets the scale of this Game Object. + * @param x The horizontal scale of this Game Object. + * @param y The vertical scale of this Game Object. If not set it will use the `x` value. Default x. + */ + setScale(x: number, y?: number): this; - /** - * Sets the angle of this Game Object. - * @param degrees The rotation of this Game Object, in degrees. Default 0. - */ - setAngle(degrees?: number): this; + /** + * Sets the x position of this Game Object. + * @param value The x position of this Game Object. Default 0. + */ + setX(value?: number): this; - /** - * Sets the scale of this Game Object. - * @param x The horizontal scale of this Game Object. - * @param y The vertical scale of this Game Object. If not set it will use the `x` value. Default x. - */ - setScale(x: number, y?: number): this; + /** + * Sets the y position of this Game Object. + * @param value The y position of this Game Object. Default 0. + */ + setY(value?: number): this; - /** - * Sets the x position of this Game Object. - * @param value The x position of this Game Object. Default 0. - */ - setX(value?: number): this; + /** + * Sets the z position of this Game Object. + * + * Note: The z position does not control the rendering order of 2D Game Objects. Use + * {@link Phaser.GameObjects.Components.Depth#setDepth} instead. + * @param value The z position of this Game Object. Default 0. + */ + setZ(value?: number): this; - /** - * Sets the y position of this Game Object. - * @param value The y position of this Game Object. Default 0. - */ - setY(value?: number): this; + /** + * Sets the w position of this Game Object. + * @param value The w position of this Game Object. Default 0. + */ + setW(value?: number): this; - /** - * Sets the z position of this Game Object. - * - * Note: The z position does not control the rendering order of 2D Game Objects. Use - * {@link Phaser.GameObjects.Components.Depth#setDepth} instead. - * @param value The z position of this Game Object. Default 0. - */ - setZ(value?: number): this; + /** + * Gets the local transform matrix for this Game Object. + * @param tempMatrix The matrix to populate with the values from this Game Object. + */ + getLocalTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; - /** - * Sets the w position of this Game Object. - * @param value The w position of this Game Object. Default 0. - */ - setW(value?: number): this; + /** + * Gets the world transform matrix for this Game Object, factoring in any parent Containers. + * @param tempMatrix The matrix to populate with the values from this Game Object. + * @param parentMatrix A temporary matrix to hold parent values during the calculations. + */ + getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; - /** - * Gets the local transform matrix for this Game Object. - * @param tempMatrix The matrix to populate with the values from this Game Object. - */ - getLocalTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. + */ + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; - /** - * Gets the world transform matrix for this Game Object, factoring in any parent Containers. - * @param tempMatrix The matrix to populate with the values from this Game Object. - * @param parentMatrix A temporary matrix to hold parent values during the calculations. - */ - getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + /** + * Gets the sum total rotation of all of this Game Objects parent Containers. + * + * The returned value is in radians and will be zero if this Game Object has no parent container. + */ + getParentRotation(): number; - /** - * Gets the sum total rotation of all of this Game Objects parent Containers. - * - * The returned value is in radians and will be zero if this Game Object has no parent container. - */ - getParentRotation(): number; + /** + * The visible state of the Game Object. + * + * An invisible Game Object will skip rendering, but will still process update logic. + */ + visible: boolean; - /** - * The visible state of the Game Object. - * - * An invisible Game Object will skip rendering, but will still process update logic. - */ - visible: boolean; + /** + * Sets the visibility of this Game Object. + * + * An invisible Game Object will skip rendering, but will still process update logic. + * @param value The visible state of the Game Object. + */ + setVisible(value: boolean): this; - /** - * Sets the visibility of this Game Object. - * - * An invisible Game Object will skip rendering, but will still process update logic. - * @param value The visible state of the Game Object. - */ - setVisible(value: boolean): this; + } - /** - * The Path this PathFollower is following. It can only follow one Path at a time. - */ - path: Phaser.Curves.Path; + namespace Zones { + /** + * A Death Zone. + * + * A Death Zone is a special type of zone that will kill a Particle as soon as it either enters, or leaves, the zone. + * + * The zone consists of a `source` which could be a Geometric shape, such as a Rectangle or Ellipse, or your own + * object as long as it includes a `contains` method for which the Particles can be tested against. + */ + class DeathZone { + /** + * + * @param source An object instance that has a `contains` method that returns a boolean when given `x` and `y` arguments. + * @param killOnEnter Should the Particle be killed when it enters the zone? `true` or leaves it? `false` + */ + constructor(source: Phaser.Types.GameObjects.Particles.DeathZoneSource, killOnEnter: boolean); - /** - * Should the PathFollower automatically rotate to point in the direction of the Path? - */ - rotateToPath: boolean; + /** + * An object instance that has a `contains` method that returns a boolean when given `x` and `y` arguments. + * This could be a Geometry shape, such as `Phaser.Geom.Circle`, or your own custom object. + */ + source: Phaser.Types.GameObjects.Particles.DeathZoneSource; - /** - * Set the Path that this PathFollower should follow. - * - * Optionally accepts {@link Phaser.Types.GameObjects.PathFollower.PathConfig} settings. - * @param path The Path this PathFollower is following. It can only follow one Path at a time. - * @param config Settings for the PathFollower. - */ - setPath(path: Phaser.Curves.Path, config?: number | Phaser.Types.GameObjects.PathFollower.PathConfig | Phaser.Types.Tweens.NumberTweenBuilderConfig): Phaser.GameObjects.PathFollower; + /** + * Set to `true` if the Particle should be killed if it enters this zone. + * Set to `false` to kill the Particle if it leaves this zone. + */ + killOnEnter: boolean; - /** - * Set whether the PathFollower should automatically rotate to point in the direction of the Path. - * @param value Whether the PathFollower should automatically rotate to point in the direction of the Path. - * @param offset Rotation offset in degrees. Default 0. - */ - setRotateToPath(value: boolean, offset?: number): Phaser.GameObjects.PathFollower; + /** + * Checks if the given Particle will be killed or not by this zone. + * @param particle The Particle to be checked against this zone. + */ + willKill(particle: Phaser.GameObjects.Particles.Particle): boolean; - /** - * Is this PathFollower actively following a Path or not? - * - * To be considered as `isFollowing` it must be currently moving on a Path, and not paused. - */ - isFollowing(): boolean; + } - /** - * Starts this PathFollower following its given Path. - * @param config The duration of the follow, or a PathFollower config object. Default {}. - * @param startAt Optional start position of the follow, between 0 and 1. Default 0. - */ - startFollow(config?: number | Phaser.Types.GameObjects.PathFollower.PathConfig | Phaser.Types.Tweens.NumberTweenBuilderConfig, startAt?: number): Phaser.GameObjects.PathFollower; + /** + * A zone that places particles on a shape's edges. + */ + class EdgeZone { + /** + * + * @param source An object instance with a `getPoints(quantity, stepRate)` method returning an array of points. + * @param quantity The number of particles to place on the source edge. Set to 0 to use `stepRate` instead. + * @param stepRate The distance between each particle. When set, `quantity` is implied and should be set to 0. + * @param yoyo Whether particles are placed from start to end and then end to start. Default false. + * @param seamless Whether one endpoint will be removed if it's identical to the other. Default true. + */ + constructor(source: Phaser.Types.GameObjects.Particles.EdgeZoneSource, quantity: number, stepRate: number, yoyo?: boolean, seamless?: boolean); - /** - * Pauses this PathFollower. It will still continue to render, but it will remain motionless at the - * point on the Path at which you paused it. - */ - pauseFollow(): Phaser.GameObjects.PathFollower; + /** + * An object instance with a `getPoints(quantity, stepRate)` method returning an array of points. + */ + source: Phaser.Types.GameObjects.Particles.EdgeZoneSource | Phaser.Types.GameObjects.Particles.RandomZoneSource; - /** - * Resumes a previously paused PathFollower. - * - * If the PathFollower was not paused this has no effect. - */ - resumeFollow(): Phaser.GameObjects.PathFollower; + /** + * The points placed on the source edge. + */ + points: Phaser.Geom.Point[]; - /** - * Stops this PathFollower from following the path any longer. - * - * This will invoke any 'stop' conditions that may exist on the Path, or for the follower. - */ - stopFollow(): Phaser.GameObjects.PathFollower; + /** + * The number of particles to place on the source edge. Set to 0 to use `stepRate` instead. + */ + quantity: number; - /** - * Internal update handler that advances this PathFollower along the path. - * - * Called automatically by the Scene step, should not typically be called directly. - */ - pathUpdate(): void; + /** + * The distance between each particle. When set, `quantity` is implied and should be set to 0. + */ + stepRate: number; - } + /** + * Whether particles are placed from start to end and then end to start. + */ + yoyo: boolean; - /** - * A Quad Game Object. - * - * A Quad is a Mesh Game Object pre-configured with two triangles arranged into a rectangle, with a single - * texture spread across them. - * - * You can manipulate the corner points of the quad via the getters and setters such as `topLeftX`, and also - * change their alpha and color values. The quad itself can be moved by adjusting the `x` and `y` properties. - */ - class Quad extends Phaser.GameObjects.Mesh { - /** - * - * @param scene The Scene to which this Quad belongs. - * @param x The horizontal position of this Game Object in the world. - * @param y The vertical position of this Game Object in the world. - * @param texture The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. - * @param frame An optional frame from the Texture this Game Object is rendering with. - */ - constructor(scene: Phaser.Scene, x: number, y: number, texture: string, frame?: string | integer); + /** + * The counter used for iterating the EdgeZone's points. + */ + counter: number; - /** - * Sets the frame this Game Object will use to render with. - * - * The Frame has to belong to the current Texture being used. - * - * It can be either a string or an index. - * - * Calling `setFrame` will modify the `width` and `height` properties of your Game Object. - * It will also change the `origin` if the Frame has a custom pivot point, as exported from packages like Texture Packer. - * @param frame The name or index of the frame within the Texture. - */ - setFrame(frame: string | integer): this; + /** + * Whether one endpoint will be removed if it's identical to the other. + */ + seamless: boolean; - /** - * The top-left x vertex of this Quad. - */ - topLeftX: number; + /** + * Update the {@link Phaser.GameObjects.Particles.Zones.EdgeZone#points} from the EdgeZone's + * {@link Phaser.GameObjects.Particles.Zones.EdgeZone#source}. + * + * Also updates internal properties. + */ + updateSource(): this; - /** - * The top-left y vertex of this Quad. - */ - topLeftY: number; + /** + * Change the source of the EdgeZone. + * @param source An object instance with a `getPoints(quantity, stepRate)` method returning an array of points. + */ + changeSource(source: Phaser.Types.GameObjects.Particles.EdgeZoneSource): this; - /** - * The top-right x vertex of this Quad. - */ - topRightX: number; + /** + * Get the next point in the Zone and set its coordinates on the given Particle. + * @param particle The Particle. + */ + getPoint(particle: Phaser.GameObjects.Particles.Particle): void; - /** - * The top-right y vertex of this Quad. - */ - topRightY: number; + } - /** - * The bottom-left x vertex of this Quad. - */ - bottomLeftX: number; + /** + * A zone that places particles randomly within a shapes area. + */ + class RandomZone { + /** + * + * @param source An object instance with a `getRandomPoint(point)` method. + */ + constructor(source: Phaser.Types.GameObjects.Particles.RandomZoneSource); - /** - * The bottom-left y vertex of this Quad. - */ - bottomLeftY: number; + /** + * An object instance with a `getRandomPoint(point)` method. + */ + source: Phaser.Types.GameObjects.Particles.RandomZoneSource; - /** - * The bottom-right x vertex of this Quad. - */ - bottomRightX: number; + /** + * Get the next point in the Zone and set its coordinates on the given Particle. + * @param particle The Particle. + */ + getPoint(particle: Phaser.GameObjects.Particles.Particle): void; - /** - * The bottom-right y vertex of this Quad. - */ - bottomRightY: number; + } - /** - * The top-left alpha value of this Quad. - */ - topLeftAlpha: number; + } + } + + /** + * A PathFollower Game Object. + * + * A PathFollower is a Sprite Game Object with some extra helpers to allow it to follow a Path automatically. + * + * Anything you can do with a standard Sprite can be done with this PathFollower, such as animate it, tint it, + * scale it and so on. + * + * PathFollowers are bound to a single Path at any one time and can traverse the length of the Path, from start + * to finish, forwards or backwards, or from any given point on the Path to its end. They can optionally rotate + * to face the direction of the path, be offset from the path coordinates or rotate independently of the Path. + */ + class PathFollower extends Phaser.GameObjects.Sprite implements Phaser.GameObjects.Components.PathFollower { /** - * The top-right alpha value of this Quad. + * + * @param scene The Scene to which this PathFollower belongs. + * @param path The Path this PathFollower is following. It can only follow one Path at a time. + * @param x The horizontal position of this Game Object in the world. + * @param y The vertical position of this Game Object in the world. + * @param texture The key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager. + * @param frame An optional frame from the Texture this Game Object is rendering with. */ - topRightAlpha: number; + constructor(scene: Phaser.Scene, path: Phaser.Curves.Path, x: number, y: number, texture: string | Phaser.Textures.Texture, frame?: string | number); /** - * The bottom-left alpha value of this Quad. + * If the PathFollower is rotating to match the Path (@see Phaser.GameObjects.PathFollower#rotateToPath) + * this value is added to the rotation value. This allows you to rotate objects to a path but control + * the angle of the rotation as well. */ - bottomLeftAlpha: number; + pathRotationOffset: number; /** - * The bottom-right alpha value of this Quad. + * An additional vector to add to the PathFollowers position, allowing you to offset it from the + * Path coordinates. */ - bottomRightAlpha: number; + pathOffset: Phaser.Math.Vector2; /** - * The top-left color value of this Quad. + * A Vector2 that stores the current point of the path the follower is on. */ - topLeftColor: number; + pathVector: Phaser.Math.Vector2; /** - * The top-right color value of this Quad. + * The distance the follower has traveled from the previous point to the current one, at the last update. */ - topRightColor: number; + pathDelta: Phaser.Math.Vector2; /** - * The bottom-left color value of this Quad. + * The Tween used for following the Path. */ - bottomLeftColor: number; + pathTween: Phaser.Tweens.Tween; /** - * The bottom-right color value of this Quad. + * Settings for the PathFollower. */ - bottomRightColor: number; + pathConfig: Phaser.Types.GameObjects.PathFollower.PathConfig; /** - * Sets the top-left vertex position of this Quad. - * @param x The horizontal coordinate of the vertex. - * @param y The vertical coordinate of the vertex. + * Internal update handler that advances this PathFollower along the path. + * + * Called automatically by the Scene step, should not typically be called directly. + * @param time The current timestamp as generated by the Request Animation Frame or SetTimeout. + * @param delta The delta time, in ms, elapsed since the last frame. */ - setTopLeft(x: number, y: number): Phaser.GameObjects.Quad; + protected preUpdate(time: number, delta: number): void; /** - * Sets the top-right vertex position of this Quad. - * @param x The horizontal coordinate of the vertex. - * @param y The vertical coordinate of the vertex. + * Clears all alpha values associated with this Game Object. + * + * Immediately sets the alpha levels back to 1 (fully opaque). */ - setTopRight(x: number, y: number): Phaser.GameObjects.Quad; + clearAlpha(): this; /** - * Sets the bottom-left vertex position of this Quad. - * @param x The horizontal coordinate of the vertex. - * @param y The vertical coordinate of the vertex. + * Set the Alpha level of this Game Object. The alpha controls the opacity of the Game Object as it renders. + * Alpha values are provided as a float between 0, fully transparent, and 1, fully opaque. + * + * If your game is running under WebGL you can optionally specify four different alpha values, each of which + * correspond to the four corners of the Game Object. Under Canvas only the `topLeft` value given is used. + * @param topLeft The alpha value used for the top-left of the Game Object. If this is the only value given it's applied across the whole Game Object. Default 1. + * @param topRight The alpha value used for the top-right of the Game Object. WebGL only. + * @param bottomLeft The alpha value used for the bottom-left of the Game Object. WebGL only. + * @param bottomRight The alpha value used for the bottom-right of the Game Object. WebGL only. */ - setBottomLeft(x: number, y: number): Phaser.GameObjects.Quad; + setAlpha(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; /** - * Sets the bottom-right vertex position of this Quad. - * @param x The horizontal coordinate of the vertex. - * @param y The vertical coordinate of the vertex. + * The alpha value of the Game Object. + * + * This is a global value, impacting the entire Game Object, not just a region of it. */ - setBottomRight(x: number, y: number): Phaser.GameObjects.Quad; + alpha: number; /** - * Resets the positions of the four corner vertices of this Quad. + * The alpha value starting from the top-left of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. */ - resetPosition(): Phaser.GameObjects.Quad; + alphaTopLeft: number; /** - * Resets the alpha values used by this Quad back to 1. + * The alpha value starting from the top-right of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. */ - resetAlpha(): Phaser.GameObjects.Quad; + alphaTopRight: number; /** - * Resets the color values used by this Quad back to 0xffffff. + * The alpha value starting from the bottom-left of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. */ - resetColors(): Phaser.GameObjects.Quad; + alphaBottomLeft: number; /** - * Resets the position, alpha and color values used by this Quad. + * The alpha value starting from the bottom-right of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. */ - reset(): Phaser.GameObjects.Quad; + alphaBottomRight: number; /** * Sets the Blend Mode being used by this Game Object. @@ -22251,7 +25080,7 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. @@ -22264,137 +25093,486 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. * @param value The depth of this Game Object. */ - setDepth(value: integer): this; + setDepth(value: number): this; /** - * The Mask this Game Object is using during render. + * The horizontally flipped state of the Game Object. + * + * A Game Object that is flipped horizontally will render inversed on the horizontal axis. + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. */ - mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask; + flipX: boolean; /** - * Sets the mask that this Game Object will use to render with. - * - * The mask must have been previously created and can be either a GeometryMask or a BitmapMask. - * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. - * - * If a mask is already set on this Game Object it will be immediately replaced. - * - * Masks are positioned in global space and are not relative to the Game Object to which they - * are applied. The reason for this is that multiple Game Objects can all share the same mask. + * The vertically flipped state of the Game Object. * - * Masks have no impact on physics or input detection. They are purely a rendering component - * that allows you to limit what is visible during the render pass. - * @param mask The mask this Game Object will use when rendering. + * A Game Object that is flipped vertically will render inversed on the vertical axis (i.e. upside down) + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. */ - setMask(mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask): this; + flipY: boolean; /** - * Clears the mask that this Game Object was using. - * @param destroyMask Destroy the mask before clearing it? Default false. + * Toggles the horizontal flipped state of this Game Object. + * + * A Game Object that is flipped horizontally will render inversed on the horizontal axis. + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. */ - clearMask(destroyMask?: boolean): this; + toggleFlipX(): this; /** - * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, - * including this one. - * - * To create the mask you need to pass in a reference to a renderable Game Object. - * A renderable Game Object is one that uses a texture to render with, such as an - * Image, Sprite, Render Texture or BitmapText. - * - * If you do not provide a renderable object, and this Game Object has a texture, - * it will use itself as the object. This means you can call this method to create - * a Bitmap Mask from any renderable Game Object. - * @param renderable A renderable Game Object that uses a texture, such as a Sprite. + * Toggles the vertical flipped state of this Game Object. */ - createBitmapMask(renderable?: Phaser.GameObjects.GameObject): Phaser.Display.Masks.BitmapMask; + toggleFlipY(): this; /** - * Creates and returns a Geometry Mask. This mask can be used by any Game Object, - * including this one. - * - * To create the mask you need to pass in a reference to a Graphics Game Object. - * - * If you do not provide a graphics object, and this Game Object is an instance - * of a Graphics object, then it will use itself to create the mask. + * Sets the horizontal flipped state of this Game Object. * - * This means you can call this method to create a Geometry Mask from any Graphics Game Object. - * @param graphics A Graphics Game Object. The geometry within it will be used as the mask. + * A Game Object that is flipped horizontally will render inversed on the horizontal axis. + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * @param value The flipped state. `false` for no flip, or `true` to be flipped. */ - createGeometryMask(graphics?: Phaser.GameObjects.Graphics): Phaser.Display.Masks.GeometryMask; + setFlipX(value: boolean): this; /** - * The initial WebGL pipeline of this Game Object. + * Sets the vertical flipped state of this Game Object. + * @param value The flipped state. `false` for no flip, or `true` to be flipped. */ - defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; + setFlipY(value: boolean): this; /** - * The current WebGL pipeline of this Game Object. + * Sets the horizontal and vertical flipped state of this Game Object. + * + * A Game Object that is flipped will render inversed on the flipped axis. + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * @param x The horizontal flipped state. `false` for no flip, or `true` to be flipped. + * @param y The horizontal flipped state. `false` for no flip, or `true` to be flipped. */ - pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + setFlip(x: boolean, y: boolean): this; /** - * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. + * Resets the horizontal and vertical flipped state of this Game Object back to their default un-flipped state. */ - initPipeline(pipelineName?: string): boolean; + resetFlip(): this; /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. + * Gets the center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. */ - setPipeline(pipelineName: string): this; + getCenter(output?: O): O; /** - * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * Gets the top-left corner coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - resetPipeline(): boolean; + getTopLeft(output?: O, includeParent?: boolean): O; /** - * Gets the name of the WebGL Pipeline this Game Object is currently using. + * Gets the top-center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - getPipelineName(): string; + getTopCenter(output?: O, includeParent?: boolean): O; /** - * The native (un-scaled) width of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayWidth` property. + * Gets the top-right corner coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - width: number; + getTopRight(output?: O, includeParent?: boolean): O; /** - * The native (un-scaled) height of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayHeight` property. + * Gets the left-center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - height: number; + getLeftCenter(output?: O, includeParent?: boolean): O; /** - * The displayed width of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. + * Gets the right-center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - displayWidth: number; + getRightCenter(output?: O, includeParent?: boolean): O; /** - * The displayed height of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. + * Gets the bottom-left corner coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + */ + getBottomLeft(output?: O, includeParent?: boolean): O; + + /** + * Gets the bottom-center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + */ + getBottomCenter(output?: O, includeParent?: boolean): O; + + /** + * Gets the bottom-right corner coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + */ + getBottomRight(output?: O, includeParent?: boolean): O; + + /** + * Gets the bounds of this Game Object, regardless of origin. + * The values are stored and returned in a Rectangle, or Rectangle-like, object. + * @param output An object to store the values in. If not provided a new Rectangle will be created. + */ + getBounds(output?: O): O; + + /** + * The Mask this Game Object is using during render. + */ + mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask; + + /** + * Sets the mask that this Game Object will use to render with. + * + * The mask must have been previously created and can be either a GeometryMask or a BitmapMask. + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * + * If a mask is already set on this Game Object it will be immediately replaced. + * + * Masks are positioned in global space and are not relative to the Game Object to which they + * are applied. The reason for this is that multiple Game Objects can all share the same mask. + * + * Masks have no impact on physics or input detection. They are purely a rendering component + * that allows you to limit what is visible during the render pass. + * @param mask The mask this Game Object will use when rendering. + */ + setMask(mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask): this; + + /** + * Clears the mask that this Game Object was using. + * @param destroyMask Destroy the mask before clearing it? Default false. + */ + clearMask(destroyMask?: boolean): this; + + /** + * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, + * including this one. + * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * + * To create the mask you need to pass in a reference to a renderable Game Object. + * A renderable Game Object is one that uses a texture to render with, such as an + * Image, Sprite, Render Texture or BitmapText. + * + * If you do not provide a renderable object, and this Game Object has a texture, + * it will use itself as the object. This means you can call this method to create + * a Bitmap Mask from any renderable Game Object. + * @param renderable A renderable Game Object that uses a texture, such as a Sprite. + */ + createBitmapMask(renderable?: Phaser.GameObjects.GameObject): Phaser.Display.Masks.BitmapMask; + + /** + * Creates and returns a Geometry Mask. This mask can be used by any Game Object, + * including this one. + * + * To create the mask you need to pass in a reference to a Graphics Game Object. + * + * If you do not provide a graphics object, and this Game Object is an instance + * of a Graphics object, then it will use itself to create the mask. + * + * This means you can call this method to create a Geometry Mask from any Graphics Game Object. + * @param graphics A Graphics Game Object. The geometry within it will be used as the mask. + */ + createGeometryMask(graphics?: Phaser.GameObjects.Graphics): Phaser.Display.Masks.GeometryMask; + + /** + * The horizontal origin of this Game Object. + * The origin maps the relationship between the size and position of the Game Object. + * The default value is 0.5, meaning all Game Objects are positioned based on their center. + * Setting the value to 0 means the position now relates to the left of the Game Object. + */ + originX: number; + + /** + * The vertical origin of this Game Object. + * The origin maps the relationship between the size and position of the Game Object. + * The default value is 0.5, meaning all Game Objects are positioned based on their center. + * Setting the value to 0 means the position now relates to the top of the Game Object. + */ + originY: number; + + /** + * The horizontal display origin of this Game Object. + * The origin is a normalized value between 0 and 1. + * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. + */ + displayOriginX: number; + + /** + * The vertical display origin of this Game Object. + * The origin is a normalized value between 0 and 1. + * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. + */ + displayOriginY: number; + + /** + * Sets the origin of this Game Object. + * + * The values are given in the range 0 to 1. + * @param x The horizontal origin value. Default 0.5. + * @param y The vertical origin value. If not defined it will be set to the value of `x`. Default x. + */ + setOrigin(x?: number, y?: number): this; + + /** + * Sets the origin of this Game Object based on the Pivot values in its Frame. + */ + setOriginFromFrame(): this; + + /** + * Sets the display origin of this Game Object. + * The difference between this and setting the origin is that you can use pixel values for setting the display origin. + * @param x The horizontal display origin value. Default 0. + * @param y The vertical display origin value. If not defined it will be set to the value of `x`. Default x. + */ + setDisplayOrigin(x?: number, y?: number): this; + + /** + * Updates the Display Origin cached values internally stored on this Game Object. + * You don't usually call this directly, but it is exposed for edge-cases where you may. + */ + updateDisplayOrigin(): this; + + /** + * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. + */ + defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; + + /** + * The current WebGL pipeline of this Game Object. + */ + pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + + /** + * Does this Game Object have any Post Pipelines set? + */ + hasPostPipeline: boolean; + + /** + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. + */ + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; + + /** + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. + */ + pipelineData: object; + + /** + * Sets the initial WebGL Pipeline of this Game Object. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + */ + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; + + /** + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; + + /** + * Sets one, or more, Post Pipelines on this Game Object. + * + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; + + /** + * Adds an entry to the `pipelineData` object belonging to this Game Object. + * + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. + */ + setPipelineData(key: string, value?: any): this; + + /** + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. + */ + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; + + /** + * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; + + /** + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPostPipeline(resetData?: boolean): void; + + /** + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. + */ + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; + + /** + * Gets the name of the WebGL Pipeline this Game Object is currently using. + */ + getPipelineName(): string; + + /** + * The horizontal scroll factor of this Game Object. + * + * The scroll factor controls the influence of the movement of a Camera upon this Game Object. + * + * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. + * It does not change the Game Objects actual position values. + * + * A value of 1 means it will move exactly in sync with a camera. + * A value of 0 means it will not move at all, even if the camera moves. + * Other values control the degree to which the camera movement is mapped to this Game Object. + * + * Please be aware that scroll factor values other than 1 are not taken in to consideration when + * calculating physics collisions. Bodies always collide based on their world position, but changing + * the scroll factor is a visual adjustment to where the textures are rendered, which can offset + * them from physics bodies if not accounted for in your code. + */ + scrollFactorX: number; + + /** + * The vertical scroll factor of this Game Object. + * + * The scroll factor controls the influence of the movement of a Camera upon this Game Object. + * + * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. + * It does not change the Game Objects actual position values. + * + * A value of 1 means it will move exactly in sync with a camera. + * A value of 0 means it will not move at all, even if the camera moves. + * Other values control the degree to which the camera movement is mapped to this Game Object. + * + * Please be aware that scroll factor values other than 1 are not taken in to consideration when + * calculating physics collisions. Bodies always collide based on their world position, but changing + * the scroll factor is a visual adjustment to where the textures are rendered, which can offset + * them from physics bodies if not accounted for in your code. + */ + scrollFactorY: number; + + /** + * Sets the scroll factor of this Game Object. + * + * The scroll factor controls the influence of the movement of a Camera upon this Game Object. + * + * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. + * It does not change the Game Objects actual position values. + * + * A value of 1 means it will move exactly in sync with a camera. + * A value of 0 means it will not move at all, even if the camera moves. + * Other values control the degree to which the camera movement is mapped to this Game Object. + * + * Please be aware that scroll factor values other than 1 are not taken in to consideration when + * calculating physics collisions. Bodies always collide based on their world position, but changing + * the scroll factor is a visual adjustment to where the textures are rendered, which can offset + * them from physics bodies if not accounted for in your code. + * @param x The horizontal scroll factor of this Game Object. + * @param y The vertical scroll factor of this Game Object. If not set it will use the `x` value. Default x. + */ + setScrollFactor(x: number, y?: number): this; + + /** + * The native (un-scaled) width of this Game Object. + * + * Changing this value will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or use + * the `displayWidth` property. + */ + width: number; + + /** + * The native (un-scaled) height of this Game Object. + * + * Changing this value will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or use + * the `displayHeight` property. + */ + height: number; + + /** + * The displayed width of this Game Object. + * + * This value takes into account the scale factor. + * + * Setting this value will adjust the Game Object's scale property. + */ + displayWidth: number; + + /** + * The displayed height of this Game Object. + * + * This value takes into account the scale factor. + * + * Setting this value will adjust the Game Object's scale property. */ displayHeight: number; @@ -22446,14 +25624,168 @@ declare namespace Phaser { */ frame: Phaser.Textures.Frame; + /** + * A boolean flag indicating if this Game Object is being cropped or not. + * You can toggle this at any time after `setCrop` has been called, to turn cropping on or off. + * Equally, calling `setCrop` with no arguments will reset the crop and disable it. + */ + isCropped: boolean; + + /** + * Applies a crop to a texture based Game Object, such as a Sprite or Image. + * + * The crop is a rectangle that limits the area of the texture frame that is visible during rendering. + * + * Cropping a Game Object does not change its size, dimensions, physics body or hit area, it just + * changes what is shown when rendered. + * + * The crop coordinates are relative to the texture frame, not the Game Object, meaning 0 x 0 is the top-left. + * + * Therefore, if you had a Game Object that had an 800x600 sized texture, and you wanted to show only the left + * half of it, you could call `setCrop(0, 0, 400, 600)`. + * + * It is also scaled to match the Game Object scale automatically. Therefore a crop rect of 100x50 would crop + * an area of 200x100 when applied to a Game Object that had a scale factor of 2. + * + * You can either pass in numeric values directly, or you can provide a single Rectangle object as the first argument. + * + * Call this method with no arguments at all to reset the crop, or toggle the property `isCropped` to `false`. + * + * You should do this if the crop rectangle becomes the same size as the frame itself, as it will allow + * the renderer to skip several internal calculations. + * @param x The x coordinate to start the crop from. Or a Phaser.Geom.Rectangle object, in which case the rest of the arguments are ignored. + * @param y The y coordinate to start the crop from. + * @param width The width of the crop rectangle in pixels. + * @param height The height of the crop rectangle in pixels. + */ + setCrop(x?: number | Phaser.Geom.Rectangle, y?: number, width?: number, height?: number): this; + /** * Sets the texture and frame this Game Object will use to render with. * * Textures are referenced by their string-based keys, as stored in the Texture Manager. - * @param key The key of the texture to be used, as stored in the Texture Manager, or a Texture instance. + * @param key The key of the texture to be used, as stored in the Texture Manager. + * @param frame The name or index of the frame within the Texture. + */ + setTexture(key: string, frame?: string | number): this; + + /** + * Sets the frame this Game Object will use to render with. + * + * The Frame has to belong to the current Texture being used. + * + * It can be either a string or an index. + * + * Calling `setFrame` will modify the `width` and `height` properties of your Game Object. + * It will also change the `origin` if the Frame has a custom pivot point, as exported from packages like Texture Packer. * @param frame The name or index of the frame within the Texture. + * @param updateSize Should this call adjust the size of the Game Object? Default true. + * @param updateOrigin Should this call adjust the origin of the Game Object? Default true. + */ + setFrame(frame: string | number, updateSize?: boolean, updateOrigin?: boolean): this; + + /** + * The tint value being applied to the top-left vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintTopLeft: number; + + /** + * The tint value being applied to the top-right vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintTopRight: number; + + /** + * The tint value being applied to the bottom-left vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintBottomLeft: number; + + /** + * The tint value being applied to the bottom-right vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintBottomRight: number; + + /** + * The tint fill mode. + * + * `false` = An additive tint (the default), where vertices colors are blended with the texture. + * `true` = A fill tint, where the vertices colors replace the texture, but respects texture alpha. + */ + tintFill: boolean; + + /** + * Clears all tint values associated with this Game Object. + * + * Immediately sets the color values back to 0xffffff and the tint type to 'additive', + * which results in no visible change to the texture. + */ + clearTint(): this; + + /** + * Sets an additive tint on this Game Object. + * + * The tint works by taking the pixel color values from the Game Objects texture, and then + * multiplying it by the color value of the tint. You can provide either one color value, + * in which case the whole Game Object will be tinted in that color. Or you can provide a color + * per corner. The colors are blended together across the extent of the Game Object. + * + * To modify the tint color once set, either call this method again with new values or use the + * `tint` property to set all colors at once. Or, use the properties `tintTopLeft`, `tintTopRight, + * `tintBottomLeft` and `tintBottomRight` to set the corner color values independently. + * + * To remove a tint call `clearTint`. + * + * To swap this from being an additive tint to a fill based tint set the property `tintFill` to `true`. + * @param topLeft The tint being applied to the top-left of the Game Object. If no other values are given this value is applied evenly, tinting the whole Game Object. Default 0xffffff. + * @param topRight The tint being applied to the top-right of the Game Object. + * @param bottomLeft The tint being applied to the bottom-left of the Game Object. + * @param bottomRight The tint being applied to the bottom-right of the Game Object. + */ + setTint(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; + + /** + * Sets a fill-based tint on this Game Object. + * + * Unlike an additive tint, a fill-tint literally replaces the pixel colors from the texture + * with those in the tint. You can use this for effects such as making a player flash 'white' + * if hit by something. You can provide either one color value, in which case the whole + * Game Object will be rendered in that color. Or you can provide a color per corner. The colors + * are blended together across the extent of the Game Object. + * + * To modify the tint color once set, either call this method again with new values or use the + * `tint` property to set all colors at once. Or, use the properties `tintTopLeft`, `tintTopRight, + * `tintBottomLeft` and `tintBottomRight` to set the corner color values independently. + * + * To remove a tint call `clearTint`. + * + * To swap this from being a fill-tint to an additive tint set the property `tintFill` to `false`. + * @param topLeft The tint being applied to the top-left of the Game Object. If not other values are given this value is applied evenly, tinting the whole Game Object. Default 0xffffff. + * @param topRight The tint being applied to the top-right of the Game Object. + * @param bottomLeft The tint being applied to the bottom-left of the Game Object. + * @param bottomRight The tint being applied to the bottom-right of the Game Object. + */ + setTintFill(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; + + /** + * The tint value being applied to the whole of the Game Object. + * This property is a setter-only. Use the properties `tintTopLeft` etc to read the current tint value. + */ + tint: number; + + /** + * Does this Game Object have a tint applied? + * + * It checks to see if the 4 tint properties are set to the value 0xffffff + * and that the `tintFill` property is `false`. This indicates that a Game Object isn't tinted. */ - setTexture(key: string | Phaser.Textures.Texture, frame?: string | integer): this; + readonly isTinted: boolean; /** * The x position of this Game Object. @@ -22505,13 +25837,13 @@ declare namespace Phaser { * * If you prefer to work in radians, see the `rotation` property instead. */ - angle: integer; + angle: number; /** * The angle of this Game Object in radians. * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. * * If you prefer to work in degrees, see the `angle` property instead. */ @@ -22526,6 +25858,12 @@ declare namespace Phaser { */ setPosition(x?: number, y?: number, z?: number, w?: number): this; + /** + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; + /** * Sets the position of this Game Object to be a random position within the confines of * the given area. @@ -22600,6 +25938,22 @@ declare namespace Phaser { */ getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. + */ + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + /** * Gets the sum total rotation of all of this Game Objects parent Containers. * @@ -22623,411 +25977,139 @@ declare namespace Phaser { setVisible(value: boolean): this; /** - * The horizontal scroll factor of this Game Object. - * - * The scroll factor controls the influence of the movement of a Camera upon this Game Object. - * - * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. - * It does not change the Game Objects actual position values. - * - * A value of 1 means it will move exactly in sync with a camera. - * A value of 0 means it will not move at all, even if the camera moves. - * Other values control the degree to which the camera movement is mapped to this Game Object. - * - * Please be aware that scroll factor values other than 1 are not taken in to consideration when - * calculating physics collisions. Bodies always collide based on their world position, but changing - * the scroll factor is a visual adjustment to where the textures are rendered, which can offset - * them from physics bodies if not accounted for in your code. + * The Path this PathFollower is following. It can only follow one Path at a time. */ - scrollFactorX: number; + path: Phaser.Curves.Path; /** - * The vertical scroll factor of this Game Object. - * - * The scroll factor controls the influence of the movement of a Camera upon this Game Object. - * - * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. - * It does not change the Game Objects actual position values. - * - * A value of 1 means it will move exactly in sync with a camera. - * A value of 0 means it will not move at all, even if the camera moves. - * Other values control the degree to which the camera movement is mapped to this Game Object. - * - * Please be aware that scroll factor values other than 1 are not taken in to consideration when - * calculating physics collisions. Bodies always collide based on their world position, but changing - * the scroll factor is a visual adjustment to where the textures are rendered, which can offset - * them from physics bodies if not accounted for in your code. + * Should the PathFollower automatically rotate to point in the direction of the Path? */ - scrollFactorY: number; + rotateToPath: boolean; /** - * Sets the scroll factor of this Game Object. - * - * The scroll factor controls the influence of the movement of a Camera upon this Game Object. - * - * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. - * It does not change the Game Objects actual position values. - * - * A value of 1 means it will move exactly in sync with a camera. - * A value of 0 means it will not move at all, even if the camera moves. - * Other values control the degree to which the camera movement is mapped to this Game Object. + * Set the Path that this PathFollower should follow. * - * Please be aware that scroll factor values other than 1 are not taken in to consideration when - * calculating physics collisions. Bodies always collide based on their world position, but changing - * the scroll factor is a visual adjustment to where the textures are rendered, which can offset - * them from physics bodies if not accounted for in your code. - * @param x The horizontal scroll factor of this Game Object. - * @param y The vertical scroll factor of this Game Object. If not set it will use the `x` value. Default x. + * Optionally accepts {@link Phaser.Types.GameObjects.PathFollower.PathConfig} settings. + * @param path The Path this PathFollower is following. It can only follow one Path at a time. + * @param config Settings for the PathFollower. */ - setScrollFactor(x: number, y?: number): this; + setPath(path: Phaser.Curves.Path, config?: number | Phaser.Types.GameObjects.PathFollower.PathConfig | Phaser.Types.Tweens.NumberTweenBuilderConfig): this; - } + /** + * Set whether the PathFollower should automatically rotate to point in the direction of the Path. + * @param value Whether the PathFollower should automatically rotate to point in the direction of the Path. + * @param offset Rotation offset in degrees. Default 0. + */ + setRotateToPath(value: boolean, offset?: number): this; - /** - * A Render Texture. - * - * A Render Texture is a special texture that allows any number of Game Objects to be drawn to it. You can take many complex objects and - * draw them all to this one texture, which can they be used as the texture for other Game Object's. It's a way to generate dynamic - * textures at run-time that are WebGL friendly and don't invoke expensive GPU uploads. - * - * Note that under WebGL a FrameBuffer, which is what the Render Texture uses internally, cannot be anti-aliased. This means - * that when drawing objects such as Shapes to a Render Texture they will appear to be drawn with no aliasing, however this - * is a technical limitation of WebGL. To get around it, create your shape as a texture in an art package, then draw that - * to the Render Texture. - */ - class RenderTexture extends Phaser.GameObjects.GameObject implements Phaser.GameObjects.Components.Alpha, Phaser.GameObjects.Components.BlendMode, Phaser.GameObjects.Components.ComputedSize, Phaser.GameObjects.Components.Crop, Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.Flip, Phaser.GameObjects.Components.GetBounds, Phaser.GameObjects.Components.Mask, Phaser.GameObjects.Components.Origin, Phaser.GameObjects.Components.Pipeline, Phaser.GameObjects.Components.ScrollFactor, Phaser.GameObjects.Components.Tint, Phaser.GameObjects.Components.Transform, Phaser.GameObjects.Components.Visible { /** + * Is this PathFollower actively following a Path or not? * - * @param scene The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. - * @param x The horizontal position of this Game Object in the world. Default 0. - * @param y The vertical position of this Game Object in the world. Default 0. - * @param width The width of the Render Texture. Default 32. - * @param height The height of the Render Texture. Default 32. - */ - constructor(scene: Phaser.Scene, x?: number, y?: number, width?: integer, height?: integer); - - /** - * A reference to either the Canvas or WebGL Renderer that the Game instance is using. - */ - renderer: Phaser.Renderer.Canvas.CanvasRenderer | Phaser.Renderer.WebGL.WebGLRenderer; - - /** - * A reference to the Texture Manager. - */ - textureManager: Phaser.Textures.TextureManager; - - /** - * The tint of the Render Texture when rendered. - */ - globalTint: number; - - /** - * The alpha of the Render Texture when rendered. - */ - globalAlpha: number; - - /** - * The HTML Canvas Element that the Render Texture is drawing to when using the Canvas Renderer. - */ - canvas: HTMLCanvasElement; - - /** - * A reference to the GL Frame Buffer this Render Texture is drawing to. - * This is only set if Phaser is running with the WebGL Renderer. - */ - framebuffer: WebGLFramebuffer; - - /** - * Is this Render Texture dirty or not? If not it won't spend time clearing or filling itself. - */ - dirty: boolean; - - /** - * The Texture corresponding to this Render Texture. - */ - texture: Phaser.Textures.Texture; - - /** - * The Frame corresponding to this Render Texture. - */ - frame: Phaser.Textures.Frame; - - /** - * A reference to the Rendering Context belonging to the Canvas Element this Render Texture is drawing to. - */ - context: CanvasRenderingContext2D; - - /** - * An internal Camera that can be used to move around the Render Texture. - * Control it just like you would any Scene Camera. The difference is that it only impacts the placement of what - * is drawn to the Render Texture. You can scroll, zoom and rotate this Camera. - */ - camera: Phaser.Cameras.Scene2D.BaseCamera; - - /** - * A reference to the WebGL Rendering Context. + * To be considered as `isFollowing` it must be currently moving on a Path, and not paused. */ - gl: WebGLRenderingContext; + isFollowing(): boolean; /** - * A reference to the WebGLTexture that is being rendered to in a WebGL Context. + * Starts this PathFollower following its given Path. + * @param config The duration of the follow, or a PathFollower config object. Default {}. + * @param startAt Optional start position of the follow, between 0 and 1. Default 0. */ - readonly glTexture: WebGLTexture; + startFollow(config?: number | Phaser.Types.GameObjects.PathFollower.PathConfig | Phaser.Types.Tweens.NumberTweenBuilderConfig, startAt?: number): this; /** - * Sets the size of this Game Object. - * @param width The width of this Game Object. - * @param height The height of this Game Object. + * Pauses this PathFollower. It will still continue to render, but it will remain motionless at the + * point on the Path at which you paused it. */ - setSize(width: number, height: number): this; + pauseFollow(): this; /** - * Resizes the Render Texture to the new dimensions given. - * - * If Render Texture was created from specific frame, only the size of the frame will be changed. The size of the source - * texture will not change. - * - * If Render Texture was not created from specific frame, the following will happen: - * In WebGL it will destroy and then re-create the frame buffer being used by the Render Texture. - * In Canvas it will resize the underlying canvas element. - * Both approaches will erase everything currently drawn to the Render Texture. + * Resumes a previously paused PathFollower. * - * If the dimensions given are the same as those already being used, calling this method will do nothing. - * @param width The new width of the Render Texture. - * @param height The new height of the Render Texture. If not specified, will be set the same as the `width`. Default width. - */ - resize(width: number, height?: number): this; - - /** - * Set the tint to use when rendering this Render Texture. - * @param tint The tint value. - */ - setGlobalTint(tint: integer): this; - - /** - * Set the alpha to use when rendering this Render Texture. - * @param alpha The alpha value. + * If the PathFollower was not paused this has no effect. */ - setGlobalAlpha(alpha: number): this; + resumeFollow(): this; /** - * Stores a copy of this Render Texture in the Texture Manager using the given key. - * - * After doing this, any texture based Game Object, such as a Sprite, can use the contents of this - * Render Texture by using the texture key: - * - * ```javascript - * var rt = this.add.renderTexture(0, 0, 128, 128); - * - * // Draw something to the Render Texture - * - * rt.saveTexture('doodle'); - * - * this.add.image(400, 300, 'doodle'); - * ``` - * - * Updating the contents of this Render Texture will automatically update _any_ Game Object - * that is using it as a texture. Calling `saveTexture` again will not save another copy - * of the same texture, it will just rename the key of the existing copy. + * Stops this PathFollower from following the path any longer. * - * By default it will create a single base texture. You can add frames to the texture - * by using the `Texture.add` method. After doing this, you can then allow Game Objects - * to use a specific frame from a Render Texture. - * @param key The unique key to store the texture as within the global Texture Manager. - */ - saveTexture(key: string): Phaser.Textures.Texture; - - /** - * Fills the Render Texture with the given color. - * @param rgb The color to fill the Render Texture with. - * @param alpha The alpha value used by the fill. Default 1. - * @param x The left coordinate of the fill rectangle. Default 0. - * @param y The top coordinate of the fill rectangle. Default 0. - * @param width The width of the fill rectangle. Default this.frame.cutWidth. - * @param height The height of the fill rectangle. Default this.frame.cutHeight. - */ - fill(rgb: number, alpha?: number, x?: number, y?: number, width?: number, height?: number): this; - - /** - * Clears the Render Texture. + * This will invoke any 'stop' conditions that may exist on the Path, or for the follower. */ - clear(): this; + stopFollow(): this; /** - * Draws the given object, or an array of objects, to this Render Texture using a blend mode of ERASE. - * This has the effect of erasing any filled pixels in the objects from this Render Texture. - * - * It can accept any of the following: - * - * * Any renderable Game Object, such as a Sprite, Text, Graphics or TileSprite. - * * Dynamic and Static Tilemap Layers. - * * A Group. The contents of which will be iterated and drawn in turn. - * * A Container. The contents of which will be iterated fully, and drawn in turn. - * * A Scene's Display List. Pass in `Scene.children` to draw the whole list. - * * Another Render Texture. - * * A Texture Frame instance. - * * A string. This is used to look-up a texture from the Texture Manager. - * - * Note: You cannot erase a Render Texture from itself. - * - * If passing in a Group or Container it will only draw children that return `true` - * when their `willRender()` method is called. I.e. a Container with 10 children, - * 5 of which have `visible=false` will only draw the 5 visible ones. - * - * If passing in an array of Game Objects it will draw them all, regardless if - * they pass a `willRender` check or not. - * - * You can pass in a string in which case it will look for a texture in the Texture - * Manager matching that string, and draw the base frame. - * - * You can pass in the `x` and `y` coordinates to draw the objects at. The use of - * the coordinates differ based on what objects are being drawn. If the object is - * a Group, Container or Display List, the coordinates are _added_ to the positions - * of the children. For all other types of object, the coordinates are exact. + * Internal update handler that advances this PathFollower along the path. * - * Calling this method causes the WebGL batch to flush, so it can write the texture - * data to the framebuffer being used internally. The batch is flushed at the end, - * after the entries have been iterated. So if you've a bunch of objects to draw, - * try and pass them in an array in one single call, rather than making lots of - * separate calls. - * @param entries Any renderable Game Object, or Group, Container, Display List, other Render Texture, Texture Frame or an array of any of these. - * @param x The x position to draw the Frame at, or the offset applied to the object. - * @param y The y position to draw the Frame at, or the offset applied to the object. + * Called automatically by the Scene step, should not typically be called directly. */ - erase(entries: any, x?: number, y?: number): this; + pathUpdate(): void; - /** - * Draws the given object, or an array of objects, to this Render Texture. - * - * It can accept any of the following: - * - * * Any renderable Game Object, such as a Sprite, Text, Graphics or TileSprite. - * * Dynamic and Static Tilemap Layers. - * * A Group. The contents of which will be iterated and drawn in turn. - * * A Container. The contents of which will be iterated fully, and drawn in turn. - * * A Scene's Display List. Pass in `Scene.children` to draw the whole list. - * * Another Render Texture. - * * A Texture Frame instance. - * * A string. This is used to look-up a texture from the Texture Manager. - * - * Note: You cannot draw a Render Texture to itself. - * - * If passing in a Group or Container it will only draw children that return `true` - * when their `willRender()` method is called. I.e. a Container with 10 children, - * 5 of which have `visible=false` will only draw the 5 visible ones. - * - * If passing in an array of Game Objects it will draw them all, regardless if - * they pass a `willRender` check or not. - * - * You can pass in a string in which case it will look for a texture in the Texture - * Manager matching that string, and draw the base frame. If you need to specify - * exactly which frame to draw then use the method `drawFrame` instead. - * - * You can pass in the `x` and `y` coordinates to draw the objects at. The use of - * the coordinates differ based on what objects are being drawn. If the object is - * a Group, Container or Display List, the coordinates are _added_ to the positions - * of the children. For all other types of object, the coordinates are exact. - * - * The `alpha` and `tint` values are only used by Texture Frames. - * Game Objects use their own alpha and tint values when being drawn. - * - * Calling this method causes the WebGL batch to flush, so it can write the texture - * data to the framebuffer being used internally. The batch is flushed at the end, - * after the entries have been iterated. So if you've a bunch of objects to draw, - * try and pass them in an array in one single call, rather than making lots of - * separate calls. - * @param entries Any renderable Game Object, or Group, Container, Display List, other Render Texture, Texture Frame or an array of any of these. - * @param x The x position to draw the Frame at, or the offset applied to the object. - * @param y The y position to draw the Frame at, or the offset applied to the object. - * @param alpha The alpha value. Only used for Texture Frames and if not specified defaults to the `globalAlpha` property. Game Objects use their own current alpha value. - * @param tint WebGL only. The tint color value. Only used for Texture Frames and if not specified defaults to the `globalTint` property. Game Objects use their own current tint value. - */ - draw(entries: any, x?: number, y?: number, alpha?: number, tint?: number): this; + } + /** + * The Point Light Game Object provides a way to add a point light effect into your game, + * without the expensive shader processing requirements of the traditional Light Game Object. + * + * The difference is that the Point Light renders using a custom shader, designed to give the + * impression of a point light source, of variable radius, intensity and color, in your game. + * However, unlike the Light Game Object, it does not impact any other Game Objects, or use their + * normal maps for calcuations. This makes them extremely fast to render compared to Lights + * and perfect for special effects, such as flickering torches or muzzle flashes. + * + * For maximum performance you should batch Point Light Game Objects together. This means + * ensuring they follow each other consecutively on the display list. Ideally, use a Layer + * Game Object and then add just Point Lights to it, so that it can batch together the rendering + * of the lights. You don't _have_ to do this, and if you've only a handful of Point Lights in + * your game then it's perfectly safe to mix them into the dislay list as normal. However, if + * you're using a large number of them, please consider how they are mixed into the display list. + * + * The renderer will automatically cull Point Lights. Those with a radius that does not intersect + * with the Camera will be skipped in the rendering list. This happens automatically and the + * culled state is refreshed every frame, for every camera. + * + * The origin of a Point Light is always 0.5 and it cannot be changed. + * + * Point Lights are a WebGL only feature and do not have a Canvas counterpart. + */ + class PointLight extends Phaser.GameObjects.GameObject implements Phaser.GameObjects.Components.AlphaSingle, Phaser.GameObjects.Components.BlendMode, Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.GetBounds, Phaser.GameObjects.Components.Mask, Phaser.GameObjects.Components.Pipeline, Phaser.GameObjects.Components.ScrollFactor, Phaser.GameObjects.Components.Transform, Phaser.GameObjects.Components.Visible { /** - * Draws the Texture Frame to the Render Texture at the given position. - * - * Textures are referenced by their string-based keys, as stored in the Texture Manager. - * - * ```javascript - * var rt = this.add.renderTexture(0, 0, 800, 600); - * rt.drawFrame(key, frame); - * ``` - * - * You can optionally provide a position, alpha and tint value to apply to the frame - * before it is drawn. - * - * Calling this method will cause a batch flush, so if you've got a stack of things to draw - * in a tight loop, try using the `draw` method instead. * - * If you need to draw a Sprite to this Render Texture, use the `draw` method instead. - * @param key The key of the texture to be used, as stored in the Texture Manager. - * @param frame The name or index of the frame within the Texture. - * @param x The x position to draw the frame at. Default 0. - * @param y The y position to draw the frame at. Default 0. - * @param alpha The alpha to use. If not specified it uses the `globalAlpha` property. - * @param tint WebGL only. The tint color to use. If not specified it uses the `globalTint` property. + * @param scene The Scene to which this Point Light belongs. A Point Light can only belong to one Scene at a time. + * @param x The horizontal position of this Point Light in the world. + * @param y The vertical position of this Point Light in the world. + * @param color The color of the Point Light, given as a hex value. Default 0xffffff. + * @param radius The radius of the Point Light. Default 128. + * @param intensity The intensity, or colr blend, of the Point Light. Default 1. + * @param attenuation The attenuation of the Point Light. This is the reduction of light from the center point. Default 0.1. */ - drawFrame(key: string, frame?: string | integer, x?: number, y?: number, alpha?: number, tint?: number): this; + constructor(scene: Phaser.Scene, x: number, y: number, color?: number, radius?: number, intensity?: number, attenuation?: number); /** - * Takes a snapshot of the given area of this Render Texture. - * - * The snapshot is taken immediately. - * - * To capture the whole Render Texture see the `snapshot` method. To capture a specific pixel, see `snapshotPixel`. - * - * Snapshots work by using the WebGL `readPixels` feature to grab every pixel from the frame buffer into an ArrayBufferView. - * It then parses this, copying the contents to a temporary Canvas and finally creating an Image object from it, - * which is the image returned to the callback provided. All in all, this is a computationally expensive and blocking process, - * which gets more expensive the larger the canvas size gets, so please be careful how you employ this in your game. - * @param x The x coordinate to grab from. - * @param y The y coordinate to grab from. - * @param width The width of the area to grab. - * @param height The height of the area to grab. - * @param callback The Function to invoke after the snapshot image is created. - * @param type The format of the image to create, usually `image/png` or `image/jpeg`. Default 'image/png'. - * @param encoderOptions The image quality, between 0 and 1. Used for image formats with lossy compression, such as `image/jpeg`. Default 0.92. + * The color of this Point Light. This property is an instance of a + * Color object, so you can use the methods within it, such as `setTo(r, g, b)` + * to change the color value. */ - snapshotArea(x: integer, y: integer, width: integer, height: integer, callback: Phaser.Types.Renderer.Snapshot.SnapshotCallback, type?: string, encoderOptions?: number): this; + color: Phaser.Display.Color; /** - * Takes a snapshot of the whole of this Render Texture. - * - * The snapshot is taken immediately. - * - * To capture just a portion of the Render Texture see the `snapshotArea` method. To capture a specific pixel, see `snapshotPixel`. + * The intensity of the Point Light. * - * Snapshots work by using the WebGL `readPixels` feature to grab every pixel from the frame buffer into an ArrayBufferView. - * It then parses this, copying the contents to a temporary Canvas and finally creating an Image object from it, - * which is the image returned to the callback provided. All in all, this is a computationally expensive and blocking process, - * which gets more expensive the larger the canvas size gets, so please be careful how you employ this in your game. - * @param callback The Function to invoke after the snapshot image is created. - * @param type The format of the image to create, usually `image/png` or `image/jpeg`. Default 'image/png'. - * @param encoderOptions The image quality, between 0 and 1. Used for image formats with lossy compression, such as `image/jpeg`. Default 0.92. + * The colors of the light are multiplied by this value during rendering. */ - snapshot(callback: Phaser.Types.Renderer.Snapshot.SnapshotCallback, type?: string, encoderOptions?: number): this; + intensity: number; /** - * Takes a snapshot of the given pixel from this Render Texture. - * - * The snapshot is taken immediately. + * The attenuation of the Point Light. * - * To capture the whole Render Texture see the `snapshot` method. To capture a specific portion, see `snapshotArea`. + * This value controls the force with which the light falls-off from the center of the light. * - * Unlike the other two snapshot methods, this one will send your callback a `Color` object containing the color data for - * the requested pixel. It doesn't need to create an internal Canvas or Image object, so is a lot faster to execute, - * using less memory, than the other snapshot methods. - * @param x The x coordinate of the pixel to get. - * @param y The y coordinate of the pixel to get. - * @param callback The Function to invoke after the snapshot pixel data is extracted. + * Use small float-based values, i.e. 0.1. */ - snapshotPixel(x: integer, y: integer, callback: Phaser.Types.Renderer.Snapshot.SnapshotCallback): this; + attenuation: number; /** - * Internal destroy handler, called as part of the destroy process. + * The radius of the Point Light. */ - protected preDestroy(): void; + radius: number; /** * Clears all alpha values associated with this Game Object. @@ -23039,15 +26121,9 @@ declare namespace Phaser { /** * Set the Alpha level of this Game Object. The alpha controls the opacity of the Game Object as it renders. * Alpha values are provided as a float between 0, fully transparent, and 1, fully opaque. - * - * If your game is running under WebGL you can optionally specify four different alpha values, each of which - * correspond to the four corners of the Game Object. Under Canvas only the `topLeft` value given is used. - * @param topLeft The alpha value used for the top-left of the Game Object. If this is the only value given it's applied across the whole Game Object. Default 1. - * @param topRight The alpha value used for the top-right of the Game Object. WebGL only. - * @param bottomLeft The alpha value used for the bottom-left of the Game Object. WebGL only. - * @param bottomRight The alpha value used for the bottom-right of the Game Object. WebGL only. + * @param value The alpha value applied across the whole Game Object. Default 1. */ - setAlpha(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; + setAlpha(value?: number): this; /** * The alpha value of the Game Object. @@ -23056,30 +26132,6 @@ declare namespace Phaser { */ alpha: number; - /** - * The alpha value starting from the top-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - alphaTopLeft: number; - - /** - * The alpha value starting from the top-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - alphaTopRight: number; - - /** - * The alpha value starting from the bottom-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - alphaBottomLeft: number; - - /** - * The alpha value starting from the bottom-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - alphaBottomRight: number; - /** * Sets the Blend Mode being used by this Game Object. * @@ -23127,94 +26179,13 @@ declare namespace Phaser { */ setBlendMode(value: string | Phaser.BlendModes): this; - /** - * The native (un-scaled) width of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayWidth` property. - */ - width: number; - - /** - * The native (un-scaled) height of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayHeight` property. - */ - height: number; - - /** - * The displayed width of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. - */ - displayWidth: number; - - /** - * The displayed height of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. - */ - displayHeight: number; - - /** - * Sets the display size of this Game Object. - * - * Calling this will adjust the scale. - * @param width The width of this Game Object. - * @param height The height of this Game Object. - */ - setDisplaySize(width: number, height: number): this; - - /** - * A boolean flag indicating if this Game Object is being cropped or not. - * You can toggle this at any time after `setCrop` has been called, to turn cropping on or off. - * Equally, calling `setCrop` with no arguments will reset the crop and disable it. - */ - isCropped: boolean; - - /** - * Applies a crop to a texture based Game Object, such as a Sprite or Image. - * - * The crop is a rectangle that limits the area of the texture frame that is visible during rendering. - * - * Cropping a Game Object does not change its size, dimensions, physics body or hit area, it just - * changes what is shown when rendered. - * - * The crop coordinates are relative to the texture frame, not the Game Object, meaning 0 x 0 is the top-left. - * - * Therefore, if you had a Game Object that had an 800x600 sized texture, and you wanted to show only the left - * half of it, you could call `setCrop(0, 0, 400, 600)`. - * - * It is also scaled to match the Game Object scale automatically. Therefore a crop rect of 100x50 would crop - * an area of 200x100 when applied to a Game Object that had a scale factor of 2. - * - * You can either pass in numeric values directly, or you can provide a single Rectangle object as the first argument. - * - * Call this method with no arguments at all to reset the crop, or toggle the property `isCropped` to `false`. - * - * You should do this if the crop rectangle becomes the same size as the frame itself, as it will allow - * the renderer to skip several internal calculations. - * @param x The x coordinate to start the crop from. Or a Phaser.Geom.Rectangle object, in which case the rest of the arguments are ignored. - * @param y The y coordinate to start the crop from. - * @param width The width of the crop rectangle in pixels. - * @param height The height of the crop rectangle in pixels. - */ - setCrop(x?: number | Phaser.Geom.Rectangle, y?: number, width?: number, height?: number): this; - /** * The depth of this Game Object within the Scene. * * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. @@ -23227,77 +26198,13 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. * @param value The depth of this Game Object. */ - setDepth(value: integer): this; - - /** - * The horizontally flipped state of the Game Object. - * - * A Game Object that is flipped horizontally will render inversed on the horizontal axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. - */ - flipX: boolean; - - /** - * The vertically flipped state of the Game Object. - * - * A Game Object that is flipped vertically will render inversed on the vertical axis (i.e. upside down) - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. - */ - flipY: boolean; - - /** - * Toggles the horizontal flipped state of this Game Object. - * - * A Game Object that is flipped horizontally will render inversed on the horizontal axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. - */ - toggleFlipX(): this; - - /** - * Toggles the vertical flipped state of this Game Object. - */ - toggleFlipY(): this; - - /** - * Sets the horizontal flipped state of this Game Object. - * - * A Game Object that is flipped horizontally will render inversed on the horizontal axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. - * @param value The flipped state. `false` for no flip, or `true` to be flipped. - */ - setFlipX(value: boolean): this; - - /** - * Sets the vertical flipped state of this Game Object. - * @param value The flipped state. `false` for no flip, or `true` to be flipped. - */ - setFlipY(value: boolean): this; - - /** - * Sets the horizontal and vertical flipped state of this Game Object. - * - * A Game Object that is flipped will render inversed on the flipped axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. - * @param x The horizontal flipped state. `false` for no flip, or `true` to be flipped. - * @param y The horizontal flipped state. `false` for no flip, or `true` to be flipped. - */ - setFlip(x: boolean, y: boolean): this; - - /** - * Resets the horizontal and vertical flipped state of this Game Object back to their default un-flipped state. - */ - resetFlip(): this; + setDepth(value: number): this; /** * Gets the center coordinate of this Game Object, regardless of origin. @@ -23409,6 +26316,8 @@ declare namespace Phaser { * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, * including this one. * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * * To create the mask you need to pass in a reference to a renderable Game Object. * A renderable Game Object is one that uses a texture to render with, such as an * Image, Sprite, Render Texture or BitmapText. @@ -23435,90 +26344,120 @@ declare namespace Phaser { createGeometryMask(graphics?: Phaser.GameObjects.Graphics): Phaser.Display.Masks.GeometryMask; /** - * The horizontal origin of this Game Object. - * The origin maps the relationship between the size and position of the Game Object. - * The default value is 0.5, meaning all Game Objects are positioned based on their center. - * Setting the value to 0 means the position now relates to the left of the Game Object. + * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. */ - originX: number; + defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; /** - * The vertical origin of this Game Object. - * The origin maps the relationship between the size and position of the Game Object. - * The default value is 0.5, meaning all Game Objects are positioned based on their center. - * Setting the value to 0 means the position now relates to the top of the Game Object. + * The current WebGL pipeline of this Game Object. */ - originY: number; + pipeline: Phaser.Renderer.WebGL.WebGLPipeline; /** - * The horizontal display origin of this Game Object. - * The origin is a normalized value between 0 and 1. - * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. + * Does this Game Object have any Post Pipelines set? */ - displayOriginX: number; + hasPostPipeline: boolean; /** - * The vertical display origin of this Game Object. - * The origin is a normalized value between 0 and 1. - * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. */ - displayOriginY: number; + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; /** - * Sets the origin of this Game Object. - * - * The values are given in the range 0 to 1. - * @param x The horizontal origin value. Default 0.5. - * @param y The vertical origin value. If not defined it will be set to the value of `x`. Default x. + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. */ - setOrigin(x?: number, y?: number): this; + pipelineData: object; /** - * Sets the origin of this Game Object based on the Pivot values in its Frame. + * Sets the initial WebGL Pipeline of this Game Object. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. */ - setOriginFromFrame(): this; + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; /** - * Sets the display origin of this Game Object. - * The difference between this and setting the origin is that you can use pixel values for setting the display origin. - * @param x The horizontal display origin value. Default 0. - * @param y The vertical display origin value. If not defined it will be set to the value of `x`. Default x. + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. */ - setDisplayOrigin(x?: number, y?: number): this; + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; /** - * Updates the Display Origin cached values internally stored on this Game Object. - * You don't usually call this directly, but it is exposed for edge-cases where you may. + * Sets one, or more, Post Pipelines on this Game Object. + * + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. */ - updateDisplayOrigin(): this; + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; /** - * The initial WebGL pipeline of this Game Object. + * Adds an entry to the `pipelineData` object belonging to this Game Object. + * + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. */ - defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; + setPipelineData(key: string, value?: any): this; /** - * The current WebGL pipeline of this Game Object. + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; /** - * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. + * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. */ - initPipeline(pipelineName?: string): boolean; + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. */ - setPipeline(pipelineName: string): this; + resetPostPipeline(resetData?: boolean): void; /** - * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - resetPipeline(): boolean; + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; /** * Gets the name of the WebGL Pipeline this Game Object is currently using. @@ -23584,99 +26523,6 @@ declare namespace Phaser { */ setScrollFactor(x: number, y?: number): this; - /** - * Fill or additive? - */ - tintFill: boolean; - - /** - * Clears all tint values associated with this Game Object. - * - * Immediately sets the color values back to 0xffffff and the tint type to 'additive', - * which results in no visible change to the texture. - */ - clearTint(): this; - - /** - * Sets an additive tint on this Game Object. - * - * The tint works by taking the pixel color values from the Game Objects texture, and then - * multiplying it by the color value of the tint. You can provide either one color value, - * in which case the whole Game Object will be tinted in that color. Or you can provide a color - * per corner. The colors are blended together across the extent of the Game Object. - * - * To modify the tint color once set, either call this method again with new values or use the - * `tint` property to set all colors at once. Or, use the properties `tintTopLeft`, `tintTopRight, - * `tintBottomLeft` and `tintBottomRight` to set the corner color values independently. - * - * To remove a tint call `clearTint`. - * - * To swap this from being an additive tint to a fill based tint set the property `tintFill` to `true`. - * @param topLeft The tint being applied to the top-left of the Game Object. If no other values are given this value is applied evenly, tinting the whole Game Object. Default 0xffffff. - * @param topRight The tint being applied to the top-right of the Game Object. - * @param bottomLeft The tint being applied to the bottom-left of the Game Object. - * @param bottomRight The tint being applied to the bottom-right of the Game Object. - */ - setTint(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; - - /** - * Sets a fill-based tint on this Game Object. - * - * Unlike an additive tint, a fill-tint literally replaces the pixel colors from the texture - * with those in the tint. You can use this for effects such as making a player flash 'white' - * if hit by something. You can provide either one color value, in which case the whole - * Game Object will be rendered in that color. Or you can provide a color per corner. The colors - * are blended together across the extent of the Game Object. - * - * To modify the tint color once set, either call this method again with new values or use the - * `tint` property to set all colors at once. Or, use the properties `tintTopLeft`, `tintTopRight, - * `tintBottomLeft` and `tintBottomRight` to set the corner color values independently. - * - * To remove a tint call `clearTint`. - * - * To swap this from being a fill-tint to an additive tint set the property `tintFill` to `false`. - * @param topLeft The tint being applied to the top-left of the Game Object. If not other values are given this value is applied evenly, tinting the whole Game Object. Default 0xffffff. - * @param topRight The tint being applied to the top-right of the Game Object. - * @param bottomLeft The tint being applied to the bottom-left of the Game Object. - * @param bottomRight The tint being applied to the bottom-right of the Game Object. - */ - setTintFill(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; - - /** - * The tint value being applied to the top-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintTopLeft: integer; - - /** - * The tint value being applied to the top-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintTopRight: integer; - - /** - * The tint value being applied to the bottom-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintBottomLeft: integer; - - /** - * The tint value being applied to the bottom-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintBottomRight: integer; - - /** - * The tint value being applied to the whole of the Game Object. - * This property is a setter-only. Use the properties `tintTopLeft` etc to read the current tint value. - */ - tint: integer; - - /** - * Does this Game Object have a tint applied to it or not? - */ - readonly isTinted: boolean; - /** * The x position of this Game Object. */ @@ -23727,13 +26573,13 @@ declare namespace Phaser { * * If you prefer to work in radians, see the `rotation` property instead. */ - angle: integer; + angle: number; /** * The angle of this Game Object in radians. * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. * * If you prefer to work in degrees, see the `angle` property instead. */ @@ -23748,6 +26594,12 @@ declare namespace Phaser { */ setPosition(x?: number, y?: number, z?: number, w?: number): this; + /** + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; + /** * Sets the position of this Game Object to be a random position within the confines of * the given area. @@ -23822,6 +26674,22 @@ declare namespace Phaser { */ getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. + */ + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + /** * Gets the sum total rotation of all of this Game Objects parent Containers. * @@ -23847,362 +26715,635 @@ declare namespace Phaser { } /** - * A Shader Game Object. - * - * This Game Object allows you to easily add a quad with its own shader into the display list, and manipulate it - * as you would any other Game Object, including scaling, rotating, positioning and adding to Containers. Shaders - * can be masked with either Bitmap or Geometry masks and can also be used as a Bitmap Mask for a Camera or other - * Game Object. They can also be made interactive and used for input events. - * - * It works by taking a reference to a `Phaser.Display.BaseShader` instance, as found in the Shader Cache. These can - * be created dynamically at runtime, or loaded in via the GLSL File Loader: - * - * ```javascript - * function preload () - * { - * this.load.glsl('fire', 'shaders/fire.glsl.js'); - * } - * - * function create () - * { - * this.add.shader('fire', 400, 300, 512, 512); - * } - * ``` - * - * Please see the Phaser 3 Examples GitHub repo for examples of loading and creating shaders dynamically. - * - * Due to the way in which they work, you cannot directly change the alpha or blend mode of a Shader. This should - * be handled via exposed uniforms in the shader code itself. - * - * By default a Shader will be created with a standard set of uniforms. These were added to match those - * found on sites such as ShaderToy or GLSLSandbox, and provide common functionality a shader may need, - * such as the timestamp, resolution or pointer position. You can replace them by specifying your own uniforms - * in the Base Shader. + * A Render Texture. * - * These Shaders work by halting the current pipeline during rendering, creating a viewport matched to the - * size of this Game Object and then renders a quad using the bound shader. At the end, the pipeline is restored. + * A Render Texture is a special texture that allows any number of Game Objects to be drawn to it. You can take many complex objects and + * draw them all to this one texture, which can they be used as the texture for other Game Object's. It's a way to generate dynamic + * textures at run-time that are WebGL friendly and don't invoke expensive GPU uploads. * - * Because it blocks the pipeline it means it will interrupt any batching that is currently going on, so you should - * use these Game Objects sparingly. If you need to have a fully batched custom shader, then please look at using - * a custom pipeline instead. However, for background or special masking effects, they are extremely effective. + * Note that under WebGL a FrameBuffer, which is what the Render Texture uses internally, cannot be anti-aliased. This means + * that when drawing objects such as Shapes to a Render Texture they will appear to be drawn with no aliasing, however this + * is a technical limitation of WebGL. To get around it, create your shape as a texture in an art package, then draw that + * to the Render Texture. */ - class Shader extends Phaser.GameObjects.GameObject implements Phaser.GameObjects.Components.ComputedSize, Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.GetBounds, Phaser.GameObjects.Components.Mask, Phaser.GameObjects.Components.Origin, Phaser.GameObjects.Components.ScrollFactor, Phaser.GameObjects.Components.Transform, Phaser.GameObjects.Components.Visible { + class RenderTexture extends Phaser.GameObjects.GameObject implements Phaser.GameObjects.Components.Alpha, Phaser.GameObjects.Components.BlendMode, Phaser.GameObjects.Components.ComputedSize, Phaser.GameObjects.Components.Crop, Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.Flip, Phaser.GameObjects.Components.GetBounds, Phaser.GameObjects.Components.Mask, Phaser.GameObjects.Components.Origin, Phaser.GameObjects.Components.Pipeline, Phaser.GameObjects.Components.ScrollFactor, Phaser.GameObjects.Components.Tint, Phaser.GameObjects.Components.Transform, Phaser.GameObjects.Components.Visible { /** * * @param scene The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. - * @param key The key of the shader to use from the shader cache, or a BaseShader instance. * @param x The horizontal position of this Game Object in the world. Default 0. * @param y The vertical position of this Game Object in the world. Default 0. - * @param width The width of the Game Object. Default 128. - * @param height The height of the Game Object. Default 128. - * @param textures Optional array of texture keys to bind to the iChannel0...3 uniforms. The textures must already exist in the Texture Manager. - * @param textureData Additional texture data if you want to create shader with none NPOT textures. + * @param width The width of the Render Texture. Default 32. + * @param height The height of the Render Texture. Default 32. */ - constructor(scene: Phaser.Scene, key: string | Phaser.Display.BaseShader, x?: number, y?: number, width?: number, height?: number, textures?: string[], textureData?: any); + constructor(scene: Phaser.Scene, x?: number, y?: number, width?: number, height?: number); /** - * The underlying shader object being used. - * Empty by default and set during a call to the `setShader` method. + * A reference to either the Canvas or WebGL Renderer that the Game instance is using. */ - shader: Phaser.Display.BaseShader; + renderer: Phaser.Renderer.Canvas.CanvasRenderer | Phaser.Renderer.WebGL.WebGLRenderer; /** - * A reference to the current renderer. - * Shaders only work with the WebGL Renderer. + * A reference to the Texture Manager. */ - renderer: Phaser.Renderer.Canvas.CanvasRenderer | Phaser.Renderer.WebGL.WebGLRenderer; + textureManager: Phaser.Textures.TextureManager; /** - * The WebGL context belonging to the renderer. + * The tint of the Render Texture when rendered. */ - gl: WebGLRenderingContext; + globalTint: number; /** - * Raw byte buffer of vertices this Shader uses. + * The alpha of the Render Texture when rendered. */ - vertexData: ArrayBuffer; + globalAlpha: number; /** - * The WebGL vertex buffer object this shader uses. + * The HTML Canvas Element that the Render Texture is drawing to when using the Canvas Renderer. */ - vertexBuffer: WebGLBuffer; + canvas: HTMLCanvasElement; /** - * The WebGL shader program this shader uses. + * Is this Render Texture dirty or not? If not it won't spend time clearing or filling itself. */ - program: WebGLProgram; + dirty: boolean; /** - * Uint8 view to the vertex raw buffer. Used for uploading vertex buffer resources to the GPU. + * The Texture corresponding to this Render Texture. */ - bytes: Uint8Array; + texture: Phaser.Textures.Texture; /** - * Float32 view of the array buffer containing the shaders vertices. + * The Frame corresponding to this Render Texture. */ - vertexViewF32: Float32Array; + frame: Phaser.Textures.Frame; /** - * The view matrix the shader uses during rendering. + * A reference to the Rendering Context belonging to the Canvas Element this Render Texture is drawing to. */ - readonly viewMatrix: Float32Array; + context: CanvasRenderingContext2D; /** - * The projection matrix the shader uses during rendering. + * An internal Camera that can be used to move around the Render Texture. + * Control it just like you would any Scene Camera. The difference is that it only impacts the placement of what + * is drawn to the Render Texture. You can scroll, zoom and rotate this Camera. */ - readonly projectionMatrix: Float32Array; + camera: Phaser.Cameras.Scene2D.BaseCamera; /** - * The default uniform mappings. These can be added to (or replaced) by specifying your own uniforms when - * creating this shader game object. The uniforms are updated automatically during the render step. + * The Render Target that belongs to this Render Texture. * - * The defaults are: + * A Render Target encapsulates a framebuffer and texture for the WebGL Renderer. * - * `resolution` (2f) - Set to the size of this shader. - * `time` (1f) - The elapsed game time, in seconds. - * `mouse` (2f) - If a pointer has been bound (with `setPointer`), this uniform contains its position each frame. - * `date` (4fv) - A vec4 containing the year, month, day and time in seconds. - * `sampleRate` (1f) - Sound sample rate. 44100 by default. - * `iChannel0...3` (sampler2D) - Input channels 0 to 3. `null` by default. - */ - uniforms: any; - - /** - * The pointer bound to this shader, if any. - * Set via the chainable `setPointer` method, or by modifying this property directly. + * This property remains `null` under Canvas. */ - pointer: Phaser.Input.Pointer; - - /** - * A reference to the GL Frame Buffer this Shader is drawing to. - * This property is only set if you have called `Shader.setRenderToTexture`. - */ - framebuffer: WebGLFramebuffer; + renderTarget: Phaser.Renderer.WebGL.RenderTarget; /** - * A reference to the WebGLTexture this Shader is rendering to. - * This property is only set if you have called `Shader.setRenderToTexture`. + * Sets the size of this Game Object. + * @param width The width of this Game Object. + * @param height The height of this Game Object. */ - glTexture: WebGLTexture; + setSize(width: number, height: number): this; /** - * A flag that indicates if this Shader has been set to render to a texture instead of the display list. + * Resizes the Render Texture to the new dimensions given. * - * This property is `true` if you have called `Shader.setRenderToTexture`, otherwise it's `false`. + * If Render Texture was created from specific frame, only the size of the frame will be changed. The size of the source + * texture will not change. * - * A Shader that is rendering to a texture _does not_ appear on the display list. + * If Render Texture was not created from specific frame, the following will happen: + * + * In WebGL it will destroy and then re-create the frame buffer being used by the Render Texture. + * In Canvas it will resize the underlying canvas element. + * + * Both approaches will erase everything currently drawn to the Render Texture. + * + * If the dimensions given are the same as those already being used, calling this method will do nothing. + * @param width The new width of the Render Texture. + * @param height The new height of the Render Texture. If not specified, will be set the same as the `width`. Default width. */ - readonly renderToTexture: boolean; + resize(width: number, height?: number): this; /** - * A reference to the Phaser.Textures.Texture that has been stored in the Texture Manager for this Shader. - * - * This property is only set if you have called `Shader.setRenderToTexture`, otherwise it is `null`. + * Set the tint to use when rendering this Render Texture. + * @param tint The tint value. */ - texture: Phaser.Textures.Texture; + setGlobalTint(tint: number): this; /** - * Compares the renderMask with the renderFlags to see if this Game Object will render or not. - * Also checks the Game Object against the given Cameras exclusion list. - * @param camera The Camera to check against this Game Object. + * Set the alpha to use when rendering this Render Texture. + * @param alpha The alpha value. */ - willRender(camera: Phaser.Cameras.Scene2D.Camera): boolean; + setGlobalAlpha(alpha: number): this; /** - * Changes this Shader so instead of rendering to the display list it renders to a - * WebGL Framebuffer and WebGL Texture instead. This allows you to use the output - * of this shader as an input for another shader, by mapping a sampler2D uniform - * to it. - * - * After calling this method the `Shader.framebuffer` and `Shader.glTexture` properties - * are populated. + * Stores a copy of this Render Texture in the Texture Manager using the given key. * - * Additionally, you can provide a key to this method. Doing so will create a Phaser Texture - * from this Shader and save it into the Texture Manager, allowing you to then use it for - * any texture-based Game Object, such as a Sprite or Image: + * After doing this, any texture based Game Object, such as a Sprite, can use the contents of this + * Render Texture by using the texture key: * * ```javascript - * var shader = this.add.shader('myShader', x, y, width, height); + * var rt = this.add.renderTexture(0, 0, 128, 128); * - * shader.setRenderToTexture('doodle'); + * // Draw something to the Render Texture + * + * rt.saveTexture('doodle'); * * this.add.image(400, 300, 'doodle'); * ``` * - * Note that it stores an active reference to this Shader. That means as this shader updates, - * so does the texture and any object using it to render with. Also, if you destroy this - * shader, be sure to clear any objects that may have been using it as a texture too. - * - * You can access the Phaser Texture that is created via the `Shader.texture` property. + * Updating the contents of this Render Texture will automatically update _any_ Game Object + * that is using it as a texture. Calling `saveTexture` again will not save another copy + * of the same texture, it will just rename the key of the existing copy. * * By default it will create a single base texture. You can add frames to the texture * by using the `Texture.add` method. After doing this, you can then allow Game Objects * to use a specific frame from a Render Texture. + * + * If you destroy this Render Texture, any Game Object using it via the Texture Manager will + * stop rendering. Ensure you remove the texture from the Texture Manager and any Game Objects + * using it first, before destroying this Render Texture. * @param key The unique key to store the texture as within the global Texture Manager. - * @param flipY Does this texture need vertically flipping before rendering? This should usually be set to `true` if being fed from a buffer. Default false. - */ - setRenderToTexture(key?: string, flipY?: boolean): this; - - /** - * Sets the fragment and, optionally, the vertex shader source code that this Shader will use. - * This will immediately delete the active shader program, if set, and then create a new one - * with the given source. Finally, the shader uniforms are initialized. - * @param key The key of the shader to use from the shader cache, or a BaseShader instance. - * @param textures Optional array of texture keys to bind to the iChannel0...3 uniforms. The textures must already exist in the Texture Manager. - * @param textureData Additional texture data. */ - setShader(key: string | Phaser.Display.BaseShader, textures?: string[], textureData?: any): this; + saveTexture(key: string): Phaser.Textures.Texture; /** - * Binds a Phaser Pointer object to this Shader. - * - * The screen position of the pointer will be set in to the shaders `mouse` uniform - * automatically every frame. Call this method with no arguments to unbind the pointer. - * @param pointer The Pointer to bind to this shader. + * Fills the Render Texture with the given color. + * @param rgb The color to fill the Render Texture with. + * @param alpha The alpha value used by the fill. Default 1. + * @param x The left coordinate of the fill rectangle. Default 0. + * @param y The top coordinate of the fill rectangle. Default 0. + * @param width The width of the fill rectangle. Default this.frame.cutWidth. + * @param height The height of the fill rectangle. Default this.frame.cutHeight. */ - setPointer(pointer?: Phaser.Input.Pointer): this; + fill(rgb: number, alpha?: number, x?: number, y?: number, width?: number, height?: number): this; /** - * Sets this shader to use an orthographic projection matrix. - * This matrix is stored locally in the `projectionMatrix` property, - * as well as being bound to the `uProjectionMatrix` uniform. - * @param left The left value. - * @param right The right value. - * @param bottom The bottom value. - * @param top The top value. + * Clears the Render Texture. */ - projOrtho(left: number, right: number, bottom: number, top: number): void; + clear(): this; /** - * Sets a sampler2D uniform on this shader where the source texture is a WebGLTexture. + * Draws the given object, or an array of objects, to this Render Texture using a blend mode of ERASE. + * This has the effect of erasing any filled pixels in the objects from this Render Texture. * - * This allows you to feed the output from one Shader into another: + * It can accept any of the following: * - * ```javascript - * let shader1 = this.add.shader(baseShader1, 0, 0, 512, 512).setRenderToTexture(); - * let shader2 = this.add.shader(baseShader2, 0, 0, 512, 512).setRenderToTexture('output'); + * * Any renderable Game Object, such as a Sprite, Text, Graphics or TileSprite. + * * Tilemap Layers. + * * A Group. The contents of which will be iterated and drawn in turn. + * * A Container. The contents of which will be iterated fully, and drawn in turn. + * * A Scene's Display List. Pass in `Scene.children` to draw the whole list. + * * Another Render Texture. + * * A Texture Frame instance. + * * A string. This is used to look-up a texture from the Texture Manager. * - * shader1.setSampler2DBuffer('iChannel0', shader2.glTexture, 512, 512); - * shader2.setSampler2DBuffer('iChannel0', shader1.glTexture, 512, 512); - * ``` + * Note: You cannot erase a Render Texture from itself. * - * In the above code, the result of baseShader1 is fed into Shader2 as the `iChannel0` sampler2D uniform. - * The result of baseShader2 is then fed back into shader1 again, creating a feedback loop. + * If passing in a Group or Container it will only draw children that return `true` + * when their `willRender()` method is called. I.e. a Container with 10 children, + * 5 of which have `visible=false` will only draw the 5 visible ones. * - * If you wish to use an image from the Texture Manager as a sampler2D input for this shader, - * see the `Shader.setSampler2D` method. - * @param uniformKey The key of the sampler2D uniform to be updated, i.e. `iChannel0`. - * @param texture A WebGLTexture reference. - * @param width The width of the texture. - * @param height The height of the texture. - * @param textureIndex The texture index. Default 0. - * @param textureData Additional texture data. + * If passing in an array of Game Objects it will draw them all, regardless if + * they pass a `willRender` check or not. + * + * You can pass in a string in which case it will look for a texture in the Texture + * Manager matching that string, and draw the base frame. + * + * You can pass in the `x` and `y` coordinates to draw the objects at. The use of + * the coordinates differ based on what objects are being drawn. If the object is + * a Group, Container or Display List, the coordinates are _added_ to the positions + * of the children. For all other types of object, the coordinates are exact. + * + * Calling this method causes the WebGL batch to flush, so it can write the texture + * data to the framebuffer being used internally. The batch is flushed at the end, + * after the entries have been iterated. So if you've a bunch of objects to draw, + * try and pass them in an array in one single call, rather than making lots of + * separate calls. + * @param entries Any renderable Game Object, or Group, Container, Display List, other Render Texture, Texture Frame or an array of any of these. + * @param x The x position to draw the Frame at, or the offset applied to the object. + * @param y The y position to draw the Frame at, or the offset applied to the object. */ - setSampler2DBuffer(uniformKey: string, texture: WebGLTexture, width: integer, height: integer, textureIndex?: integer, textureData?: any): this; + erase(entries: any, x?: number, y?: number): this; /** - * Sets a sampler2D uniform on this shader. + * Draws the given object, or an array of objects, to this Render Texture. * - * The textureKey given is the key from the Texture Manager cache. You cannot use a single frame - * from a texture, only the full image. Also, lots of shaders expect textures to be power-of-two sized. + * It can accept any of the following: * - * If you wish to use another Shader as a sampler2D input for this shader, see the `Shader.setSampler2DBuffer` method. - * @param uniformKey The key of the sampler2D uniform to be updated, i.e. `iChannel0`. - * @param textureKey The key of the texture, as stored in the Texture Manager. Must already be loaded. - * @param textureIndex The texture index. Default 0. - * @param textureData Additional texture data. + * * Any renderable Game Object, such as a Sprite, Text, Graphics or TileSprite. + * * Tilemap Layers. + * * A Group. The contents of which will be iterated and drawn in turn. + * * A Container. The contents of which will be iterated fully, and drawn in turn. + * * A Scene's Display List. Pass in `Scene.children` to draw the whole list. + * * Another Render Texture. + * * A Texture Frame instance. + * * A string. This is used to look-up a texture from the Texture Manager. + * + * Note: You cannot draw a Render Texture to itself. + * + * If passing in a Group or Container it will only draw children that return `true` + * when their `willRender()` method is called. I.e. a Container with 10 children, + * 5 of which have `visible=false` will only draw the 5 visible ones. + * + * If passing in an array of Game Objects it will draw them all, regardless if + * they pass a `willRender` check or not. + * + * You can pass in a string in which case it will look for a texture in the Texture + * Manager matching that string, and draw the base frame. If you need to specify + * exactly which frame to draw then use the method `drawFrame` instead. + * + * You can pass in the `x` and `y` coordinates to draw the objects at. The use of + * the coordinates differ based on what objects are being drawn. If the object is + * a Group, Container or Display List, the coordinates are _added_ to the positions + * of the children. For all other types of object, the coordinates are exact. + * + * The `alpha` and `tint` values are only used by Texture Frames. + * Game Objects use their own alpha and tint values when being drawn. + * + * Calling this method causes the WebGL batch to flush, so it can write the texture + * data to the framebuffer being used internally. The batch is flushed at the end, + * after the entries have been iterated. So if you've a bunch of objects to draw, + * try and pass them in an array in one single call, rather than making lots of + * separate calls. + * @param entries Any renderable Game Object, or Group, Container, Display List, other Render Texture, Texture Frame or an array of any of these. + * @param x The x position to draw the Frame at, or the offset applied to the object. + * @param y The y position to draw the Frame at, or the offset applied to the object. + * @param alpha The alpha value. Only used for Texture Frames and if not specified defaults to the `globalAlpha` property. Game Objects use their own current alpha value. + * @param tint WebGL only. The tint color value. Only used for Texture Frames and if not specified defaults to the `globalTint` property. Game Objects use their own current tint value. */ - setSampler2D(uniformKey: string, textureKey: string, textureIndex?: integer, textureData?: any): this; + draw(entries: any, x?: number, y?: number, alpha?: number, tint?: number): this; /** - * Sets a property of a uniform already present on this shader. + * Draws the Texture Frame to the Render Texture at the given position. * - * To modify the value of a uniform such as a 1f or 1i use the `value` property directly: + * Textures are referenced by their string-based keys, as stored in the Texture Manager. * * ```javascript - * shader.setUniform('size.value', 16); + * var rt = this.add.renderTexture(0, 0, 800, 600); + * rt.drawFrame(key, frame); * ``` * - * You can use dot notation to access deeper values, for example: + * You can optionally provide a position, alpha and tint value to apply to the frame + * before it is drawn. * - * ```javascript - * shader.setUniform('resolution.value.x', 512); - * ``` + * Calling this method will cause a batch flush, so if you've got a stack of things to draw + * in a tight loop, try using the `draw` method instead. * - * The change to the uniform will take effect the next time the shader is rendered. - * @param key The key of the uniform to modify. Use dots for deep properties, i.e. `resolution.value.x`. - * @param value The value to set into the uniform. - */ - setUniform(key: string, value: any): this; - - /** - * Returns the uniform object for the given key, or `null` if the uniform couldn't be found. - * @param key The key of the uniform to return the value for. + * If you need to draw a Sprite to this Render Texture, use the `draw` method instead. + * @param key The key of the texture to be used, as stored in the Texture Manager. + * @param frame The name or index of the frame within the Texture. + * @param x The x position to draw the frame at. Default 0. + * @param y The y position to draw the frame at. Default 0. + * @param alpha The alpha to use. If not specified it uses the `globalAlpha` property. + * @param tint WebGL only. The tint color to use. If not specified it uses the `globalTint` property. */ - getUniform(key: string): any; + drawFrame(key: string, frame?: string | number, x?: number, y?: number, alpha?: number, tint?: number): this; /** - * A short-cut method that will directly set the texture being used by the `iChannel0` sampler2D uniform. + * Use this method if you need to batch draw a large number of Game Objects to + * this Render Texture in a single go, or on a frequent basis. * - * The textureKey given is the key from the Texture Manager cache. You cannot use a single frame - * from a texture, only the full image. Also, lots of shaders expect textures to be power-of-two sized. - * @param textureKey The key of the texture, as stored in the Texture Manager. Must already be loaded. - * @param textureData Additional texture data. + * This method starts the beginning of a batched draw. + * + * It is faster than calling `draw`, but you must be very careful to manage the + * flow of code and remember to call `endDraw()`. If you don't need to draw large + * numbers of objects it's much safer and easier to use the `draw` method instead. + * + * The flow should be: + * + * ```javascript + * // Call once: + * RenderTexture.beginDraw(); + * + * // repeat n times: + * RenderTexture.batchDraw(); + * // or + * RenderTexture.batchDrawFrame(); + * + * // Call once: + * RenderTexture.endDraw(); + * ``` + * + * Do not call any methods other than `batchDraw`, `batchDrawFrame`, or `endDraw` once you + * have started a batch. Also, be very careful not to destroy this Render Texture while the + * batch is still open, or call `beginDraw` again. */ - setChannel0(textureKey: string, textureData?: any): this; + beginDraw(): this; /** - * A short-cut method that will directly set the texture being used by the `iChannel1` sampler2D uniform. + * Use this method if you have already called `beginDraw` and need to batch + * draw a large number of objects to this Render Texture. * - * The textureKey given is the key from the Texture Manager cache. You cannot use a single frame - * from a texture, only the full image. Also, lots of shaders expect textures to be power-of-two sized. - * @param textureKey The key of the texture, as stored in the Texture Manager. Must already be loaded. - * @param textureData Additional texture data. - */ - setChannel1(textureKey: string, textureData?: any): this; + * This method batches the drawing of the given objects to this Render Texture, + * without causing a bind or batch flush. + * + * It is faster than calling `draw`, but you must be very careful to manage the + * flow of code and remember to call `endDraw()`. If you don't need to draw large + * numbers of objects it's much safer and easier to use the `draw` method instead. + * + * The flow should be: + * + * ```javascript + * // Call once: + * RenderTexture.beginDraw(); + * + * // repeat n times: + * RenderTexture.batchDraw(); + * // or + * RenderTexture.batchDrawFrame(); + * + * // Call once: + * RenderTexture.endDraw(); + * ``` + * + * Do not call any methods other than `batchDraw`, `batchDrawFrame`, or `endDraw` once you + * have started a batch. Also, be very careful not to destroy this Render Texture while the + * batch is still open, or call `beginDraw` again. + * + * Draws the given object, or an array of objects, to this Render Texture. + * + * It can accept any of the following: + * + * * Any renderable Game Object, such as a Sprite, Text, Graphics or TileSprite. + * * Tilemap Layers. + * * A Group. The contents of which will be iterated and drawn in turn. + * * A Container. The contents of which will be iterated fully, and drawn in turn. + * * A Scene's Display List. Pass in `Scene.children` to draw the whole list. + * * Another Render Texture. + * * A Texture Frame instance. + * * A string. This is used to look-up a texture from the Texture Manager. + * + * Note: You cannot draw a Render Texture to itself. + * + * If passing in a Group or Container it will only draw children that return `true` + * when their `willRender()` method is called. I.e. a Container with 10 children, + * 5 of which have `visible=false` will only draw the 5 visible ones. + * + * If passing in an array of Game Objects it will draw them all, regardless if + * they pass a `willRender` check or not. + * + * You can pass in a string in which case it will look for a texture in the Texture + * Manager matching that string, and draw the base frame. If you need to specify + * exactly which frame to draw then use the method `drawFrame` instead. + * + * You can pass in the `x` and `y` coordinates to draw the objects at. The use of + * the coordinates differ based on what objects are being drawn. If the object is + * a Group, Container or Display List, the coordinates are _added_ to the positions + * of the children. For all other types of object, the coordinates are exact. + * + * The `alpha` and `tint` values are only used by Texture Frames. + * Game Objects use their own alpha and tint values when being drawn. + * @param entries Any renderable Game Object, or Group, Container, Display List, other Render Texture, Texture Frame or an array of any of these. + * @param x The x position to draw the Frame at, or the offset applied to the object. + * @param y The y position to draw the Frame at, or the offset applied to the object. + * @param alpha The alpha value. Only used for Texture Frames and if not specified defaults to the `globalAlpha` property. Game Objects use their own current alpha value. + * @param tint WebGL only. The tint color value. Only used for Texture Frames and if not specified defaults to the `globalTint` property. Game Objects use their own current tint value. + */ + batchDraw(entries: any, x?: number, y?: number, alpha?: number, tint?: number): this; /** - * A short-cut method that will directly set the texture being used by the `iChannel2` sampler2D uniform. + * Use this method if you have already called `beginDraw` and need to batch + * draw a large number of texture frames to this Render Texture. * - * The textureKey given is the key from the Texture Manager cache. You cannot use a single frame - * from a texture, only the full image. Also, lots of shaders expect textures to be power-of-two sized. - * @param textureKey The key of the texture, as stored in the Texture Manager. Must already be loaded. - * @param textureData Additional texture data. + * This method batches the drawing of the given frames to this Render Texture, + * without causing a bind or batch flush. + * + * It is faster than calling `drawFrame`, but you must be very careful to manage the + * flow of code and remember to call `endDraw()`. If you don't need to draw large + * numbers of frames it's much safer and easier to use the `drawFrame` method instead. + * + * The flow should be: + * + * ```javascript + * // Call once: + * RenderTexture.beginDraw(); + * + * // repeat n times: + * RenderTexture.batchDraw(); + * // or + * RenderTexture.batchDrawFrame(); + * + * // Call once: + * RenderTexture.endDraw(); + * ``` + * + * Do not call any methods other than `batchDraw`, `batchDrawFrame`, or `endDraw` once you + * have started a batch. Also, be very careful not to destroy this Render Texture while the + * batch is still open, or call `beginDraw` again. + * + * Draws the Texture Frame to the Render Texture at the given position. + * + * Textures are referenced by their string-based keys, as stored in the Texture Manager. + * + * ```javascript + * var rt = this.add.renderTexture(0, 0, 800, 600); + * rt.drawFrame(key, frame); + * ``` + * + * You can optionally provide a position, alpha and tint value to apply to the frame + * before it is drawn. + * + * Calling this method will cause a batch flush, so if you've got a stack of things to draw + * in a tight loop, try using the `draw` method instead. + * + * If you need to draw a Sprite to this Render Texture, use the `draw` method instead. + * @param key The key of the texture to be used, as stored in the Texture Manager. + * @param frame The name or index of the frame within the Texture. + * @param x The x position to draw the frame at. Default 0. + * @param y The y position to draw the frame at. Default 0. + * @param alpha The alpha to use. If not specified it uses the `globalAlpha` property. + * @param tint WebGL only. The tint color to use. If not specified it uses the `globalTint` property. */ - setChannel2(textureKey: string, textureData?: any): this; + batchDrawFrame(key: string, frame?: string | number, x?: number, y?: number, alpha?: number, tint?: number): this; /** - * A short-cut method that will directly set the texture being used by the `iChannel3` sampler2D uniform. + * Use this method to finish batch drawing to this Render Texture. * - * The textureKey given is the key from the Texture Manager cache. You cannot use a single frame - * from a texture, only the full image. Also, lots of shaders expect textures to be power-of-two sized. - * @param textureKey The key of the texture, as stored in the Texture Manager. Must already be loaded. - * @param textureData Additional texture data. + * Never call this method without first calling `beginDraw`. + * + * It is faster than calling `draw`, but you must be very careful to manage the + * flow of code and remember to call `endDraw()`. If you don't need to draw large + * numbers of objects it's much safer and easier to use the `draw` method instead. + * + * The flow should be: + * + * ```javascript + * // Call once: + * RenderTexture.beginDraw(); + * + * // repeat n times: + * RenderTexture.batchDraw(); + * // or + * RenderTexture.batchDrawFrame(); + * + * // Call once: + * RenderTexture.endDraw(); + * ``` + * + * Do not call any methods other than `batchDraw`, `batchDrawFrame`, or `endDraw` once you + * have started a batch. Also, be very careful not to destroy this Render Texture while the + * batch is still open, or call `beginDraw` again. */ - setChannel3(textureKey: string, textureData?: any): this; + endDraw(): this; /** - * Called automatically during render. + * Takes a snapshot of the given area of this Render Texture. * - * This method performs matrix ITRS and then stores the resulting value in the `uViewMatrix` uniform. - * It then sets up the vertex buffer and shader, updates and syncs the uniforms ready - * for flush to be called. - * @param matrix2D The transform matrix to use during rendering. + * The snapshot is taken immediately. + * + * To capture the whole Render Texture see the `snapshot` method. To capture a specific pixel, see `snapshotPixel`. + * + * Snapshots work by using the WebGL `readPixels` feature to grab every pixel from the frame buffer into an ArrayBufferView. + * It then parses this, copying the contents to a temporary Canvas and finally creating an Image object from it, + * which is the image returned to the callback provided. All in all, this is a computationally expensive and blocking process, + * which gets more expensive the larger the canvas size gets, so please be careful how you employ this in your game. + * @param x The x coordinate to grab from. + * @param y The y coordinate to grab from. + * @param width The width of the area to grab. + * @param height The height of the area to grab. + * @param callback The Function to invoke after the snapshot image is created. + * @param type The format of the image to create, usually `image/png` or `image/jpeg`. Default 'image/png'. + * @param encoderOptions The image quality, between 0 and 1. Used for image formats with lossy compression, such as `image/jpeg`. Default 0.92. */ - load(matrix2D?: Phaser.GameObjects.Components.TransformMatrix): void; + snapshotArea(x: number, y: number, width: number, height: number, callback: Phaser.Types.Renderer.Snapshot.SnapshotCallback, type?: string, encoderOptions?: number): this; /** - * Called automatically during render. + * Takes a snapshot of the whole of this Render Texture. * - * Sets the active shader, loads the vertex buffer and then draws. + * The snapshot is taken immediately. + * + * To capture just a portion of the Render Texture see the `snapshotArea` method. To capture a specific pixel, see `snapshotPixel`. + * + * Snapshots work by using the WebGL `readPixels` feature to grab every pixel from the frame buffer into an ArrayBufferView. + * It then parses this, copying the contents to a temporary Canvas and finally creating an Image object from it, + * which is the image returned to the callback provided. All in all, this is a computationally expensive and blocking process, + * which gets more expensive the larger the canvas size gets, so please be careful how you employ this in your game. + * @param callback The Function to invoke after the snapshot image is created. + * @param type The format of the image to create, usually `image/png` or `image/jpeg`. Default 'image/png'. + * @param encoderOptions The image quality, between 0 and 1. Used for image formats with lossy compression, such as `image/jpeg`. Default 0.92. */ - flush(): void; + snapshot(callback: Phaser.Types.Renderer.Snapshot.SnapshotCallback, type?: string, encoderOptions?: number): this; + + /** + * Takes a snapshot of the given pixel from this Render Texture. + * + * The snapshot is taken immediately. + * + * To capture the whole Render Texture see the `snapshot` method. To capture a specific portion, see `snapshotArea`. + * + * Unlike the other two snapshot methods, this one will send your callback a `Color` object containing the color data for + * the requested pixel. It doesn't need to create an internal Canvas or Image object, so is a lot faster to execute, + * using less memory, than the other snapshot methods. + * @param x The x coordinate of the pixel to get. + * @param y The y coordinate of the pixel to get. + * @param callback The Function to invoke after the snapshot pixel data is extracted. + */ + snapshotPixel(x: number, y: number, callback: Phaser.Types.Renderer.Snapshot.SnapshotCallback): this; /** * Internal destroy handler, called as part of the destroy process. */ protected preDestroy(): void; + /** + * Clears all alpha values associated with this Game Object. + * + * Immediately sets the alpha levels back to 1 (fully opaque). + */ + clearAlpha(): this; + + /** + * Set the Alpha level of this Game Object. The alpha controls the opacity of the Game Object as it renders. + * Alpha values are provided as a float between 0, fully transparent, and 1, fully opaque. + * + * If your game is running under WebGL you can optionally specify four different alpha values, each of which + * correspond to the four corners of the Game Object. Under Canvas only the `topLeft` value given is used. + * @param topLeft The alpha value used for the top-left of the Game Object. If this is the only value given it's applied across the whole Game Object. Default 1. + * @param topRight The alpha value used for the top-right of the Game Object. WebGL only. + * @param bottomLeft The alpha value used for the bottom-left of the Game Object. WebGL only. + * @param bottomRight The alpha value used for the bottom-right of the Game Object. WebGL only. + */ + setAlpha(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; + + /** + * The alpha value of the Game Object. + * + * This is a global value, impacting the entire Game Object, not just a region of it. + */ + alpha: number; + + /** + * The alpha value starting from the top-left of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + */ + alphaTopLeft: number; + + /** + * The alpha value starting from the top-right of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + */ + alphaTopRight: number; + + /** + * The alpha value starting from the bottom-left of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + */ + alphaBottomLeft: number; + + /** + * The alpha value starting from the bottom-right of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + */ + alphaBottomRight: number; + + /** + * Sets the Blend Mode being used by this Game Object. + * + * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) + * + * Under WebGL only the following Blend Modes are available: + * + * * ADD + * * MULTIPLY + * * SCREEN + * * ERASE + * + * Canvas has more available depending on browser support. + * + * You can also create your own custom Blend Modes in WebGL. + * + * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending + * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these + * reasons try to be careful about the construction of your Scene and the frequency of which blend modes + * are used. + */ + blendMode: Phaser.BlendModes | string; + + /** + * Sets the Blend Mode being used by this Game Object. + * + * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) + * + * Under WebGL only the following Blend Modes are available: + * + * * ADD + * * MULTIPLY + * * SCREEN + * * ERASE (only works when rendering to a framebuffer, like a Render Texture) + * + * Canvas has more available depending on browser support. + * + * You can also create your own custom Blend Modes in WebGL. + * + * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending + * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these + * reasons try to be careful about the construction of your Scene and the frequency in which blend modes + * are used. + * @param value The BlendMode value. Either a string or a CONST. + */ + setBlendMode(value: string | Phaser.BlendModes): this; + /** * The native (un-scaled) width of this Game Object. * @@ -24240,28 +27381,49 @@ declare namespace Phaser { displayHeight: number; /** - * Sets the internal size of this Game Object, as used for frame or physics body creation. - * - * This will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or call the - * `setDisplaySize` method, which is the same thing as changing the scale but allows you - * to do so by giving pixel values. + * Sets the display size of this Game Object. * - * If you have enabled this Game Object for input, changing the size will _not_ change the - * size of the hit area. To do this you should adjust the `input.hitArea` object directly. + * Calling this will adjust the scale. * @param width The width of this Game Object. * @param height The height of this Game Object. */ - setSize(width: number, height: number): this; + setDisplaySize(width: number, height: number): this; /** - * Sets the display size of this Game Object. + * A boolean flag indicating if this Game Object is being cropped or not. + * You can toggle this at any time after `setCrop` has been called, to turn cropping on or off. + * Equally, calling `setCrop` with no arguments will reset the crop and disable it. + */ + isCropped: boolean; + + /** + * Applies a crop to a texture based Game Object, such as a Sprite or Image. * - * Calling this will adjust the scale. - * @param width The width of this Game Object. - * @param height The height of this Game Object. + * The crop is a rectangle that limits the area of the texture frame that is visible during rendering. + * + * Cropping a Game Object does not change its size, dimensions, physics body or hit area, it just + * changes what is shown when rendered. + * + * The crop coordinates are relative to the texture frame, not the Game Object, meaning 0 x 0 is the top-left. + * + * Therefore, if you had a Game Object that had an 800x600 sized texture, and you wanted to show only the left + * half of it, you could call `setCrop(0, 0, 400, 600)`. + * + * It is also scaled to match the Game Object scale automatically. Therefore a crop rect of 100x50 would crop + * an area of 200x100 when applied to a Game Object that had a scale factor of 2. + * + * You can either pass in numeric values directly, or you can provide a single Rectangle object as the first argument. + * + * Call this method with no arguments at all to reset the crop, or toggle the property `isCropped` to `false`. + * + * You should do this if the crop rectangle becomes the same size as the frame itself, as it will allow + * the renderer to skip several internal calculations. + * @param x The x coordinate to start the crop from. Or a Phaser.Geom.Rectangle object, in which case the rest of the arguments are ignored. + * @param y The y coordinate to start the crop from. + * @param width The width of the crop rectangle in pixels. + * @param height The height of the crop rectangle in pixels. */ - setDisplaySize(width: number, height: number): this; + setCrop(x?: number | Phaser.Geom.Rectangle, y?: number, width?: number, height?: number): this; /** * The depth of this Game Object within the Scene. @@ -24269,7 +27431,7 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. @@ -24282,13 +27444,77 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. * @param value The depth of this Game Object. */ - setDepth(value: integer): this; + setDepth(value: number): this; + + /** + * The horizontally flipped state of the Game Object. + * + * A Game Object that is flipped horizontally will render inversed on the horizontal axis. + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + */ + flipX: boolean; + + /** + * The vertically flipped state of the Game Object. + * + * A Game Object that is flipped vertically will render inversed on the vertical axis (i.e. upside down) + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + */ + flipY: boolean; + + /** + * Toggles the horizontal flipped state of this Game Object. + * + * A Game Object that is flipped horizontally will render inversed on the horizontal axis. + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + */ + toggleFlipX(): this; + + /** + * Toggles the vertical flipped state of this Game Object. + */ + toggleFlipY(): this; + + /** + * Sets the horizontal flipped state of this Game Object. + * + * A Game Object that is flipped horizontally will render inversed on the horizontal axis. + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * @param value The flipped state. `false` for no flip, or `true` to be flipped. + */ + setFlipX(value: boolean): this; + + /** + * Sets the vertical flipped state of this Game Object. + * @param value The flipped state. `false` for no flip, or `true` to be flipped. + */ + setFlipY(value: boolean): this; + + /** + * Sets the horizontal and vertical flipped state of this Game Object. + * + * A Game Object that is flipped will render inversed on the flipped axis. + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * @param x The horizontal flipped state. `false` for no flip, or `true` to be flipped. + * @param y The horizontal flipped state. `false` for no flip, or `true` to be flipped. + */ + setFlip(x: boolean, y: boolean): this; + + /** + * Resets the horizontal and vertical flipped state of this Game Object back to their default un-flipped state. + */ + resetFlip(): this; /** * Gets the center coordinate of this Game Object, regardless of origin. @@ -24400,6 +27626,8 @@ declare namespace Phaser { * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, * including this one. * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * * To create the mask you need to pass in a reference to a renderable Game Object. * A renderable Game Object is one that uses a texture to render with, such as an * Image, Sprite, Render Texture or BitmapText. @@ -24483,6 +27711,127 @@ declare namespace Phaser { */ updateDisplayOrigin(): this; + /** + * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. + */ + defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; + + /** + * The current WebGL pipeline of this Game Object. + */ + pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + + /** + * Does this Game Object have any Post Pipelines set? + */ + hasPostPipeline: boolean; + + /** + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. + */ + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; + + /** + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. + */ + pipelineData: object; + + /** + * Sets the initial WebGL Pipeline of this Game Object. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + */ + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; + + /** + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; + + /** + * Sets one, or more, Post Pipelines on this Game Object. + * + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; + + /** + * Adds an entry to the `pipelineData` object belonging to this Game Object. + * + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. + */ + setPipelineData(key: string, value?: any): this; + + /** + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. + */ + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; + + /** + * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; + + /** + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPostPipeline(resetData?: boolean): void; + + /** + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. + */ + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; + + /** + * Gets the name of the WebGL Pipeline this Game Object is currently using. + */ + getPipelineName(): string; + /** * The horizontal scroll factor of this Game Object. * @@ -24543,66 +27892,169 @@ declare namespace Phaser { setScrollFactor(x: number, y?: number): this; /** - * The x position of this Game Object. + * The tint value being applied to the top-left vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. */ - x: number; + tintTopLeft: number; /** - * The y position of this Game Object. + * The tint value being applied to the top-right vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. */ - y: number; + tintTopRight: number; /** - * The z position of this Game Object. - * - * Note: The z position does not control the rendering order of 2D Game Objects. Use - * {@link Phaser.GameObjects.Components.Depth#depth} instead. + * The tint value being applied to the bottom-left vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. */ - z: number; + tintBottomLeft: number; /** - * The w position of this Game Object. + * The tint value being applied to the bottom-right vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. */ - w: number; + tintBottomRight: number; /** - * This is a special setter that allows you to set both the horizontal and vertical scale of this Game Object - * to the same value, at the same time. When reading this value the result returned is `(scaleX + scaleY) / 2`. + * The tint fill mode. * - * Use of this property implies you wish the horizontal and vertical scales to be equal to each other. If this - * isn't the case, use the `scaleX` or `scaleY` properties instead. + * `false` = An additive tint (the default), where vertices colors are blended with the texture. + * `true` = A fill tint, where the vertices colors replace the texture, but respects texture alpha. */ - scale: number; + tintFill: boolean; /** - * The horizontal scale of this Game Object. + * Clears all tint values associated with this Game Object. + * + * Immediately sets the color values back to 0xffffff and the tint type to 'additive', + * which results in no visible change to the texture. */ - scaleX: number; + clearTint(): this; /** - * The vertical scale of this Game Object. + * Sets an additive tint on this Game Object. + * + * The tint works by taking the pixel color values from the Game Objects texture, and then + * multiplying it by the color value of the tint. You can provide either one color value, + * in which case the whole Game Object will be tinted in that color. Or you can provide a color + * per corner. The colors are blended together across the extent of the Game Object. + * + * To modify the tint color once set, either call this method again with new values or use the + * `tint` property to set all colors at once. Or, use the properties `tintTopLeft`, `tintTopRight, + * `tintBottomLeft` and `tintBottomRight` to set the corner color values independently. + * + * To remove a tint call `clearTint`. + * + * To swap this from being an additive tint to a fill based tint set the property `tintFill` to `true`. + * @param topLeft The tint being applied to the top-left of the Game Object. If no other values are given this value is applied evenly, tinting the whole Game Object. Default 0xffffff. + * @param topRight The tint being applied to the top-right of the Game Object. + * @param bottomLeft The tint being applied to the bottom-left of the Game Object. + * @param bottomRight The tint being applied to the bottom-right of the Game Object. */ - scaleY: number; + setTint(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; /** - * The angle of this Game Object as expressed in degrees. + * Sets a fill-based tint on this Game Object. * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Unlike an additive tint, a fill-tint literally replaces the pixel colors from the texture + * with those in the tint. You can use this for effects such as making a player flash 'white' + * if hit by something. You can provide either one color value, in which case the whole + * Game Object will be rendered in that color. Or you can provide a color per corner. The colors + * are blended together across the extent of the Game Object. * - * If you prefer to work in radians, see the `rotation` property instead. + * To modify the tint color once set, either call this method again with new values or use the + * `tint` property to set all colors at once. Or, use the properties `tintTopLeft`, `tintTopRight, + * `tintBottomLeft` and `tintBottomRight` to set the corner color values independently. + * + * To remove a tint call `clearTint`. + * + * To swap this from being a fill-tint to an additive tint set the property `tintFill` to `false`. + * @param topLeft The tint being applied to the top-left of the Game Object. If not other values are given this value is applied evenly, tinting the whole Game Object. Default 0xffffff. + * @param topRight The tint being applied to the top-right of the Game Object. + * @param bottomLeft The tint being applied to the bottom-left of the Game Object. + * @param bottomRight The tint being applied to the bottom-right of the Game Object. */ - angle: integer; + setTintFill(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; /** - * The angle of this Game Object in radians. - * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * The tint value being applied to the whole of the Game Object. + * This property is a setter-only. Use the properties `tintTopLeft` etc to read the current tint value. + */ + tint: number; + + /** + * Does this Game Object have a tint applied? * - * If you prefer to work in degrees, see the `angle` property instead. + * It checks to see if the 4 tint properties are set to the value 0xffffff + * and that the `tintFill` property is `false`. This indicates that a Game Object isn't tinted. */ - rotation: number; + readonly isTinted: boolean; + + /** + * The x position of this Game Object. + */ + x: number; + + /** + * The y position of this Game Object. + */ + y: number; + + /** + * The z position of this Game Object. + * + * Note: The z position does not control the rendering order of 2D Game Objects. Use + * {@link Phaser.GameObjects.Components.Depth#depth} instead. + */ + z: number; + + /** + * The w position of this Game Object. + */ + w: number; + + /** + * This is a special setter that allows you to set both the horizontal and vertical scale of this Game Object + * to the same value, at the same time. When reading this value the result returned is `(scaleX + scaleY) / 2`. + * + * Use of this property implies you wish the horizontal and vertical scales to be equal to each other. If this + * isn't the case, use the `scaleX` or `scaleY` properties instead. + */ + scale: number; + + /** + * The horizontal scale of this Game Object. + */ + scaleX: number; + + /** + * The vertical scale of this Game Object. + */ + scaleY: number; + + /** + * The angle of this Game Object as expressed in degrees. + * + * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left + * and -90 is up. + * + * If you prefer to work in radians, see the `rotation` property instead. + */ + angle: number; + + /** + * The angle of this Game Object in radians. + * + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. + * + * If you prefer to work in degrees, see the `angle` property instead. + */ + rotation: number; /** * Sets the position of this Game Object. @@ -24613,6 +28065,12 @@ declare namespace Phaser { */ setPosition(x?: number, y?: number, z?: number, w?: number): this; + /** + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; + /** * Sets the position of this Game Object to be a random position within the confines of * the given area. @@ -24687,6 +28145,22 @@ declare namespace Phaser { */ getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. + */ + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + /** * Gets the sum total rotation of all of this Game Objects parent Containers. * @@ -24712,93 +28186,349 @@ declare namespace Phaser { } /** - * The Arc Shape is a Game Object that can be added to a Scene, Group or Container. You can - * treat it like any other Game Object in your game, such as tweening it, scaling it, or enabling - * it for input or physics. It provides a quick and easy way for you to render this shape in your - * game without using a texture, while still taking advantage of being fully batched in WebGL. + * A Rope Game Object. * - * This shape supports both fill and stroke colors. + * The Rope object is WebGL only and does not have a Canvas counterpart. * - * When it renders it displays an arc shape. You can control the start and end angles of the arc, - * as well as if the angles are winding clockwise or anti-clockwise. With the default settings - * it renders as a complete circle. By changing the angles you can create other arc shapes, - * such as half-circles. + * A Rope is a special kind of Game Object that has a texture that repeats along its entire length. + * Unlike a Sprite, it isn't restricted to using just a quad and can have as many vertices as you define + * when creating it. The vertices can be arranged in a horizontal or vertical strip and have their own + * color and alpha values as well. * - * Arcs also have an `iterations` property and corresponding `setIterations` method. This allows - * you to control how smooth the shape renders in WebGL, by controlling the number of iterations - * that take place during construction. + * A Ropes origin is always 0.5 x 0.5 and cannot be changed. */ - class Arc extends Phaser.GameObjects.Shape { + class Rope extends Phaser.GameObjects.GameObject implements Phaser.GameObjects.Components.AlphaSingle, Phaser.GameObjects.Components.BlendMode, Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.Flip, Phaser.GameObjects.Components.Mask, Phaser.GameObjects.Components.Pipeline, Phaser.GameObjects.Components.Size, Phaser.GameObjects.Components.Texture, Phaser.GameObjects.Components.Transform, Phaser.GameObjects.Components.Visible, Phaser.GameObjects.Components.ScrollFactor { /** * * @param scene The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. * @param x The horizontal position of this Game Object in the world. Default 0. * @param y The vertical position of this Game Object in the world. Default 0. - * @param radius The radius of the arc. Default 128. - * @param startAngle The start angle of the arc, in degrees. Default 0. - * @param endAngle The end angle of the arc, in degrees. Default 360. - * @param anticlockwise The winding order of the start and end angles. Default false. - * @param fillColor The color the arc will be filled with, i.e. 0xff0000 for red. - * @param fillAlpha The alpha the arc will be filled with. You can also set the alpha of the overall Shape using its `alpha` property. + * @param texture The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. If not given, `__DEFAULT` is used. + * @param frame An optional frame from the Texture this Game Object is rendering with. + * @param points An array containing the vertices data for this Rope, or a number that indicates how many segments to split the texture frame into. If none is provided a simple quad is created. See `setPoints` to set this post-creation. Default 2. + * @param horizontal Should the vertices of this Rope be aligned horizontally (`true`), or vertically (`false`)? Default true. + * @param colors An optional array containing the color data for this Rope. You should provide one color value per pair of vertices. + * @param alphas An optional array containing the alpha data for this Rope. You should provide one alpha value per pair of vertices. */ - constructor(scene: Phaser.Scene, x?: number, y?: number, radius?: number, startAngle?: integer, endAngle?: integer, anticlockwise?: boolean, fillColor?: number, fillAlpha?: number); + constructor(scene: Phaser.Scene, x?: number, y?: number, texture?: string, frame?: string | number | null, points?: number | Phaser.Types.Math.Vector2Like[], horizontal?: boolean, colors?: number[], alphas?: number[]); /** - * The number of iterations used when drawing the arc. - * Increase this value for smoother arcs, at the cost of more polygons being rendered. - * Modify this value by small amounts, such as 0.01. + * The Animation State of this Rope. */ - iterations: number; + anims: Phaser.Animations.AnimationState; /** - * The radius of the arc. + * An array containing the points data for this Rope. + * + * Each point should be given as a Vector2Like object (i.e. a Vector2, Geom.Point or object with public x/y properties). + * + * The point coordinates are given in local space, where 0 x 0 is the start of the Rope strip. + * + * You can modify the contents of this array directly in real-time to create interesting effects. + * If you do so, be sure to call `setDirty` _after_ modifying this array, so that the vertices data is + * updated before the next render. Alternatively, you can use the `setPoints` method instead. + * + * Should you need to change the _size_ of this array, then you should always use the `setPoints` method. */ - radius: number; + points: Phaser.Types.Math.Vector2Like[]; /** - * The start angle of the arc, in degrees. + * An array containing the vertices data for this Rope. + * + * This data is calculated automatically in the `updateVertices` method, based on the points provided. */ - startAngle: integer; + vertices: Float32Array; /** - * The end angle of the arc, in degrees. + * An array containing the uv data for this Rope. + * + * This data is calculated automatically in the `setPoints` method, based on the points provided. */ - endAngle: integer; + uv: Float32Array; /** - * The winding order of the start and end angles. + * An array containing the color data for this Rope. + * + * Colors should be given as numeric RGB values, such as 0xff0000. + * You should provide _two_ color values for every point in the Rope, one for the top and one for the bottom of each quad. + * + * You can modify the contents of this array directly in real-time, however, should you need to change the _size_ + * of the array, then you should use the `setColors` method instead. */ - anticlockwise: boolean; + colors: Uint32Array; /** - * Sets the radius of the arc. - * This call can be chained. - * @param value The value to set the radius to. + * An array containing the alpha data for this Rope. + * + * Alphas should be given as float values, such as 0.5. + * You should provide _two_ alpha values for every point in the Rope, one for the top and one for the bottom of each quad. + * + * You can modify the contents of this array directly in real-time, however, should you need to change the _size_ + * of the array, then you should use the `setAlphas` method instead. */ - setRadius(value: number): this; + alphas: Float32Array; /** - * Sets the number of iterations used when drawing the arc. - * Increase this value for smoother arcs, at the cost of more polygons being rendered. - * Modify this value by small amounts, such as 0.01. - * This call can be chained. - * @param value The value to set the iterations to. + * The tint fill mode. + * + * `false` = An additive tint (the default), where vertices colors are blended with the texture. + * `true` = A fill tint, where the vertices colors replace the texture, but respects texture alpha. */ - setIterations(value: number): this; + tintFill: boolean; /** - * Sets the starting angle of the arc, in degrees. - * This call can be chained. - * @param value The value to set the starting angle to. + * If the Rope is marked as `dirty` it will automatically recalculate its vertices + * the next time it renders. You can also force this by calling `updateVertices`. + */ + dirty: boolean; + + /** + * Are the Rope vertices aligned horizontally, in a strip, or vertically, in a column? + * + * This property is set during instantiation and cannot be changed directly. + * See the `setVertical` and `setHorizontal` methods. */ - setStartAngle(value: integer): this; + readonly horizontal: boolean; /** - * Sets the ending angle of the arc, in degrees. - * This call can be chained. - * @param value The value to set the ending angle to. + * You can optionally choose to render the vertices of this Rope to a Graphics instance. + * + * Achieve this by setting the `debugCallback` and the `debugGraphic` properties. + * + * You can do this in a single call via the `Rope.setDebug` method, which will use the + * built-in debug function. You can also set it to your own callback. The callback + * will be invoked _once per render_ and sent the following parameters: + * + * `debugCallback(src, meshLength, verts)` + * + * `src` is the Rope instance being debugged. + * `meshLength` is the number of mesh vertices in total. + * `verts` is an array of the translated vertex coordinates. + * + * To disable rendering, set this property back to `null`. + */ + debugCallback: Function; + + /** + * The Graphics instance that the debug vertices will be drawn to, if `setDebug` has + * been called. + */ + debugGraphic: Phaser.GameObjects.Graphics; + + /** + * The Rope update loop. + * @param time The current timestamp. + * @param delta The delta time, in ms, elapsed since the last frame. + */ + protected preUpdate(time: number, delta: number): void; + + /** + * Start playing the given animation. + * @param key The string-based key of the animation to play. + * @param ignoreIfPlaying If an animation is already playing then ignore this call. Default false. + * @param startFrame Optionally start the animation playing from this frame index. Default 0. + */ + play(key: string, ignoreIfPlaying?: boolean, startFrame?: number): this; + + /** + * Flags this Rope as being dirty. A dirty rope will recalculate all of its vertices data + * the _next_ time it renders. You should set this rope as dirty if you update the points + * array directly. + */ + setDirty(): this; + + /** + * Sets the alignment of the points in this Rope to be horizontal, in a strip format. + * + * Calling this method will reset this Rope. The current points, vertices, colors and alpha + * values will be reset to thoes values given as parameters. + * @param points An array containing the vertices data for this Rope, or a number that indicates how many segments to split the texture frame into. If none is provided the current points length is used. + * @param colors Either a single color value, or an array of values. + * @param alphas Either a single alpha value, or an array of values. + */ + setHorizontal(points?: number | Phaser.Types.Math.Vector2Like[], colors?: number | number[], alphas?: number | number[]): this; + + /** + * Sets the alignment of the points in this Rope to be vertical, in a column format. + * + * Calling this method will reset this Rope. The current points, vertices, colors and alpha + * values will be reset to thoes values given as parameters. + * @param points An array containing the vertices data for this Rope, or a number that indicates how many segments to split the texture frame into. If none is provided the current points length is used. + * @param colors Either a single color value, or an array of values. + * @param alphas Either a single alpha value, or an array of values. + */ + setVertical(points?: number | Phaser.Types.Math.Vector2Like[], colors?: number | number[], alphas?: number | number[]): this; + + /** + * Sets the tint fill mode. + * + * Mode 0 (`false`) is an additive tint, the default, which blends the vertices colors with the texture. + * This mode respects the texture alpha. + * + * Mode 1 (`true`) is a fill tint. Unlike an additive tint, a fill-tint literally replaces the pixel colors + * from the texture with those in the tint. You can use this for effects such as making a player flash 'white' + * if hit by something. This mode respects the texture alpha. + * + * See the `setColors` method for details of how to color each of the vertices. + * @param value Set to `false` for an Additive tint or `true` fill tint with alpha. Default false. + */ + setTintFill(value?: boolean): this; + + /** + * Set the alpha values used by the Rope during rendering. + * + * You can provide the values in a number of ways: + * + * 1) One single numeric value: `setAlphas(0.5)` - This will set a single alpha for the whole Rope. + * 2) Two numeric value: `setAlphas(1, 0.5)` - This will set a 'top' and 'bottom' alpha value across the whole Rope. + * 3) An array of values: `setAlphas([ 1, 0.5, 0.2 ])` + * + * If you provide an array of values and the array has exactly the same number of values as `points` in the Rope, it + * will use each alpha value per rope segment. + * + * If the provided array has a different number of values than `points` then it will use the values in order, from + * the first Rope segment and on, until it runs out of values. This allows you to control the alpha values at all + * vertices in the Rope. + * + * Note this method is called `setAlphas` (plural) and not `setAlpha`. + * @param alphas Either a single alpha value, or an array of values. If nothing is provided alpha is reset to 1. + * @param bottomAlpha An optional bottom alpha value. See the method description for details. + */ + setAlphas(alphas?: number | number[], bottomAlpha?: number): this; + + /** + * Set the color values used by the Rope during rendering. + * + * Colors are used to control the level of tint applied across the Rope texture. + * + * You can provide the values in a number of ways: + * + * * One single numeric value: `setColors(0xff0000)` - This will set a single color tint for the whole Rope. + * * An array of values: `setColors([ 0xff0000, 0x00ff00, 0x0000ff ])` + * + * If you provide an array of values and the array has exactly the same number of values as `points` in the Rope, it + * will use each color per rope segment. + * + * If the provided array has a different number of values than `points` then it will use the values in order, from + * the first Rope segment and on, until it runs out of values. This allows you to control the color values at all + * vertices in the Rope. + * @param colors Either a single color value, or an array of values. If nothing is provided color is reset to 0xffffff. + */ + setColors(colors?: number | number[]): this; + + /** + * Sets the points used by this Rope. + * + * The points should be provided as an array of Vector2, or vector2-like objects (i.e. those with public x/y properties). + * + * Each point corresponds to one segment of the Rope. The more points in the array, the more segments the rope has. + * + * Point coordinates are given in local-space, not world-space, and are directly related to the size of the texture + * this Rope object is using. + * + * For example, a Rope using a 512 px wide texture, split into 4 segments (128px each) would use the following points: + * + * ```javascript + * rope.setPoints([ + * { x: 0, y: 0 }, + * { x: 128, y: 0 }, + * { x: 256, y: 0 }, + * { x: 384, y: 0 } + * ]); + * ``` + * + * Or, you can provide an integer to do the same thing: + * + * ```javascript + * rope.setPoints(4); + * ``` + * + * Which will divide the Rope into 4 equally sized segments based on the frame width. + * + * Note that calling this method with a different number of points than the Rope has currently will + * _reset_ the color and alpha values, unless you provide them as arguments to this method. + * @param points An array containing the vertices data for this Rope, or a number that indicates how many segments to split the texture frame into. If none is provided a simple quad is created. Default 2. + * @param colors Either a single color value, or an array of values. + * @param alphas Either a single alpha value, or an array of values. + */ + setPoints(points?: number | Phaser.Types.Math.Vector2Like[], colors?: number | number[], alphas?: number | number[]): this; + + /** + * Updates all of the UVs based on the Rope.points and `flipX` and `flipY` settings. + */ + updateUVs(): this; + + /** + * Resizes all of the internal arrays: `vertices`, `uv`, `colors` and `alphas` to the new + * given Rope segment total. + * @param newSize The amount of segments to split the Rope in to. + */ + resizeArrays(newSize: number): this; + + /** + * Updates the vertices based on the Rope points. + * + * This method is called automatically during rendering if `Rope.dirty` is `true`, which is set + * by the `setPoints` and `setDirty` methods. You should flag the Rope as being dirty if you modify + * the Rope points directly. + */ + updateVertices(): this; + + /** + * This method enables rendering of the Rope vertices to the given Graphics instance. + * + * If you enable this feature, you **must** call `Graphics.clear()` in your Scene `update`, + * otherwise the Graphics instance you provide to debug will fill-up with draw calls, + * eventually crashing the browser. This is not done automatically to allow you to debug + * draw multiple Rope objects to a single Graphics instance. + * + * The Rope class has a built-in debug rendering callback `Rope.renderDebugVerts`, however + * you can also provide your own callback to be used instead. Do this by setting the `callback` parameter. + * + * The callback is invoked _once per render_ and sent the following parameters: + * + * `callback(src, meshLength, verts)` + * + * `src` is the Rope instance being debugged. + * `meshLength` is the number of mesh vertices in total. + * `verts` is an array of the translated vertex coordinates. + * + * If using your own callback you do not have to provide a Graphics instance to this method. + * + * To disable debug rendering, to either your own callback or the built-in one, call this method + * with no arguments. + * @param graphic The Graphic instance to render to if using the built-in callback. + * @param callback The callback to invoke during debug render. Leave as undefined to use the built-in callback. + */ + setDebug(graphic?: Phaser.GameObjects.Graphics, callback?: Function): this; + + /** + * The built-in Rope vertices debug rendering method. + * + * See `Rope.setDebug` for more details. + * @param src The Rope object being rendered. + * @param meshLength The number of vertices in the mesh. + * @param verts An array of translated vertex coordinates. + */ + renderDebugVerts(src: Phaser.GameObjects.Rope, meshLength: number, verts: number[]): void; + + /** + * The horizontally flipped state of the Game Object. + * + * A Game Object that is flipped horizontally will render inversed on the horizontal axis. + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + */ + flipX: boolean; + + /** + * The vertically flipped state of the Game Object. + * + * A Game Object that is flipped vertically will render inversed on the vertical axis (i.e. upside down) + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. */ - setEndAngle(value: integer): this; + flipY: boolean; /** * Clears all alpha values associated with this Game Object. @@ -24868,73 +28598,13 @@ declare namespace Phaser { */ setBlendMode(value: string | Phaser.BlendModes): this; - /** - * The native (un-scaled) width of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayWidth` property. - */ - width: number; - - /** - * The native (un-scaled) height of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayHeight` property. - */ - height: number; - - /** - * The displayed width of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. - */ - displayWidth: number; - - /** - * The displayed height of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. - */ - displayHeight: number; - - /** - * Sets the internal size of this Game Object, as used for frame or physics body creation. - * - * This will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or call the - * `setDisplaySize` method, which is the same thing as changing the scale but allows you - * to do so by giving pixel values. - * - * If you have enabled this Game Object for input, changing the size will _not_ change the - * size of the hit area. To do this you should adjust the `input.hitArea` object directly. - * @param width The width of this Game Object. - * @param height The height of this Game Object. - */ - setSize(width: number, height: number): this; - - /** - * Sets the display size of this Game Object. - * - * Calling this will adjust the scale. - * @param width The width of this Game Object. - * @param height The height of this Game Object. - */ - setDisplaySize(width: number, height: number): this; - /** * The depth of this Game Object within the Scene. * * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. @@ -24947,91 +28617,59 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. * @param value The depth of this Game Object. */ - setDepth(value: integer): this; - - /** - * Gets the center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - */ - getCenter(output?: O): O; - - /** - * Gets the top-left corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. - */ - getTopLeft(output?: O, includeParent?: boolean): O; - - /** - * Gets the top-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. - */ - getTopCenter(output?: O, includeParent?: boolean): O; - - /** - * Gets the top-right corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. - */ - getTopRight(output?: O, includeParent?: boolean): O; + setDepth(value: number): this; /** - * Gets the left-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * Toggles the horizontal flipped state of this Game Object. + * + * A Game Object that is flipped horizontally will render inversed on the horizontal axis. + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. */ - getLeftCenter(output?: O, includeParent?: boolean): O; + toggleFlipX(): this; /** - * Gets the right-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * Toggles the vertical flipped state of this Game Object. */ - getRightCenter(output?: O, includeParent?: boolean): O; + toggleFlipY(): this; /** - * Gets the bottom-left corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * Sets the horizontal flipped state of this Game Object. + * + * A Game Object that is flipped horizontally will render inversed on the horizontal axis. + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * @param value The flipped state. `false` for no flip, or `true` to be flipped. */ - getBottomLeft(output?: O, includeParent?: boolean): O; + setFlipX(value: boolean): this; /** - * Gets the bottom-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * Sets the vertical flipped state of this Game Object. + * @param value The flipped state. `false` for no flip, or `true` to be flipped. */ - getBottomCenter(output?: O, includeParent?: boolean): O; + setFlipY(value: boolean): this; /** - * Gets the bottom-right corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * Sets the horizontal and vertical flipped state of this Game Object. + * + * A Game Object that is flipped will render inversed on the flipped axis. + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * @param x The horizontal flipped state. `false` for no flip, or `true` to be flipped. + * @param y The horizontal flipped state. `false` for no flip, or `true` to be flipped. */ - getBottomRight(output?: O, includeParent?: boolean): O; + setFlip(x: boolean, y: boolean): this; /** - * Gets the bounds of this Game Object, regardless of origin. - * The values are stored and returned in a Rectangle, or Rectangle-like, object. - * @param output An object to store the values in. If not provided a new Rectangle will be created. + * Resets the horizontal and vertical flipped state of this Game Object back to their default un-flipped state. */ - getBounds(output?: O): O; + resetFlip(): this; /** * The Mask this Game Object is using during render. @@ -25065,6 +28703,8 @@ declare namespace Phaser { * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, * including this one. * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * * To create the mask you need to pass in a reference to a renderable Game Object. * A renderable Game Object is one that uses a texture to render with, such as an * Image, Sprite, Render Texture or BitmapText. @@ -25091,90 +28731,120 @@ declare namespace Phaser { createGeometryMask(graphics?: Phaser.GameObjects.Graphics): Phaser.Display.Masks.GeometryMask; /** - * The horizontal origin of this Game Object. - * The origin maps the relationship between the size and position of the Game Object. - * The default value is 0.5, meaning all Game Objects are positioned based on their center. - * Setting the value to 0 means the position now relates to the left of the Game Object. + * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. */ - originX: number; + defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; /** - * The vertical origin of this Game Object. - * The origin maps the relationship between the size and position of the Game Object. - * The default value is 0.5, meaning all Game Objects are positioned based on their center. - * Setting the value to 0 means the position now relates to the top of the Game Object. + * The current WebGL pipeline of this Game Object. */ - originY: number; + pipeline: Phaser.Renderer.WebGL.WebGLPipeline; /** - * The horizontal display origin of this Game Object. - * The origin is a normalized value between 0 and 1. - * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. + * Does this Game Object have any Post Pipelines set? */ - displayOriginX: number; + hasPostPipeline: boolean; /** - * The vertical display origin of this Game Object. - * The origin is a normalized value between 0 and 1. - * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. */ - displayOriginY: number; + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; /** - * Sets the origin of this Game Object. - * - * The values are given in the range 0 to 1. - * @param x The horizontal origin value. Default 0.5. - * @param y The vertical origin value. If not defined it will be set to the value of `x`. Default x. + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. */ - setOrigin(x?: number, y?: number): this; + pipelineData: object; /** - * Sets the origin of this Game Object based on the Pivot values in its Frame. + * Sets the initial WebGL Pipeline of this Game Object. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. */ - setOriginFromFrame(): this; + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; /** - * Sets the display origin of this Game Object. - * The difference between this and setting the origin is that you can use pixel values for setting the display origin. - * @param x The horizontal display origin value. Default 0. - * @param y The vertical display origin value. If not defined it will be set to the value of `x`. Default x. + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. */ - setDisplayOrigin(x?: number, y?: number): this; + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; /** - * Updates the Display Origin cached values internally stored on this Game Object. - * You don't usually call this directly, but it is exposed for edge-cases where you may. + * Sets one, or more, Post Pipelines on this Game Object. + * + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. */ - updateDisplayOrigin(): this; + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; /** - * The initial WebGL pipeline of this Game Object. + * Adds an entry to the `pipelineData` object belonging to this Game Object. + * + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. */ - defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; + setPipelineData(key: string, value?: any): this; /** - * The current WebGL pipeline of this Game Object. + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; /** - * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. + * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. */ - initPipeline(pipelineName?: string): boolean; + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. */ - setPipeline(pipelineName: string): this; + resetPostPipeline(resetData?: boolean): void; /** - * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - resetPipeline(): boolean; + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; /** * Gets the name of the WebGL Pipeline this Game Object is currently using. @@ -25182,63 +28852,112 @@ declare namespace Phaser { getPipelineName(): string; /** - * The horizontal scroll factor of this Game Object. - * - * The scroll factor controls the influence of the movement of a Camera upon this Game Object. - * - * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. - * It does not change the Game Objects actual position values. + * The native (un-scaled) width of this Game Object. * - * A value of 1 means it will move exactly in sync with a camera. - * A value of 0 means it will not move at all, even if the camera moves. - * Other values control the degree to which the camera movement is mapped to this Game Object. + * Changing this value will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or use + * the `displayWidth` property. + */ + width: number; + + /** + * The native (un-scaled) height of this Game Object. * - * Please be aware that scroll factor values other than 1 are not taken in to consideration when - * calculating physics collisions. Bodies always collide based on their world position, but changing - * the scroll factor is a visual adjustment to where the textures are rendered, which can offset - * them from physics bodies if not accounted for in your code. + * Changing this value will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or use + * the `displayHeight` property. */ - scrollFactorX: number; + height: number; /** - * The vertical scroll factor of this Game Object. + * The displayed width of this Game Object. * - * The scroll factor controls the influence of the movement of a Camera upon this Game Object. + * This value takes into account the scale factor. * - * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. - * It does not change the Game Objects actual position values. + * Setting this value will adjust the Game Object's scale property. + */ + displayWidth: number; + + /** + * The displayed height of this Game Object. * - * A value of 1 means it will move exactly in sync with a camera. - * A value of 0 means it will not move at all, even if the camera moves. - * Other values control the degree to which the camera movement is mapped to this Game Object. + * This value takes into account the scale factor. * - * Please be aware that scroll factor values other than 1 are not taken in to consideration when - * calculating physics collisions. Bodies always collide based on their world position, but changing - * the scroll factor is a visual adjustment to where the textures are rendered, which can offset - * them from physics bodies if not accounted for in your code. + * Setting this value will adjust the Game Object's scale property. */ - scrollFactorY: number; + displayHeight: number; /** - * Sets the scroll factor of this Game Object. - * - * The scroll factor controls the influence of the movement of a Camera upon this Game Object. + * Sets the size of this Game Object to be that of the given Frame. * - * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. - * It does not change the Game Objects actual position values. + * This will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or call the + * `setDisplaySize` method, which is the same thing as changing the scale but allows you + * to do so by giving pixel values. * - * A value of 1 means it will move exactly in sync with a camera. - * A value of 0 means it will not move at all, even if the camera moves. - * Other values control the degree to which the camera movement is mapped to this Game Object. + * If you have enabled this Game Object for input, changing the size will _not_ change the + * size of the hit area. To do this you should adjust the `input.hitArea` object directly. + * @param frame The frame to base the size of this Game Object on. + */ + setSizeToFrame(frame: Phaser.Textures.Frame): this; + + /** + * Sets the internal size of this Game Object, as used for frame or physics body creation. * - * Please be aware that scroll factor values other than 1 are not taken in to consideration when - * calculating physics collisions. Bodies always collide based on their world position, but changing - * the scroll factor is a visual adjustment to where the textures are rendered, which can offset - * them from physics bodies if not accounted for in your code. - * @param x The horizontal scroll factor of this Game Object. - * @param y The vertical scroll factor of this Game Object. If not set it will use the `x` value. Default x. + * This will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or call the + * `setDisplaySize` method, which is the same thing as changing the scale but allows you + * to do so by giving pixel values. + * + * If you have enabled this Game Object for input, changing the size will _not_ change the + * size of the hit area. To do this you should adjust the `input.hitArea` object directly. + * @param width The width of this Game Object. + * @param height The height of this Game Object. */ - setScrollFactor(x: number, y?: number): this; + setSize(width: number, height: number): this; + + /** + * Sets the display size of this Game Object. + * + * Calling this will adjust the scale. + * @param width The width of this Game Object. + * @param height The height of this Game Object. + */ + setDisplaySize(width: number, height: number): this; + + /** + * The Texture this Game Object is using to render with. + */ + texture: Phaser.Textures.Texture | Phaser.Textures.CanvasTexture; + + /** + * The Texture Frame this Game Object is using to render with. + */ + frame: Phaser.Textures.Frame; + + /** + * Sets the texture and frame this Game Object will use to render with. + * + * Textures are referenced by their string-based keys, as stored in the Texture Manager. + * @param key The key of the texture to be used, as stored in the Texture Manager, or a Texture instance. + * @param frame The name or index of the frame within the Texture. + */ + setTexture(key: string | Phaser.Textures.Texture, frame?: string | number): this; + + /** + * Sets the frame this Game Object will use to render with. + * + * The Frame has to belong to the current Texture being used. + * + * It can be either a string or an index. + * + * Calling `setFrame` will modify the `width` and `height` properties of your Game Object. + * It will also change the `origin` if the Frame has a custom pivot point, as exported from packages like Texture Packer. + * @param frame The name or index of the frame within the Texture. + * @param updateSize Should this call adjust the size of the Game Object? Default true. + * @param updateOrigin Should this call adjust the origin of the Game Object? Default true. + */ + setFrame(frame: string | number, updateSize?: boolean, updateOrigin?: boolean): this; /** * The x position of this Game Object. @@ -25290,13 +29009,13 @@ declare namespace Phaser { * * If you prefer to work in radians, see the `rotation` property instead. */ - angle: integer; + angle: number; /** * The angle of this Game Object in radians. * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. * * If you prefer to work in degrees, see the `angle` property instead. */ @@ -25311,6 +29030,12 @@ declare namespace Phaser { */ setPosition(x?: number, y?: number, z?: number, w?: number): this; + /** + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; + /** * Sets the position of this Game Object to be a random position within the confines of * the given area. @@ -25385,6 +29110,22 @@ declare namespace Phaser { */ getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. + */ + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + /** * Gets the sum total rotation of all of this Game Objects parent Containers. * @@ -25407,329 +29148,637 @@ declare namespace Phaser { */ setVisible(value: boolean): this; - } - - /** - * The Curve Shape is a Game Object that can be added to a Scene, Group or Container. You can - * treat it like any other Game Object in your game, such as tweening it, scaling it, or enabling - * it for input or physics. It provides a quick and easy way for you to render this shape in your - * game without using a texture, while still taking advantage of being fully batched in WebGL. - * - * This shape supports both fill and stroke colors. - * - * To render a Curve Shape you must first create a `Phaser.Curves.Curve` object, then pass it to - * the Curve Shape in the constructor. - * - * The Curve shape also has a `smoothness` property and corresponding `setSmoothness` method. - * This allows you to control how smooth the shape renders in WebGL, by controlling the number of iterations - * that take place during construction. Increase and decrease the default value for smoother, or more - * jagged, shapes. - */ - class Curve extends Phaser.GameObjects.Shape { /** + * The horizontal scroll factor of this Game Object. * - * @param scene The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. - * @param x The horizontal position of this Game Object in the world. Default 0. - * @param y The vertical position of this Game Object in the world. Default 0. - * @param curve The Curve object to use to create the Shape. - * @param fillColor The color the curve will be filled with, i.e. 0xff0000 for red. - * @param fillAlpha The alpha the curve will be filled with. You can also set the alpha of the overall Shape using its `alpha` property. - */ - constructor(scene: Phaser.Scene, x?: number, y?: number, curve?: Phaser.Curves.Curve, fillColor?: number, fillAlpha?: number); - - /** - * The smoothness of the curve. The number of points used when rendering it. - * Increase this value for smoother curves, at the cost of more polygons being rendered. - */ - smoothness: integer; - - /** - * Sets the smoothness of the curve. The number of points used when rendering it. - * Increase this value for smoother curves, at the cost of more polygons being rendered. - * This call can be chained. - * @param value The value to set the smoothness to. - */ - setSmoothness(value: integer): this; - - /** - * Clears all alpha values associated with this Game Object. + * The scroll factor controls the influence of the movement of a Camera upon this Game Object. * - * Immediately sets the alpha levels back to 1 (fully opaque). - */ - clearAlpha(): this; - - /** - * Set the Alpha level of this Game Object. The alpha controls the opacity of the Game Object as it renders. - * Alpha values are provided as a float between 0, fully transparent, and 1, fully opaque. - * @param value The alpha value applied across the whole Game Object. Default 1. - */ - setAlpha(value?: number): this; - - /** - * The alpha value of the Game Object. + * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. + * It does not change the Game Objects actual position values. * - * This is a global value, impacting the entire Game Object, not just a region of it. + * A value of 1 means it will move exactly in sync with a camera. + * A value of 0 means it will not move at all, even if the camera moves. + * Other values control the degree to which the camera movement is mapped to this Game Object. + * + * Please be aware that scroll factor values other than 1 are not taken in to consideration when + * calculating physics collisions. Bodies always collide based on their world position, but changing + * the scroll factor is a visual adjustment to where the textures are rendered, which can offset + * them from physics bodies if not accounted for in your code. */ - alpha: number; + scrollFactorX: number; /** - * Sets the Blend Mode being used by this Game Object. - * - * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) - * - * Under WebGL only the following Blend Modes are available: + * The vertical scroll factor of this Game Object. * - * * ADD - * * MULTIPLY - * * SCREEN - * * ERASE + * The scroll factor controls the influence of the movement of a Camera upon this Game Object. * - * Canvas has more available depending on browser support. + * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. + * It does not change the Game Objects actual position values. * - * You can also create your own custom Blend Modes in WebGL. + * A value of 1 means it will move exactly in sync with a camera. + * A value of 0 means it will not move at all, even if the camera moves. + * Other values control the degree to which the camera movement is mapped to this Game Object. * - * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending - * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these - * reasons try to be careful about the construction of your Scene and the frequency of which blend modes - * are used. + * Please be aware that scroll factor values other than 1 are not taken in to consideration when + * calculating physics collisions. Bodies always collide based on their world position, but changing + * the scroll factor is a visual adjustment to where the textures are rendered, which can offset + * them from physics bodies if not accounted for in your code. */ - blendMode: Phaser.BlendModes | string; + scrollFactorY: number; /** - * Sets the Blend Mode being used by this Game Object. - * - * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) - * - * Under WebGL only the following Blend Modes are available: + * Sets the scroll factor of this Game Object. * - * * ADD - * * MULTIPLY - * * SCREEN - * * ERASE (only works when rendering to a framebuffer, like a Render Texture) + * The scroll factor controls the influence of the movement of a Camera upon this Game Object. * - * Canvas has more available depending on browser support. + * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. + * It does not change the Game Objects actual position values. * - * You can also create your own custom Blend Modes in WebGL. + * A value of 1 means it will move exactly in sync with a camera. + * A value of 0 means it will not move at all, even if the camera moves. + * Other values control the degree to which the camera movement is mapped to this Game Object. * - * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending - * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these - * reasons try to be careful about the construction of your Scene and the frequency in which blend modes - * are used. - * @param value The BlendMode value. Either a string or a CONST. + * Please be aware that scroll factor values other than 1 are not taken in to consideration when + * calculating physics collisions. Bodies always collide based on their world position, but changing + * the scroll factor is a visual adjustment to where the textures are rendered, which can offset + * them from physics bodies if not accounted for in your code. + * @param x The horizontal scroll factor of this Game Object. + * @param y The vertical scroll factor of this Game Object. If not set it will use the `x` value. Default x. */ - setBlendMode(value: string | Phaser.BlendModes): this; + setScrollFactor(x: number, y?: number): this; - /** - * The native (un-scaled) width of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayWidth` property. - */ - width: number; + } + /** + * A Shader Game Object. + * + * This Game Object allows you to easily add a quad with its own shader into the display list, and manipulate it + * as you would any other Game Object, including scaling, rotating, positioning and adding to Containers. Shaders + * can be masked with either Bitmap or Geometry masks and can also be used as a Bitmap Mask for a Camera or other + * Game Object. They can also be made interactive and used for input events. + * + * It works by taking a reference to a `Phaser.Display.BaseShader` instance, as found in the Shader Cache. These can + * be created dynamically at runtime, or loaded in via the GLSL File Loader: + * + * ```javascript + * function preload () + * { + * this.load.glsl('fire', 'shaders/fire.glsl.js'); + * } + * + * function create () + * { + * this.add.shader('fire', 400, 300, 512, 512); + * } + * ``` + * + * Please see the Phaser 3 Examples GitHub repo for examples of loading and creating shaders dynamically. + * + * Due to the way in which they work, you cannot directly change the alpha or blend mode of a Shader. This should + * be handled via exposed uniforms in the shader code itself. + * + * By default a Shader will be created with a standard set of uniforms. These were added to match those + * found on sites such as ShaderToy or GLSLSandbox, and provide common functionality a shader may need, + * such as the timestamp, resolution or pointer position. You can replace them by specifying your own uniforms + * in the Base Shader. + * + * These Shaders work by halting the current pipeline during rendering, creating a viewport matched to the + * size of this Game Object and then renders a quad using the bound shader. At the end, the pipeline is restored. + * + * Because it blocks the pipeline it means it will interrupt any batching that is currently going on, so you should + * use these Game Objects sparingly. If you need to have a fully batched custom shader, then please look at using + * a custom pipeline instead. However, for background or special masking effects, they are extremely effective. + */ + class Shader extends Phaser.GameObjects.GameObject implements Phaser.GameObjects.Components.ComputedSize, Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.GetBounds, Phaser.GameObjects.Components.Mask, Phaser.GameObjects.Components.Origin, Phaser.GameObjects.Components.ScrollFactor, Phaser.GameObjects.Components.Transform, Phaser.GameObjects.Components.Visible { /** - * The native (un-scaled) height of this Game Object. * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayHeight` property. + * @param scene The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. + * @param key The key of the shader to use from the shader cache, or a BaseShader instance. + * @param x The horizontal position of this Game Object in the world. Default 0. + * @param y The vertical position of this Game Object in the world. Default 0. + * @param width The width of the Game Object. Default 128. + * @param height The height of the Game Object. Default 128. + * @param textures Optional array of texture keys to bind to the iChannel0...3 uniforms. The textures must already exist in the Texture Manager. + * @param textureData Additional texture data if you want to create shader with none NPOT textures. */ - height: number; + constructor(scene: Phaser.Scene, key: string | Phaser.Display.BaseShader, x?: number, y?: number, width?: number, height?: number, textures?: string[], textureData?: any); /** - * The displayed width of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. + * The underlying shader object being used. + * Empty by default and set during a call to the `setShader` method. */ - displayWidth: number; + shader: Phaser.Display.BaseShader; /** - * The displayed height of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. + * A reference to the current renderer. + * Shaders only work with the WebGL Renderer. */ - displayHeight: number; + renderer: Phaser.Renderer.Canvas.CanvasRenderer | Phaser.Renderer.WebGL.WebGLRenderer; /** - * Sets the internal size of this Game Object, as used for frame or physics body creation. - * - * This will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or call the - * `setDisplaySize` method, which is the same thing as changing the scale but allows you - * to do so by giving pixel values. - * - * If you have enabled this Game Object for input, changing the size will _not_ change the - * size of the hit area. To do this you should adjust the `input.hitArea` object directly. - * @param width The width of this Game Object. - * @param height The height of this Game Object. + * The WebGL context belonging to the renderer. */ - setSize(width: number, height: number): this; + gl: WebGLRenderingContext; /** - * Sets the display size of this Game Object. - * - * Calling this will adjust the scale. - * @param width The width of this Game Object. - * @param height The height of this Game Object. + * Raw byte buffer of vertices this Shader uses. */ - setDisplaySize(width: number, height: number): this; + vertexData: ArrayBuffer; /** - * The depth of this Game Object within the Scene. - * - * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order - * of Game Objects, without actually moving their position in the display list. - * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth - * value will always render in front of one with a lower value. - * - * Setting the depth will queue a depth sort event within the Scene. + * The WebGL vertex buffer object this shader uses. */ - depth: number; + vertexBuffer: WebGLBuffer; /** - * The depth of this Game Object within the Scene. - * - * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order - * of Game Objects, without actually moving their position in the display list. - * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth - * value will always render in front of one with a lower value. - * - * Setting the depth will queue a depth sort event within the Scene. - * @param value The depth of this Game Object. + * The WebGL shader program this shader uses. */ - setDepth(value: integer): this; + program: WebGLProgram; /** - * Gets the center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. + * Uint8 view to the vertex raw buffer. Used for uploading vertex buffer resources to the GPU. */ - getCenter(output?: O): O; + bytes: Uint8Array; /** - * Gets the top-left corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * Float32 view of the array buffer containing the shaders vertices. */ - getTopLeft(output?: O, includeParent?: boolean): O; + vertexViewF32: Float32Array; /** - * Gets the top-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * The view matrix the shader uses during rendering. */ - getTopCenter(output?: O, includeParent?: boolean): O; + readonly viewMatrix: Float32Array; /** - * Gets the top-right corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * The projection matrix the shader uses during rendering. */ - getTopRight(output?: O, includeParent?: boolean): O; + readonly projectionMatrix: Float32Array; /** - * Gets the left-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * The default uniform mappings. These can be added to (or replaced) by specifying your own uniforms when + * creating this shader game object. The uniforms are updated automatically during the render step. + * + * The defaults are: + * + * `resolution` (2f) - Set to the size of this shader. + * `time` (1f) - The elapsed game time, in seconds. + * `mouse` (2f) - If a pointer has been bound (with `setPointer`), this uniform contains its position each frame. + * `date` (4fv) - A vec4 containing the year, month, day and time in seconds. + * `sampleRate` (1f) - Sound sample rate. 44100 by default. + * `iChannel0...3` (sampler2D) - Input channels 0 to 3. `null` by default. */ - getLeftCenter(output?: O, includeParent?: boolean): O; + uniforms: any; /** - * Gets the right-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * The pointer bound to this shader, if any. + * Set via the chainable `setPointer` method, or by modifying this property directly. */ - getRightCenter(output?: O, includeParent?: boolean): O; + pointer: Phaser.Input.Pointer; /** - * Gets the bottom-left corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * A reference to the GL Frame Buffer this Shader is drawing to. + * This property is only set if you have called `Shader.setRenderToTexture`. */ - getBottomLeft(output?: O, includeParent?: boolean): O; + framebuffer: WebGLFramebuffer; /** - * Gets the bottom-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * A reference to the WebGLTexture this Shader is rendering to. + * This property is only set if you have called `Shader.setRenderToTexture`. */ - getBottomCenter(output?: O, includeParent?: boolean): O; + glTexture: WebGLTexture; /** - * Gets the bottom-right corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * A flag that indicates if this Shader has been set to render to a texture instead of the display list. + * + * This property is `true` if you have called `Shader.setRenderToTexture`, otherwise it's `false`. + * + * A Shader that is rendering to a texture _does not_ appear on the display list. */ - getBottomRight(output?: O, includeParent?: boolean): O; + readonly renderToTexture: boolean; /** - * Gets the bounds of this Game Object, regardless of origin. - * The values are stored and returned in a Rectangle, or Rectangle-like, object. - * @param output An object to store the values in. If not provided a new Rectangle will be created. + * A reference to the Phaser.Textures.Texture that has been stored in the Texture Manager for this Shader. + * + * This property is only set if you have called `Shader.setRenderToTexture`, otherwise it is `null`. */ - getBounds(output?: O): O; + texture: Phaser.Textures.Texture; /** - * The Mask this Game Object is using during render. + * Compares the renderMask with the renderFlags to see if this Game Object will render or not. + * Also checks the Game Object against the given Cameras exclusion list. + * @param camera The Camera to check against this Game Object. */ - mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask; + willRender(camera: Phaser.Cameras.Scene2D.Camera): boolean; /** - * Sets the mask that this Game Object will use to render with. + * Changes this Shader so instead of rendering to the display list it renders to a + * WebGL Framebuffer and WebGL Texture instead. This allows you to use the output + * of this shader as an input for another shader, by mapping a sampler2D uniform + * to it. * - * The mask must have been previously created and can be either a GeometryMask or a BitmapMask. - * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * After calling this method the `Shader.framebuffer` and `Shader.glTexture` properties + * are populated. * - * If a mask is already set on this Game Object it will be immediately replaced. + * Additionally, you can provide a key to this method. Doing so will create a Phaser Texture + * from this Shader and save it into the Texture Manager, allowing you to then use it for + * any texture-based Game Object, such as a Sprite or Image: * - * Masks are positioned in global space and are not relative to the Game Object to which they - * are applied. The reason for this is that multiple Game Objects can all share the same mask. + * ```javascript + * var shader = this.add.shader('myShader', x, y, width, height); * - * Masks have no impact on physics or input detection. They are purely a rendering component - * that allows you to limit what is visible during the render pass. - * @param mask The mask this Game Object will use when rendering. + * shader.setRenderToTexture('doodle'); + * + * this.add.image(400, 300, 'doodle'); + * ``` + * + * Note that it stores an active reference to this Shader. That means as this shader updates, + * so does the texture and any object using it to render with. Also, if you destroy this + * shader, be sure to clear any objects that may have been using it as a texture too. + * + * You can access the Phaser Texture that is created via the `Shader.texture` property. + * + * By default it will create a single base texture. You can add frames to the texture + * by using the `Texture.add` method. After doing this, you can then allow Game Objects + * to use a specific frame from a Render Texture. + * @param key The unique key to store the texture as within the global Texture Manager. + * @param flipY Does this texture need vertically flipping before rendering? This should usually be set to `true` if being fed from a buffer. Default false. */ - setMask(mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask): this; + setRenderToTexture(key?: string, flipY?: boolean): this; /** - * Clears the mask that this Game Object was using. - * @param destroyMask Destroy the mask before clearing it? Default false. + * Sets the fragment and, optionally, the vertex shader source code that this Shader will use. + * This will immediately delete the active shader program, if set, and then create a new one + * with the given source. Finally, the shader uniforms are initialized. + * @param key The key of the shader to use from the shader cache, or a BaseShader instance. + * @param textures Optional array of texture keys to bind to the iChannel0...3 uniforms. The textures must already exist in the Texture Manager. + * @param textureData Additional texture data. */ - clearMask(destroyMask?: boolean): this; + setShader(key: string | Phaser.Display.BaseShader, textures?: string[], textureData?: any): this; /** - * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, - * including this one. - * - * To create the mask you need to pass in a reference to a renderable Game Object. - * A renderable Game Object is one that uses a texture to render with, such as an - * Image, Sprite, Render Texture or BitmapText. + * Binds a Phaser Pointer object to this Shader. * - * If you do not provide a renderable object, and this Game Object has a texture, - * it will use itself as the object. This means you can call this method to create - * a Bitmap Mask from any renderable Game Object. - * @param renderable A renderable Game Object that uses a texture, such as a Sprite. + * The screen position of the pointer will be set in to the shaders `mouse` uniform + * automatically every frame. Call this method with no arguments to unbind the pointer. + * @param pointer The Pointer to bind to this shader. */ - createBitmapMask(renderable?: Phaser.GameObjects.GameObject): Phaser.Display.Masks.BitmapMask; + setPointer(pointer?: Phaser.Input.Pointer): this; /** - * Creates and returns a Geometry Mask. This mask can be used by any Game Object, - * including this one. + * Sets this shader to use an orthographic projection matrix. + * This matrix is stored locally in the `projectionMatrix` property, + * as well as being bound to the `uProjectionMatrix` uniform. + * @param left The left value. + * @param right The right value. + * @param bottom The bottom value. + * @param top The top value. + */ + projOrtho(left: number, right: number, bottom: number, top: number): void; + + /** + * Sets a sampler2D uniform on this shader where the source texture is a WebGLTexture. + * + * This allows you to feed the output from one Shader into another: + * + * ```javascript + * let shader1 = this.add.shader(baseShader1, 0, 0, 512, 512).setRenderToTexture(); + * let shader2 = this.add.shader(baseShader2, 0, 0, 512, 512).setRenderToTexture('output'); + * + * shader1.setSampler2DBuffer('iChannel0', shader2.glTexture, 512, 512); + * shader2.setSampler2DBuffer('iChannel0', shader1.glTexture, 512, 512); + * ``` + * + * In the above code, the result of baseShader1 is fed into Shader2 as the `iChannel0` sampler2D uniform. + * The result of baseShader2 is then fed back into shader1 again, creating a feedback loop. + * + * If you wish to use an image from the Texture Manager as a sampler2D input for this shader, + * see the `Shader.setSampler2D` method. + * @param uniformKey The key of the sampler2D uniform to be updated, i.e. `iChannel0`. + * @param texture A WebGLTexture reference. + * @param width The width of the texture. + * @param height The height of the texture. + * @param textureIndex The texture index. Default 0. + * @param textureData Additional texture data. + */ + setSampler2DBuffer(uniformKey: string, texture: WebGLTexture, width: number, height: number, textureIndex?: number, textureData?: any): this; + + /** + * Sets a sampler2D uniform on this shader. + * + * The textureKey given is the key from the Texture Manager cache. You cannot use a single frame + * from a texture, only the full image. Also, lots of shaders expect textures to be power-of-two sized. + * + * If you wish to use another Shader as a sampler2D input for this shader, see the `Shader.setSampler2DBuffer` method. + * @param uniformKey The key of the sampler2D uniform to be updated, i.e. `iChannel0`. + * @param textureKey The key of the texture, as stored in the Texture Manager. Must already be loaded. + * @param textureIndex The texture index. Default 0. + * @param textureData Additional texture data. + */ + setSampler2D(uniformKey: string, textureKey: string, textureIndex?: number, textureData?: any): this; + + /** + * Sets a property of a uniform already present on this shader. + * + * To modify the value of a uniform such as a 1f or 1i use the `value` property directly: + * + * ```javascript + * shader.setUniform('size.value', 16); + * ``` + * + * You can use dot notation to access deeper values, for example: + * + * ```javascript + * shader.setUniform('resolution.value.x', 512); + * ``` + * + * The change to the uniform will take effect the next time the shader is rendered. + * @param key The key of the uniform to modify. Use dots for deep properties, i.e. `resolution.value.x`. + * @param value The value to set into the uniform. + */ + setUniform(key: string, value: any): this; + + /** + * Returns the uniform object for the given key, or `null` if the uniform couldn't be found. + * @param key The key of the uniform to return the value for. + */ + getUniform(key: string): any; + + /** + * A short-cut method that will directly set the texture being used by the `iChannel0` sampler2D uniform. + * + * The textureKey given is the key from the Texture Manager cache. You cannot use a single frame + * from a texture, only the full image. Also, lots of shaders expect textures to be power-of-two sized. + * @param textureKey The key of the texture, as stored in the Texture Manager. Must already be loaded. + * @param textureData Additional texture data. + */ + setChannel0(textureKey: string, textureData?: any): this; + + /** + * A short-cut method that will directly set the texture being used by the `iChannel1` sampler2D uniform. + * + * The textureKey given is the key from the Texture Manager cache. You cannot use a single frame + * from a texture, only the full image. Also, lots of shaders expect textures to be power-of-two sized. + * @param textureKey The key of the texture, as stored in the Texture Manager. Must already be loaded. + * @param textureData Additional texture data. + */ + setChannel1(textureKey: string, textureData?: any): this; + + /** + * A short-cut method that will directly set the texture being used by the `iChannel2` sampler2D uniform. + * + * The textureKey given is the key from the Texture Manager cache. You cannot use a single frame + * from a texture, only the full image. Also, lots of shaders expect textures to be power-of-two sized. + * @param textureKey The key of the texture, as stored in the Texture Manager. Must already be loaded. + * @param textureData Additional texture data. + */ + setChannel2(textureKey: string, textureData?: any): this; + + /** + * A short-cut method that will directly set the texture being used by the `iChannel3` sampler2D uniform. + * + * The textureKey given is the key from the Texture Manager cache. You cannot use a single frame + * from a texture, only the full image. Also, lots of shaders expect textures to be power-of-two sized. + * @param textureKey The key of the texture, as stored in the Texture Manager. Must already be loaded. + * @param textureData Additional texture data. + */ + setChannel3(textureKey: string, textureData?: any): this; + + /** + * Called automatically during render. + * + * This method performs matrix ITRS and then stores the resulting value in the `uViewMatrix` uniform. + * It then sets up the vertex buffer and shader, updates and syncs the uniforms ready + * for flush to be called. + * @param matrix2D The transform matrix to use during rendering. + */ + load(matrix2D?: Phaser.GameObjects.Components.TransformMatrix): void; + + /** + * Called automatically during render. + * + * Sets the active shader, loads the vertex buffer and then draws. + */ + flush(): void; + + /** + * Internal destroy handler, called as part of the destroy process. + */ + protected preDestroy(): void; + + /** + * The native (un-scaled) width of this Game Object. + * + * Changing this value will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or use + * the `displayWidth` property. + */ + width: number; + + /** + * The native (un-scaled) height of this Game Object. + * + * Changing this value will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or use + * the `displayHeight` property. + */ + height: number; + + /** + * The displayed width of this Game Object. + * + * This value takes into account the scale factor. + * + * Setting this value will adjust the Game Object's scale property. + */ + displayWidth: number; + + /** + * The displayed height of this Game Object. + * + * This value takes into account the scale factor. + * + * Setting this value will adjust the Game Object's scale property. + */ + displayHeight: number; + + /** + * Sets the internal size of this Game Object, as used for frame or physics body creation. + * + * This will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or call the + * `setDisplaySize` method, which is the same thing as changing the scale but allows you + * to do so by giving pixel values. + * + * If you have enabled this Game Object for input, changing the size will _not_ change the + * size of the hit area. To do this you should adjust the `input.hitArea` object directly. + * @param width The width of this Game Object. + * @param height The height of this Game Object. + */ + setSize(width: number, height: number): this; + + /** + * Sets the display size of this Game Object. + * + * Calling this will adjust the scale. + * @param width The width of this Game Object. + * @param height The height of this Game Object. + */ + setDisplaySize(width: number, height: number): this; + + /** + * The depth of this Game Object within the Scene. + * + * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order + * of Game Objects, without actually moving their position in the display list. + * + * The default depth is zero. A Game Object with a higher depth + * value will always render in front of one with a lower value. + * + * Setting the depth will queue a depth sort event within the Scene. + */ + depth: number; + + /** + * The depth of this Game Object within the Scene. + * + * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order + * of Game Objects, without actually moving their position in the display list. + * + * The default depth is zero. A Game Object with a higher depth + * value will always render in front of one with a lower value. + * + * Setting the depth will queue a depth sort event within the Scene. + * @param value The depth of this Game Object. + */ + setDepth(value: number): this; + + /** + * Gets the center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + */ + getCenter(output?: O): O; + + /** + * Gets the top-left corner coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + */ + getTopLeft(output?: O, includeParent?: boolean): O; + + /** + * Gets the top-center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + */ + getTopCenter(output?: O, includeParent?: boolean): O; + + /** + * Gets the top-right corner coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + */ + getTopRight(output?: O, includeParent?: boolean): O; + + /** + * Gets the left-center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + */ + getLeftCenter(output?: O, includeParent?: boolean): O; + + /** + * Gets the right-center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + */ + getRightCenter(output?: O, includeParent?: boolean): O; + + /** + * Gets the bottom-left corner coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + */ + getBottomLeft(output?: O, includeParent?: boolean): O; + + /** + * Gets the bottom-center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + */ + getBottomCenter(output?: O, includeParent?: boolean): O; + + /** + * Gets the bottom-right corner coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + */ + getBottomRight(output?: O, includeParent?: boolean): O; + + /** + * Gets the bounds of this Game Object, regardless of origin. + * The values are stored and returned in a Rectangle, or Rectangle-like, object. + * @param output An object to store the values in. If not provided a new Rectangle will be created. + */ + getBounds(output?: O): O; + + /** + * The Mask this Game Object is using during render. + */ + mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask; + + /** + * Sets the mask that this Game Object will use to render with. + * + * The mask must have been previously created and can be either a GeometryMask or a BitmapMask. + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * + * If a mask is already set on this Game Object it will be immediately replaced. + * + * Masks are positioned in global space and are not relative to the Game Object to which they + * are applied. The reason for this is that multiple Game Objects can all share the same mask. + * + * Masks have no impact on physics or input detection. They are purely a rendering component + * that allows you to limit what is visible during the render pass. + * @param mask The mask this Game Object will use when rendering. + */ + setMask(mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask): this; + + /** + * Clears the mask that this Game Object was using. + * @param destroyMask Destroy the mask before clearing it? Default false. + */ + clearMask(destroyMask?: boolean): this; + + /** + * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, + * including this one. + * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * + * To create the mask you need to pass in a reference to a renderable Game Object. + * A renderable Game Object is one that uses a texture to render with, such as an + * Image, Sprite, Render Texture or BitmapText. + * + * If you do not provide a renderable object, and this Game Object has a texture, + * it will use itself as the object. This means you can call this method to create + * a Bitmap Mask from any renderable Game Object. + * @param renderable A renderable Game Object that uses a texture, such as a Sprite. + */ + createBitmapMask(renderable?: Phaser.GameObjects.GameObject): Phaser.Display.Masks.BitmapMask; + + /** + * Creates and returns a Geometry Mask. This mask can be used by any Game Object, + * including this one. * * To create the mask you need to pass in a reference to a Graphics Game Object. * @@ -25799,39 +29848,6 @@ declare namespace Phaser { */ updateDisplayOrigin(): this; - /** - * The initial WebGL pipeline of this Game Object. - */ - defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; - - /** - * The current WebGL pipeline of this Game Object. - */ - pipeline: Phaser.Renderer.WebGL.WebGLPipeline; - - /** - * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. - */ - initPipeline(pipelineName?: string): boolean; - - /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. - */ - setPipeline(pipelineName: string): this; - - /** - * Resets the WebGL Pipeline of this Game Object back to the default it was created with. - */ - resetPipeline(): boolean; - - /** - * Gets the name of the WebGL Pipeline this Game Object is currently using. - */ - getPipelineName(): string; - /** * The horizontal scroll factor of this Game Object. * @@ -25941,13 +29957,13 @@ declare namespace Phaser { * * If you prefer to work in radians, see the `rotation` property instead. */ - angle: integer; + angle: number; /** * The angle of this Game Object in radians. * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. * * If you prefer to work in degrees, see the `angle` property instead. */ @@ -25962,6 +29978,12 @@ declare namespace Phaser { */ setPosition(x?: number, y?: number, z?: number, w?: number): this; + /** + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; + /** * Sets the position of this Game Object to be a random position within the confines of * the given area. @@ -26036,6 +30058,22 @@ declare namespace Phaser { */ getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. + */ + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + /** * Gets the sum total rotation of all of this Game Objects parent Containers. * @@ -26061,56 +30099,93 @@ declare namespace Phaser { } /** - * The Ellipse Shape is a Game Object that can be added to a Scene, Group or Container. You can + * The Arc Shape is a Game Object that can be added to a Scene, Group or Container. You can * treat it like any other Game Object in your game, such as tweening it, scaling it, or enabling * it for input or physics. It provides a quick and easy way for you to render this shape in your * game without using a texture, while still taking advantage of being fully batched in WebGL. * * This shape supports both fill and stroke colors. * - * When it renders it displays an ellipse shape. You can control the width and height of the ellipse. - * If the width and height match it will render as a circle. If the width is less than the height, - * it will look more like an egg shape. + * When it renders it displays an arc shape. You can control the start and end angles of the arc, + * as well as if the angles are winding clockwise or anti-clockwise. With the default settings + * it renders as a complete circle. By changing the angles you can create other arc shapes, + * such as half-circles. * - * The Ellipse shape also has a `smoothness` property and corresponding `setSmoothness` method. - * This allows you to control how smooth the shape renders in WebGL, by controlling the number of iterations - * that take place during construction. Increase and decrease the default value for smoother, or more - * jagged, shapes. + * Arcs also have an `iterations` property and corresponding `setIterations` method. This allows + * you to control how smooth the shape renders in WebGL, by controlling the number of iterations + * that take place during construction. */ - class Ellipse extends Phaser.GameObjects.Shape { + class Arc extends Phaser.GameObjects.Shape { /** * * @param scene The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. * @param x The horizontal position of this Game Object in the world. Default 0. * @param y The vertical position of this Game Object in the world. Default 0. - * @param width The width of the ellipse. An ellipse with equal width and height renders as a circle. Default 128. - * @param height The height of the ellipse. An ellipse with equal width and height renders as a circle. Default 128. - * @param fillColor The color the ellipse will be filled with, i.e. 0xff0000 for red. - * @param fillAlpha The alpha the ellipse will be filled with. You can also set the alpha of the overall Shape using its `alpha` property. + * @param radius The radius of the arc. Default 128. + * @param startAngle The start angle of the arc, in degrees. Default 0. + * @param endAngle The end angle of the arc, in degrees. Default 360. + * @param anticlockwise The winding order of the start and end angles. Default false. + * @param fillColor The color the arc will be filled with, i.e. 0xff0000 for red. + * @param fillAlpha The alpha the arc will be filled with. You can also set the alpha of the overall Shape using its `alpha` property. */ - constructor(scene: Phaser.Scene, x?: number, y?: number, width?: number, height?: number, fillColor?: number, fillAlpha?: number); + constructor(scene: Phaser.Scene, x?: number, y?: number, radius?: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean, fillColor?: number, fillAlpha?: number); /** - * The smoothness of the ellipse. The number of points used when rendering it. - * Increase this value for a smoother ellipse, at the cost of more polygons being rendered. + * The number of iterations used when drawing the arc. + * Increase this value for smoother arcs, at the cost of more polygons being rendered. + * Modify this value by small amounts, such as 0.01. + */ + iterations: number; + + /** + * The radius of the arc. */ - smoothness: integer; + radius: number; /** - * Sets the size of the ellipse by changing the underlying geometry data, rather than scaling the object. + * The start angle of the arc, in degrees. + */ + startAngle: number; + + /** + * The end angle of the arc, in degrees. + */ + endAngle: number; + + /** + * The winding order of the start and end angles. + */ + anticlockwise: boolean; + + /** + * Sets the radius of the arc. * This call can be chained. - * @param width The width of the ellipse. - * @param height The height of the ellipse. + * @param value The value to set the radius to. */ - setSize(width: number, height: number): this; + setRadius(value: number): this; /** - * Sets the smoothness of the ellipse. The number of points used when rendering it. - * Increase this value for a smoother ellipse, at the cost of more polygons being rendered. + * Sets the number of iterations used when drawing the arc. + * Increase this value for smoother arcs, at the cost of more polygons being rendered. + * Modify this value by small amounts, such as 0.01. * This call can be chained. - * @param value The value to set the smoothness to. + * @param value The value to set the iterations to. + */ + setIterations(value: number): this; + + /** + * Sets the starting angle of the arc, in degrees. + * This call can be chained. + * @param value The value to set the starting angle to. + */ + setStartAngle(value: number): this; + + /** + * Sets the ending angle of the arc, in degrees. + * This call can be chained. + * @param value The value to set the ending angle to. */ - setSmoothness(value: integer): this; + setEndAngle(value: number): this; /** * Clears all alpha values associated with this Game Object. @@ -26180,58 +30255,13 @@ declare namespace Phaser { */ setBlendMode(value: string | Phaser.BlendModes): this; - /** - * The native (un-scaled) width of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayWidth` property. - */ - width: number; - - /** - * The native (un-scaled) height of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayHeight` property. - */ - height: number; - - /** - * The displayed width of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. - */ - displayWidth: number; - - /** - * The displayed height of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. - */ - displayHeight: number; - - /** - * Sets the display size of this Game Object. - * - * Calling this will adjust the scale. - * @param width The width of this Game Object. - * @param height The height of this Game Object. - */ - setDisplaySize(width: number, height: number): this; - /** * The depth of this Game Object within the Scene. * * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. @@ -26244,13 +30274,13 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. * @param value The depth of this Game Object. */ - setDepth(value: integer): this; + setDepth(value: number): this; /** * Gets the center coordinate of this Game Object, regardless of origin. @@ -26362,6 +30392,8 @@ declare namespace Phaser { * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, * including this one. * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * * To create the mask you need to pass in a reference to a renderable Game Object. * A renderable Game Object is one that uses a texture to render with, such as an * Image, Sprite, Render Texture or BitmapText. @@ -26447,6 +30479,8 @@ declare namespace Phaser { /** * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. */ defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; @@ -26456,30 +30490,116 @@ declare namespace Phaser { pipeline: Phaser.Renderer.WebGL.WebGLPipeline; /** - * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. + * Does this Game Object have any Post Pipelines set? */ - initPipeline(pipelineName?: string): boolean; + hasPostPipeline: boolean; /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. */ - setPipeline(pipelineName: string): this; + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; /** - * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. */ - resetPipeline(): boolean; + pipelineData: object; /** - * Gets the name of the WebGL Pipeline this Game Object is currently using. + * Sets the initial WebGL Pipeline of this Game Object. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. */ - getPipelineName(): string; + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; /** - * The horizontal scroll factor of this Game Object. + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; + + /** + * Sets one, or more, Post Pipelines on this Game Object. + * + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; + + /** + * Adds an entry to the `pipelineData` object belonging to this Game Object. + * + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. + */ + setPipelineData(key: string, value?: any): this; + + /** + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. + */ + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; + + /** + * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; + + /** + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPostPipeline(resetData?: boolean): void; + + /** + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. + */ + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; + + /** + * Gets the name of the WebGL Pipeline this Game Object is currently using. + */ + getPipelineName(): string; + + /** + * The horizontal scroll factor of this Game Object. * * The scroll factor controls the influence of the movement of a Camera upon this Game Object. * @@ -26587,13 +30707,13 @@ declare namespace Phaser { * * If you prefer to work in radians, see the `rotation` property instead. */ - angle: integer; + angle: number; /** * The angle of this Game Object in radians. * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. * * If you prefer to work in degrees, see the `angle` property instead. */ @@ -26608,6 +30728,12 @@ declare namespace Phaser { */ setPosition(x?: number, y?: number, z?: number, w?: number): this; + /** + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; + /** * Sets the position of this Game Object to be a random position within the confines of * the given area. @@ -26682,6 +30808,22 @@ declare namespace Phaser { */ getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. + */ + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + /** * Gets the sum total rotation of all of this Game Objects parent Containers. * @@ -26707,126 +30849,46 @@ declare namespace Phaser { } /** - * The Grid Shape is a Game Object that can be added to a Scene, Group or Container. You can + * The Curve Shape is a Game Object that can be added to a Scene, Group or Container. You can * treat it like any other Game Object in your game, such as tweening it, scaling it, or enabling * it for input or physics. It provides a quick and easy way for you to render this shape in your * game without using a texture, while still taking advantage of being fully batched in WebGL. * - * This shape supports only fill colors and cannot be stroked. + * This shape supports both fill and stroke colors. * - * A Grid Shape allows you to display a grid in your game, where you can control the size of the - * grid as well as the width and height of the grid cells. You can set a fill color for each grid - * cell as well as an alternate fill color. When the alternate fill color is set then the grid - * cells will alternate the fill colors as they render, creating a chess-board effect. You can - * also optionally have an outline fill color. If set, this draws lines between the grid cells - * in the given color. If you specify an outline color with an alpha of zero, then it will draw - * the cells spaced out, but without the lines between them. + * To render a Curve Shape you must first create a `Phaser.Curves.Curve` object, then pass it to + * the Curve Shape in the constructor. + * + * The Curve shape also has a `smoothness` property and corresponding `setSmoothness` method. + * This allows you to control how smooth the shape renders in WebGL, by controlling the number of iterations + * that take place during construction. Increase and decrease the default value for smoother, or more + * jagged, shapes. */ - class Grid extends Phaser.GameObjects.Shape { + class Curve extends Phaser.GameObjects.Shape { /** * * @param scene The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. * @param x The horizontal position of this Game Object in the world. Default 0. * @param y The vertical position of this Game Object in the world. Default 0. - * @param width The width of the grid. Default 128. - * @param height The height of the grid. Default 128. - * @param cellWidth The width of one cell in the grid. Default 32. - * @param cellHeight The height of one cell in the grid. Default 32. - * @param fillColor The color the grid cells will be filled with, i.e. 0xff0000 for red. - * @param fillAlpha The alpha the grid cells will be filled with. You can also set the alpha of the overall Shape using its `alpha` property. - * @param outlineFillColor The color of the lines between the grid cells. See the `setOutline` method. - * @param outlineFillAlpha The alpha of the lines between the grid cells. - */ - constructor(scene: Phaser.Scene, x?: number, y?: number, width?: number, height?: number, cellWidth?: number, cellHeight?: number, fillColor?: number, fillAlpha?: number, outlineFillColor?: number, outlineFillAlpha?: number); - - /** - * The width of each grid cell. - * Must be a positive value. - */ - cellWidth: number; - - /** - * The height of each grid cell. - * Must be a positive value. - */ - cellHeight: number; - - /** - * Will the grid render its cells in the `fillColor`? - */ - showCells: boolean; - - /** - * The color of the lines between each grid cell. - */ - outlineFillColor: number; - - /** - * The alpha value for the color of the lines between each grid cell. - */ - outlineFillAlpha: number; - - /** - * Will the grid display the lines between each cell when it renders? - */ - showOutline: boolean; - - /** - * Will the grid render the alternating cells in the `altFillColor`? - */ - showAltCells: boolean; - - /** - * The color the alternating grid cells will be filled with, i.e. 0xff0000 for red. - */ - altFillColor: number; - - /** - * The alpha the alternating grid cells will be filled with. - * You can also set the alpha of the overall Shape using its `alpha` property. - */ - altFillAlpha: number; - - /** - * Sets the fill color and alpha level the grid cells will use when rendering. - * - * If this method is called with no values then the grid cells will not be rendered, - * however the grid lines and alternating cells may still be. - * - * Also see the `setOutlineStyle` and `setAltFillStyle` methods. - * - * This call can be chained. - * @param fillColor The color the grid cells will be filled with, i.e. 0xff0000 for red. - * @param fillAlpha The alpha the grid cells will be filled with. You can also set the alpha of the overall Shape using its `alpha` property. Default 1. + * @param curve The Curve object to use to create the Shape. + * @param fillColor The color the curve will be filled with, i.e. 0xff0000 for red. + * @param fillAlpha The alpha the curve will be filled with. You can also set the alpha of the overall Shape using its `alpha` property. */ - setFillStyle(fillColor?: number, fillAlpha?: number): this; + constructor(scene: Phaser.Scene, x?: number, y?: number, curve?: Phaser.Curves.Curve, fillColor?: number, fillAlpha?: number); /** - * Sets the fill color and alpha level that the alternating grid cells will use. - * - * If this method is called with no values then alternating grid cells will not be rendered in a different color. - * - * Also see the `setOutlineStyle` and `setFillStyle` methods. - * - * This call can be chained. - * @param fillColor The color the alternating grid cells will be filled with, i.e. 0xff0000 for red. - * @param fillAlpha The alpha the alternating grid cells will be filled with. You can also set the alpha of the overall Shape using its `alpha` property. Default 1. + * The smoothness of the curve. The number of points used when rendering it. + * Increase this value for smoother curves, at the cost of more polygons being rendered. */ - setAltFillStyle(fillColor?: number, fillAlpha?: number): this; + smoothness: number; /** - * Sets the fill color and alpha level that the lines between each grid cell will use. - * - * If this method is called with no values then the grid lines will not be rendered at all, however - * the cells themselves may still be if they have colors set. - * - * Also see the `setFillStyle` and `setAltFillStyle` methods. - * + * Sets the smoothness of the curve. The number of points used when rendering it. + * Increase this value for smoother curves, at the cost of more polygons being rendered. * This call can be chained. - * @param fillColor The color the lines between the grid cells will be filled with, i.e. 0xff0000 for red. - * @param fillAlpha The alpha the lines between the grid cells will be filled with. You can also set the alpha of the overall Shape using its `alpha` property. Default 1. + * @param value The value to set the smoothness to. */ - setOutlineStyle(fillColor?: number, fillAlpha?: number): this; + setSmoothness(value: number): this; /** * Clears all alpha values associated with this Game Object. @@ -26896,73 +30958,13 @@ declare namespace Phaser { */ setBlendMode(value: string | Phaser.BlendModes): this; - /** - * The native (un-scaled) width of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayWidth` property. - */ - width: number; - - /** - * The native (un-scaled) height of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayHeight` property. - */ - height: number; - - /** - * The displayed width of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. - */ - displayWidth: number; - - /** - * The displayed height of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. - */ - displayHeight: number; - - /** - * Sets the internal size of this Game Object, as used for frame or physics body creation. - * - * This will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or call the - * `setDisplaySize` method, which is the same thing as changing the scale but allows you - * to do so by giving pixel values. - * - * If you have enabled this Game Object for input, changing the size will _not_ change the - * size of the hit area. To do this you should adjust the `input.hitArea` object directly. - * @param width The width of this Game Object. - * @param height The height of this Game Object. - */ - setSize(width: number, height: number): this; - - /** - * Sets the display size of this Game Object. - * - * Calling this will adjust the scale. - * @param width The width of this Game Object. - * @param height The height of this Game Object. - */ - setDisplaySize(width: number, height: number): this; - /** * The depth of this Game Object within the Scene. * * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. @@ -26975,13 +30977,13 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. * @param value The depth of this Game Object. */ - setDepth(value: integer): this; + setDepth(value: number): this; /** * Gets the center coordinate of this Game Object, regardless of origin. @@ -27093,6 +31095,8 @@ declare namespace Phaser { * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, * including this one. * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * * To create the mask you need to pass in a reference to a renderable Game Object. * A renderable Game Object is one that uses a texture to render with, such as an * Image, Sprite, Render Texture or BitmapText. @@ -27178,6 +31182,8 @@ declare namespace Phaser { /** * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. */ defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; @@ -27186,23 +31192,109 @@ declare namespace Phaser { */ pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + /** + * Does this Game Object have any Post Pipelines set? + */ + hasPostPipeline: boolean; + + /** + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. + */ + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; + + /** + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. + */ + pipelineData: object; + /** * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. */ - initPipeline(pipelineName?: string): boolean; + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; + + /** + * Sets one, or more, Post Pipelines on this Game Object. + * + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. */ - setPipeline(pipelineName: string): this; + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; + + /** + * Adds an entry to the `pipelineData` object belonging to this Game Object. + * + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. + */ + setPipelineData(key: string, value?: any): this; + + /** + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. + */ + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; /** * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; + + /** + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPostPipeline(resetData?: boolean): void; + + /** + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - resetPipeline(): boolean; + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; /** * Gets the name of the WebGL Pipeline this Game Object is currently using. @@ -27318,13 +31410,13 @@ declare namespace Phaser { * * If you prefer to work in radians, see the `rotation` property instead. */ - angle: integer; + angle: number; /** * The angle of this Game Object in radians. * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. * * If you prefer to work in degrees, see the `angle` property instead. */ @@ -27339,6 +31431,12 @@ declare namespace Phaser { */ setPosition(x?: number, y?: number, z?: number, w?: number): this; + /** + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; + /** * Sets the position of this Game Object to be a random position within the confines of * the given area. @@ -27413,6 +31511,22 @@ declare namespace Phaser { */ getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. + */ + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + /** * Gets the sum total rotation of all of this Game Objects parent Containers. * @@ -27438,93 +31552,56 @@ declare namespace Phaser { } /** - * The IsoBox Shape is a Game Object that can be added to a Scene, Group or Container. You can + * The Ellipse Shape is a Game Object that can be added to a Scene, Group or Container. You can * treat it like any other Game Object in your game, such as tweening it, scaling it, or enabling * it for input or physics. It provides a quick and easy way for you to render this shape in your * game without using a texture, while still taking advantage of being fully batched in WebGL. * - * This shape supports only fill colors and cannot be stroked. + * This shape supports both fill and stroke colors. * - * An IsoBox is an 'isometric' rectangle. Each face of it has a different fill color. You can set - * the color of the top, left and right faces of the rectangle respectively. You can also choose - * which of the faces are rendered via the `showTop`, `showLeft` and `showRight` properties. + * When it renders it displays an ellipse shape. You can control the width and height of the ellipse. + * If the width and height match it will render as a circle. If the width is less than the height, + * it will look more like an egg shape. * - * You cannot view an IsoBox from under-neath, however you can change the 'angle' by setting - * the `projection` property. + * The Ellipse shape also has a `smoothness` property and corresponding `setSmoothness` method. + * This allows you to control how smooth the shape renders in WebGL, by controlling the number of iterations + * that take place during construction. Increase and decrease the default value for smoother, or more + * jagged, shapes. */ - class IsoBox extends Phaser.GameObjects.Shape { + class Ellipse extends Phaser.GameObjects.Shape { /** * * @param scene The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. * @param x The horizontal position of this Game Object in the world. Default 0. * @param y The vertical position of this Game Object in the world. Default 0. - * @param size The width of the iso box in pixels. The left and right faces will be exactly half this value. Default 48. - * @param height The height of the iso box. The left and right faces will be this tall. The overall height of the isobox will be this value plus half the `size` value. Default 32. - * @param fillTop The fill color of the top face of the iso box. Default 0xeeeeee. - * @param fillLeft The fill color of the left face of the iso box. Default 0x999999. - * @param fillRight The fill color of the right face of the iso box. Default 0xcccccc. - */ - constructor(scene: Phaser.Scene, x?: number, y?: number, size?: number, height?: number, fillTop?: number, fillLeft?: number, fillRight?: number); - - /** - * The projection level of the iso box. Change this to change the 'angle' at which you are looking at the box. - */ - projection: integer; - - /** - * The color used to fill in the top of the iso box. - */ - fillTop: number; - - /** - * The color used to fill in the left-facing side of the iso box. - */ - fillLeft: number; - - /** - * The color used to fill in the right-facing side of the iso box. - */ - fillRight: number; - - /** - * Controls if the top-face of the iso box be rendered. - */ - showTop: boolean; - - /** - * Controls if the left-face of the iso box be rendered. - */ - showLeft: boolean; - - /** - * Controls if the right-face of the iso box be rendered. + * @param width The width of the ellipse. An ellipse with equal width and height renders as a circle. Default 128. + * @param height The height of the ellipse. An ellipse with equal width and height renders as a circle. Default 128. + * @param fillColor The color the ellipse will be filled with, i.e. 0xff0000 for red. + * @param fillAlpha The alpha the ellipse will be filled with. You can also set the alpha of the overall Shape using its `alpha` property. */ - showRight: boolean; + constructor(scene: Phaser.Scene, x?: number, y?: number, width?: number, height?: number, fillColor?: number, fillAlpha?: number); /** - * Sets the projection level of the iso box. Change this to change the 'angle' at which you are looking at the box. - * This call can be chained. - * @param value The value to set the projection to. + * The smoothness of the ellipse. The number of points used when rendering it. + * Increase this value for a smoother ellipse, at the cost of more polygons being rendered. */ - setProjection(value: integer): this; + smoothness: number; /** - * Sets which faces of the iso box will be rendered. + * Sets the size of the ellipse by changing the underlying geometry data, rather than scaling the object. * This call can be chained. - * @param showTop Show the top-face of the iso box. Default true. - * @param showLeft Show the left-face of the iso box. Default true. - * @param showRight Show the right-face of the iso box. Default true. + * @param width The width of the ellipse. + * @param height The height of the ellipse. */ - setFaces(showTop?: boolean, showLeft?: boolean, showRight?: boolean): this; + setSize(width: number, height: number): this; /** - * Sets the fill colors for each face of the iso box. + * Sets the smoothness of the ellipse. The number of points used when rendering it. + * Increase this value for a smoother ellipse, at the cost of more polygons being rendered. * This call can be chained. - * @param fillTop The color used to fill the top of the iso box. - * @param fillLeft The color used to fill in the left-facing side of the iso box. - * @param fillRight The color used to fill in the right-facing side of the iso box. + * @param value The value to set the smoothness to. */ - setFillStyle(fillTop?: number, fillLeft?: number, fillRight?: number): this; + setSmoothness(value: number): this; /** * Clears all alpha values associated with this Game Object. @@ -27594,73 +31671,13 @@ declare namespace Phaser { */ setBlendMode(value: string | Phaser.BlendModes): this; - /** - * The native (un-scaled) width of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayWidth` property. - */ - width: number; - - /** - * The native (un-scaled) height of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayHeight` property. - */ - height: number; - - /** - * The displayed width of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. - */ - displayWidth: number; - - /** - * The displayed height of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. - */ - displayHeight: number; - - /** - * Sets the internal size of this Game Object, as used for frame or physics body creation. - * - * This will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or call the - * `setDisplaySize` method, which is the same thing as changing the scale but allows you - * to do so by giving pixel values. - * - * If you have enabled this Game Object for input, changing the size will _not_ change the - * size of the hit area. To do this you should adjust the `input.hitArea` object directly. - * @param width The width of this Game Object. - * @param height The height of this Game Object. - */ - setSize(width: number, height: number): this; - - /** - * Sets the display size of this Game Object. - * - * Calling this will adjust the scale. - * @param width The width of this Game Object. - * @param height The height of this Game Object. - */ - setDisplaySize(width: number, height: number): this; - /** * The depth of this Game Object within the Scene. * * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. @@ -27673,13 +31690,13 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. * @param value The depth of this Game Object. */ - setDepth(value: integer): this; + setDepth(value: number): this; /** * Gets the center coordinate of this Game Object, regardless of origin. @@ -27791,6 +31808,8 @@ declare namespace Phaser { * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, * including this one. * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * * To create the mask you need to pass in a reference to a renderable Game Object. * A renderable Game Object is one that uses a texture to render with, such as an * Image, Sprite, Render Texture or BitmapText. @@ -27876,6 +31895,8 @@ declare namespace Phaser { /** * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. */ defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; @@ -27884,23 +31905,109 @@ declare namespace Phaser { */ pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + /** + * Does this Game Object have any Post Pipelines set? + */ + hasPostPipeline: boolean; + + /** + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. + */ + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; + + /** + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. + */ + pipelineData: object; + /** * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. */ - initPipeline(pipelineName?: string): boolean; + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; + + /** + * Sets one, or more, Post Pipelines on this Game Object. + * + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. */ - setPipeline(pipelineName: string): this; + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; + + /** + * Adds an entry to the `pipelineData` object belonging to this Game Object. + * + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. + */ + setPipelineData(key: string, value?: any): this; + + /** + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. + */ + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; /** * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; + + /** + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPostPipeline(resetData?: boolean): void; + + /** + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - resetPipeline(): boolean; + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; /** * Gets the name of the WebGL Pipeline this Game Object is currently using. @@ -28016,13 +32123,13 @@ declare namespace Phaser { * * If you prefer to work in radians, see the `rotation` property instead. */ - angle: integer; + angle: number; /** * The angle of this Game Object in radians. * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. * * If you prefer to work in degrees, see the `angle` property instead. */ @@ -28037,6 +32144,12 @@ declare namespace Phaser { */ setPosition(x?: number, y?: number, z?: number, w?: number): this; + /** + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; + /** * Sets the position of this Game Object to be a random position within the confines of * the given area. @@ -28111,6 +32224,22 @@ declare namespace Phaser { */ getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. + */ + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + /** * Gets the sum total rotation of all of this Game Objects parent Containers. * @@ -28136,107 +32265,126 @@ declare namespace Phaser { } /** - * The IsoTriangle Shape is a Game Object that can be added to a Scene, Group or Container. You can + * The Grid Shape is a Game Object that can be added to a Scene, Group or Container. You can * treat it like any other Game Object in your game, such as tweening it, scaling it, or enabling * it for input or physics. It provides a quick and easy way for you to render this shape in your * game without using a texture, while still taking advantage of being fully batched in WebGL. * * This shape supports only fill colors and cannot be stroked. * - * An IsoTriangle is an 'isometric' triangle. Think of it like a pyramid. Each face has a different - * fill color. You can set the color of the top, left and right faces of the triangle respectively - * You can also choose which of the faces are rendered via the `showTop`, `showLeft` and `showRight` properties. - * - * You cannot view an IsoTriangle from under-neath, however you can change the 'angle' by setting - * the `projection` property. The `reversed` property controls if the IsoTriangle is rendered upside - * down or not. + * A Grid Shape allows you to display a grid in your game, where you can control the size of the + * grid as well as the width and height of the grid cells. You can set a fill color for each grid + * cell as well as an alternate fill color. When the alternate fill color is set then the grid + * cells will alternate the fill colors as they render, creating a chess-board effect. You can + * also optionally have an outline fill color. If set, this draws lines between the grid cells + * in the given color. If you specify an outline color with an alpha of zero, then it will draw + * the cells spaced out, but without the lines between them. */ - class IsoTriangle extends Phaser.GameObjects.Shape { + class Grid extends Phaser.GameObjects.Shape { /** * * @param scene The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. * @param x The horizontal position of this Game Object in the world. Default 0. * @param y The vertical position of this Game Object in the world. Default 0. - * @param size The width of the iso triangle in pixels. The left and right faces will be exactly half this value. Default 48. - * @param height The height of the iso triangle. The left and right faces will be this tall. The overall height of the iso triangle will be this value plus half the `size` value. Default 32. - * @param reversed Is the iso triangle upside down? Default false. - * @param fillTop The fill color of the top face of the iso triangle. Default 0xeeeeee. - * @param fillLeft The fill color of the left face of the iso triangle. Default 0x999999. - * @param fillRight The fill color of the right face of the iso triangle. Default 0xcccccc. + * @param width The width of the grid. Default 128. + * @param height The height of the grid. Default 128. + * @param cellWidth The width of one cell in the grid. Default 32. + * @param cellHeight The height of one cell in the grid. Default 32. + * @param fillColor The color the grid cells will be filled with, i.e. 0xff0000 for red. + * @param fillAlpha The alpha the grid cells will be filled with. You can also set the alpha of the overall Shape using its `alpha` property. + * @param outlineFillColor The color of the lines between the grid cells. See the `setOutline` method. + * @param outlineFillAlpha The alpha of the lines between the grid cells. */ - constructor(scene: Phaser.Scene, x?: number, y?: number, size?: number, height?: number, reversed?: boolean, fillTop?: number, fillLeft?: number, fillRight?: number); + constructor(scene: Phaser.Scene, x?: number, y?: number, width?: number, height?: number, cellWidth?: number, cellHeight?: number, fillColor?: number, fillAlpha?: number, outlineFillColor?: number, outlineFillAlpha?: number); /** - * The projection level of the iso box. Change this to change the 'angle' at which you are looking at the box. + * The width of each grid cell. + * Must be a positive value. */ - projection: integer; + cellWidth: number; /** - * The color used to fill in the top of the iso triangle. This is only used if the triangle is reversed. + * The height of each grid cell. + * Must be a positive value. */ - fillTop: number; + cellHeight: number; /** - * The color used to fill in the left-facing side of the iso triangle. + * Will the grid render its cells in the `fillColor`? */ - fillLeft: number; + showCells: boolean; /** - * The color used to fill in the right-facing side of the iso triangle. + * The color of the lines between each grid cell. */ - fillRight: number; + outlineFillColor: number; /** - * Controls if the top-face of the iso triangle be rendered. + * The alpha value for the color of the lines between each grid cell. */ - showTop: boolean; + outlineFillAlpha: number; /** - * Controls if the left-face of the iso triangle be rendered. + * Will the grid display the lines between each cell when it renders? */ - showLeft: boolean; + showOutline: boolean; /** - * Controls if the right-face of the iso triangle be rendered. + * Will the grid render the alternating cells in the `altFillColor`? */ - showRight: boolean; + showAltCells: boolean; /** - * Sets if the iso triangle will be rendered upside down or not. + * The color the alternating grid cells will be filled with, i.e. 0xff0000 for red. */ - isReversed: boolean; + altFillColor: number; /** - * Sets the projection level of the iso triangle. Change this to change the 'angle' at which you are looking at the pyramid. - * This call can be chained. - * @param value The value to set the projection to. + * The alpha the alternating grid cells will be filled with. + * You can also set the alpha of the overall Shape using its `alpha` property. */ - setProjection(value: integer): this; + altFillAlpha: number; /** - * Sets if the iso triangle will be rendered upside down or not. + * Sets the fill color and alpha level the grid cells will use when rendering. + * + * If this method is called with no values then the grid cells will not be rendered, + * however the grid lines and alternating cells may still be. + * + * Also see the `setOutlineStyle` and `setAltFillStyle` methods. + * * This call can be chained. - * @param reversed Sets if the iso triangle will be rendered upside down or not. + * @param fillColor The color the grid cells will be filled with, i.e. 0xff0000 for red. + * @param fillAlpha The alpha the grid cells will be filled with. You can also set the alpha of the overall Shape using its `alpha` property. Default 1. */ - setReversed(reversed: boolean): this; + setFillStyle(fillColor?: number, fillAlpha?: number): this; /** - * Sets which faces of the iso triangle will be rendered. + * Sets the fill color and alpha level that the alternating grid cells will use. + * + * If this method is called with no values then alternating grid cells will not be rendered in a different color. + * + * Also see the `setOutlineStyle` and `setFillStyle` methods. + * * This call can be chained. - * @param showTop Show the top-face of the iso triangle (only if `reversed` is true) Default true. - * @param showLeft Show the left-face of the iso triangle. Default true. - * @param showRight Show the right-face of the iso triangle. Default true. + * @param fillColor The color the alternating grid cells will be filled with, i.e. 0xff0000 for red. + * @param fillAlpha The alpha the alternating grid cells will be filled with. You can also set the alpha of the overall Shape using its `alpha` property. Default 1. */ - setFaces(showTop?: boolean, showLeft?: boolean, showRight?: boolean): this; + setAltFillStyle(fillColor?: number, fillAlpha?: number): this; /** - * Sets the fill colors for each face of the iso triangle. + * Sets the fill color and alpha level that the lines between each grid cell will use. + * + * If this method is called with no values then the grid lines will not be rendered at all, however + * the cells themselves may still be if they have colors set. + * + * Also see the `setFillStyle` and `setAltFillStyle` methods. + * * This call can be chained. - * @param fillTop The color used to fill the top of the iso triangle. - * @param fillLeft The color used to fill in the left-facing side of the iso triangle. - * @param fillRight The color used to fill in the right-facing side of the iso triangle. + * @param fillColor The color the lines between the grid cells will be filled with, i.e. 0xff0000 for red. + * @param fillAlpha The alpha the lines between the grid cells will be filled with. You can also set the alpha of the overall Shape using its `alpha` property. Default 1. */ - setFillStyle(fillTop?: number, fillLeft?: number, fillRight?: number): this; + setOutlineStyle(fillColor?: number, fillAlpha?: number): this; /** * Clears all alpha values associated with this Game Object. @@ -28306,73 +32454,13 @@ declare namespace Phaser { */ setBlendMode(value: string | Phaser.BlendModes): this; - /** - * The native (un-scaled) width of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayWidth` property. - */ - width: number; - - /** - * The native (un-scaled) height of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayHeight` property. - */ - height: number; - - /** - * The displayed width of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. - */ - displayWidth: number; - - /** - * The displayed height of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. - */ - displayHeight: number; - - /** - * Sets the internal size of this Game Object, as used for frame or physics body creation. - * - * This will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or call the - * `setDisplaySize` method, which is the same thing as changing the scale but allows you - * to do so by giving pixel values. - * - * If you have enabled this Game Object for input, changing the size will _not_ change the - * size of the hit area. To do this you should adjust the `input.hitArea` object directly. - * @param width The width of this Game Object. - * @param height The height of this Game Object. - */ - setSize(width: number, height: number): this; - - /** - * Sets the display size of this Game Object. - * - * Calling this will adjust the scale. - * @param width The width of this Game Object. - * @param height The height of this Game Object. - */ - setDisplaySize(width: number, height: number): this; - /** * The depth of this Game Object within the Scene. * * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. @@ -28385,13 +32473,13 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. * @param value The depth of this Game Object. */ - setDepth(value: integer): this; + setDepth(value: number): this; /** * Gets the center coordinate of this Game Object, regardless of origin. @@ -28503,6 +32591,8 @@ declare namespace Phaser { * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, * including this one. * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * * To create the mask you need to pass in a reference to a renderable Game Object. * A renderable Game Object is one that uses a texture to render with, such as an * Image, Sprite, Render Texture or BitmapText. @@ -28588,6 +32678,8 @@ declare namespace Phaser { /** * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. */ defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; @@ -28596,23 +32688,109 @@ declare namespace Phaser { */ pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + /** + * Does this Game Object have any Post Pipelines set? + */ + hasPostPipeline: boolean; + + /** + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. + */ + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; + + /** + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. + */ + pipelineData: object; + /** * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + */ + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; + + /** + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; + + /** + * Sets one, or more, Post Pipelines on this Game Object. + * + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. */ - initPipeline(pipelineName?: string): boolean; + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. + * Adds an entry to the `pipelineData` object belonging to this Game Object. + * + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. */ - setPipeline(pipelineName: string): this; + setPipelineData(key: string, value?: any): this; + + /** + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. + */ + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; /** * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; + + /** + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPostPipeline(resetData?: boolean): void; + + /** + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - resetPipeline(): boolean; + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; /** * Gets the name of the WebGL Pipeline this Game Object is currently using. @@ -28728,13 +32906,13 @@ declare namespace Phaser { * * If you prefer to work in radians, see the `rotation` property instead. */ - angle: integer; + angle: number; /** * The angle of this Game Object in radians. * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. * * If you prefer to work in degrees, see the `angle` property instead. */ @@ -28749,6 +32927,12 @@ declare namespace Phaser { */ setPosition(x?: number, y?: number, z?: number, w?: number): this; + /** + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; + /** * Sets the position of this Game Object to be a random position within the confines of * the given area. @@ -28823,6 +33007,22 @@ declare namespace Phaser { */ getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. + */ + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + /** * Gets the sum total rotation of all of this Game Objects parent Containers. * @@ -28848,63 +33048,93 @@ declare namespace Phaser { } /** - * The Line Shape is a Game Object that can be added to a Scene, Group or Container. You can + * The IsoBox Shape is a Game Object that can be added to a Scene, Group or Container. You can * treat it like any other Game Object in your game, such as tweening it, scaling it, or enabling * it for input or physics. It provides a quick and easy way for you to render this shape in your * game without using a texture, while still taking advantage of being fully batched in WebGL. * - * This shape supports only stroke colors and cannot be filled. - * - * A Line Shape allows you to draw a line between two points in your game. You can control the - * stroke color and thickness of the line. In WebGL only you can also specify a different - * thickness for the start and end of the line, allowing you to render lines that taper-off. + * This shape supports only fill colors and cannot be stroked. * - * If you need to draw multiple lines in a sequence you may wish to use the Polygon Shape instead. + * An IsoBox is an 'isometric' rectangle. Each face of it has a different fill color. You can set + * the color of the top, left and right faces of the rectangle respectively. You can also choose + * which of the faces are rendered via the `showTop`, `showLeft` and `showRight` properties. * - * Be aware that as with all Game Objects the default origin is 0.5. If you need to draw a Line - * between two points and want the x1/y1 values to match the x/y values, then set the origin to 0. + * You cannot view an IsoBox from under-neath, however you can change the 'angle' by setting + * the `projection` property. */ - class Line extends Phaser.GameObjects.Shape { + class IsoBox extends Phaser.GameObjects.Shape { /** * * @param scene The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. * @param x The horizontal position of this Game Object in the world. Default 0. * @param y The vertical position of this Game Object in the world. Default 0. - * @param x1 The horizontal position of the start of the line. Default 0. - * @param y1 The vertical position of the start of the line. Default 0. - * @param x2 The horizontal position of the end of the line. Default 128. - * @param y2 The vertical position of the end of the line. Default 0. - * @param strokeColor The color the line will be drawn in, i.e. 0xff0000 for red. - * @param strokeAlpha The alpha the line will be drawn in. You can also set the alpha of the overall Shape using its `alpha` property. + * @param size The width of the iso box in pixels. The left and right faces will be exactly half this value. Default 48. + * @param height The height of the iso box. The left and right faces will be this tall. The overall height of the isobox will be this value plus half the `size` value. Default 32. + * @param fillTop The fill color of the top face of the iso box. Default 0xeeeeee. + * @param fillLeft The fill color of the left face of the iso box. Default 0x999999. + * @param fillRight The fill color of the right face of the iso box. Default 0xcccccc. */ - constructor(scene: Phaser.Scene, x?: number, y?: number, x1?: number, y1?: number, x2?: number, y2?: number, strokeColor?: number, strokeAlpha?: number); + constructor(scene: Phaser.Scene, x?: number, y?: number, size?: number, height?: number, fillTop?: number, fillLeft?: number, fillRight?: number); /** - * The width (or thickness) of the line. - * See the setLineWidth method for extra details on changing this on WebGL. + * The projection level of the iso box. Change this to change the 'angle' at which you are looking at the box. */ - lineWidth: number; + projection: number; /** - * Sets the width of the line. - * - * When using the WebGL renderer you can have different start and end widths. - * When using the Canvas renderer only the `startWidth` value is used. The `endWidth` is ignored. - * + * The color used to fill in the top of the iso box. + */ + fillTop: number; + + /** + * The color used to fill in the left-facing side of the iso box. + */ + fillLeft: number; + + /** + * The color used to fill in the right-facing side of the iso box. + */ + fillRight: number; + + /** + * Controls if the top-face of the iso box be rendered. + */ + showTop: boolean; + + /** + * Controls if the left-face of the iso box be rendered. + */ + showLeft: boolean; + + /** + * Controls if the right-face of the iso box be rendered. + */ + showRight: boolean; + + /** + * Sets the projection level of the iso box. Change this to change the 'angle' at which you are looking at the box. * This call can be chained. - * @param startWidth The start width of the line. - * @param endWidth The end width of the line. Only used in WebGL. + * @param value The value to set the projection to. */ - setLineWidth(startWidth: number, endWidth?: number): this; + setProjection(value: number): this; /** - * Sets the start and end coordinates of this Line. - * @param x1 The horizontal position of the start of the line. Default 0. - * @param y1 The vertical position of the start of the line. Default 0. - * @param x2 The horizontal position of the end of the line. Default 0. - * @param y2 The vertical position of the end of the line. Default 0. + * Sets which faces of the iso box will be rendered. + * This call can be chained. + * @param showTop Show the top-face of the iso box. Default true. + * @param showLeft Show the left-face of the iso box. Default true. + * @param showRight Show the right-face of the iso box. Default true. */ - setTo(x1?: number, y1?: number, x2?: number, y2?: number): this; + setFaces(showTop?: boolean, showLeft?: boolean, showRight?: boolean): this; + + /** + * Sets the fill colors for each face of the iso box. + * This call can be chained. + * @param fillTop The color used to fill the top of the iso box. + * @param fillLeft The color used to fill in the left-facing side of the iso box. + * @param fillRight The color used to fill in the right-facing side of the iso box. + */ + setFillStyle(fillTop?: number, fillLeft?: number, fillRight?: number): this; /** * Clears all alpha values associated with this Game Object. @@ -28974,73 +33204,13 @@ declare namespace Phaser { */ setBlendMode(value: string | Phaser.BlendModes): this; - /** - * The native (un-scaled) width of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayWidth` property. - */ - width: number; - - /** - * The native (un-scaled) height of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayHeight` property. - */ - height: number; - - /** - * The displayed width of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. - */ - displayWidth: number; - - /** - * The displayed height of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. - */ - displayHeight: number; - - /** - * Sets the internal size of this Game Object, as used for frame or physics body creation. - * - * This will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or call the - * `setDisplaySize` method, which is the same thing as changing the scale but allows you - * to do so by giving pixel values. - * - * If you have enabled this Game Object for input, changing the size will _not_ change the - * size of the hit area. To do this you should adjust the `input.hitArea` object directly. - * @param width The width of this Game Object. - * @param height The height of this Game Object. - */ - setSize(width: number, height: number): this; - - /** - * Sets the display size of this Game Object. - * - * Calling this will adjust the scale. - * @param width The width of this Game Object. - * @param height The height of this Game Object. - */ - setDisplaySize(width: number, height: number): this; - /** * The depth of this Game Object within the Scene. * * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. @@ -29053,13 +33223,13 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. * @param value The depth of this Game Object. */ - setDepth(value: integer): this; + setDepth(value: number): this; /** * Gets the center coordinate of this Game Object, regardless of origin. @@ -29171,6 +33341,8 @@ declare namespace Phaser { * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, * including this one. * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * * To create the mask you need to pass in a reference to a renderable Game Object. * A renderable Game Object is one that uses a texture to render with, such as an * Image, Sprite, Render Texture or BitmapText. @@ -29256,6 +33428,8 @@ declare namespace Phaser { /** * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. */ defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; @@ -29264,23 +33438,109 @@ declare namespace Phaser { */ pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + /** + * Does this Game Object have any Post Pipelines set? + */ + hasPostPipeline: boolean; + + /** + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. + */ + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; + + /** + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. + */ + pipelineData: object; + /** * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + */ + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; + + /** + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; + + /** + * Sets one, or more, Post Pipelines on this Game Object. + * + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; + + /** + * Adds an entry to the `pipelineData` object belonging to this Game Object. + * + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. */ - initPipeline(pipelineName?: string): boolean; + setPipelineData(key: string, value?: any): this; /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - setPipeline(pipelineName: string): this; + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; /** * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. */ - resetPipeline(): boolean; + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; + + /** + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPostPipeline(resetData?: boolean): void; + + /** + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. + */ + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; /** * Gets the name of the WebGL Pipeline this Game Object is currently using. @@ -29396,13 +33656,13 @@ declare namespace Phaser { * * If you prefer to work in radians, see the `rotation` property instead. */ - angle: integer; + angle: number; /** * The angle of this Game Object in radians. * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. * * If you prefer to work in degrees, see the `angle` property instead. */ @@ -29417,6 +33677,12 @@ declare namespace Phaser { */ setPosition(x?: number, y?: number, z?: number, w?: number): this; + /** + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; + /** * Sets the position of this Game Object to be a random position within the confines of * the given area. @@ -29491,6 +33757,22 @@ declare namespace Phaser { */ getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. + */ + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + /** * Gets the sum total rotation of all of this Game Objects parent Containers. * @@ -29516,44 +33798,107 @@ declare namespace Phaser { } /** - * The Polygon Shape is a Game Object that can be added to a Scene, Group or Container. You can + * The IsoTriangle Shape is a Game Object that can be added to a Scene, Group or Container. You can * treat it like any other Game Object in your game, such as tweening it, scaling it, or enabling * it for input or physics. It provides a quick and easy way for you to render this shape in your * game without using a texture, while still taking advantage of being fully batched in WebGL. * - * This shape supports both fill and stroke colors. - * - * The Polygon Shape is created by providing a list of points, which are then used to create an - * internal Polygon geometry object. The points can be set from a variety of formats: + * This shape supports only fill colors and cannot be stroked. * - * - A string containing paired values separated by a single space: `'40 0 40 20 100 20 100 80 40 80 40 100 0 50'` - * - An array of Point or Vector2 objects: `[new Phaser.Math.Vector2(x1, y1), ...]` - * - An array of objects with public x/y properties: `[obj1, obj2, ...]` - * - An array of paired numbers that represent point coordinates: `[x1,y1, x2,y2, ...]` - * - An array of arrays with two elements representing x/y coordinates: `[[x1, y1], [x2, y2], ...]` + * An IsoTriangle is an 'isometric' triangle. Think of it like a pyramid. Each face has a different + * fill color. You can set the color of the top, left and right faces of the triangle respectively + * You can also choose which of the faces are rendered via the `showTop`, `showLeft` and `showRight` properties. * - * By default the `x` and `y` coordinates of this Shape refer to the center of it. However, depending - * on the coordinates of the points provided, the final shape may be rendered offset from its origin. + * You cannot view an IsoTriangle from under-neath, however you can change the 'angle' by setting + * the `projection` property. The `reversed` property controls if the IsoTriangle is rendered upside + * down or not. */ - class Polygon extends Phaser.GameObjects.Shape { + class IsoTriangle extends Phaser.GameObjects.Shape { /** * * @param scene The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. * @param x The horizontal position of this Game Object in the world. Default 0. * @param y The vertical position of this Game Object in the world. Default 0. - * @param points The points that make up the polygon. - * @param fillColor The color the polygon will be filled with, i.e. 0xff0000 for red. - * @param fillAlpha The alpha the polygon will be filled with. You can also set the alpha of the overall Shape using its `alpha` property. + * @param size The width of the iso triangle in pixels. The left and right faces will be exactly half this value. Default 48. + * @param height The height of the iso triangle. The left and right faces will be this tall. The overall height of the iso triangle will be this value plus half the `size` value. Default 32. + * @param reversed Is the iso triangle upside down? Default false. + * @param fillTop The fill color of the top face of the iso triangle. Default 0xeeeeee. + * @param fillLeft The fill color of the left face of the iso triangle. Default 0x999999. + * @param fillRight The fill color of the right face of the iso triangle. Default 0xcccccc. */ - constructor(scene: Phaser.Scene, x?: number, y?: number, points?: any, fillColor?: number, fillAlpha?: number); + constructor(scene: Phaser.Scene, x?: number, y?: number, size?: number, height?: number, reversed?: boolean, fillTop?: number, fillLeft?: number, fillRight?: number); /** - * Smooths the polygon over the number of iterations specified. - * The base polygon data will be updated and replaced with the smoothed values. + * The projection level of the iso box. Change this to change the 'angle' at which you are looking at the box. + */ + projection: number; + + /** + * The color used to fill in the top of the iso triangle. This is only used if the triangle is reversed. + */ + fillTop: number; + + /** + * The color used to fill in the left-facing side of the iso triangle. + */ + fillLeft: number; + + /** + * The color used to fill in the right-facing side of the iso triangle. + */ + fillRight: number; + + /** + * Controls if the top-face of the iso triangle be rendered. + */ + showTop: boolean; + + /** + * Controls if the left-face of the iso triangle be rendered. + */ + showLeft: boolean; + + /** + * Controls if the right-face of the iso triangle be rendered. + */ + showRight: boolean; + + /** + * Sets if the iso triangle will be rendered upside down or not. + */ + isReversed: boolean; + + /** + * Sets the projection level of the iso triangle. Change this to change the 'angle' at which you are looking at the pyramid. * This call can be chained. - * @param iterations The number of times to apply the polygon smoothing. Default 1. + * @param value The value to set the projection to. */ - smooth(iterations?: integer): this; + setProjection(value: number): this; + + /** + * Sets if the iso triangle will be rendered upside down or not. + * This call can be chained. + * @param reversed Sets if the iso triangle will be rendered upside down or not. + */ + setReversed(reversed: boolean): this; + + /** + * Sets which faces of the iso triangle will be rendered. + * This call can be chained. + * @param showTop Show the top-face of the iso triangle (only if `reversed` is true) Default true. + * @param showLeft Show the left-face of the iso triangle. Default true. + * @param showRight Show the right-face of the iso triangle. Default true. + */ + setFaces(showTop?: boolean, showLeft?: boolean, showRight?: boolean): this; + + /** + * Sets the fill colors for each face of the iso triangle. + * This call can be chained. + * @param fillTop The color used to fill the top of the iso triangle. + * @param fillLeft The color used to fill in the left-facing side of the iso triangle. + * @param fillRight The color used to fill in the right-facing side of the iso triangle. + */ + setFillStyle(fillTop?: number, fillLeft?: number, fillRight?: number): this; /** * Clears all alpha values associated with this Game Object. @@ -29623,73 +33968,13 @@ declare namespace Phaser { */ setBlendMode(value: string | Phaser.BlendModes): this; - /** - * The native (un-scaled) width of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayWidth` property. - */ - width: number; - - /** - * The native (un-scaled) height of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayHeight` property. - */ - height: number; - - /** - * The displayed width of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. - */ - displayWidth: number; - - /** - * The displayed height of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. - */ - displayHeight: number; - - /** - * Sets the internal size of this Game Object, as used for frame or physics body creation. - * - * This will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or call the - * `setDisplaySize` method, which is the same thing as changing the scale but allows you - * to do so by giving pixel values. - * - * If you have enabled this Game Object for input, changing the size will _not_ change the - * size of the hit area. To do this you should adjust the `input.hitArea` object directly. - * @param width The width of this Game Object. - * @param height The height of this Game Object. - */ - setSize(width: number, height: number): this; - - /** - * Sets the display size of this Game Object. - * - * Calling this will adjust the scale. - * @param width The width of this Game Object. - * @param height The height of this Game Object. - */ - setDisplaySize(width: number, height: number): this; - /** * The depth of this Game Object within the Scene. * * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. @@ -29702,13 +33987,13 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. * @param value The depth of this Game Object. */ - setDepth(value: integer): this; + setDepth(value: number): this; /** * Gets the center coordinate of this Game Object, regardless of origin. @@ -29820,6 +34105,8 @@ declare namespace Phaser { * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, * including this one. * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * * To create the mask you need to pass in a reference to a renderable Game Object. * A renderable Game Object is one that uses a texture to render with, such as an * Image, Sprite, Render Texture or BitmapText. @@ -29905,6 +34192,8 @@ declare namespace Phaser { /** * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. */ defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; @@ -29913,23 +34202,109 @@ declare namespace Phaser { */ pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + /** + * Does this Game Object have any Post Pipelines set? + */ + hasPostPipeline: boolean; + + /** + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. + */ + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; + + /** + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. + */ + pipelineData: object; + /** * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. */ - initPipeline(pipelineName?: string): boolean; + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; + + /** + * Sets one, or more, Post Pipelines on this Game Object. + * + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; + + /** + * Adds an entry to the `pipelineData` object belonging to this Game Object. + * + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. */ - setPipeline(pipelineName: string): this; + setPipelineData(key: string, value?: any): this; + + /** + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. + */ + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; /** * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; + + /** + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPostPipeline(resetData?: boolean): void; + + /** + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - resetPipeline(): boolean; + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; /** * Gets the name of the WebGL Pipeline this Game Object is currently using. @@ -30045,13 +34420,13 @@ declare namespace Phaser { * * If you prefer to work in radians, see the `rotation` property instead. */ - angle: integer; + angle: number; /** * The angle of this Game Object in radians. * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. * * If you prefer to work in degrees, see the `angle` property instead. */ @@ -30066,6 +34441,12 @@ declare namespace Phaser { */ setPosition(x?: number, y?: number, z?: number, w?: number): this; + /** + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; + /** * Sets the position of this Game Object to be a random position within the confines of * the given area. @@ -30140,6 +34521,22 @@ declare namespace Phaser { */ getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. + */ + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + /** * Gets the sum total rotation of all of this Game Objects parent Containers. * @@ -30165,27 +34562,63 @@ declare namespace Phaser { } /** - * The Rectangle Shape is a Game Object that can be added to a Scene, Group or Container. You can + * The Line Shape is a Game Object that can be added to a Scene, Group or Container. You can * treat it like any other Game Object in your game, such as tweening it, scaling it, or enabling * it for input or physics. It provides a quick and easy way for you to render this shape in your * game without using a texture, while still taking advantage of being fully batched in WebGL. * - * This shape supports both fill and stroke colors. + * This shape supports only stroke colors and cannot be filled. * - * You can change the size of the rectangle by changing the `width` and `height` properties. + * A Line Shape allows you to draw a line between two points in your game. You can control the + * stroke color and thickness of the line. In WebGL only you can also specify a different + * thickness for the start and end of the line, allowing you to render lines that taper-off. + * + * If you need to draw multiple lines in a sequence you may wish to use the Polygon Shape instead. + * + * Be aware that as with all Game Objects the default origin is 0.5. If you need to draw a Line + * between two points and want the x1/y1 values to match the x/y values, then set the origin to 0. */ - class Rectangle extends Phaser.GameObjects.Shape { + class Line extends Phaser.GameObjects.Shape { /** * * @param scene The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. - * @param x The horizontal position of this Game Object in the world. - * @param y The vertical position of this Game Object in the world. - * @param width The width of the rectangle. Default 128. - * @param height The height of the rectangle. Default 128. - * @param fillColor The color the rectangle will be filled with, i.e. 0xff0000 for red. - * @param fillAlpha The alpha the rectangle will be filled with. You can also set the alpha of the overall Shape using its `alpha` property. + * @param x The horizontal position of this Game Object in the world. Default 0. + * @param y The vertical position of this Game Object in the world. Default 0. + * @param x1 The horizontal position of the start of the line. Default 0. + * @param y1 The vertical position of the start of the line. Default 0. + * @param x2 The horizontal position of the end of the line. Default 128. + * @param y2 The vertical position of the end of the line. Default 0. + * @param strokeColor The color the line will be drawn in, i.e. 0xff0000 for red. + * @param strokeAlpha The alpha the line will be drawn in. You can also set the alpha of the overall Shape using its `alpha` property. */ - constructor(scene: Phaser.Scene, x: number, y: number, width?: number, height?: number, fillColor?: number, fillAlpha?: number); + constructor(scene: Phaser.Scene, x?: number, y?: number, x1?: number, y1?: number, x2?: number, y2?: number, strokeColor?: number, strokeAlpha?: number); + + /** + * The width (or thickness) of the line. + * See the setLineWidth method for extra details on changing this on WebGL. + */ + lineWidth: number; + + /** + * Sets the width of the line. + * + * When using the WebGL renderer you can have different start and end widths. + * When using the Canvas renderer only the `startWidth` value is used. The `endWidth` is ignored. + * + * This call can be chained. + * @param startWidth The start width of the line. + * @param endWidth The end width of the line. Only used in WebGL. + */ + setLineWidth(startWidth: number, endWidth?: number): this; + + /** + * Sets the start and end coordinates of this Line. + * @param x1 The horizontal position of the start of the line. Default 0. + * @param y1 The vertical position of the start of the line. Default 0. + * @param x2 The horizontal position of the end of the line. Default 0. + * @param y2 The vertical position of the end of the line. Default 0. + */ + setTo(x1?: number, y1?: number, x2?: number, y2?: number): this; /** * Clears all alpha values associated with this Game Object. @@ -30255,73 +34688,13 @@ declare namespace Phaser { */ setBlendMode(value: string | Phaser.BlendModes): this; - /** - * The native (un-scaled) width of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayWidth` property. - */ - width: number; - - /** - * The native (un-scaled) height of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayHeight` property. - */ - height: number; - - /** - * The displayed width of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. - */ - displayWidth: number; - - /** - * The displayed height of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. - */ - displayHeight: number; - - /** - * Sets the internal size of this Game Object, as used for frame or physics body creation. - * - * This will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or call the - * `setDisplaySize` method, which is the same thing as changing the scale but allows you - * to do so by giving pixel values. - * - * If you have enabled this Game Object for input, changing the size will _not_ change the - * size of the hit area. To do this you should adjust the `input.hitArea` object directly. - * @param width The width of this Game Object. - * @param height The height of this Game Object. - */ - setSize(width: number, height: number): this; - - /** - * Sets the display size of this Game Object. - * - * Calling this will adjust the scale. - * @param width The width of this Game Object. - * @param height The height of this Game Object. - */ - setDisplaySize(width: number, height: number): this; - /** * The depth of this Game Object within the Scene. * * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. @@ -30334,13 +34707,13 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. * @param value The depth of this Game Object. */ - setDepth(value: integer): this; + setDepth(value: number): this; /** * Gets the center coordinate of this Game Object, regardless of origin. @@ -30452,6 +34825,8 @@ declare namespace Phaser { * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, * including this one. * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * * To create the mask you need to pass in a reference to a renderable Game Object. * A renderable Game Object is one that uses a texture to render with, such as an * Image, Sprite, Render Texture or BitmapText. @@ -30537,6 +34912,8 @@ declare namespace Phaser { /** * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. */ defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; @@ -30545,23 +34922,109 @@ declare namespace Phaser { */ pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + /** + * Does this Game Object have any Post Pipelines set? + */ + hasPostPipeline: boolean; + + /** + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. + */ + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; + + /** + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. + */ + pipelineData: object; + /** * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + */ + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; + + /** + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; + + /** + * Sets one, or more, Post Pipelines on this Game Object. + * + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. */ - initPipeline(pipelineName?: string): boolean; + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. + * Adds an entry to the `pipelineData` object belonging to this Game Object. + * + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. + */ + setPipelineData(key: string, value?: any): this; + + /** + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - setPipeline(pipelineName: string): this; + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; /** * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. */ - resetPipeline(): boolean; + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; + + /** + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPostPipeline(resetData?: boolean): void; + + /** + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. + */ + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; /** * Gets the name of the WebGL Pipeline this Game Object is currently using. @@ -30677,13 +35140,13 @@ declare namespace Phaser { * * If you prefer to work in radians, see the `rotation` property instead. */ - angle: integer; + angle: number; /** * The angle of this Game Object in radians. * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. * * If you prefer to work in degrees, see the `angle` property instead. */ @@ -30698,6 +35161,12 @@ declare namespace Phaser { */ setPosition(x?: number, y?: number, z?: number, w?: number): this; + /** + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; + /** * Sets the position of this Game Object to be a random position within the confines of * the given area. @@ -30772,6 +35241,22 @@ declare namespace Phaser { */ getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. + */ + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + /** * Gets the sum total rotation of all of this Game Objects parent Containers. * @@ -30797,117 +35282,44 @@ declare namespace Phaser { } /** - * The Shape Game Object is a base class for the various different shapes, such as the Arc, Star or Polygon. - * You cannot add a Shape directly to your Scene, it is meant as a base for your own custom Shape classes. + * The Polygon Shape is a Game Object that can be added to a Scene, Group or Container. You can + * treat it like any other Game Object in your game, such as tweening it, scaling it, or enabling + * it for input or physics. It provides a quick and easy way for you to render this shape in your + * game without using a texture, while still taking advantage of being fully batched in WebGL. + * + * This shape supports both fill and stroke colors. + * + * The Polygon Shape is created by providing a list of points, which are then used to create an + * internal Polygon geometry object. The points can be set from a variety of formats: + * + * - A string containing paired values separated by a single space: `'40 0 40 20 100 20 100 80 40 80 40 100 0 50'` + * - An array of Point or Vector2 objects: `[new Phaser.Math.Vector2(x1, y1), ...]` + * - An array of objects with public x/y properties: `[obj1, obj2, ...]` + * - An array of paired numbers that represent point coordinates: `[x1,y1, x2,y2, ...]` + * - An array of arrays with two elements representing x/y coordinates: `[[x1, y1], [x2, y2], ...]` + * + * By default the `x` and `y` coordinates of this Shape refer to the center of it. However, depending + * on the coordinates of the points provided, the final shape may be rendered offset from its origin. */ - class Shape extends Phaser.GameObjects.GameObject implements Phaser.GameObjects.Components.AlphaSingle, Phaser.GameObjects.Components.BlendMode, Phaser.GameObjects.Components.ComputedSize, Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.GetBounds, Phaser.GameObjects.Components.Mask, Phaser.GameObjects.Components.Origin, Phaser.GameObjects.Components.Pipeline, Phaser.GameObjects.Components.ScrollFactor, Phaser.GameObjects.Components.Transform, Phaser.GameObjects.Components.Visible { + class Polygon extends Phaser.GameObjects.Shape { /** * * @param scene The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. - * @param type The internal type of the Shape. - * @param data The data of the source shape geometry, if any. - */ - constructor(scene: Phaser.Scene, type?: string, data?: any); - - /** - * The source Shape data. Typically a geometry object. - * You should not manipulate this directly. - */ - readonly data: any; - - /** - * Holds the polygon path data for filled rendering. - */ - readonly pathData: number[]; - - /** - * Holds the earcut polygon path index data for filled rendering. - */ - readonly pathIndexes: integer[]; - - /** - * The fill color used by this Shape. - */ - fillColor: number; - - /** - * The fill alpha value used by this Shape. - */ - fillAlpha: number; - - /** - * The stroke color used by this Shape. - */ - strokeColor: number; - - /** - * The stroke alpha value used by this Shape. - */ - strokeAlpha: number; - - /** - * The stroke line width used by this Shape. - */ - lineWidth: number; - - /** - * Controls if this Shape is filled or not. - * Note that some Shapes do not support being filled (such as Line shapes) - */ - isFilled: boolean; - - /** - * Controls if this Shape is stroked or not. - * Note that some Shapes do not support being stroked (such as Iso Box shapes) - */ - isStroked: boolean; - - /** - * Controls if this Shape path is closed during rendering when stroked. - * Note that some Shapes are always closed when stroked (such as Ellipse shapes) - */ - closePath: boolean; - - /** - * Sets the fill color and alpha for this Shape. - * - * If you wish for the Shape to not be filled then call this method with no arguments, or just set `isFilled` to `false`. - * - * Note that some Shapes do not support fill colors, such as the Line shape. - * - * This call can be chained. - * @param color The color used to fill this shape. If not provided the Shape will not be filled. - * @param alpha The alpha value used when filling this shape, if a fill color is given. Default 1. - */ - setFillStyle(color?: number, alpha?: number): this; - - /** - * Sets the stroke color and alpha for this Shape. - * - * If you wish for the Shape to not be stroked then call this method with no arguments, or just set `isStroked` to `false`. - * - * Note that some Shapes do not support being stroked, such as the Iso Box shape. - * - * This call can be chained. - * @param lineWidth The width of line to stroke with. If not provided or undefined the Shape will not be stroked. - * @param color The color used to stroke this shape. If not provided the Shape will not be stroked. - * @param alpha The alpha value used when stroking this shape, if a stroke color is given. Default 1. + * @param x The horizontal position of this Game Object in the world. Default 0. + * @param y The vertical position of this Game Object in the world. Default 0. + * @param points The points that make up the polygon. + * @param fillColor The color the polygon will be filled with, i.e. 0xff0000 for red. + * @param fillAlpha The alpha the polygon will be filled with. You can also set the alpha of the overall Shape using its `alpha` property. */ - setStrokeStyle(lineWidth?: number, color?: number, alpha?: number): this; + constructor(scene: Phaser.Scene, x?: number, y?: number, points?: any, fillColor?: number, fillAlpha?: number); /** - * Sets if this Shape path is closed during rendering when stroked. - * Note that some Shapes are always closed when stroked (such as Ellipse shapes) - * + * Smooths the polygon over the number of iterations specified. + * The base polygon data will be updated and replaced with the smoothed values. * This call can be chained. - * @param value Set to `true` if the Shape should be closed when stroked, otherwise `false`. - */ - setClosePath(value: boolean): this; - - /** - * Internal destroy handler, called as part of the destroy process. + * @param iterations The number of times to apply the polygon smoothing. Default 1. */ - protected preDestroy(): void; + smooth(iterations?: number): this; /** * Clears all alpha values associated with this Game Object. @@ -30977,73 +35389,13 @@ declare namespace Phaser { */ setBlendMode(value: string | Phaser.BlendModes): this; - /** - * The native (un-scaled) width of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayWidth` property. - */ - width: number; - - /** - * The native (un-scaled) height of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayHeight` property. - */ - height: number; - - /** - * The displayed width of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. - */ - displayWidth: number; - - /** - * The displayed height of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. - */ - displayHeight: number; - - /** - * Sets the internal size of this Game Object, as used for frame or physics body creation. - * - * This will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or call the - * `setDisplaySize` method, which is the same thing as changing the scale but allows you - * to do so by giving pixel values. - * - * If you have enabled this Game Object for input, changing the size will _not_ change the - * size of the hit area. To do this you should adjust the `input.hitArea` object directly. - * @param width The width of this Game Object. - * @param height The height of this Game Object. - */ - setSize(width: number, height: number): this; - - /** - * Sets the display size of this Game Object. - * - * Calling this will adjust the scale. - * @param width The width of this Game Object. - * @param height The height of this Game Object. - */ - setDisplaySize(width: number, height: number): this; - /** * The depth of this Game Object within the Scene. * * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. @@ -31056,13 +35408,13 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. * @param value The depth of this Game Object. */ - setDepth(value: integer): this; + setDepth(value: number): this; /** * Gets the center coordinate of this Game Object, regardless of origin. @@ -31174,6 +35526,8 @@ declare namespace Phaser { * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, * including this one. * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * * To create the mask you need to pass in a reference to a renderable Game Object. * A renderable Game Object is one that uses a texture to render with, such as an * Image, Sprite, Render Texture or BitmapText. @@ -31259,6 +35613,8 @@ declare namespace Phaser { /** * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. */ defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; @@ -31267,23 +35623,109 @@ declare namespace Phaser { */ pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + /** + * Does this Game Object have any Post Pipelines set? + */ + hasPostPipeline: boolean; + + /** + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. + */ + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; + + /** + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. + */ + pipelineData: object; + /** * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + */ + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; + + /** + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; + + /** + * Sets one, or more, Post Pipelines on this Game Object. + * + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; + + /** + * Adds an entry to the `pipelineData` object belonging to this Game Object. + * + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. */ - initPipeline(pipelineName?: string): boolean; + setPipelineData(key: string, value?: any): this; /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - setPipeline(pipelineName: string): this; + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; /** * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; + + /** + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPostPipeline(resetData?: boolean): void; + + /** + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - resetPipeline(): boolean; + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; /** * Gets the name of the WebGL Pipeline this Game Object is currently using. @@ -31399,13 +35841,13 @@ declare namespace Phaser { * * If you prefer to work in radians, see the `rotation` property instead. */ - angle: integer; + angle: number; /** * The angle of this Game Object in radians. * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. * * If you prefer to work in degrees, see the `angle` property instead. */ @@ -31420,6 +35862,12 @@ declare namespace Phaser { */ setPosition(x?: number, y?: number, z?: number, w?: number): this; + /** + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; + /** * Sets the position of this Game Object to be a random position within the confines of * the given area. @@ -31494,6 +35942,22 @@ declare namespace Phaser { */ getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. + */ + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + /** * Gets the sum total rotation of all of this Game Objects parent Containers. * @@ -31519,70 +35983,42 @@ declare namespace Phaser { } /** - * The Star Shape is a Game Object that can be added to a Scene, Group or Container. You can + * The Rectangle Shape is a Game Object that can be added to a Scene, Group or Container. You can * treat it like any other Game Object in your game, such as tweening it, scaling it, or enabling * it for input or physics. It provides a quick and easy way for you to render this shape in your * game without using a texture, while still taking advantage of being fully batched in WebGL. * * This shape supports both fill and stroke colors. * - * As the name implies, the Star shape will display a star in your game. You can control several - * aspects of it including the number of points that constitute the star. The default is 5. If - * you change it to 4 it will render as a diamond. If you increase them, you'll get a more spiky - * star shape. - * - * You can also control the inner and outer radius, which is how 'long' each point of the star is. - * Modify these values to create more interesting shapes. + * You can change the size of the rectangle by changing the `width` and `height` properties. */ - class Star extends Phaser.GameObjects.Shape { + class Rectangle extends Phaser.GameObjects.Shape { /** * * @param scene The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. - * @param x The horizontal position of this Game Object in the world. Default 0. - * @param y The vertical position of this Game Object in the world. Default 0. - * @param points The number of points on the star. Default 5. - * @param innerRadius The inner radius of the star. Default 32. - * @param outerRadius The outer radius of the star. Default 64. - * @param fillColor The color the star will be filled with, i.e. 0xff0000 for red. - * @param fillAlpha The alpha the star will be filled with. You can also set the alpha of the overall Shape using its `alpha` property. - */ - constructor(scene: Phaser.Scene, x?: number, y?: number, points?: number, innerRadius?: number, outerRadius?: number, fillColor?: number, fillAlpha?: number); - - /** - * Sets the number of points that make up the Star shape. - * This call can be chained. - * @param value The amount of points the Star will have. - */ - setPoints(value: integer): this; - - /** - * Sets the inner radius of the Star shape. - * This call can be chained. - * @param value The amount to set the inner radius to. - */ - setInnerRadius(value: number): this; - - /** - * Sets the outer radius of the Star shape. - * This call can be chained. - * @param value The amount to set the outer radius to. - */ - setOuterRadius(value: number): this; - - /** - * The number of points that make up the Star shape. - */ - points: integer; - - /** - * The inner radius of the Star shape. + * @param x The horizontal position of this Game Object in the world. + * @param y The vertical position of this Game Object in the world. + * @param width The width of the rectangle. Default 128. + * @param height The height of the rectangle. Default 128. + * @param fillColor The color the rectangle will be filled with, i.e. 0xff0000 for red. + * @param fillAlpha The alpha the rectangle will be filled with. You can also set the alpha of the overall Shape using its `alpha` property. */ - innerRadius: number; + constructor(scene: Phaser.Scene, x: number, y: number, width?: number, height?: number, fillColor?: number, fillAlpha?: number); /** - * The outer radius of the Star shape. + * Sets the internal size of this Game Object, as used for frame or physics body creation. + * + * This will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or call the + * `setDisplaySize` method, which is the same thing as changing the scale but allows you + * to do so by giving pixel values. + * + * If you have enabled this Game Object for input, changing the size will _not_ change the + * size of the hit area. To do this you should adjust the `input.hitArea` object directly. + * @param width The width of this Game Object. + * @param height The height of this Game Object. */ - outerRadius: number; + setSize(width: number, height: number): this; /** * Clears all alpha values associated with this Game Object. @@ -31652,73 +36088,13 @@ declare namespace Phaser { */ setBlendMode(value: string | Phaser.BlendModes): this; - /** - * The native (un-scaled) width of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayWidth` property. - */ - width: number; - - /** - * The native (un-scaled) height of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayHeight` property. - */ - height: number; - - /** - * The displayed width of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. - */ - displayWidth: number; - - /** - * The displayed height of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. - */ - displayHeight: number; - - /** - * Sets the internal size of this Game Object, as used for frame or physics body creation. - * - * This will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or call the - * `setDisplaySize` method, which is the same thing as changing the scale but allows you - * to do so by giving pixel values. - * - * If you have enabled this Game Object for input, changing the size will _not_ change the - * size of the hit area. To do this you should adjust the `input.hitArea` object directly. - * @param width The width of this Game Object. - * @param height The height of this Game Object. - */ - setSize(width: number, height: number): this; - - /** - * Sets the display size of this Game Object. - * - * Calling this will adjust the scale. - * @param width The width of this Game Object. - * @param height The height of this Game Object. - */ - setDisplaySize(width: number, height: number): this; - /** * The depth of this Game Object within the Scene. * * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. @@ -31731,13 +36107,13 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. * @param value The depth of this Game Object. */ - setDepth(value: integer): this; + setDepth(value: number): this; /** * Gets the center coordinate of this Game Object, regardless of origin. @@ -31849,6 +36225,8 @@ declare namespace Phaser { * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, * including this one. * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * * To create the mask you need to pass in a reference to a renderable Game Object. * A renderable Game Object is one that uses a texture to render with, such as an * Image, Sprite, Render Texture or BitmapText. @@ -31934,6 +36312,8 @@ declare namespace Phaser { /** * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. */ defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; @@ -31942,23 +36322,109 @@ declare namespace Phaser { */ pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + /** + * Does this Game Object have any Post Pipelines set? + */ + hasPostPipeline: boolean; + + /** + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. + */ + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; + + /** + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. + */ + pipelineData: object; + /** * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. */ - initPipeline(pipelineName?: string): boolean; + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. */ - setPipeline(pipelineName: string): this; + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; + + /** + * Sets one, or more, Post Pipelines on this Game Object. + * + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; + + /** + * Adds an entry to the `pipelineData` object belonging to this Game Object. + * + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. + */ + setPipelineData(key: string, value?: any): this; + + /** + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. + */ + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; /** * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; + + /** + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPostPipeline(resetData?: boolean): void; + + /** + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - resetPipeline(): boolean; + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; /** * Gets the name of the WebGL Pipeline this Game Object is currently using. @@ -32074,13 +36540,13 @@ declare namespace Phaser { * * If you prefer to work in radians, see the `rotation` property instead. */ - angle: integer; + angle: number; /** * The angle of this Game Object in radians. * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. * * If you prefer to work in degrees, see the `angle` property instead. */ @@ -32095,6 +36561,12 @@ declare namespace Phaser { */ setPosition(x?: number, y?: number, z?: number, w?: number): this; + /** + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; + /** * Sets the position of this Game Object to be a random position within the confines of * the given area. @@ -32169,6 +36641,22 @@ declare namespace Phaser { */ getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. + */ + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + /** * Gets the sum total rotation of all of this Game Objects parent Containers. * @@ -32194,44 +36682,153 @@ declare namespace Phaser { } /** - * The Triangle Shape is a Game Object that can be added to a Scene, Group or Container. You can - * treat it like any other Game Object in your game, such as tweening it, scaling it, or enabling - * it for input or physics. It provides a quick and easy way for you to render this shape in your - * game without using a texture, while still taking advantage of being fully batched in WebGL. - * - * This shape supports both fill and stroke colors. - * - * The Triangle consists of 3 lines, joining up to form a triangular shape. You can control the - * position of each point of these lines. The triangle is always closed and cannot have an open - * face. If you require that, consider using a Polygon instead. + * The Shape Game Object is a base class for the various different shapes, such as the Arc, Star or Polygon. + * You cannot add a Shape directly to your Scene, it is meant as a base for your own custom Shape classes. */ - class Triangle extends Phaser.GameObjects.Shape { + class Shape extends Phaser.GameObjects.GameObject implements Phaser.GameObjects.Components.AlphaSingle, Phaser.GameObjects.Components.BlendMode, Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.GetBounds, Phaser.GameObjects.Components.Mask, Phaser.GameObjects.Components.Origin, Phaser.GameObjects.Components.Pipeline, Phaser.GameObjects.Components.ScrollFactor, Phaser.GameObjects.Components.Transform, Phaser.GameObjects.Components.Visible { /** * * @param scene The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. - * @param x The horizontal position of this Game Object in the world. Default 0. - * @param y The vertical position of this Game Object in the world. Default 0. - * @param x1 The horizontal position of the first point in the triangle. Default 0. - * @param y1 The vertical position of the first point in the triangle. Default 128. - * @param x2 The horizontal position of the second point in the triangle. Default 64. - * @param y2 The vertical position of the second point in the triangle. Default 0. - * @param x3 The horizontal position of the third point in the triangle. Default 128. - * @param y3 The vertical position of the third point in the triangle. Default 128. - * @param fillColor The color the triangle will be filled with, i.e. 0xff0000 for red. - * @param fillAlpha The alpha the triangle will be filled with. You can also set the alpha of the overall Shape using its `alpha` property. + * @param type The internal type of the Shape. + * @param data The data of the source shape geometry, if any. */ - constructor(scene: Phaser.Scene, x?: number, y?: number, x1?: number, y1?: number, x2?: number, y2?: number, x3?: number, y3?: number, fillColor?: number, fillAlpha?: number); + constructor(scene: Phaser.Scene, type?: string, data?: any); /** - * Sets the data for the lines that make up this Triangle shape. - * @param x1 The horizontal position of the first point in the triangle. Default 0. - * @param y1 The vertical position of the first point in the triangle. Default 0. - * @param x2 The horizontal position of the second point in the triangle. Default 0. - * @param y2 The vertical position of the second point in the triangle. Default 0. - * @param x3 The horizontal position of the third point in the triangle. Default 0. - * @param y3 The vertical position of the third point in the triangle. Default 0. + * The source Shape data. Typically a geometry object. + * You should not manipulate this directly. */ - setTo(x1?: number, y1?: number, x2?: number, y2?: number, x3?: number, y3?: number): this; + readonly geom: any; + + /** + * Holds the polygon path data for filled rendering. + */ + readonly pathData: number[]; + + /** + * Holds the earcut polygon path index data for filled rendering. + */ + readonly pathIndexes: number[]; + + /** + * The fill color used by this Shape. + */ + fillColor: number; + + /** + * The fill alpha value used by this Shape. + */ + fillAlpha: number; + + /** + * The stroke color used by this Shape. + */ + strokeColor: number; + + /** + * The stroke alpha value used by this Shape. + */ + strokeAlpha: number; + + /** + * The stroke line width used by this Shape. + */ + lineWidth: number; + + /** + * Controls if this Shape is filled or not. + * Note that some Shapes do not support being filled (such as Line shapes) + */ + isFilled: boolean; + + /** + * Controls if this Shape is stroked or not. + * Note that some Shapes do not support being stroked (such as Iso Box shapes) + */ + isStroked: boolean; + + /** + * Controls if this Shape path is closed during rendering when stroked. + * Note that some Shapes are always closed when stroked (such as Ellipse shapes) + */ + closePath: boolean; + + /** + * The native (un-scaled) width of this Game Object. + * + * Changing this value will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or use + * the `displayWidth` property. + */ + width: number; + + /** + * The native (un-scaled) height of this Game Object. + * + * Changing this value will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or use + * the `displayHeight` property. + */ + height: number; + + /** + * Sets the fill color and alpha for this Shape. + * + * If you wish for the Shape to not be filled then call this method with no arguments, or just set `isFilled` to `false`. + * + * Note that some Shapes do not support fill colors, such as the Line shape. + * + * This call can be chained. + * @param color The color used to fill this shape. If not provided the Shape will not be filled. + * @param alpha The alpha value used when filling this shape, if a fill color is given. Default 1. + */ + setFillStyle(color?: number, alpha?: number): this; + + /** + * Sets the stroke color and alpha for this Shape. + * + * If you wish for the Shape to not be stroked then call this method with no arguments, or just set `isStroked` to `false`. + * + * Note that some Shapes do not support being stroked, such as the Iso Box shape. + * + * This call can be chained. + * @param lineWidth The width of line to stroke with. If not provided or undefined the Shape will not be stroked. + * @param color The color used to stroke this shape. If not provided the Shape will not be stroked. + * @param alpha The alpha value used when stroking this shape, if a stroke color is given. Default 1. + */ + setStrokeStyle(lineWidth?: number, color?: number, alpha?: number): this; + + /** + * Sets if this Shape path is closed during rendering when stroked. + * Note that some Shapes are always closed when stroked (such as Ellipse shapes) + * + * This call can be chained. + * @param value Set to `true` if the Shape should be closed when stroked, otherwise `false`. + */ + setClosePath(value: boolean): this; + + /** + * Internal destroy handler, called as part of the destroy process. + */ + protected preDestroy(): void; + + /** + * The displayed width of this Game Object. + * + * This value takes into account the scale factor. + * + * Setting this value will adjust the Game Object's scale property. + */ + displayWidth: number; + + /** + * The displayed height of this Game Object. + * + * This value takes into account the scale factor. + * + * Setting this value will adjust the Game Object's scale property. + */ + displayHeight: number; /** * Clears all alpha values associated with this Game Object. @@ -32301,73 +36898,13 @@ declare namespace Phaser { */ setBlendMode(value: string | Phaser.BlendModes): this; - /** - * The native (un-scaled) width of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayWidth` property. - */ - width: number; - - /** - * The native (un-scaled) height of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayHeight` property. - */ - height: number; - - /** - * The displayed width of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. - */ - displayWidth: number; - - /** - * The displayed height of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. - */ - displayHeight: number; - - /** - * Sets the internal size of this Game Object, as used for frame or physics body creation. - * - * This will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or call the - * `setDisplaySize` method, which is the same thing as changing the scale but allows you - * to do so by giving pixel values. - * - * If you have enabled this Game Object for input, changing the size will _not_ change the - * size of the hit area. To do this you should adjust the `input.hitArea` object directly. - * @param width The width of this Game Object. - * @param height The height of this Game Object. - */ - setSize(width: number, height: number): this; - - /** - * Sets the display size of this Game Object. - * - * Calling this will adjust the scale. - * @param width The width of this Game Object. - * @param height The height of this Game Object. - */ - setDisplaySize(width: number, height: number): this; - /** * The depth of this Game Object within the Scene. * * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. @@ -32380,13 +36917,13 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. * @param value The depth of this Game Object. */ - setDepth(value: integer): this; + setDepth(value: number): this; /** * Gets the center coordinate of this Game Object, regardless of origin. @@ -32498,6 +37035,8 @@ declare namespace Phaser { * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, * including this one. * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * * To create the mask you need to pass in a reference to a renderable Game Object. * A renderable Game Object is one that uses a texture to render with, such as an * Image, Sprite, Render Texture or BitmapText. @@ -32583,6 +37122,8 @@ declare namespace Phaser { /** * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. */ defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; @@ -32591,23 +37132,109 @@ declare namespace Phaser { */ pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + /** + * Does this Game Object have any Post Pipelines set? + */ + hasPostPipeline: boolean; + + /** + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. + */ + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; + + /** + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. + */ + pipelineData: object; + /** * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + */ + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; + + /** + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; + + /** + * Sets one, or more, Post Pipelines on this Game Object. + * + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. */ - initPipeline(pipelineName?: string): boolean; + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. + * Adds an entry to the `pipelineData` object belonging to this Game Object. + * + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. */ - setPipeline(pipelineName: string): this; + setPipelineData(key: string, value?: any): this; + + /** + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. + */ + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; /** * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; + + /** + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPostPipeline(resetData?: boolean): void; + + /** + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - resetPipeline(): boolean; + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; /** * Gets the name of the WebGL Pipeline this Game Object is currently using. @@ -32723,13 +37350,13 @@ declare namespace Phaser { * * If you prefer to work in radians, see the `rotation` property instead. */ - angle: integer; + angle: number; /** * The angle of this Game Object in radians. * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. * * If you prefer to work in degrees, see the `angle` property instead. */ @@ -32744,6 +37371,12 @@ declare namespace Phaser { */ setPosition(x?: number, y?: number, z?: number, w?: number): this; + /** + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; + /** * Sets the position of this Game Object to be a random position within the confines of * the given area. @@ -32818,6 +37451,22 @@ declare namespace Phaser { */ getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. + */ + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + /** * Gets the sum total rotation of all of this Game Objects parent Containers. * @@ -32843,51 +37492,70 @@ declare namespace Phaser { } /** - * A Sprite Game Object. + * The Star Shape is a Game Object that can be added to a Scene, Group or Container. You can + * treat it like any other Game Object in your game, such as tweening it, scaling it, or enabling + * it for input or physics. It provides a quick and easy way for you to render this shape in your + * game without using a texture, while still taking advantage of being fully batched in WebGL. * - * A Sprite Game Object is used for the display of both static and animated images in your game. - * Sprites can have input events and physics bodies. They can also be tweened, tinted, scrolled - * and animated. + * This shape supports both fill and stroke colors. * - * The main difference between a Sprite and an Image Game Object is that you cannot animate Images. - * As such, Sprites take a fraction longer to process and have a larger API footprint due to the Animation - * Component. If you do not require animation then you can safely use Images to replace Sprites in all cases. + * As the name implies, the Star shape will display a star in your game. You can control several + * aspects of it including the number of points that constitute the star. The default is 5. If + * you change it to 4 it will render as a diamond. If you increase them, you'll get a more spiky + * star shape. + * + * You can also control the inner and outer radius, which is how 'long' each point of the star is. + * Modify these values to create more interesting shapes. */ - class Sprite extends Phaser.GameObjects.GameObject implements Phaser.GameObjects.Components.Alpha, Phaser.GameObjects.Components.BlendMode, Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.Flip, Phaser.GameObjects.Components.GetBounds, Phaser.GameObjects.Components.Mask, Phaser.GameObjects.Components.Origin, Phaser.GameObjects.Components.Pipeline, Phaser.GameObjects.Components.ScrollFactor, Phaser.GameObjects.Components.Size, Phaser.GameObjects.Components.TextureCrop, Phaser.GameObjects.Components.Tint, Phaser.GameObjects.Components.Transform, Phaser.GameObjects.Components.Visible { + class Star extends Phaser.GameObjects.Shape { /** * * @param scene The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. - * @param x The horizontal position of this Game Object in the world. - * @param y The vertical position of this Game Object in the world. - * @param texture The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. - * @param frame An optional frame from the Texture this Game Object is rendering with. + * @param x The horizontal position of this Game Object in the world. Default 0. + * @param y The vertical position of this Game Object in the world. Default 0. + * @param points The number of points on the star. Default 5. + * @param innerRadius The inner radius of the star. Default 32. + * @param outerRadius The outer radius of the star. Default 64. + * @param fillColor The color the star will be filled with, i.e. 0xff0000 for red. + * @param fillAlpha The alpha the star will be filled with. You can also set the alpha of the overall Shape using its `alpha` property. */ - constructor(scene: Phaser.Scene, x: number, y: number, texture: string, frame?: string | integer); + constructor(scene: Phaser.Scene, x?: number, y?: number, points?: number, innerRadius?: number, outerRadius?: number, fillColor?: number, fillAlpha?: number); /** - * The Animation Controller of this Sprite. + * Sets the number of points that make up the Star shape. + * This call can be chained. + * @param value The amount of points the Star will have. */ - anims: Phaser.GameObjects.Components.Animation; + setPoints(value: number): this; /** - * Update this Sprite's animations. - * @param time The current timestamp. - * @param delta The delta time, in ms, elapsed since the last frame. + * Sets the inner radius of the Star shape. + * This call can be chained. + * @param value The amount to set the inner radius to. */ - protected preUpdate(time: number, delta: number): void; + setInnerRadius(value: number): this; /** - * Start playing the given animation. - * @param key The string-based key of the animation to play. - * @param ignoreIfPlaying If an animation is already playing then ignore this call. Default false. - * @param startFrame Optionally start the animation playing from this frame index. Default 0. + * Sets the outer radius of the Star shape. + * This call can be chained. + * @param value The amount to set the outer radius to. */ - play(key: string, ignoreIfPlaying?: boolean, startFrame?: integer): Phaser.GameObjects.Sprite; + setOuterRadius(value: number): this; /** - * Build a JSON representation of this Sprite. + * The number of points that make up the Star shape. */ - toJSON(): Phaser.Types.GameObjects.JSONGameObject; + points: number; + + /** + * The inner radius of the Star shape. + */ + innerRadius: number; + + /** + * The outer radius of the Star shape. + */ + outerRadius: number; /** * Clears all alpha values associated with this Game Object. @@ -32899,15 +37567,9 @@ declare namespace Phaser { /** * Set the Alpha level of this Game Object. The alpha controls the opacity of the Game Object as it renders. * Alpha values are provided as a float between 0, fully transparent, and 1, fully opaque. - * - * If your game is running under WebGL you can optionally specify four different alpha values, each of which - * correspond to the four corners of the Game Object. Under Canvas only the `topLeft` value given is used. - * @param topLeft The alpha value used for the top-left of the Game Object. If this is the only value given it's applied across the whole Game Object. Default 1. - * @param topRight The alpha value used for the top-right of the Game Object. WebGL only. - * @param bottomLeft The alpha value used for the bottom-left of the Game Object. WebGL only. - * @param bottomRight The alpha value used for the bottom-right of the Game Object. WebGL only. + * @param value The alpha value applied across the whole Game Object. Default 1. */ - setAlpha(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; + setAlpha(value?: number): this; /** * The alpha value of the Game Object. @@ -32916,30 +37578,6 @@ declare namespace Phaser { */ alpha: number; - /** - * The alpha value starting from the top-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - alphaTopLeft: number; - - /** - * The alpha value starting from the top-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - alphaTopRight: number; - - /** - * The alpha value starting from the bottom-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - alphaBottomLeft: number; - - /** - * The alpha value starting from the bottom-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - alphaBottomRight: number; - /** * Sets the Blend Mode being used by this Game Object. * @@ -32993,7 +37631,7 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. @@ -33006,77 +37644,13 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. * @param value The depth of this Game Object. */ - setDepth(value: integer): this; - - /** - * The horizontally flipped state of the Game Object. - * - * A Game Object that is flipped horizontally will render inversed on the horizontal axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. - */ - flipX: boolean; - - /** - * The vertically flipped state of the Game Object. - * - * A Game Object that is flipped vertically will render inversed on the vertical axis (i.e. upside down) - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. - */ - flipY: boolean; - - /** - * Toggles the horizontal flipped state of this Game Object. - * - * A Game Object that is flipped horizontally will render inversed on the horizontal axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. - */ - toggleFlipX(): this; - - /** - * Toggles the vertical flipped state of this Game Object. - */ - toggleFlipY(): this; - - /** - * Sets the horizontal flipped state of this Game Object. - * - * A Game Object that is flipped horizontally will render inversed on the horizontal axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. - * @param value The flipped state. `false` for no flip, or `true` to be flipped. - */ - setFlipX(value: boolean): this; - - /** - * Sets the vertical flipped state of this Game Object. - * @param value The flipped state. `false` for no flip, or `true` to be flipped. - */ - setFlipY(value: boolean): this; - - /** - * Sets the horizontal and vertical flipped state of this Game Object. - * - * A Game Object that is flipped will render inversed on the flipped axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. - * @param x The horizontal flipped state. `false` for no flip, or `true` to be flipped. - * @param y The horizontal flipped state. `false` for no flip, or `true` to be flipped. - */ - setFlip(x: boolean, y: boolean): this; - - /** - * Resets the horizontal and vertical flipped state of this Game Object back to their default un-flipped state. - */ - resetFlip(): this; + setDepth(value: number): this; /** * Gets the center coordinate of this Game Object, regardless of origin. @@ -33188,6 +37762,8 @@ declare namespace Phaser { * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, * including this one. * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * * To create the mask you need to pass in a reference to a renderable Game Object. * A renderable Game Object is one that uses a texture to render with, such as an * Image, Sprite, Render Texture or BitmapText. @@ -33273,6 +37849,8 @@ declare namespace Phaser { /** * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. */ defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; @@ -33281,23 +37859,109 @@ declare namespace Phaser { */ pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + /** + * Does this Game Object have any Post Pipelines set? + */ + hasPostPipeline: boolean; + + /** + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. + */ + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; + + /** + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. + */ + pipelineData: object; + /** * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + */ + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; + + /** + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; + + /** + * Sets one, or more, Post Pipelines on this Game Object. + * + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; + + /** + * Adds an entry to the `pipelineData` object belonging to this Game Object. + * + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. */ - initPipeline(pipelineName?: string): boolean; + setPipelineData(key: string, value?: any): this; /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - setPipeline(pipelineName: string): this; + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; /** * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; + + /** + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPostPipeline(resetData?: boolean): void; + + /** + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - resetPipeline(): boolean; + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; /** * Gets the name of the WebGL Pipeline this Game Object is currently using. @@ -33363,243 +38027,6 @@ declare namespace Phaser { */ setScrollFactor(x: number, y?: number): this; - /** - * The native (un-scaled) width of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayWidth` property. - */ - width: number; - - /** - * The native (un-scaled) height of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayHeight` property. - */ - height: number; - - /** - * The displayed width of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. - */ - displayWidth: number; - - /** - * The displayed height of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. - */ - displayHeight: number; - - /** - * Sets the size of this Game Object to be that of the given Frame. - * - * This will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or call the - * `setDisplaySize` method, which is the same thing as changing the scale but allows you - * to do so by giving pixel values. - * - * If you have enabled this Game Object for input, changing the size will _not_ change the - * size of the hit area. To do this you should adjust the `input.hitArea` object directly. - * @param frame The frame to base the size of this Game Object on. - */ - setSizeToFrame(frame: Phaser.Textures.Frame): this; - - /** - * Sets the internal size of this Game Object, as used for frame or physics body creation. - * - * This will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or call the - * `setDisplaySize` method, which is the same thing as changing the scale but allows you - * to do so by giving pixel values. - * - * If you have enabled this Game Object for input, changing the size will _not_ change the - * size of the hit area. To do this you should adjust the `input.hitArea` object directly. - * @param width The width of this Game Object. - * @param height The height of this Game Object. - */ - setSize(width: number, height: number): this; - - /** - * Sets the display size of this Game Object. - * - * Calling this will adjust the scale. - * @param width The width of this Game Object. - * @param height The height of this Game Object. - */ - setDisplaySize(width: number, height: number): this; - - /** - * The Texture this Game Object is using to render with. - */ - texture: Phaser.Textures.Texture | Phaser.Textures.CanvasTexture; - - /** - * The Texture Frame this Game Object is using to render with. - */ - frame: Phaser.Textures.Frame; - - /** - * A boolean flag indicating if this Game Object is being cropped or not. - * You can toggle this at any time after `setCrop` has been called, to turn cropping on or off. - * Equally, calling `setCrop` with no arguments will reset the crop and disable it. - */ - isCropped: boolean; - - /** - * Applies a crop to a texture based Game Object, such as a Sprite or Image. - * - * The crop is a rectangle that limits the area of the texture frame that is visible during rendering. - * - * Cropping a Game Object does not change its size, dimensions, physics body or hit area, it just - * changes what is shown when rendered. - * - * The crop coordinates are relative to the texture frame, not the Game Object, meaning 0 x 0 is the top-left. - * - * Therefore, if you had a Game Object that had an 800x600 sized texture, and you wanted to show only the left - * half of it, you could call `setCrop(0, 0, 400, 600)`. - * - * It is also scaled to match the Game Object scale automatically. Therefore a crop rect of 100x50 would crop - * an area of 200x100 when applied to a Game Object that had a scale factor of 2. - * - * You can either pass in numeric values directly, or you can provide a single Rectangle object as the first argument. - * - * Call this method with no arguments at all to reset the crop, or toggle the property `isCropped` to `false`. - * - * You should do this if the crop rectangle becomes the same size as the frame itself, as it will allow - * the renderer to skip several internal calculations. - * @param x The x coordinate to start the crop from. Or a Phaser.Geom.Rectangle object, in which case the rest of the arguments are ignored. - * @param y The y coordinate to start the crop from. - * @param width The width of the crop rectangle in pixels. - * @param height The height of the crop rectangle in pixels. - */ - setCrop(x?: number | Phaser.Geom.Rectangle, y?: number, width?: number, height?: number): this; - - /** - * Sets the texture and frame this Game Object will use to render with. - * - * Textures are referenced by their string-based keys, as stored in the Texture Manager. - * @param key The key of the texture to be used, as stored in the Texture Manager. - * @param frame The name or index of the frame within the Texture. - */ - setTexture(key: string, frame?: string | integer): this; - - /** - * Sets the frame this Game Object will use to render with. - * - * The Frame has to belong to the current Texture being used. - * - * It can be either a string or an index. - * - * Calling `setFrame` will modify the `width` and `height` properties of your Game Object. - * It will also change the `origin` if the Frame has a custom pivot point, as exported from packages like Texture Packer. - * @param frame The name or index of the frame within the Texture. - * @param updateSize Should this call adjust the size of the Game Object? Default true. - * @param updateOrigin Should this call adjust the origin of the Game Object? Default true. - */ - setFrame(frame: string | integer, updateSize?: boolean, updateOrigin?: boolean): this; - - /** - * Fill or additive? - */ - tintFill: boolean; - - /** - * Clears all tint values associated with this Game Object. - * - * Immediately sets the color values back to 0xffffff and the tint type to 'additive', - * which results in no visible change to the texture. - */ - clearTint(): this; - - /** - * Sets an additive tint on this Game Object. - * - * The tint works by taking the pixel color values from the Game Objects texture, and then - * multiplying it by the color value of the tint. You can provide either one color value, - * in which case the whole Game Object will be tinted in that color. Or you can provide a color - * per corner. The colors are blended together across the extent of the Game Object. - * - * To modify the tint color once set, either call this method again with new values or use the - * `tint` property to set all colors at once. Or, use the properties `tintTopLeft`, `tintTopRight, - * `tintBottomLeft` and `tintBottomRight` to set the corner color values independently. - * - * To remove a tint call `clearTint`. - * - * To swap this from being an additive tint to a fill based tint set the property `tintFill` to `true`. - * @param topLeft The tint being applied to the top-left of the Game Object. If no other values are given this value is applied evenly, tinting the whole Game Object. Default 0xffffff. - * @param topRight The tint being applied to the top-right of the Game Object. - * @param bottomLeft The tint being applied to the bottom-left of the Game Object. - * @param bottomRight The tint being applied to the bottom-right of the Game Object. - */ - setTint(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; - - /** - * Sets a fill-based tint on this Game Object. - * - * Unlike an additive tint, a fill-tint literally replaces the pixel colors from the texture - * with those in the tint. You can use this for effects such as making a player flash 'white' - * if hit by something. You can provide either one color value, in which case the whole - * Game Object will be rendered in that color. Or you can provide a color per corner. The colors - * are blended together across the extent of the Game Object. - * - * To modify the tint color once set, either call this method again with new values or use the - * `tint` property to set all colors at once. Or, use the properties `tintTopLeft`, `tintTopRight, - * `tintBottomLeft` and `tintBottomRight` to set the corner color values independently. - * - * To remove a tint call `clearTint`. - * - * To swap this from being a fill-tint to an additive tint set the property `tintFill` to `false`. - * @param topLeft The tint being applied to the top-left of the Game Object. If not other values are given this value is applied evenly, tinting the whole Game Object. Default 0xffffff. - * @param topRight The tint being applied to the top-right of the Game Object. - * @param bottomLeft The tint being applied to the bottom-left of the Game Object. - * @param bottomRight The tint being applied to the bottom-right of the Game Object. - */ - setTintFill(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; - - /** - * The tint value being applied to the top-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintTopLeft: integer; - - /** - * The tint value being applied to the top-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintTopRight: integer; - - /** - * The tint value being applied to the bottom-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintBottomLeft: integer; - - /** - * The tint value being applied to the bottom-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintBottomRight: integer; - - /** - * The tint value being applied to the whole of the Game Object. - * This property is a setter-only. Use the properties `tintTopLeft` etc to read the current tint value. - */ - tint: integer; - - /** - * Does this Game Object have a tint applied to it or not? - */ - readonly isTinted: boolean; - /** * The x position of this Game Object. */ @@ -33650,13 +38077,13 @@ declare namespace Phaser { * * If you prefer to work in radians, see the `rotation` property instead. */ - angle: integer; + angle: number; /** * The angle of this Game Object in radians. * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. * * If you prefer to work in degrees, see the `angle` property instead. */ @@ -33671,6 +38098,12 @@ declare namespace Phaser { */ setPosition(x?: number, y?: number, z?: number, w?: number): this; + /** + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; + /** * Sets the position of this Game Object to be a random position within the confines of * the given area. @@ -33745,6 +38178,22 @@ declare namespace Phaser { */ getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. + */ + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + /** * Gets the sum total rotation of all of this Game Objects parent Containers. * @@ -33770,606 +38219,1065 @@ declare namespace Phaser { } /** - * A Text Game Object. - * - * Text objects work by creating their own internal hidden Canvas and then renders text to it using - * the standard Canvas `fillText` API. It then creates a texture from this canvas which is rendered - * to your game during the render pass. - * - * Because it uses the Canvas API you can take advantage of all the features this offers, such as - * applying gradient fills to the text, or strokes, shadows and more. You can also use custom fonts - * loaded externally, such as Google or TypeKit Web fonts. - * - * **Important:** If the font you wish to use has a space or digit in its name, such as - * 'Press Start 2P' or 'Roboto Condensed', then you _must_ put the font name in quotes, either - * when creating the Text object, or when setting the font via `setFont` or `setFontFamily`. I.e.: - * - * ```javascript - * this.add.text(0, 0, 'Hello World', { fontFamily: '"Roboto Condensed"' }); - * ``` - * - * Equally, if you wish to provide a list of fallback fonts, then you should ensure they are all - * quoted properly, too: - * - * ```javascript - * this.add.text(0, 0, 'Hello World', { fontFamily: 'Verdana, "Times New Roman", Tahoma, serif' }); - * ``` - * - * You can only display fonts that are currently loaded and available to the browser: therefore fonts must - * be pre-loaded. Phaser does not do ths for you, so you will require the use of a 3rd party font loader, - * or have the fonts ready available in the CSS on the page in which your Phaser game resides. + * The Triangle Shape is a Game Object that can be added to a Scene, Group or Container. You can + * treat it like any other Game Object in your game, such as tweening it, scaling it, or enabling + * it for input or physics. It provides a quick and easy way for you to render this shape in your + * game without using a texture, while still taking advantage of being fully batched in WebGL. * - * See {@link http://www.jordanm.co.uk/tinytype this compatibility table} for the available default fonts - * across mobile browsers. + * This shape supports both fill and stroke colors. * - * A note on performance: Every time the contents of a Text object changes, i.e. changing the text being - * displayed, or the style of the text, it needs to remake the Text canvas, and if on WebGL, re-upload the - * new texture to the GPU. This can be an expensive operation if used often, or with large quantities of - * Text objects in your game. If you run into performance issues you would be better off using Bitmap Text - * instead, as it benefits from batching and avoids expensive Canvas API calls. + * The Triangle consists of 3 lines, joining up to form a triangular shape. You can control the + * position of each point of these lines. The triangle is always closed and cannot have an open + * face. If you require that, consider using a Polygon instead. */ - class Text extends Phaser.GameObjects.GameObject implements Phaser.GameObjects.Components.Alpha, Phaser.GameObjects.Components.BlendMode, Phaser.GameObjects.Components.ComputedSize, Phaser.GameObjects.Components.Crop, Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.Flip, Phaser.GameObjects.Components.GetBounds, Phaser.GameObjects.Components.Mask, Phaser.GameObjects.Components.Origin, Phaser.GameObjects.Components.Pipeline, Phaser.GameObjects.Components.ScrollFactor, Phaser.GameObjects.Components.Tint, Phaser.GameObjects.Components.Transform, Phaser.GameObjects.Components.Visible { + class Triangle extends Phaser.GameObjects.Shape { /** * * @param scene The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. - * @param x The horizontal position of this Game Object in the world. - * @param y The vertical position of this Game Object in the world. - * @param text The text this Text object will display. - * @param style The text style configuration object. + * @param x The horizontal position of this Game Object in the world. Default 0. + * @param y The vertical position of this Game Object in the world. Default 0. + * @param x1 The horizontal position of the first point in the triangle. Default 0. + * @param y1 The vertical position of the first point in the triangle. Default 128. + * @param x2 The horizontal position of the second point in the triangle. Default 64. + * @param y2 The vertical position of the second point in the triangle. Default 0. + * @param x3 The horizontal position of the third point in the triangle. Default 128. + * @param y3 The vertical position of the third point in the triangle. Default 128. + * @param fillColor The color the triangle will be filled with, i.e. 0xff0000 for red. + * @param fillAlpha The alpha the triangle will be filled with. You can also set the alpha of the overall Shape using its `alpha` property. */ - constructor(scene: Phaser.Scene, x: number, y: number, text: string | string[], style: Phaser.Types.GameObjects.Text.TextStyle); + constructor(scene: Phaser.Scene, x?: number, y?: number, x1?: number, y1?: number, x2?: number, y2?: number, x3?: number, y3?: number, fillColor?: number, fillAlpha?: number); /** - * Returns an object containing dimensions of the Text object. - * @param text The Text object to calculate the size from. - * @param size The Text metrics to use when calculating the size. - * @param lines The lines of text to calculate the size from. + * Sets the data for the lines that make up this Triangle shape. + * @param x1 The horizontal position of the first point in the triangle. Default 0. + * @param y1 The vertical position of the first point in the triangle. Default 0. + * @param x2 The horizontal position of the second point in the triangle. Default 0. + * @param y2 The vertical position of the second point in the triangle. Default 0. + * @param x3 The horizontal position of the third point in the triangle. Default 0. + * @param y3 The vertical position of the third point in the triangle. Default 0. */ - static GetTextSize(text: Phaser.GameObjects.Text, size: Phaser.Types.GameObjects.Text.TextMetrics, lines: any[]): object; + setTo(x1?: number, y1?: number, x2?: number, y2?: number, x3?: number, y3?: number): this; /** - * Calculates the ascent, descent and fontSize of a given font style. - * @param textStyle The TextStyle object to measure. + * Clears all alpha values associated with this Game Object. + * + * Immediately sets the alpha levels back to 1 (fully opaque). */ - static MeasureText(textStyle: Phaser.GameObjects.TextStyle): Phaser.Types.GameObjects.Text.TextMetrics; + clearAlpha(): this; /** - * The renderer in use by this Text object. + * Set the Alpha level of this Game Object. The alpha controls the opacity of the Game Object as it renders. + * Alpha values are provided as a float between 0, fully transparent, and 1, fully opaque. + * @param value The alpha value applied across the whole Game Object. Default 1. */ - renderer: Phaser.Renderer.Canvas.CanvasRenderer | Phaser.Renderer.WebGL.WebGLRenderer; + setAlpha(value?: number): this; /** - * The canvas element that the text is rendered to. + * The alpha value of the Game Object. + * + * This is a global value, impacting the entire Game Object, not just a region of it. */ - canvas: HTMLCanvasElement; + alpha: number; /** - * The context of the canvas element that the text is rendered to. + * Sets the Blend Mode being used by this Game Object. + * + * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) + * + * Under WebGL only the following Blend Modes are available: + * + * * ADD + * * MULTIPLY + * * SCREEN + * * ERASE + * + * Canvas has more available depending on browser support. + * + * You can also create your own custom Blend Modes in WebGL. + * + * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending + * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these + * reasons try to be careful about the construction of your Scene and the frequency of which blend modes + * are used. */ - context: CanvasRenderingContext2D; + blendMode: Phaser.BlendModes | string; /** - * The Text Style object. + * Sets the Blend Mode being used by this Game Object. * - * Manages the style of this Text object. + * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) + * + * Under WebGL only the following Blend Modes are available: + * + * * ADD + * * MULTIPLY + * * SCREEN + * * ERASE (only works when rendering to a framebuffer, like a Render Texture) + * + * Canvas has more available depending on browser support. + * + * You can also create your own custom Blend Modes in WebGL. + * + * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending + * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these + * reasons try to be careful about the construction of your Scene and the frequency in which blend modes + * are used. + * @param value The BlendMode value. Either a string or a CONST. */ - style: Phaser.GameObjects.TextStyle; + setBlendMode(value: string | Phaser.BlendModes): this; /** - * Whether to automatically round line positions. + * The depth of this Game Object within the Scene. + * + * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order + * of Game Objects, without actually moving their position in the display list. + * + * The default depth is zero. A Game Object with a higher depth + * value will always render in front of one with a lower value. + * + * Setting the depth will queue a depth sort event within the Scene. */ - autoRound: boolean; + depth: number; /** - * The Regular Expression that is used to split the text up into lines, in - * multi-line text. By default this is `/(?:\r\n|\r|\n)/`. - * You can change this RegExp to be anything else that you may need. + * The depth of this Game Object within the Scene. + * + * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order + * of Game Objects, without actually moving their position in the display list. + * + * The default depth is zero. A Game Object with a higher depth + * value will always render in front of one with a lower value. + * + * Setting the depth will queue a depth sort event within the Scene. + * @param value The depth of this Game Object. */ - splitRegExp: object; + setDepth(value: number): this; /** - * Specify a padding value which is added to the line width and height when calculating the Text size. - * Allows you to add extra spacing if the browser is unable to accurately determine the true font dimensions. + * Gets the center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. */ - padding: Object; + getCenter(output?: O): O; /** - * The width of this Text object. + * Gets the top-left corner coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - width: number; + getTopLeft(output?: O, includeParent?: boolean): O; /** - * The height of this Text object. + * Gets the top-center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - height: number; + getTopCenter(output?: O, includeParent?: boolean): O; /** - * The line spacing value. - * This value is added to the font height to calculate the overall line height. - * Only has an effect if this Text object contains multiple lines of text. - * - * If you update this property directly, instead of using the `setLineSpacing` method, then - * be sure to call `updateText` after, or you won't see the change reflected in the Text object. + * Gets the top-right corner coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - lineSpacing: number; + getTopRight(output?: O, includeParent?: boolean): O; /** - * Whether the text or its settings have changed and need updating. + * Gets the left-center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - dirty: boolean; + getLeftCenter(output?: O, includeParent?: boolean): O; /** - * Initialize right to left text. + * Gets the right-center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - initRTL(): void; + getRightCenter(output?: O, includeParent?: boolean): O; /** - * Greedy wrapping algorithm that will wrap words as the line grows longer than its horizontal - * bounds. - * @param text The text to perform word wrap detection against. + * Gets the bottom-left corner coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - runWordWrap(text: string): string; + getBottomLeft(output?: O, includeParent?: boolean): O; /** - * Advanced wrapping algorithm that will wrap words as the line grows longer than its horizontal - * bounds. Consecutive spaces will be collapsed and replaced with a single space. Lines will be - * trimmed of white space before processing. Throws an error if wordWrapWidth is less than a - * single character. - * @param text The text to perform word wrap detection against. - * @param context The Canvas Rendering Context. - * @param wordWrapWidth The word wrap width. + * Gets the bottom-center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - advancedWordWrap(text: string, context: CanvasRenderingContext2D, wordWrapWidth: number): string; + getBottomCenter(output?: O, includeParent?: boolean): O; /** - * Greedy wrapping algorithm that will wrap words as the line grows longer than its horizontal - * bounds. Spaces are not collapsed and whitespace is not trimmed. - * @param text The text to perform word wrap detection against. - * @param context The Canvas Rendering Context. - * @param wordWrapWidth The word wrap width. + * Gets the bottom-right corner coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - basicWordWrap(text: string, context: CanvasRenderingContext2D, wordWrapWidth: number): string; + getBottomRight(output?: O, includeParent?: boolean): O; /** - * Runs the given text through this Text objects word wrapping and returns the results as an - * array, where each element of the array corresponds to a wrapped line of text. - * @param text The text for which the wrapping will be calculated. If unspecified, the Text objects current text will be used. + * Gets the bounds of this Game Object, regardless of origin. + * The values are stored and returned in a Rectangle, or Rectangle-like, object. + * @param output An object to store the values in. If not provided a new Rectangle will be created. */ - getWrappedText(text: string): string[]; + getBounds(output?: O): O; /** - * Set the text to display. + * The Mask this Game Object is using during render. + */ + mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask; + + /** + * Sets the mask that this Game Object will use to render with. * - * An array of strings will be joined with `\n` line breaks. - * @param value The string, or array of strings, to be set as the content of this Text object. + * The mask must have been previously created and can be either a GeometryMask or a BitmapMask. + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * + * If a mask is already set on this Game Object it will be immediately replaced. + * + * Masks are positioned in global space and are not relative to the Game Object to which they + * are applied. The reason for this is that multiple Game Objects can all share the same mask. + * + * Masks have no impact on physics or input detection. They are purely a rendering component + * that allows you to limit what is visible during the render pass. + * @param mask The mask this Game Object will use when rendering. */ - setText(value: string | string[]): Phaser.GameObjects.Text; + setMask(mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask): this; /** - * Set the text style. - * @param style The style settings to set. + * Clears the mask that this Game Object was using. + * @param destroyMask Destroy the mask before clearing it? Default false. */ - setStyle(style: object): Phaser.GameObjects.Text; + clearMask(destroyMask?: boolean): this; /** - * Set the font. - * - * If a string is given, the font family is set. - * - * If an object is given, the `fontFamily`, `fontSize` and `fontStyle` - * properties of that object are set. - * - * **Important:** If the font you wish to use has a space or digit in its name, such as - * 'Press Start 2P' or 'Roboto Condensed', then you _must_ put the font name in quotes: + * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, + * including this one. * - * ```javascript - * Text.setFont('"Roboto Condensed"'); - * ``` + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. * - * Equally, if you wish to provide a list of fallback fonts, then you should ensure they are all - * quoted properly, too: + * To create the mask you need to pass in a reference to a renderable Game Object. + * A renderable Game Object is one that uses a texture to render with, such as an + * Image, Sprite, Render Texture or BitmapText. * - * ```javascript - * Text.setFont('Verdana, "Times New Roman", Tahoma, serif'); - * ``` - * @param font The font family or font settings to set. + * If you do not provide a renderable object, and this Game Object has a texture, + * it will use itself as the object. This means you can call this method to create + * a Bitmap Mask from any renderable Game Object. + * @param renderable A renderable Game Object that uses a texture, such as a Sprite. */ - setFont(font: string): Phaser.GameObjects.Text; + createBitmapMask(renderable?: Phaser.GameObjects.GameObject): Phaser.Display.Masks.BitmapMask; /** - * Set the font family. - * - * **Important:** If the font you wish to use has a space or digit in its name, such as - * 'Press Start 2P' or 'Roboto Condensed', then you _must_ put the font name in quotes: + * Creates and returns a Geometry Mask. This mask can be used by any Game Object, + * including this one. * - * ```javascript - * Text.setFont('"Roboto Condensed"'); - * ``` + * To create the mask you need to pass in a reference to a Graphics Game Object. * - * Equally, if you wish to provide a list of fallback fonts, then you should ensure they are all - * quoted properly, too: + * If you do not provide a graphics object, and this Game Object is an instance + * of a Graphics object, then it will use itself to create the mask. * - * ```javascript - * Text.setFont('Verdana, "Times New Roman", Tahoma, serif'); - * ``` - * @param family The font family. + * This means you can call this method to create a Geometry Mask from any Graphics Game Object. + * @param graphics A Graphics Game Object. The geometry within it will be used as the mask. */ - setFontFamily(family: string): Phaser.GameObjects.Text; + createGeometryMask(graphics?: Phaser.GameObjects.Graphics): Phaser.Display.Masks.GeometryMask; /** - * Set the font size. - * @param size The font size. + * The horizontal origin of this Game Object. + * The origin maps the relationship between the size and position of the Game Object. + * The default value is 0.5, meaning all Game Objects are positioned based on their center. + * Setting the value to 0 means the position now relates to the left of the Game Object. */ - setFontSize(size: number): Phaser.GameObjects.Text; + originX: number; /** - * Set the font style. - * @param style The font style. + * The vertical origin of this Game Object. + * The origin maps the relationship between the size and position of the Game Object. + * The default value is 0.5, meaning all Game Objects are positioned based on their center. + * Setting the value to 0 means the position now relates to the top of the Game Object. */ - setFontStyle(style: string): Phaser.GameObjects.Text; + originY: number; /** - * Set a fixed width and height for the text. - * - * Pass in `0` for either of these parameters to disable fixed width or height respectively. - * @param width The fixed width to set. `0` disables fixed width. - * @param height The fixed height to set. `0` disables fixed height. + * The horizontal display origin of this Game Object. + * The origin is a normalized value between 0 and 1. + * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. */ - setFixedSize(width: number, height: number): Phaser.GameObjects.Text; + displayOriginX: number; /** - * Set the background color. - * @param color The background color. + * The vertical display origin of this Game Object. + * The origin is a normalized value between 0 and 1. + * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. */ - setBackgroundColor(color: string): Phaser.GameObjects.Text; + displayOriginY: number; /** - * Set the fill style to be used by the Text object. - * - * This can be any valid CanvasRenderingContext2D fillStyle value, such as - * a color (in hex, rgb, rgba, hsl or named values), a gradient or a pattern. + * Sets the origin of this Game Object. * - * See the [MDN fillStyle docs](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/fillStyle) for more details. - * @param color The text fill style. Can be any valid CanvasRenderingContext `fillStyle` value. + * The values are given in the range 0 to 1. + * @param x The horizontal origin value. Default 0.5. + * @param y The vertical origin value. If not defined it will be set to the value of `x`. Default x. */ - setFill(color: string | any): Phaser.GameObjects.Text; + setOrigin(x?: number, y?: number): this; /** - * Set the text fill color. - * @param color The text fill color. + * Sets the origin of this Game Object based on the Pivot values in its Frame. */ - setColor(color: string): Phaser.GameObjects.Text; + setOriginFromFrame(): this; /** - * Set the stroke settings. - * @param color The stroke color. - * @param thickness The stroke thickness. + * Sets the display origin of this Game Object. + * The difference between this and setting the origin is that you can use pixel values for setting the display origin. + * @param x The horizontal display origin value. Default 0. + * @param y The vertical display origin value. If not defined it will be set to the value of `x`. Default x. */ - setStroke(color: string, thickness: number): Phaser.GameObjects.Text; + setDisplayOrigin(x?: number, y?: number): this; /** - * Set the shadow settings. - * @param x The horizontal shadow offset. Default 0. - * @param y The vertical shadow offset. Default 0. - * @param color The shadow color. Default '#000'. - * @param blur The shadow blur radius. Default 0. - * @param shadowStroke Whether to stroke the shadow. Default false. - * @param shadowFill Whether to fill the shadow. Default true. + * Updates the Display Origin cached values internally stored on this Game Object. + * You don't usually call this directly, but it is exposed for edge-cases where you may. */ - setShadow(x?: number, y?: number, color?: string, blur?: number, shadowStroke?: boolean, shadowFill?: boolean): Phaser.GameObjects.Text; + updateDisplayOrigin(): this; /** - * Set the shadow offset. - * @param x The horizontal shadow offset. - * @param y The vertical shadow offset. + * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. */ - setShadowOffset(x: number, y: number): Phaser.GameObjects.Text; + defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; /** - * Set the shadow color. - * @param color The shadow color. + * The current WebGL pipeline of this Game Object. */ - setShadowColor(color: string): Phaser.GameObjects.Text; + pipeline: Phaser.Renderer.WebGL.WebGLPipeline; /** - * Set the shadow blur radius. - * @param blur The shadow blur radius. + * Does this Game Object have any Post Pipelines set? */ - setShadowBlur(blur: number): Phaser.GameObjects.Text; + hasPostPipeline: boolean; /** - * Enable or disable shadow stroke. - * @param enabled Whether shadow stroke is enabled or not. + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. */ - setShadowStroke(enabled: boolean): Phaser.GameObjects.Text; + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; /** - * Enable or disable shadow fill. - * @param enabled Whether shadow fill is enabled or not. + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. */ - setShadowFill(enabled: boolean): Phaser.GameObjects.Text; + pipelineData: object; /** - * Set the width (in pixels) to use for wrapping lines. Pass in null to remove wrapping by width. - * @param width The maximum width of a line in pixels. Set to null to remove wrapping. - * @param useAdvancedWrap Whether or not to use the advanced wrapping - * algorithm. If true, spaces are collapsed and whitespace is trimmed from lines. If false, - * spaces and whitespace are left as is. Default false. + * Sets the initial WebGL Pipeline of this Game Object. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. */ - setWordWrapWidth(width: number, useAdvancedWrap?: boolean): Phaser.GameObjects.Text; + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; /** - * Set a custom callback for wrapping lines. Pass in null to remove wrapping by callback. - * @param callback A custom function that will be responsible for wrapping the - * text. It will receive two arguments: text (the string to wrap), textObject (this Text - * instance). It should return the wrapped lines either as an array of lines or as a string with - * newline characters in place to indicate where breaks should happen. - * @param scope The scope that will be applied when the callback is invoked. Default null. + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. */ - setWordWrapCallback(callback: TextStyleWordWrapCallback, scope?: object): Phaser.GameObjects.Text; + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; /** - * Set the alignment of the text in this Text object. + * Sets one, or more, Post Pipelines on this Game Object. * - * The argument can be one of: `left`, `right`, `center` or `justify`. + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. * - * Alignment only works if the Text object has more than one line of text. - * @param align The text alignment for multi-line text. Default 'left'. + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. */ - setAlign(align?: string): Phaser.GameObjects.Text; + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; /** - * Set the resolution used by this Text object. + * Adds an entry to the `pipelineData` object belonging to this Game Object. * - * By default it will be set to match the resolution set in the Game Config, - * but you can override it via this method, or by specifying it in the Text style configuration object. + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. * - * It allows for much clearer text on High DPI devices, at the cost of memory because it uses larger - * internal Canvas textures for the Text. + * If `value` is undefined, and `key` exists, `key` is removed from the data object. * - * Therefore, please use with caution, as the more high res Text you have, the more memory it uses. - * @param value The resolution for this Text object to use. + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. */ - setResolution(value: number): Phaser.GameObjects.Text; + setPipelineData(key: string, value?: any): this; /** - * Sets the line spacing value. - * - * This value is _added_ to the height of the font when calculating the overall line height. - * This only has an effect if this Text object consists of multiple lines of text. - * @param value The amount to add to the font height to achieve the overall line height. + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - setLineSpacing(value: number): Phaser.GameObjects.Text; + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; /** - * Set the text padding. - * - * 'left' can be an object. - * - * If only 'left' and 'top' are given they are treated as 'x' and 'y'. - * @param left The left padding value, or a padding config object. - * @param top The top padding value. - * @param right The right padding value. - * @param bottom The bottom padding value. + * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. */ - setPadding(left: number | Phaser.Types.GameObjects.Text.TextPadding, top: number, right: number, bottom: number): Phaser.GameObjects.Text; + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; /** - * Set the maximum number of lines to draw. - * @param max The maximum number of lines to draw. Default 0. + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. */ - setMaxLines(max?: integer): Phaser.GameObjects.Text; + resetPostPipeline(resetData?: boolean): void; /** - * Update the displayed text. + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - updateText(): Phaser.GameObjects.Text; + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; /** - * Get the current text metrics. + * Gets the name of the WebGL Pipeline this Game Object is currently using. */ - getTextMetrics(): object; + getPipelineName(): string; /** - * The text string being rendered by this Text Game Object. + * The horizontal scroll factor of this Game Object. + * + * The scroll factor controls the influence of the movement of a Camera upon this Game Object. + * + * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. + * It does not change the Game Objects actual position values. + * + * A value of 1 means it will move exactly in sync with a camera. + * A value of 0 means it will not move at all, even if the camera moves. + * Other values control the degree to which the camera movement is mapped to this Game Object. + * + * Please be aware that scroll factor values other than 1 are not taken in to consideration when + * calculating physics collisions. Bodies always collide based on their world position, but changing + * the scroll factor is a visual adjustment to where the textures are rendered, which can offset + * them from physics bodies if not accounted for in your code. */ - text: string; + scrollFactorX: number; /** - * Build a JSON representation of the Text object. + * The vertical scroll factor of this Game Object. + * + * The scroll factor controls the influence of the movement of a Camera upon this Game Object. + * + * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. + * It does not change the Game Objects actual position values. + * + * A value of 1 means it will move exactly in sync with a camera. + * A value of 0 means it will not move at all, even if the camera moves. + * Other values control the degree to which the camera movement is mapped to this Game Object. + * + * Please be aware that scroll factor values other than 1 are not taken in to consideration when + * calculating physics collisions. Bodies always collide based on their world position, but changing + * the scroll factor is a visual adjustment to where the textures are rendered, which can offset + * them from physics bodies if not accounted for in your code. */ - toJSON(): Phaser.Types.GameObjects.JSONGameObject; + scrollFactorY: number; /** - * Internal destroy handler, called as part of the destroy process. + * Sets the scroll factor of this Game Object. + * + * The scroll factor controls the influence of the movement of a Camera upon this Game Object. + * + * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. + * It does not change the Game Objects actual position values. + * + * A value of 1 means it will move exactly in sync with a camera. + * A value of 0 means it will not move at all, even if the camera moves. + * Other values control the degree to which the camera movement is mapped to this Game Object. + * + * Please be aware that scroll factor values other than 1 are not taken in to consideration when + * calculating physics collisions. Bodies always collide based on their world position, but changing + * the scroll factor is a visual adjustment to where the textures are rendered, which can offset + * them from physics bodies if not accounted for in your code. + * @param x The horizontal scroll factor of this Game Object. + * @param y The vertical scroll factor of this Game Object. If not set it will use the `x` value. Default x. */ - protected preDestroy(): void; + setScrollFactor(x: number, y?: number): this; /** - * Clears all alpha values associated with this Game Object. - * - * Immediately sets the alpha levels back to 1 (fully opaque). + * The x position of this Game Object. */ - clearAlpha(): this; + x: number; /** - * Set the Alpha level of this Game Object. The alpha controls the opacity of the Game Object as it renders. - * Alpha values are provided as a float between 0, fully transparent, and 1, fully opaque. - * - * If your game is running under WebGL you can optionally specify four different alpha values, each of which - * correspond to the four corners of the Game Object. Under Canvas only the `topLeft` value given is used. - * @param topLeft The alpha value used for the top-left of the Game Object. If this is the only value given it's applied across the whole Game Object. Default 1. - * @param topRight The alpha value used for the top-right of the Game Object. WebGL only. - * @param bottomLeft The alpha value used for the bottom-left of the Game Object. WebGL only. - * @param bottomRight The alpha value used for the bottom-right of the Game Object. WebGL only. + * The y position of this Game Object. */ - setAlpha(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; + y: number; /** - * The alpha value of the Game Object. + * The z position of this Game Object. * - * This is a global value, impacting the entire Game Object, not just a region of it. + * Note: The z position does not control the rendering order of 2D Game Objects. Use + * {@link Phaser.GameObjects.Components.Depth#depth} instead. */ - alpha: number; + z: number; /** - * The alpha value starting from the top-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * The w position of this Game Object. */ - alphaTopLeft: number; + w: number; /** - * The alpha value starting from the top-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * This is a special setter that allows you to set both the horizontal and vertical scale of this Game Object + * to the same value, at the same time. When reading this value the result returned is `(scaleX + scaleY) / 2`. + * + * Use of this property implies you wish the horizontal and vertical scales to be equal to each other. If this + * isn't the case, use the `scaleX` or `scaleY` properties instead. */ - alphaTopRight: number; + scale: number; /** - * The alpha value starting from the bottom-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * The horizontal scale of this Game Object. */ - alphaBottomLeft: number; + scaleX: number; /** - * The alpha value starting from the bottom-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * The vertical scale of this Game Object. */ - alphaBottomRight: number; + scaleY: number; /** - * Sets the Blend Mode being used by this Game Object. - * - * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) - * - * Under WebGL only the following Blend Modes are available: - * - * * ADD - * * MULTIPLY - * * SCREEN - * * ERASE - * - * Canvas has more available depending on browser support. + * The angle of this Game Object as expressed in degrees. * - * You can also create your own custom Blend Modes in WebGL. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left + * and -90 is up. * - * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending - * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these - * reasons try to be careful about the construction of your Scene and the frequency of which blend modes - * are used. + * If you prefer to work in radians, see the `rotation` property instead. */ - blendMode: Phaser.BlendModes | string; + angle: number; /** - * Sets the Blend Mode being used by this Game Object. + * The angle of this Game Object in radians. * - * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. * - * Under WebGL only the following Blend Modes are available: + * If you prefer to work in degrees, see the `angle` property instead. + */ + rotation: number; + + /** + * Sets the position of this Game Object. + * @param x The x position of this Game Object. Default 0. + * @param y The y position of this Game Object. If not set it will use the `x` value. Default x. + * @param z The z position of this Game Object. Default 0. + * @param w The w position of this Game Object. Default 0. + */ + setPosition(x?: number, y?: number, z?: number, w?: number): this; + + /** + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; + + /** + * Sets the position of this Game Object to be a random position within the confines of + * the given area. * - * * ADD - * * MULTIPLY - * * SCREEN - * * ERASE (only works when rendering to a framebuffer, like a Render Texture) + * If no area is specified a random position between 0 x 0 and the game width x height is used instead. * - * Canvas has more available depending on browser support. + * The position does not factor in the size of this Game Object, meaning that only the origin is + * guaranteed to be within the area. + * @param x The x position of the top-left of the random area. Default 0. + * @param y The y position of the top-left of the random area. Default 0. + * @param width The width of the random area. + * @param height The height of the random area. + */ + setRandomPosition(x?: number, y?: number, width?: number, height?: number): this; + + /** + * Sets the rotation of this Game Object. + * @param radians The rotation of this Game Object, in radians. Default 0. + */ + setRotation(radians?: number): this; + + /** + * Sets the angle of this Game Object. + * @param degrees The rotation of this Game Object, in degrees. Default 0. + */ + setAngle(degrees?: number): this; + + /** + * Sets the scale of this Game Object. + * @param x The horizontal scale of this Game Object. + * @param y The vertical scale of this Game Object. If not set it will use the `x` value. Default x. + */ + setScale(x: number, y?: number): this; + + /** + * Sets the x position of this Game Object. + * @param value The x position of this Game Object. Default 0. + */ + setX(value?: number): this; + + /** + * Sets the y position of this Game Object. + * @param value The y position of this Game Object. Default 0. + */ + setY(value?: number): this; + + /** + * Sets the z position of this Game Object. * - * You can also create your own custom Blend Modes in WebGL. + * Note: The z position does not control the rendering order of 2D Game Objects. Use + * {@link Phaser.GameObjects.Components.Depth#setDepth} instead. + * @param value The z position of this Game Object. Default 0. + */ + setZ(value?: number): this; + + /** + * Sets the w position of this Game Object. + * @param value The w position of this Game Object. Default 0. + */ + setW(value?: number): this; + + /** + * Gets the local transform matrix for this Game Object. + * @param tempMatrix The matrix to populate with the values from this Game Object. + */ + getLocalTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + + /** + * Gets the world transform matrix for this Game Object, factoring in any parent Containers. + * @param tempMatrix The matrix to populate with the values from this Game Object. + * @param parentMatrix A temporary matrix to hold parent values during the calculations. + */ + getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. * - * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending - * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these - * reasons try to be careful about the construction of your Scene and the frequency in which blend modes - * are used. - * @param value The BlendMode value. Either a string or a CONST. + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. */ - setBlendMode(value: string | Phaser.BlendModes): this; + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; /** - * The displayed width of this Game Object. + * Gets the sum total rotation of all of this Game Objects parent Containers. * - * This value takes into account the scale factor. + * The returned value is in radians and will be zero if this Game Object has no parent container. + */ + getParentRotation(): number; + + /** + * The visible state of the Game Object. * - * Setting this value will adjust the Game Object's scale property. + * An invisible Game Object will skip rendering, but will still process update logic. */ - displayWidth: number; + visible: boolean; /** - * The displayed height of this Game Object. + * Sets the visibility of this Game Object. * - * This value takes into account the scale factor. + * An invisible Game Object will skip rendering, but will still process update logic. + * @param value The visible state of the Game Object. + */ + setVisible(value: boolean): this; + + } + + /** + * A Sprite Game Object. + * + * A Sprite Game Object is used for the display of both static and animated images in your game. + * Sprites can have input events and physics bodies. They can also be tweened, tinted, scrolled + * and animated. + * + * The main difference between a Sprite and an Image Game Object is that you cannot animate Images. + * As such, Sprites take a fraction longer to process and have a larger API footprint due to the Animation + * Component. If you do not require animation then you can safely use Images to replace Sprites in all cases. + */ + class Sprite extends Phaser.GameObjects.GameObject implements Phaser.GameObjects.Components.Alpha, Phaser.GameObjects.Components.BlendMode, Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.Flip, Phaser.GameObjects.Components.GetBounds, Phaser.GameObjects.Components.Mask, Phaser.GameObjects.Components.Origin, Phaser.GameObjects.Components.Pipeline, Phaser.GameObjects.Components.ScrollFactor, Phaser.GameObjects.Components.Size, Phaser.GameObjects.Components.TextureCrop, Phaser.GameObjects.Components.Tint, Phaser.GameObjects.Components.Transform, Phaser.GameObjects.Components.Visible { + /** * - * Setting this value will adjust the Game Object's scale property. + * @param scene The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. + * @param x The horizontal position of this Game Object in the world. + * @param y The vertical position of this Game Object in the world. + * @param texture The key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager. + * @param frame An optional frame from the Texture this Game Object is rendering with. */ - displayHeight: number; + constructor(scene: Phaser.Scene, x: number, y: number, texture: string | Phaser.Textures.Texture, frame?: string | number); /** - * Sets the internal size of this Game Object, as used for frame or physics body creation. + * The Animation State component of this Sprite. * - * This will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or call the - * `setDisplaySize` method, which is the same thing as changing the scale but allows you - * to do so by giving pixel values. + * This component provides features to apply animations to this Sprite. + * It is responsible for playing, loading, queuing animations for later playback, + * mixing between animations and setting the current animation frame to this Sprite. + */ + anims: Phaser.Animations.AnimationState; + + /** + * Update this Sprite's animations. + * @param time The current timestamp. + * @param delta The delta time, in ms, elapsed since the last frame. + */ + protected preUpdate(time: number, delta: number): void; + + /** + * Start playing the given animation on this Sprite. * - * If you have enabled this Game Object for input, changing the size will _not_ change the - * size of the hit area. To do this you should adjust the `input.hitArea` object directly. - * @param width The width of this Game Object. - * @param height The height of this Game Object. + * Animations in Phaser can either belong to the global Animation Manager, or specifically to this Sprite. + * + * The benefit of a global animation is that multiple Sprites can all play the same animation, without + * having to duplicate the data. You can just create it once and then play it on any Sprite. + * + * The following code shows how to create a global repeating animation. The animation will be created + * from all of the frames within the sprite sheet that was loaded with the key 'muybridge': + * + * ```javascript + * var config = { + * key: 'run', + * frames: 'muybridge', + * frameRate: 15, + * repeat: -1 + * }; + * + * // This code should be run from within a Scene: + * this.anims.create(config); + * ``` + * + * However, if you wish to create an animation that is unique to this Sprite, and this Sprite alone, + * you can call the `Animation.create` method instead. It accepts the exact same parameters as when + * creating a global animation, however the resulting data is kept locally in this Sprite. + * + * With the animation created, either globally or locally, you can now play it on this Sprite: + * + * ```javascript + * this.add.sprite(x, y).play('run'); + * ``` + * + * Alternatively, if you wish to run it at a different frame rate, for example, you can pass a config + * object instead: + * + * ```javascript + * this.add.sprite(x, y).play({ key: 'run', frameRate: 24 }); + * ``` + * + * When playing an animation on a Sprite it will first check to see if it can find a matching key + * locally within the Sprite. If it can, it will play the local animation. If not, it will then + * search the global Animation Manager and look for it there. + * + * If you need a Sprite to be able to play both local and global animations, make sure they don't + * have conflicting keys. + * + * See the documentation for the `PlayAnimationConfig` config object for more details about this. + * + * Also, see the documentation in the Animation Manager for further details on creating animations. + * @param key The string-based key of the animation to play, or an Animation instance, or a `PlayAnimationConfig` object. + * @param ignoreIfPlaying If an animation is already playing then ignore this call. Default false. */ - setSize(width: number, height: number): this; + play(key: string | Phaser.Animations.Animation | Phaser.Types.Animations.PlayAnimationConfig, ignoreIfPlaying?: boolean): this; /** - * Sets the display size of this Game Object. + * Start playing the given animation on this Sprite, in reverse. * - * Calling this will adjust the scale. - * @param width The width of this Game Object. - * @param height The height of this Game Object. + * Animations in Phaser can either belong to the global Animation Manager, or specifically to this Sprite. + * + * The benefit of a global animation is that multiple Sprites can all play the same animation, without + * having to duplicate the data. You can just create it once and then play it on any Sprite. + * + * The following code shows how to create a global repeating animation. The animation will be created + * from all of the frames within the sprite sheet that was loaded with the key 'muybridge': + * + * ```javascript + * var config = { + * key: 'run', + * frames: 'muybridge', + * frameRate: 15, + * repeat: -1 + * }; + * + * // This code should be run from within a Scene: + * this.anims.create(config); + * ``` + * + * However, if you wish to create an animation that is unique to this Sprite, and this Sprite alone, + * you can call the `Animation.create` method instead. It accepts the exact same parameters as when + * creating a global animation, however the resulting data is kept locally in this Sprite. + * + * With the animation created, either globally or locally, you can now play it on this Sprite: + * + * ```javascript + * this.add.sprite(x, y).playReverse('run'); + * ``` + * + * Alternatively, if you wish to run it at a different frame rate, for example, you can pass a config + * object instead: + * + * ```javascript + * this.add.sprite(x, y).playReverse({ key: 'run', frameRate: 24 }); + * ``` + * + * When playing an animation on a Sprite it will first check to see if it can find a matching key + * locally within the Sprite. If it can, it will play the local animation. If not, it will then + * search the global Animation Manager and look for it there. + * + * If you need a Sprite to be able to play both local and global animations, make sure they don't + * have conflicting keys. + * + * See the documentation for the `PlayAnimationConfig` config object for more details about this. + * + * Also, see the documentation in the Animation Manager for further details on creating animations. + * @param key The string-based key of the animation to play, or an Animation instance, or a `PlayAnimationConfig` object. + * @param ignoreIfPlaying If an animation is already playing then ignore this call. Default false. */ - setDisplaySize(width: number, height: number): this; + playReverse(key: string | Phaser.Animations.Animation | Phaser.Types.Animations.PlayAnimationConfig, ignoreIfPlaying?: boolean): this; /** - * The Texture this Game Object is using to render with. + * Waits for the specified delay, in milliseconds, then starts playback of the given animation. + * + * If the animation _also_ has a delay value set in its config, it will be **added** to the delay given here. + * + * If an animation is already running and a new animation is given to this method, it will wait for + * the given delay before starting the new animation. + * + * If no animation is currently running, the given one begins after the delay. + * + * When playing an animation on a Sprite it will first check to see if it can find a matching key + * locally within the Sprite. If it can, it will play the local animation. If not, it will then + * search the global Animation Manager and look for it there. + * + * Prior to Phaser 3.50 this method was called 'delayedPlay'. + * @param key The string-based key of the animation to play, or an Animation instance, or a `PlayAnimationConfig` object. + * @param delay The delay, in milliseconds, to wait before starting the animation playing. */ - texture: Phaser.Textures.Texture | Phaser.Textures.CanvasTexture; + playAfterDelay(key: string | Phaser.Animations.Animation | Phaser.Types.Animations.PlayAnimationConfig, delay: number): this; /** - * The Texture Frame this Game Object is using to render with. + * Waits for the current animation to complete the `repeatCount` number of repeat cycles, then starts playback + * of the given animation. + * + * You can use this to ensure there are no harsh jumps between two sets of animations, i.e. going from an + * idle animation to a walking animation, by making them blend smoothly into each other. + * + * If no animation is currently running, the given one will start immediately. + * + * When playing an animation on a Sprite it will first check to see if it can find a matching key + * locally within the Sprite. If it can, it will play the local animation. If not, it will then + * search the global Animation Manager and look for it there. + * @param key The string-based key of the animation to play, or an Animation instance, or a `PlayAnimationConfig` object. + * @param repeatCount How many times should the animation repeat before the next one starts? Default 1. */ - frame: Phaser.Textures.Frame; + playAfterRepeat(key: string | Phaser.Animations.Animation | Phaser.Types.Animations.PlayAnimationConfig, repeatCount?: number): this; /** - * A boolean flag indicating if this Game Object is being cropped or not. - * You can toggle this at any time after `setCrop` has been called, to turn cropping on or off. - * Equally, calling `setCrop` with no arguments will reset the crop and disable it. + * Sets an animation, or an array of animations, to be played immediately after the current one completes or stops. + * + * The current animation must enter a 'completed' state for this to happen, i.e. finish all of its repeats, delays, etc, + * or have the `stop` method called directly on it. + * + * An animation set to repeat forever will never enter a completed state. + * + * You can chain a new animation at any point, including before the current one starts playing, during it, + * or when it ends (via its `animationcomplete` event). + * + * Chained animations are specific to a Game Object, meaning different Game Objects can have different chained + * animations without impacting the animation they're playing. + * + * Call this method with no arguments to reset all currently chained animations. + * + * When playing an animation on a Sprite it will first check to see if it can find a matching key + * locally within the Sprite. If it can, it will play the local animation. If not, it will then + * search the global Animation Manager and look for it there. + * @param key The string-based key of the animation to play, or an Animation instance, or a `PlayAnimationConfig` object, or an array of them. */ - isCropped: boolean; + chain(key: string | Phaser.Animations.Animation | Phaser.Types.Animations.PlayAnimationConfig | string[] | Phaser.Animations.Animation[] | Phaser.Types.Animations.PlayAnimationConfig[]): this; /** - * Applies a crop to a texture based Game Object, such as a Sprite or Image. + * Immediately stops the current animation from playing and dispatches the `ANIMATION_STOP` events. * - * The crop is a rectangle that limits the area of the texture frame that is visible during rendering. + * If no animation is playing, no event will be dispatched. * - * Cropping a Game Object does not change its size, dimensions, physics body or hit area, it just - * changes what is shown when rendered. + * If there is another animation queued (via the `chain` method) then it will start playing immediately. + */ + stop(): this; + + /** + * Stops the current animation from playing after the specified time delay, given in milliseconds. * - * The crop coordinates are relative to the texture frame, not the Game Object, meaning 0 x 0 is the top-left. + * It then dispatches the `ANIMATION_STOP` event. * - * Therefore, if you had a Game Object that had an 800x600 sized texture, and you wanted to show only the left - * half of it, you could call `setCrop(0, 0, 400, 600)`. + * If no animation is running, no events will be dispatched. * - * It is also scaled to match the Game Object scale automatically. Therefore a crop rect of 100x50 would crop - * an area of 200x100 when applied to a Game Object that had a scale factor of 2. + * If there is another animation in the queue (set via the `chain` method) then it will start playing, + * when the current one stops. + * @param delay The number of milliseconds to wait before stopping this animation. + */ + stopAfterDelay(delay: number): this; + + /** + * Stops the current animation from playing after the given number of repeats. * - * You can either pass in numeric values directly, or you can provide a single Rectangle object as the first argument. + * It then dispatches the `ANIMATION_STOP` event. * - * Call this method with no arguments at all to reset the crop, or toggle the property `isCropped` to `false`. + * If no animation is running, no events will be dispatched. * - * You should do this if the crop rectangle becomes the same size as the frame itself, as it will allow - * the renderer to skip several internal calculations. - * @param x The x coordinate to start the crop from. Or a Phaser.Geom.Rectangle object, in which case the rest of the arguments are ignored. - * @param y The y coordinate to start the crop from. - * @param width The width of the crop rectangle in pixels. - * @param height The height of the crop rectangle in pixels. + * If there is another animation in the queue (set via the `chain` method) then it will start playing, + * when the current one stops. + * @param repeatCount How many times should the animation repeat before stopping? Default 1. */ - setCrop(x?: number | Phaser.Geom.Rectangle, y?: number, width?: number, height?: number): this; + stopAfterRepeat(repeatCount?: number): this; + + /** + * Stops the current animation from playing when it next sets the given frame. + * If this frame doesn't exist within the animation it will not stop it from playing. + * + * It then dispatches the `ANIMATION_STOP` event. + * + * If no animation is running, no events will be dispatched. + * + * If there is another animation in the queue (set via the `chain` method) then it will start playing, + * when the current one stops. + * @param frame The frame to check before stopping this animation. + */ + stopOnFrame(frame: Phaser.Animations.AnimationFrame): this; + + /** + * Build a JSON representation of this Sprite. + */ + toJSON(): Phaser.Types.GameObjects.JSONGameObject; + + /** + * Clears all alpha values associated with this Game Object. + * + * Immediately sets the alpha levels back to 1 (fully opaque). + */ + clearAlpha(): this; + + /** + * Set the Alpha level of this Game Object. The alpha controls the opacity of the Game Object as it renders. + * Alpha values are provided as a float between 0, fully transparent, and 1, fully opaque. + * + * If your game is running under WebGL you can optionally specify four different alpha values, each of which + * correspond to the four corners of the Game Object. Under Canvas only the `topLeft` value given is used. + * @param topLeft The alpha value used for the top-left of the Game Object. If this is the only value given it's applied across the whole Game Object. Default 1. + * @param topRight The alpha value used for the top-right of the Game Object. WebGL only. + * @param bottomLeft The alpha value used for the bottom-left of the Game Object. WebGL only. + * @param bottomRight The alpha value used for the bottom-right of the Game Object. WebGL only. + */ + setAlpha(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; + + /** + * The alpha value of the Game Object. + * + * This is a global value, impacting the entire Game Object, not just a region of it. + */ + alpha: number; + + /** + * The alpha value starting from the top-left of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + */ + alphaTopLeft: number; + + /** + * The alpha value starting from the top-right of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + */ + alphaTopRight: number; + + /** + * The alpha value starting from the bottom-left of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + */ + alphaBottomLeft: number; + + /** + * The alpha value starting from the bottom-right of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + */ + alphaBottomRight: number; + + /** + * Sets the Blend Mode being used by this Game Object. + * + * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) + * + * Under WebGL only the following Blend Modes are available: + * + * * ADD + * * MULTIPLY + * * SCREEN + * * ERASE + * + * Canvas has more available depending on browser support. + * + * You can also create your own custom Blend Modes in WebGL. + * + * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending + * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these + * reasons try to be careful about the construction of your Scene and the frequency of which blend modes + * are used. + */ + blendMode: Phaser.BlendModes | string; + + /** + * Sets the Blend Mode being used by this Game Object. + * + * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) + * + * Under WebGL only the following Blend Modes are available: + * + * * ADD + * * MULTIPLY + * * SCREEN + * * ERASE (only works when rendering to a framebuffer, like a Render Texture) + * + * Canvas has more available depending on browser support. + * + * You can also create your own custom Blend Modes in WebGL. + * + * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending + * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these + * reasons try to be careful about the construction of your Scene and the frequency in which blend modes + * are used. + * @param value The BlendMode value. Either a string or a CONST. + */ + setBlendMode(value: string | Phaser.BlendModes): this; /** * The depth of this Game Object within the Scene. @@ -34377,7 +39285,7 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. @@ -34390,13 +39298,13 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. * @param value The depth of this Game Object. */ - setDepth(value: integer): this; + setDepth(value: number): this; /** * The horizontally flipped state of the Game Object. @@ -34572,6 +39480,8 @@ declare namespace Phaser { * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, * including this one. * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * * To create the mask you need to pass in a reference to a renderable Game Object. * A renderable Game Object is one that uses a texture to render with, such as an * Image, Sprite, Render Texture or BitmapText. @@ -34657,6 +39567,8 @@ declare namespace Phaser { /** * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. */ defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; @@ -34665,23 +39577,109 @@ declare namespace Phaser { */ pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + /** + * Does this Game Object have any Post Pipelines set? + */ + hasPostPipeline: boolean; + + /** + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. + */ + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; + + /** + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. + */ + pipelineData: object; + /** * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + */ + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; + + /** + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; + + /** + * Sets one, or more, Post Pipelines on this Game Object. + * + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; + + /** + * Adds an entry to the `pipelineData` object belonging to this Game Object. + * + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. */ - initPipeline(pipelineName?: string): boolean; + setPipelineData(key: string, value?: any): this; /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - setPipeline(pipelineName: string): this; + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; /** * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; + + /** + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPostPipeline(resetData?: boolean): void; + + /** + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - resetPipeline(): boolean; + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; /** * Gets the name of the WebGL Pipeline this Game Object is currently using. @@ -34748,102 +39746,256 @@ declare namespace Phaser { setScrollFactor(x: number, y?: number): this; /** - * Fill or additive? + * The native (un-scaled) width of this Game Object. + * + * Changing this value will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or use + * the `displayWidth` property. */ - tintFill: boolean; + width: number; /** - * Clears all tint values associated with this Game Object. + * The native (un-scaled) height of this Game Object. * - * Immediately sets the color values back to 0xffffff and the tint type to 'additive', - * which results in no visible change to the texture. + * Changing this value will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or use + * the `displayHeight` property. */ - clearTint(): this; + height: number; /** - * Sets an additive tint on this Game Object. - * - * The tint works by taking the pixel color values from the Game Objects texture, and then - * multiplying it by the color value of the tint. You can provide either one color value, - * in which case the whole Game Object will be tinted in that color. Or you can provide a color - * per corner. The colors are blended together across the extent of the Game Object. - * - * To modify the tint color once set, either call this method again with new values or use the - * `tint` property to set all colors at once. Or, use the properties `tintTopLeft`, `tintTopRight, - * `tintBottomLeft` and `tintBottomRight` to set the corner color values independently. + * The displayed width of this Game Object. * - * To remove a tint call `clearTint`. + * This value takes into account the scale factor. * - * To swap this from being an additive tint to a fill based tint set the property `tintFill` to `true`. - * @param topLeft The tint being applied to the top-left of the Game Object. If no other values are given this value is applied evenly, tinting the whole Game Object. Default 0xffffff. - * @param topRight The tint being applied to the top-right of the Game Object. - * @param bottomLeft The tint being applied to the bottom-left of the Game Object. - * @param bottomRight The tint being applied to the bottom-right of the Game Object. + * Setting this value will adjust the Game Object's scale property. */ - setTint(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; + displayWidth: number; /** - * Sets a fill-based tint on this Game Object. - * - * Unlike an additive tint, a fill-tint literally replaces the pixel colors from the texture - * with those in the tint. You can use this for effects such as making a player flash 'white' - * if hit by something. You can provide either one color value, in which case the whole - * Game Object will be rendered in that color. Or you can provide a color per corner. The colors - * are blended together across the extent of the Game Object. - * - * To modify the tint color once set, either call this method again with new values or use the - * `tint` property to set all colors at once. Or, use the properties `tintTopLeft`, `tintTopRight, - * `tintBottomLeft` and `tintBottomRight` to set the corner color values independently. + * The displayed height of this Game Object. * - * To remove a tint call `clearTint`. + * This value takes into account the scale factor. * - * To swap this from being a fill-tint to an additive tint set the property `tintFill` to `false`. - * @param topLeft The tint being applied to the top-left of the Game Object. If not other values are given this value is applied evenly, tinting the whole Game Object. Default 0xffffff. - * @param topRight The tint being applied to the top-right of the Game Object. - * @param bottomLeft The tint being applied to the bottom-left of the Game Object. - * @param bottomRight The tint being applied to the bottom-right of the Game Object. + * Setting this value will adjust the Game Object's scale property. */ - setTintFill(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; + displayHeight: number; /** - * The tint value being applied to the top-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * Sets the size of this Game Object to be that of the given Frame. + * + * This will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or call the + * `setDisplaySize` method, which is the same thing as changing the scale but allows you + * to do so by giving pixel values. + * + * If you have enabled this Game Object for input, changing the size will _not_ change the + * size of the hit area. To do this you should adjust the `input.hitArea` object directly. + * @param frame The frame to base the size of this Game Object on. */ - tintTopLeft: integer; + setSizeToFrame(frame: Phaser.Textures.Frame): this; /** - * The tint value being applied to the top-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * Sets the internal size of this Game Object, as used for frame or physics body creation. + * + * This will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or call the + * `setDisplaySize` method, which is the same thing as changing the scale but allows you + * to do so by giving pixel values. + * + * If you have enabled this Game Object for input, changing the size will _not_ change the + * size of the hit area. To do this you should adjust the `input.hitArea` object directly. + * @param width The width of this Game Object. + * @param height The height of this Game Object. */ - tintTopRight: integer; + setSize(width: number, height: number): this; /** - * The tint value being applied to the bottom-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * Sets the display size of this Game Object. + * + * Calling this will adjust the scale. + * @param width The width of this Game Object. + * @param height The height of this Game Object. */ - tintBottomLeft: integer; + setDisplaySize(width: number, height: number): this; /** - * The tint value being applied to the bottom-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * The Texture this Game Object is using to render with. */ - tintBottomRight: integer; + texture: Phaser.Textures.Texture | Phaser.Textures.CanvasTexture; /** - * The tint value being applied to the whole of the Game Object. - * This property is a setter-only. Use the properties `tintTopLeft` etc to read the current tint value. + * The Texture Frame this Game Object is using to render with. */ - tint: integer; + frame: Phaser.Textures.Frame; /** - * Does this Game Object have a tint applied to it or not? + * A boolean flag indicating if this Game Object is being cropped or not. + * You can toggle this at any time after `setCrop` has been called, to turn cropping on or off. + * Equally, calling `setCrop` with no arguments will reset the crop and disable it. */ - readonly isTinted: boolean; + isCropped: boolean; /** - * The x position of this Game Object. - */ - x: number; + * Applies a crop to a texture based Game Object, such as a Sprite or Image. + * + * The crop is a rectangle that limits the area of the texture frame that is visible during rendering. + * + * Cropping a Game Object does not change its size, dimensions, physics body or hit area, it just + * changes what is shown when rendered. + * + * The crop coordinates are relative to the texture frame, not the Game Object, meaning 0 x 0 is the top-left. + * + * Therefore, if you had a Game Object that had an 800x600 sized texture, and you wanted to show only the left + * half of it, you could call `setCrop(0, 0, 400, 600)`. + * + * It is also scaled to match the Game Object scale automatically. Therefore a crop rect of 100x50 would crop + * an area of 200x100 when applied to a Game Object that had a scale factor of 2. + * + * You can either pass in numeric values directly, or you can provide a single Rectangle object as the first argument. + * + * Call this method with no arguments at all to reset the crop, or toggle the property `isCropped` to `false`. + * + * You should do this if the crop rectangle becomes the same size as the frame itself, as it will allow + * the renderer to skip several internal calculations. + * @param x The x coordinate to start the crop from. Or a Phaser.Geom.Rectangle object, in which case the rest of the arguments are ignored. + * @param y The y coordinate to start the crop from. + * @param width The width of the crop rectangle in pixels. + * @param height The height of the crop rectangle in pixels. + */ + setCrop(x?: number | Phaser.Geom.Rectangle, y?: number, width?: number, height?: number): this; + + /** + * Sets the texture and frame this Game Object will use to render with. + * + * Textures are referenced by their string-based keys, as stored in the Texture Manager. + * @param key The key of the texture to be used, as stored in the Texture Manager. + * @param frame The name or index of the frame within the Texture. + */ + setTexture(key: string, frame?: string | number): this; + + /** + * Sets the frame this Game Object will use to render with. + * + * The Frame has to belong to the current Texture being used. + * + * It can be either a string or an index. + * + * Calling `setFrame` will modify the `width` and `height` properties of your Game Object. + * It will also change the `origin` if the Frame has a custom pivot point, as exported from packages like Texture Packer. + * @param frame The name or index of the frame within the Texture. + * @param updateSize Should this call adjust the size of the Game Object? Default true. + * @param updateOrigin Should this call adjust the origin of the Game Object? Default true. + */ + setFrame(frame: string | number, updateSize?: boolean, updateOrigin?: boolean): this; + + /** + * The tint value being applied to the top-left vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintTopLeft: number; + + /** + * The tint value being applied to the top-right vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintTopRight: number; + + /** + * The tint value being applied to the bottom-left vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintBottomLeft: number; + + /** + * The tint value being applied to the bottom-right vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintBottomRight: number; + + /** + * The tint fill mode. + * + * `false` = An additive tint (the default), where vertices colors are blended with the texture. + * `true` = A fill tint, where the vertices colors replace the texture, but respects texture alpha. + */ + tintFill: boolean; + + /** + * Clears all tint values associated with this Game Object. + * + * Immediately sets the color values back to 0xffffff and the tint type to 'additive', + * which results in no visible change to the texture. + */ + clearTint(): this; + + /** + * Sets an additive tint on this Game Object. + * + * The tint works by taking the pixel color values from the Game Objects texture, and then + * multiplying it by the color value of the tint. You can provide either one color value, + * in which case the whole Game Object will be tinted in that color. Or you can provide a color + * per corner. The colors are blended together across the extent of the Game Object. + * + * To modify the tint color once set, either call this method again with new values or use the + * `tint` property to set all colors at once. Or, use the properties `tintTopLeft`, `tintTopRight, + * `tintBottomLeft` and `tintBottomRight` to set the corner color values independently. + * + * To remove a tint call `clearTint`. + * + * To swap this from being an additive tint to a fill based tint set the property `tintFill` to `true`. + * @param topLeft The tint being applied to the top-left of the Game Object. If no other values are given this value is applied evenly, tinting the whole Game Object. Default 0xffffff. + * @param topRight The tint being applied to the top-right of the Game Object. + * @param bottomLeft The tint being applied to the bottom-left of the Game Object. + * @param bottomRight The tint being applied to the bottom-right of the Game Object. + */ + setTint(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; + + /** + * Sets a fill-based tint on this Game Object. + * + * Unlike an additive tint, a fill-tint literally replaces the pixel colors from the texture + * with those in the tint. You can use this for effects such as making a player flash 'white' + * if hit by something. You can provide either one color value, in which case the whole + * Game Object will be rendered in that color. Or you can provide a color per corner. The colors + * are blended together across the extent of the Game Object. + * + * To modify the tint color once set, either call this method again with new values or use the + * `tint` property to set all colors at once. Or, use the properties `tintTopLeft`, `tintTopRight, + * `tintBottomLeft` and `tintBottomRight` to set the corner color values independently. + * + * To remove a tint call `clearTint`. + * + * To swap this from being a fill-tint to an additive tint set the property `tintFill` to `false`. + * @param topLeft The tint being applied to the top-left of the Game Object. If not other values are given this value is applied evenly, tinting the whole Game Object. Default 0xffffff. + * @param topRight The tint being applied to the top-right of the Game Object. + * @param bottomLeft The tint being applied to the bottom-left of the Game Object. + * @param bottomRight The tint being applied to the bottom-right of the Game Object. + */ + setTintFill(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; + + /** + * The tint value being applied to the whole of the Game Object. + * This property is a setter-only. Use the properties `tintTopLeft` etc to read the current tint value. + */ + tint: number; + + /** + * Does this Game Object have a tint applied? + * + * It checks to see if the 4 tint properties are set to the value 0xffffff + * and that the `tintFill` property is `false`. This indicates that a Game Object isn't tinted. + */ + readonly isTinted: boolean; + + /** + * The x position of this Game Object. + */ + x: number; /** * The y position of this Game Object. @@ -34890,13 +40042,13 @@ declare namespace Phaser { * * If you prefer to work in radians, see the `rotation` property instead. */ - angle: integer; + angle: number; /** * The angle of this Game Object in radians. * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. * * If you prefer to work in degrees, see the `angle` property instead. */ @@ -34911,6 +40063,12 @@ declare namespace Phaser { */ setPosition(x?: number, y?: number, z?: number, w?: number): this; + /** + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; + /** * Sets the position of this Game Object to be a random position within the confines of * the given area. @@ -34985,6 +40143,22 @@ declare namespace Phaser { */ getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. + */ + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + /** * Gets the sum total rotation of all of this Game Objects parent Containers. * @@ -35010,174 +40184,183 @@ declare namespace Phaser { } /** - * A TextStyle class manages all of the style settings for a Text object. + * Returns an object containing dimensions of the Text object. + * @param text The Text object to calculate the size from. + * @param size The Text metrics to use when calculating the size. + * @param lines The lines of text to calculate the size from. + */ + function GetTextSize(text: Phaser.GameObjects.Text, size: Phaser.Types.GameObjects.Text.TextMetrics, lines: string[]): Phaser.Types.GameObjects.Text.GetTextSizeObject; + + /** + * Calculates the ascent, descent and fontSize of a given font style. + * @param textStyle The TextStyle object to measure. + */ + function MeasureText(textStyle: Phaser.GameObjects.TextStyle): Phaser.Types.GameObjects.Text.TextMetrics; + + /** + * A Text Game Object. * - * Text Game Objects create a TextStyle instance automatically, which is - * accessed via the `Text.style` property. You do not normally need to - * instantiate one yourself. + * Text objects work by creating their own internal hidden Canvas and then renders text to it using + * the standard Canvas `fillText` API. It then creates a texture from this canvas which is rendered + * to your game during the render pass. + * + * Because it uses the Canvas API you can take advantage of all the features this offers, such as + * applying gradient fills to the text, or strokes, shadows and more. You can also use custom fonts + * loaded externally, such as Google or TypeKit Web fonts. + * + * **Important:** The font name must be quoted if it contains certain combinations of digits or + * special characters, either when creating the Text object, or when setting the font via `setFont` + * or `setFontFamily`, e.g.: + * + * ```javascript + * this.add.text(0, 0, 'Hello World', { fontFamily: 'Georgia, "Goudy Bookletter 1911", Times, serif' }); + * ``` + * + * ```javascript + * this.add.text(0, 0, 'Hello World', { font: '"Press Start 2P"' }); + * ``` + * + * You can only display fonts that are currently loaded and available to the browser: therefore fonts must + * be pre-loaded. Phaser does not do ths for you, so you will require the use of a 3rd party font loader, + * or have the fonts ready available in the CSS on the page in which your Phaser game resides. + * + * See {@link http://www.jordanm.co.uk/tinytype this compatibility table} for the available default fonts + * across mobile browsers. + * + * A note on performance: Every time the contents of a Text object changes, i.e. changing the text being + * displayed, or the style of the text, it needs to remake the Text canvas, and if on WebGL, re-upload the + * new texture to the GPU. This can be an expensive operation if used often, or with large quantities of + * Text objects in your game. If you run into performance issues you would be better off using Bitmap Text + * instead, as it benefits from batching and avoids expensive Canvas API calls. */ - class TextStyle { + class Text extends Phaser.GameObjects.GameObject implements Phaser.GameObjects.Components.Alpha, Phaser.GameObjects.Components.BlendMode, Phaser.GameObjects.Components.ComputedSize, Phaser.GameObjects.Components.Crop, Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.Flip, Phaser.GameObjects.Components.GetBounds, Phaser.GameObjects.Components.Mask, Phaser.GameObjects.Components.Origin, Phaser.GameObjects.Components.Pipeline, Phaser.GameObjects.Components.ScrollFactor, Phaser.GameObjects.Components.Tint, Phaser.GameObjects.Components.Transform, Phaser.GameObjects.Components.Visible { /** * - * @param text The Text object that this TextStyle is styling. - * @param style The style settings to set. - */ - constructor(text: Phaser.GameObjects.Text, style: Phaser.Types.GameObjects.Text.TextStyle); - - /** - * The Text object that this TextStyle is styling. + * @param scene The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. + * @param x The horizontal position of this Game Object in the world. + * @param y The vertical position of this Game Object in the world. + * @param text The text this Text object will display. + * @param style The text style configuration object. */ - parent: Phaser.GameObjects.Text; + constructor(scene: Phaser.Scene, x: number, y: number, text: string | string[], style: Phaser.Types.GameObjects.Text.TextStyle); /** - * The font family. + * The renderer in use by this Text object. */ - fontFamily: string; + renderer: Phaser.Renderer.Canvas.CanvasRenderer | Phaser.Renderer.WebGL.WebGLRenderer; /** - * The font size. + * The canvas element that the text is rendered to. */ - fontSize: string; + canvas: HTMLCanvasElement; /** - * The font style. + * The context of the canvas element that the text is rendered to. */ - fontStyle: string; + context: CanvasRenderingContext2D; /** - * The background color. + * The Text Style object. + * + * Manages the style of this Text object. */ - backgroundColor: string; + style: Phaser.GameObjects.TextStyle; /** - * The text fill color. + * Whether to automatically round line positions. */ - color: string; + autoRound: boolean; /** - * The text stroke color. + * The Regular Expression that is used to split the text up into lines, in + * multi-line text. By default this is `/(?:\r\n|\r|\n)/`. + * You can change this RegExp to be anything else that you may need. */ - stroke: string; + splitRegExp: object; /** - * The text stroke thickness. + * Specify a padding value which is added to the line width and height when calculating the Text size. + * Allows you to add extra spacing if the browser is unable to accurately determine the true font dimensions. */ - strokeThickness: number; + padding: Phaser.Types.GameObjects.Text.TextPadding; /** - * The horizontal shadow offset. + * The width of this Text object. */ - shadowOffsetX: number; + width: number; /** - * The vertical shadow offset. + * The height of this Text object. */ - shadowOffsetY: number; + height: number; /** - * The shadow color. + * The line spacing value. + * This value is added to the font height to calculate the overall line height. + * Only has an effect if this Text object contains multiple lines of text. + * + * If you update this property directly, instead of using the `setLineSpacing` method, then + * be sure to call `updateText` after, or you won't see the change reflected in the Text object. */ - shadowColor: string; + lineSpacing: number; /** - * The shadow blur radius. + * Whether the text or its settings have changed and need updating. */ - shadowBlur: number; + dirty: boolean; /** - * Whether shadow stroke is enabled or not. + * Initialize right to left text. */ - shadowStroke: boolean; + initRTL(): void; /** - * Whether shadow fill is enabled or not. + * Greedy wrapping algorithm that will wrap words as the line grows longer than its horizontal + * bounds. + * @param text The text to perform word wrap detection against. */ - shadowFill: boolean; + runWordWrap(text: string): string; /** - * The text alignment. + * Advanced wrapping algorithm that will wrap words as the line grows longer than its horizontal + * bounds. Consecutive spaces will be collapsed and replaced with a single space. Lines will be + * trimmed of white space before processing. Throws an error if wordWrapWidth is less than a + * single character. + * @param text The text to perform word wrap detection against. + * @param context The Canvas Rendering Context. + * @param wordWrapWidth The word wrap width. */ - align: string; + advancedWordWrap(text: string, context: CanvasRenderingContext2D, wordWrapWidth: number): string; /** - * The maximum number of lines to draw. + * Greedy wrapping algorithm that will wrap words as the line grows longer than its horizontal + * bounds. Spaces are not collapsed and whitespace is not trimmed. + * @param text The text to perform word wrap detection against. + * @param context The Canvas Rendering Context. + * @param wordWrapWidth The word wrap width. */ - maxLines: integer; + basicWordWrap(text: string, context: CanvasRenderingContext2D, wordWrapWidth: number): string; /** - * The fixed width of the text. - * - * `0` means no fixed with. + * Runs the given text through this Text objects word wrapping and returns the results as an + * array, where each element of the array corresponds to a wrapped line of text. + * @param text The text for which the wrapping will be calculated. If unspecified, the Text objects current text will be used. */ - fixedWidth: number; + getWrappedText(text: string): string[]; /** - * The fixed height of the text. + * Set the text to display. * - * `0` means no fixed height. - */ - fixedHeight: number; - - /** - * The resolution the text is rendered to its internal canvas at. - * The default is 0, which means it will use the resolution set in the Game Config. - */ - resolution: number; - - /** - * Whether the text should render right to left. - */ - rtl: boolean; - - /** - * The test string to use when measuring the font. - */ - testString: string; - - /** - * The amount of horizontal padding added to the width of the text when calculating the font metrics. - */ - baselineX: number; - - /** - * The amount of vertical padding added to the height of the text when calculating the font metrics. + * An array of strings will be joined with `\n` line breaks. + * @param value The string, or array of strings, to be set as the content of this Text object. */ - baselineY: number; + setText(value: string | string[]): this; /** * Set the text style. * @param style The style settings to set. - * @param updateText Whether to update the text immediately. Default true. - * @param setDefaults Use the default values is not set, or the local values. Default false. - */ - setStyle(style: Phaser.Types.GameObjects.Text.TextStyle, updateText?: boolean, setDefaults?: boolean): Phaser.GameObjects.Text; - - /** - * Synchronize the font settings to the given Canvas Rendering Context. - * @param canvas The Canvas Element. - * @param context The Canvas Rendering Context. - */ - syncFont(canvas: HTMLCanvasElement, context: CanvasRenderingContext2D): void; - - /** - * Synchronize the text style settings to the given Canvas Rendering Context. - * @param canvas The Canvas Element. - * @param context The Canvas Rendering Context. - */ - syncStyle(canvas: HTMLCanvasElement, context: CanvasRenderingContext2D): void; - - /** - * Synchronize the shadow settings to the given Canvas Rendering Context. - * @param context The Canvas Rendering Context. - * @param enabled Whether shadows are enabled or not. - */ - syncShadow(context: CanvasRenderingContext2D, enabled: boolean): void; - - /** - * Update the style settings for the parent Text object. - * @param recalculateMetrics Whether to recalculate font and text metrics. */ - update(recalculateMetrics: boolean): Phaser.GameObjects.Text; + setStyle(style: object): this; /** * Set the font. @@ -35186,86 +40369,97 @@ declare namespace Phaser { * * If an object is given, the `fontFamily`, `fontSize` and `fontStyle` * properties of that object are set. + * + * **Important:** The font name must be quoted if it contains certain combinations of digits or + * special characters: + * + * ```javascript + * Text.setFont('"Press Start 2P"'); + * ``` + * + * Equally, if you wish to provide a list of fallback fonts, then you should ensure they are all + * quoted properly, too: + * + * ```javascript + * Text.setFont('Georgia, "Goudy Bookletter 1911", Times, serif'); + * ``` * @param font The font family or font settings to set. - * @param updateText Whether to update the text immediately. Default true. */ - setFont(font: string | object, updateText?: boolean): Phaser.GameObjects.Text; + setFont(font: string): this; /** * Set the font family. + * + * **Important:** The font name must be quoted if it contains certain combinations of digits or + * special characters: + * + * ```javascript + * Text.setFont('"Press Start 2P"'); + * ``` + * + * Equally, if you wish to provide a list of fallback fonts, then you should ensure they are all + * quoted properly, too: + * + * ```javascript + * Text.setFont('Georgia, "Goudy Bookletter 1911", Times, serif'); + * ``` * @param family The font family. */ - setFontFamily(family: string): Phaser.GameObjects.Text; - - /** - * Set the font style. - * @param style The font style. - */ - setFontStyle(style: string): Phaser.GameObjects.Text; + setFontFamily(family: string): this; /** * Set the font size. * @param size The font size. */ - setFontSize(size: number | string): Phaser.GameObjects.Text; + setFontSize(size: number): this; /** - * Set the test string to use when measuring the font. - * @param string The test string to use when measuring the font. + * Set the font style. + * @param style The font style. */ - setTestString(string: string): Phaser.GameObjects.Text; + setFontStyle(style: string): this; /** * Set a fixed width and height for the text. * * Pass in `0` for either of these parameters to disable fixed width or height respectively. - * @param width The fixed width to set. - * @param height The fixed height to set. + * @param width The fixed width to set. `0` disables fixed width. + * @param height The fixed height to set. `0` disables fixed height. */ - setFixedSize(width: number, height: number): Phaser.GameObjects.Text; + setFixedSize(width: number, height: number): this; /** * Set the background color. * @param color The background color. */ - setBackgroundColor(color: string): Phaser.GameObjects.Text; + setBackgroundColor(color: string): this; /** - * Set the text fill color. - * @param color The text fill color. + * Set the fill style to be used by the Text object. + * + * This can be any valid CanvasRenderingContext2D fillStyle value, such as + * a color (in hex, rgb, rgba, hsl or named values), a gradient or a pattern. + * + * See the [MDN fillStyle docs](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/fillStyle) for more details. + * @param color The text fill style. Can be any valid CanvasRenderingContext `fillStyle` value. */ - setFill(color: string): Phaser.GameObjects.Text; + setFill(color: string | any): this; /** * Set the text fill color. * @param color The text fill color. */ - setColor(color: string): Phaser.GameObjects.Text; - - /** - * Set the resolution used by the Text object. - * - * By default it will be set to match the resolution set in the Game Config, - * but you can override it via this method. It allows for much clearer text on High DPI devices, - * at the cost of memory because it uses larger internal Canvas textures for the Text. - * - * Please use with caution, as the more high res Text you have, the more memory it uses up. - * @param value The resolution for this Text object to use. - */ - setResolution(value: number): Phaser.GameObjects.Text; + setColor(color: string): this; /** * Set the stroke settings. * @param color The stroke color. * @param thickness The stroke thickness. */ - setStroke(color: string, thickness: number): Phaser.GameObjects.Text; + setStroke(color: string, thickness: number): this; /** * Set the shadow settings. - * - * Calling this method always re-measures the parent Text object, - * so only call it when you actually change the shadow settings. * @param x The horizontal shadow offset. Default 0. * @param y The vertical shadow offset. Default 0. * @param color The shadow color. Default '#000'. @@ -35273,61 +40467,57 @@ declare namespace Phaser { * @param shadowStroke Whether to stroke the shadow. Default false. * @param shadowFill Whether to fill the shadow. Default true. */ - setShadow(x?: number, y?: number, color?: string, blur?: number, shadowStroke?: boolean, shadowFill?: boolean): Phaser.GameObjects.Text; + setShadow(x?: number, y?: number, color?: string, blur?: number, shadowStroke?: boolean, shadowFill?: boolean): this; /** * Set the shadow offset. - * @param x The horizontal shadow offset. Default 0. - * @param y The vertical shadow offset. Default 0. + * @param x The horizontal shadow offset. + * @param y The vertical shadow offset. */ - setShadowOffset(x?: number, y?: number): Phaser.GameObjects.Text; + setShadowOffset(x: number, y: number): this; /** * Set the shadow color. - * @param color The shadow color. Default '#000'. + * @param color The shadow color. */ - setShadowColor(color?: string): Phaser.GameObjects.Text; + setShadowColor(color: string): this; /** * Set the shadow blur radius. - * @param blur The shadow blur radius. Default 0. + * @param blur The shadow blur radius. */ - setShadowBlur(blur?: number): Phaser.GameObjects.Text; + setShadowBlur(blur: number): this; /** * Enable or disable shadow stroke. * @param enabled Whether shadow stroke is enabled or not. */ - setShadowStroke(enabled: boolean): Phaser.GameObjects.Text; + setShadowStroke(enabled: boolean): this; /** * Enable or disable shadow fill. * @param enabled Whether shadow fill is enabled or not. */ - setShadowFill(enabled: boolean): Phaser.GameObjects.Text; + setShadowFill(enabled: boolean): this; /** - * Set the width (in pixels) to use for wrapping lines. - * - * Pass in null to remove wrapping by width. + * Set the width (in pixels) to use for wrapping lines. Pass in null to remove wrapping by width. * @param width The maximum width of a line in pixels. Set to null to remove wrapping. * @param useAdvancedWrap Whether or not to use the advanced wrapping * algorithm. If true, spaces are collapsed and whitespace is trimmed from lines. If false, * spaces and whitespace are left as is. Default false. */ - setWordWrapWidth(width: number, useAdvancedWrap?: boolean): Phaser.GameObjects.Text; + setWordWrapWidth(width: number, useAdvancedWrap?: boolean): this; /** - * Set a custom callback for wrapping lines. - * - * Pass in null to remove wrapping by callback. + * Set a custom callback for wrapping lines. Pass in null to remove wrapping by callback. * @param callback A custom function that will be responsible for wrapping the * text. It will receive two arguments: text (the string to wrap), textObject (this Text * instance). It should return the wrapped lines either as an array of lines or as a string with * newline characters in place to indicate where breaks should happen. * @param scope The scope that will be applied when the callback is invoked. Default null. */ - setWordWrapCallback(callback: TextStyleWordWrapCallback, scope?: object): Phaser.GameObjects.Text; + setWordWrapCallback(callback: TextStyleWordWrapCallback, scope?: object): this; /** * Set the alignment of the text in this Text object. @@ -35337,13 +40527,54 @@ declare namespace Phaser { * Alignment only works if the Text object has more than one line of text. * @param align The text alignment for multi-line text. Default 'left'. */ - setAlign(align?: string): Phaser.GameObjects.Text; + setAlign(align?: string): this; + + /** + * Set the resolution used by this Text object. + * + * By default it will be set to match the resolution set in the Game Config, + * but you can override it via this method, or by specifying it in the Text style configuration object. + * + * It allows for much clearer text on High DPI devices, at the cost of memory because it uses larger + * internal Canvas textures for the Text. + * + * Therefore, please use with caution, as the more high res Text you have, the more memory it uses. + * @param value The resolution for this Text object to use. + */ + setResolution(value: number): this; + + /** + * Sets the line spacing value. + * + * This value is _added_ to the height of the font when calculating the overall line height. + * This only has an effect if this Text object consists of multiple lines of text. + * @param value The amount to add to the font height to achieve the overall line height. + */ + setLineSpacing(value: number): this; + + /** + * Set the text padding. + * + * 'left' can be an object. + * + * If only 'left' and 'top' are given they are treated as 'x' and 'y'. + * @param left The left padding value, or a padding config object. + * @param top The top padding value. + * @param right The right padding value. + * @param bottom The bottom padding value. + */ + setPadding(left: number | Phaser.Types.GameObjects.Text.TextPadding, top?: number, right?: number, bottom?: number): this; /** * Set the maximum number of lines to draw. * @param max The maximum number of lines to draw. Default 0. */ - setMaxLines(max?: integer): Phaser.GameObjects.Text; + setMaxLines(max?: number): this; + + /** + * Update the displayed text. + */ + updateText(): this; /** * Get the current text metrics. @@ -35351,170 +40582,19 @@ declare namespace Phaser { getTextMetrics(): Phaser.Types.GameObjects.Text.TextMetrics; /** - * Build a JSON representation of this Text Style. + * The text string being rendered by this Text Game Object. */ - toJSON(): object; + text: string; /** - * Destroy this Text Style. + * Build a JSON representation of the Text object. */ - destroy(): void; + toJSON(): Phaser.Types.GameObjects.JSONGameObject; - } - - /** - * A TileSprite is a Sprite that has a repeating texture. - * - * The texture can be scrolled and scaled independently of the TileSprite itself. Textures will automatically wrap and - * are designed so that you can create game backdrops using seamless textures as a source. - * - * You shouldn't ever create a TileSprite any larger than your actual canvas size. If you want to create a large repeating background - * that scrolls across the whole map of your game, then you create a TileSprite that fits the canvas size and then use the `tilePosition` - * property to scroll the texture as the player moves. If you create a TileSprite that is thousands of pixels in size then it will - * consume huge amounts of memory and cause performance issues. Remember: use `tilePosition` to scroll your texture and `tileScale` to - * adjust the scale of the texture - don't resize the sprite itself or make it larger than it needs. - * - * An important note about Tile Sprites and NPOT textures: Internally, TileSprite textures use GL_REPEAT to provide - * seamless repeating of the textures. This, combined with the way in which the textures are handled in WebGL, means - * they need to be POT (power-of-two) sizes in order to wrap. If you provide a NPOT (non power-of-two) texture to a - * TileSprite it will generate a POT sized canvas and draw your texture to it, scaled up to the POT size. It's then - * scaled back down again during rendering to the original dimensions. While this works, in that it allows you to use - * any size texture for a Tile Sprite, it does mean that NPOT textures are going to appear anti-aliased when rendered, - * due to the interpolation that took place when it was resized into a POT texture. This is especially visible in - * pixel art graphics. If you notice it and it becomes an issue, the only way to avoid it is to ensure that you - * provide POT textures for Tile Sprites. - */ - class TileSprite extends Phaser.GameObjects.GameObject implements Phaser.GameObjects.Components.Alpha, Phaser.GameObjects.Components.BlendMode, Phaser.GameObjects.Components.ComputedSize, Phaser.GameObjects.Components.Crop, Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.Flip, Phaser.GameObjects.Components.GetBounds, Phaser.GameObjects.Components.Mask, Phaser.GameObjects.Components.Origin, Phaser.GameObjects.Components.Pipeline, Phaser.GameObjects.Components.ScrollFactor, Phaser.GameObjects.Components.Tint, Phaser.GameObjects.Components.Transform, Phaser.GameObjects.Components.Visible { - /** - * - * @param scene The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. - * @param x The horizontal position of this Game Object in the world. - * @param y The vertical position of this Game Object in the world. - * @param width The width of the Game Object. If zero it will use the size of the texture frame. - * @param height The height of the Game Object. If zero it will use the size of the texture frame. - * @param textureKey The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. - * @param frameKey An optional frame from the Texture this Game Object is rendering with. - */ - constructor(scene: Phaser.Scene, x: number, y: number, width: integer, height: integer, textureKey: string, frameKey?: string | integer); - - /** - * Whether the Tile Sprite has changed in some way, requiring an re-render of its tile texture. - * - * Such changes include the texture frame and scroll position of the Tile Sprite. - */ - dirty: boolean; - - /** - * The renderer in use by this Tile Sprite. - */ - renderer: Phaser.Renderer.Canvas.CanvasRenderer | Phaser.Renderer.WebGL.WebGLRenderer; - - /** - * The Canvas element that the TileSprite renders its fill pattern in to. - * Only used in Canvas mode. - */ - canvas: HTMLCanvasElement; - - /** - * The Context of the Canvas element that the TileSprite renders its fill pattern in to. - * Only used in Canvas mode. - */ - context: CanvasRenderingContext2D; - - /** - * The Texture this Game Object is using to render with. - */ - texture: Phaser.Textures.Texture | Phaser.Textures.CanvasTexture; - - /** - * The Texture Frame this Game Object is using to render with. - */ - frame: Phaser.Textures.Frame; - - /** - * The next power of two value from the width of the Fill Pattern frame. - */ - potWidth: integer; - - /** - * The next power of two value from the height of the Fill Pattern frame. - */ - potHeight: integer; - - /** - * The Canvas that the TileSprites texture is rendered to. - * This is used to create a WebGL texture from. - */ - fillCanvas: HTMLCanvasElement; - - /** - * The Canvas Context used to render the TileSprites texture. - */ - fillContext: CanvasRenderingContext2D; - - /** - * The texture that the Tile Sprite is rendered to, which is then rendered to a Scene. - * In WebGL this is a WebGLTexture. In Canvas it's a Canvas Fill Pattern. - */ - fillPattern: WebGLTexture | CanvasPattern; - - /** - * Sets the texture and frame this Game Object will use to render with. - * - * Textures are referenced by their string-based keys, as stored in the Texture Manager. - * @param key The key of the texture to be used, as stored in the Texture Manager. - * @param frame The name or index of the frame within the Texture. - */ - setTexture(key: string, frame?: string | integer): this; - - /** - * Sets the frame this Game Object will use to render with. - * - * The Frame has to belong to the current Texture being used. - * - * It can be either a string or an index. - * @param frame The name or index of the frame within the Texture. - */ - setFrame(frame: string | integer): this; - - /** - * Sets {@link Phaser.GameObjects.TileSprite#tilePositionX} and {@link Phaser.GameObjects.TileSprite#tilePositionY}. - * @param x The x position of this sprite's tiling texture. - * @param y The y position of this sprite's tiling texture. - */ - setTilePosition(x?: number, y?: number): this; - - /** - * Sets {@link Phaser.GameObjects.TileSprite#tileScaleX} and {@link Phaser.GameObjects.TileSprite#tileScaleY}. - * @param x The horizontal scale of the tiling texture. If not given it will use the current `tileScaleX` value. - * @param y The vertical scale of the tiling texture. If not given it will use the `x` value. Default x. - */ - setTileScale(x?: number, y?: number): this; - - /** - * Internal destroy handler, called as part of the destroy process. - */ - protected preDestroy(): void; - - /** - * The horizontal scroll position of the Tile Sprite. - */ - tilePositionX: number; - - /** - * The vertical scroll position of the Tile Sprite. - */ - tilePositionY: number; - - /** - * The horizontal scale of the Tile Sprite texture. - */ - tileScaleX: number; - - /** - * The vertical scale of the Tile Sprite texture. - */ - tileScaleY: number; + /** + * Internal destroy handler, called as part of the destroy process. + */ + protected preDestroy(): void; /** * Clears all alpha values associated with this Game Object. @@ -35614,24 +40694,6 @@ declare namespace Phaser { */ setBlendMode(value: string | Phaser.BlendModes): this; - /** - * The native (un-scaled) width of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayWidth` property. - */ - width: number; - - /** - * The native (un-scaled) height of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayHeight` property. - */ - height: number; - /** * The displayed width of this Game Object. * @@ -35674,6 +40736,16 @@ declare namespace Phaser { */ setDisplaySize(width: number, height: number): this; + /** + * The Texture this Game Object is using to render with. + */ + texture: Phaser.Textures.Texture | Phaser.Textures.CanvasTexture; + + /** + * The Texture Frame this Game Object is using to render with. + */ + frame: Phaser.Textures.Frame; + /** * A boolean flag indicating if this Game Object is being cropped or not. * You can toggle this at any time after `setCrop` has been called, to turn cropping on or off. @@ -35716,7 +40788,7 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. @@ -35729,13 +40801,13 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. * @param value The depth of this Game Object. */ - setDepth(value: integer): this; + setDepth(value: number): this; /** * The horizontally flipped state of the Game Object. @@ -35911,6 +40983,8 @@ declare namespace Phaser { * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, * including this one. * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * * To create the mask you need to pass in a reference to a renderable Game Object. * A renderable Game Object is one that uses a texture to render with, such as an * Image, Sprite, Render Texture or BitmapText. @@ -35996,6 +41070,8 @@ declare namespace Phaser { /** * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. */ defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; @@ -36004,23 +41080,109 @@ declare namespace Phaser { */ pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + /** + * Does this Game Object have any Post Pipelines set? + */ + hasPostPipeline: boolean; + + /** + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. + */ + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; + + /** + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. + */ + pipelineData: object; + /** * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + */ + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; + + /** + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; + + /** + * Sets one, or more, Post Pipelines on this Game Object. + * + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; + + /** + * Adds an entry to the `pipelineData` object belonging to this Game Object. + * + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. */ - initPipeline(pipelineName?: string): boolean; + setPipelineData(key: string, value?: any): this; /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - setPipeline(pipelineName: string): this; + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; /** * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; + + /** + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPostPipeline(resetData?: boolean): void; + + /** + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - resetPipeline(): boolean; + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; /** * Gets the name of the WebGL Pipeline this Game Object is currently using. @@ -36087,7 +41249,38 @@ declare namespace Phaser { setScrollFactor(x: number, y?: number): this; /** - * Fill or additive? + * The tint value being applied to the top-left vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintTopLeft: number; + + /** + * The tint value being applied to the top-right vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintTopRight: number; + + /** + * The tint value being applied to the bottom-left vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintBottomLeft: number; + + /** + * The tint value being applied to the bottom-right vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintBottomRight: number; + + /** + * The tint fill mode. + * + * `false` = An additive tint (the default), where vertices colors are blended with the texture. + * `true` = A fill tint, where the vertices colors replace the texture, but respects texture alpha. */ tintFill: boolean; @@ -36119,7 +41312,7 @@ declare namespace Phaser { * @param bottomLeft The tint being applied to the bottom-left of the Game Object. * @param bottomRight The tint being applied to the bottom-right of the Game Object. */ - setTint(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; + setTint(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; /** * Sets a fill-based tint on this Game Object. @@ -36142,40 +41335,19 @@ declare namespace Phaser { * @param bottomLeft The tint being applied to the bottom-left of the Game Object. * @param bottomRight The tint being applied to the bottom-right of the Game Object. */ - setTintFill(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; - - /** - * The tint value being applied to the top-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintTopLeft: integer; - - /** - * The tint value being applied to the top-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintTopRight: integer; - - /** - * The tint value being applied to the bottom-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintBottomLeft: integer; - - /** - * The tint value being applied to the bottom-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintBottomRight: integer; + setTintFill(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; /** * The tint value being applied to the whole of the Game Object. * This property is a setter-only. Use the properties `tintTopLeft` etc to read the current tint value. */ - tint: integer; + tint: number; /** - * Does this Game Object have a tint applied to it or not? + * Does this Game Object have a tint applied? + * + * It checks to see if the 4 tint properties are set to the value 0xffffff + * and that the `tintFill` property is `false`. This indicates that a Game Object isn't tinted. */ readonly isTinted: boolean; @@ -36229,13 +41401,13 @@ declare namespace Phaser { * * If you prefer to work in radians, see the `rotation` property instead. */ - angle: integer; + angle: number; /** * The angle of this Game Object in radians. * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. * * If you prefer to work in degrees, see the `angle` property instead. */ @@ -36250,6 +41422,12 @@ declare namespace Phaser { */ setPosition(x?: number, y?: number, z?: number, w?: number): this; + /** + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; + /** * Sets the position of this Game Object to be a random position within the confines of * the given area. @@ -36324,6 +41502,22 @@ declare namespace Phaser { */ getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. + */ + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + /** * Gets the sum total rotation of all of this Game Objects parent Containers. * @@ -36349,560 +41543,543 @@ declare namespace Phaser { } /** - * The Update List plugin. - * - * Update Lists belong to a Scene and maintain the list Game Objects to be updated every frame. + * A TextStyle class manages all of the style settings for a Text object. * - * Some or all of these Game Objects may also be part of the Scene's [Display List]{@link Phaser.GameObjects.DisplayList}, for Rendering. + * Text Game Objects create a TextStyle instance automatically, which is + * accessed via the `Text.style` property. You do not normally need to + * instantiate one yourself. */ - class UpdateList extends Phaser.Structs.ProcessQueue { + class TextStyle { /** * - * @param scene The Scene that the Update List belongs to. + * @param text The Text object that this TextStyle is styling. + * @param style The style settings to set. */ - constructor(scene: Phaser.Scene); + constructor(text: Phaser.GameObjects.Text, style: Phaser.Types.GameObjects.Text.TextStyle); /** - * The Scene that the Update List belongs to. + * The Text object that this TextStyle is styling. */ - scene: Phaser.Scene; + parent: Phaser.GameObjects.Text; /** - * The Scene's Systems. + * The font family. */ - systems: Phaser.Scenes.Systems; + fontFamily: string; /** - * The update step. - * - * Pre-updates every active Game Object in the list. - * @param time The current timestamp. - * @param delta The delta time elapsed since the last frame. + * The font size. */ - sceneUpdate(time: number, delta: number): void; + fontSize: string; /** - * The Scene that owns this plugin is shutting down. - * - * We need to kill and reset all internal properties as well as stop listening to Scene events. + * The font style. */ - shutdown(): void; + fontStyle: string; /** - * The Scene that owns this plugin is being destroyed. - * - * We need to shutdown and then kill off all external references. + * The background color. */ - destroy(): void; + backgroundColor: string; - } + /** + * The text fill color. + */ + color: string; - /** - * A Video Game Object. - * - * This Game Object is capable of handling playback of a previously loaded video from the Phaser Video Cache, - * or playing a video based on a given URL. Videos can be either local, or streamed. - * - * ```javascript - * preload () { - * this.load.video('pixar', 'nemo.mp4'); - * } - * - * create () { - * this.add.video(400, 300, 'pixar'); - * } - * ``` - * - * To all intents and purposes, a video is a standard Game Object, just like a Sprite. And as such, you can do - * all the usual things to it, such as scaling, rotating, cropping, tinting, making interactive, giving a - * physics body, etc. - * - * Transparent videos are also possible via the WebM file format. Providing the video file has was encoded with - * an alpha channel, and providing the browser supports WebM playback (not all of them do), then it will render - * in-game with full transparency. - * - * ### Autoplaying Videos - * - * Videos can only autoplay if the browser has been unlocked with an interaction, or satisfies the MEI settings. - * The policies that control autoplaying are vast and vary between browser. - * You can, ahd should, read more about it here: https://developer.mozilla.org/en-US/docs/Web/Media/Autoplay_guide - * - * If your video doesn't contain any audio, then set the `noAudio` parameter to `true` when the video is _loaded_, - * and it will often allow the video to play immediately: - * - * ```javascript - * preload () { - * this.load.video('pixar', 'nemo.mp4', 'loadeddata', false, true); - * } - * ``` - * - * The 5th parameter in the load call tells Phaser that the video doesn't contain any audio tracks. Video without - * audio can autoplay without requiring a user interaction. Video with audio cannot do this unless it satisfies - * the browsers MEI settings. See the MDN Autoplay Guide for further details. - * - * Note that due to a bug in IE11 you cannot play a video texture to a Sprite in WebGL. For IE11 force Canvas mode. - * - * More details about video playback and the supported media formats can be found on MDN: - * - * https://developer.mozilla.org/en-US/docs/Web/API/HTMLVideoElement - * https://developer.mozilla.org/en-US/docs/Web/Media/Formats - */ - class Video extends Phaser.GameObjects.GameObject implements Phaser.GameObjects.Components.Alpha, Phaser.GameObjects.Components.BlendMode, Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.Flip, Phaser.GameObjects.Components.GetBounds, Phaser.GameObjects.Components.Mask, Phaser.GameObjects.Components.Origin, Phaser.GameObjects.Components.Pipeline, Phaser.GameObjects.Components.ScrollFactor, Phaser.GameObjects.Components.Size, Phaser.GameObjects.Components.TextureCrop, Phaser.GameObjects.Components.Tint, Phaser.GameObjects.Components.Transform, Phaser.GameObjects.Components.Visible { /** - * - * @param scene The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. - * @param x The horizontal position of this Game Object in the world. - * @param y The vertical position of this Game Object in the world. - * @param key Optional key of the Video this Game Object will play, as stored in the Video Cache. + * The text stroke color. */ - constructor(scene: Phaser.Scene, x: number, y: number, key?: string); + stroke: string; /** - * A reference to the HTML Video Element this Video Game Object is playing. - * Will be `null` until a video is loaded for playback. + * The text stroke thickness. */ - video: HTMLVideoElement; + strokeThickness: number; /** - * The Phaser Texture this Game Object is using to render the video to. - * Will be `null` until a video is loaded for playback. + * The horizontal shadow offset. */ - videoTexture: Phaser.Textures.Texture; + shadowOffsetX: number; /** - * A reference to the TextureSource belong to the `videoTexture` Texture object. - * Will be `null` until a video is loaded for playback. + * The vertical shadow offset. */ - videoTextureSource: Phaser.Textures.TextureSource; + shadowOffsetY: number; /** - * A Phaser CanvasTexture instance that holds the most recent snapshot taken from the video. - * This will only be set if `snapshot` or `snapshotArea` have been called, and will be `null` until that point. + * The shadow color. */ - snapshotTexture: Phaser.Textures.CanvasTexture; + shadowColor: string; /** - * If you have saved this video to a texture via the `saveTexture` method, this controls if the video - * is rendered with `flipY` in WebGL or not. You often need to set this if you wish to use the video texture - * as the input source for a shader. If you find your video is appearing upside down within a shader or - * custom pipeline, flip this property. + * The shadow blur radius. */ - flipY: boolean; + shadowBlur: number; /** - * An internal flag holding the current state of the video lock, should document interaction be required - * before playback can begin. + * Whether shadow stroke is enabled or not. */ - touchLocked: boolean; + shadowStroke: boolean; /** - * Should the video auto play when document interaction is required and happens? + * Whether shadow fill is enabled or not. */ - playWhenUnlocked: boolean; + shadowFill: boolean; /** - * When starting playback of a video Phaser will monitor its `readyState` using a `setTimeout` call. - * The `setTimeout` happens once every `Video.retryInterval` ms. It will carry on monitoring the video - * state in this manner until the `retryLimit` is reached and then abort. + * The text alignment. */ - retryLimit: integer; + align: string; /** - * The current retry attempt. + * The maximum number of lines to draw. */ - retry: integer; + maxLines: number; /** - * The number of ms between each retry while monitoring the ready state of a downloading video. + * The fixed width of the text. + * + * `0` means no fixed with. */ - retryInterval: integer; + fixedWidth: number; /** - * An object containing in and out markers for sequence playback. + * The fixed height of the text. + * + * `0` means no fixed height. */ - markers: any; + fixedHeight: number; /** - * Should the Video element that this Video is using, be removed from the DOM - * when this Video is destroyed? + * The resolution the text is rendered to its internal canvas at. + * The default is 0, which means it will use the resolution set in the Game Config. */ - removeVideoElementOnDestroy: boolean; + resolution: number; /** - * Starts this video playing. - * - * If the video is already playing, or has been queued to play with `changeSource` then this method just returns. - * - * Videos can only autoplay if the browser has been unlocked. This happens if you have interacted with the browser, i.e. - * by clicking on it or pressing a key, or due to server settings. The policies that control autoplaying are vast and - * vary between browser. You can read more here: https://developer.mozilla.org/en-US/docs/Web/Media/Autoplay_guide - * - * If your video doesn't contain any audio, then set the `noAudio` parameter to `true` when the video is loaded, - * and it will often allow the video to play immediately: - * - * ```javascript - * preload () { - * this.load.video('pixar', 'nemo.mp4', 'loadeddata', false, true); - * } - * ``` - * - * The 5th parameter in the load call tells Phaser that the video doesn't contain any audio tracks. Video without - * audio can autoplay without requiring a user interaction. Video with audio cannot do this unless it satisfies - * the browsers MEI settings. See the MDN Autoplay Guide for details. - * - * If you need audio in your videos, then you'll have to consider the fact that the video cannot start playing until the - * user has interacted with the browser, into your game flow. - * @param loop Should the video loop automatically when it reaches the end? Please note that not all browsers support _seamless_ video looping for all encoding formats. Default false. - * @param markerIn Optional in marker time, in seconds, for playback of a sequence of the video. - * @param markerOut Optional out marker time, in seconds, for playback of a sequence of the video. + * Whether the text should render right to left. */ - play(loop?: boolean, markerIn?: integer, markerOut?: integer): this; + rtl: boolean; /** - * This method allows you to change the source of the current video element. It works by first stopping the - * current video, if playing. Then deleting the video texture, if one has been created. Finally, it makes a - * new video texture and starts playback of the new source through the existing video element. - * - * The reason you may wish to do this is because videos that require interaction to unlock, remain in an unlocked - * state, even if you change the source of the video. By changing the source to a new video you avoid having to - * go through the unlock process again. - * @param key The key of the Video this Game Object will swap to playing, as stored in the Video Cache. - * @param autoplay Should the video start playing immediately, once the swap is complete? Default true. - * @param loop Should the video loop automatically when it reaches the end? Please note that not all browsers support _seamless_ video looping for all encoding formats. Default false. - * @param markerIn Optional in marker time, in seconds, for playback of a sequence of the video. - * @param markerOut Optional out marker time, in seconds, for playback of a sequence of the video. + * The test string to use when measuring the font. */ - changeSource(key: string, autoplay?: boolean, loop?: boolean, markerIn?: integer, markerOut?: integer): this; + testString: string; /** - * Adds a sequence marker to this video. - * - * Markers allow you to split a video up into sequences, delineated by a start and end time, given in seconds. - * - * You can then play back specific markers via the `playMarker` method. - * - * Note that marker timing is _not_ frame-perfect. You should construct your videos in such a way that you allow for - * plenty of extra padding before and after each sequence to allow for discrepancies in browser seek and currentTime accuracy. - * - * See https://github.com/w3c/media-and-entertainment/issues/4 for more details about this issue. - * @param key A unique name to give this marker. - * @param markerIn The time, in seconds, representing the start of this marker. - * @param markerOut The time, in seconds, representing the end of this marker. + * The amount of horizontal padding added to the width of the text when calculating the font metrics. */ - addMarker(key: string, markerIn: integer, markerOut: integer): this; + baselineX: number; /** - * Plays a pre-defined sequence in this video. - * - * Markers allow you to split a video up into sequences, delineated by a start and end time, given in seconds and - * specified via the `addMarker` method. - * - * Note that marker timing is _not_ frame-perfect. You should construct your videos in such a way that you allow for - * plenty of extra padding before and after each sequence to allow for discrepancies in browser seek and currentTime accuracy. - * - * See https://github.com/w3c/media-and-entertainment/issues/4 for more details about this issue. - * @param key The name of the marker sequence to play. - * @param loop Should the video loop automatically when it reaches the end? Please note that not all browsers support _seamless_ video looping for all encoding formats. Default false. + * The amount of vertical padding added to the height of the text when calculating the font metrics. */ - playMarker(key: string, loop?: boolean): this; + baselineY: number; /** - * Removes a previously set marker from this video. - * - * If the marker is currently playing it will _not_ stop playback. - * @param key The name of the marker to remove. + * The maximum width of a line of text in pixels. Null means no line wrapping. Setting this + * property directly will not re-run the word wrapping algorithm. To change the width and + * re-wrap, use {@link Phaser.GameObjects.TextStyle#setWordWrapWidth}. */ - removeMarker(key: string): this; + wordWrapWidth: number | null; /** - * Takes a snapshot of the current frame of the video and renders it to a CanvasTexture object, - * which is then returned. You can optionally resize the grab by passing a width and height. - * - * This method returns a reference to the `Video.snapshotTexture` object. Calling this method - * multiple times will overwrite the previous snapshot with the most recent one. - * @param width The width of the resulting CanvasTexture. - * @param height The height of the resulting CanvasTexture. + * A custom function that will be responsible for wrapping the text. It will receive two + * arguments: text (the string to wrap), textObject (this Text instance). It should return + * the wrapped lines either as an array of lines or as a string with newline characters in + * place to indicate where breaks should happen. Setting this directly will not re-run the + * word wrapping algorithm. To change the callback and re-wrap, use + * {@link Phaser.GameObjects.TextStyle#setWordWrapCallback}. */ - snapshot(width?: integer, height?: integer): Phaser.Textures.CanvasTexture; + wordWrapCallback: TextStyleWordWrapCallback | null; /** - * Takes a snapshot of the specified area of the current frame of the video and renders it to a CanvasTexture object, - * which is then returned. You can optionally resize the grab by passing a different `destWidth` and `destHeight`. - * - * This method returns a reference to the `Video.snapshotTexture` object. Calling this method - * multiple times will overwrite the previous snapshot with the most recent one. - * @param x The horizontal location of the top-left of the area to grab from. Default 0. - * @param y The vertical location of the top-left of the area to grab from. Default 0. - * @param srcWidth The width of area to grab from the video. If not given it will grab the full video dimensions. - * @param srcHeight The height of area to grab from the video. If not given it will grab the full video dimensions. - * @param destWidth The destination width of the grab, allowing you to resize it. - * @param destHeight The destination height of the grab, allowing you to resize it. + * The scope that will be applied when the wordWrapCallback is invoked. Setting this directly will not re-run the + * word wrapping algorithm. To change the callback and re-wrap, use + * {@link Phaser.GameObjects.TextStyle#setWordWrapCallback}. */ - snapshotArea(x?: integer, y?: integer, srcWidth?: integer, srcHeight?: integer, destWidth?: integer, destHeight?: integer): Phaser.Textures.CanvasTexture; + wordWrapCallbackScope: object | null; /** - * Stores a copy of this Videos `snapshotTexture` in the Texture Manager using the given key. - * - * This texture is created when the `snapshot` or `snapshotArea` methods are called. - * - * After doing this, any texture based Game Object, such as a Sprite, can use the contents of the - * snapshot by using the texture key: - * - * ```javascript - * var vid = this.add.video(0, 0, 'intro'); - * - * vid.snapshot(); - * - * vid.saveSnapshotTexture('doodle'); - * - * this.add.image(400, 300, 'doodle'); - * ``` + * Whether or not to use the advanced wrapping algorithm. If true, spaces are collapsed and + * whitespace is trimmed from lines. If false, spaces and whitespace are left as is. Setting + * this property directly will not re-run the word wrapping algorithm. To change the + * advanced setting and re-wrap, use {@link Phaser.GameObjects.TextStyle#setWordWrapWidth}. + */ + wordWrapUseAdvanced: boolean; + + /** + * Set the text style. + * @param style The style settings to set. + * @param updateText Whether to update the text immediately. Default true. + * @param setDefaults Use the default values is not set, or the local values. Default false. + */ + setStyle(style: Phaser.Types.GameObjects.Text.TextStyle, updateText?: boolean, setDefaults?: boolean): Phaser.GameObjects.Text; + + /** + * Synchronize the font settings to the given Canvas Rendering Context. + * @param canvas The Canvas Element. + * @param context The Canvas Rendering Context. + */ + syncFont(canvas: HTMLCanvasElement, context: CanvasRenderingContext2D): void; + + /** + * Synchronize the text style settings to the given Canvas Rendering Context. + * @param canvas The Canvas Element. + * @param context The Canvas Rendering Context. + */ + syncStyle(canvas: HTMLCanvasElement, context: CanvasRenderingContext2D): void; + + /** + * Synchronize the shadow settings to the given Canvas Rendering Context. + * @param context The Canvas Rendering Context. + * @param enabled Whether shadows are enabled or not. + */ + syncShadow(context: CanvasRenderingContext2D, enabled: boolean): void; + + /** + * Update the style settings for the parent Text object. + * @param recalculateMetrics Whether to recalculate font and text metrics. + */ + update(recalculateMetrics: boolean): Phaser.GameObjects.Text; + + /** + * Set the font. * - * Updating the contents of the `snapshotTexture`, for example by calling `snapshot` again, - * will automatically update _any_ Game Object that is using it as a texture. - * Calling `saveSnapshotTexture` again will not save another copy of the same texture, - * it will just rename the existing one. + * If a string is given, the font family is set. * - * By default it will create a single base texture. You can add frames to the texture - * by using the `Texture.add` method. After doing this, you can then allow Game Objects - * to use a specific frame. - * @param key The unique key to store the texture as within the global Texture Manager. + * If an object is given, the `fontFamily`, `fontSize` and `fontStyle` + * properties of that object are set. + * @param font The font family or font settings to set. + * @param updateText Whether to update the text immediately. Default true. */ - saveSnapshotTexture(key: string): Phaser.Textures.CanvasTexture; + setFont(font: string | object, updateText?: boolean): Phaser.GameObjects.Text; /** - * Loads a Video from the given URL, ready for playback with the `Video.play` method. - * - * You can control at what point the browser determines the video as being ready for playback via - * the `loadEvent` parameter. See https://developer.mozilla.org/en-US/docs/Web/API/HTMLVideoElement - * for more details. - * @param url The URL of the video to load or be streamed. - * @param loadEvent The load event to listen for. Either `loadeddata`, `canplay` or `canplaythrough`. Default 'loadeddata'. - * @param noAudio Does the video have an audio track? If not you can enable auto-playing on it. Default false. + * Set the font family. + * @param family The font family. */ - loadURL(url: string, loadEvent?: string, noAudio?: boolean): this; + setFontFamily(family: string): Phaser.GameObjects.Text; /** - * Called when the video emits a `playing` event during load. - * - * This is only listened for if the browser doesn't support Promises. + * Set the font style. + * @param style The font style. */ - playHandler(): void; + setFontStyle(style: string): Phaser.GameObjects.Text; /** - * Called when the video completes playback, i.e. reaches an `ended` state. - * - * This will never happen if the video is coming from a live stream, where the duration is `Infinity`. + * Set the font size. + * @param size The font size. */ - completeHandler(): void; + setFontSize(size: number | string): Phaser.GameObjects.Text; /** - * Called when the video emits a `timeUpdate` event during playback. + * Set the test string to use when measuring the font. + * @param string The test string to use when measuring the font. + */ + setTestString(string: string): Phaser.GameObjects.Text; + + /** + * Set a fixed width and height for the text. * - * This event is too slow and irregular to be used for actual video timing or texture updating, - * but we can use it to determine if a video has looped. + * Pass in `0` for either of these parameters to disable fixed width or height respectively. + * @param width The fixed width to set. + * @param height The fixed height to set. */ - timeUpdateHandler(): void; + setFixedSize(width: number, height: number): Phaser.GameObjects.Text; /** - * Internal method that is called when enough video data has been received in order to create a texture - * from it. The texture is assigned to the `Video.videoTexture` property and given a base frame that - * encompases the whole video size. + * Set the background color. + * @param color The background color. */ - updateTexture(): void; + setBackgroundColor(color: string): Phaser.GameObjects.Text; /** - * Returns the key of the currently played video, as stored in the Video Cache. - * If the video did not come from the cache this will return an empty string. + * Set the text fill color. + * @param color The text fill color. */ - getVideoKey(): string; + setFill(color: string): Phaser.GameObjects.Text; /** - * Seeks to a given point in the video. The value is given as a float between 0 and 1, - * where 0 represents the start of the video and 1 represents the end. + * Set the text fill color. + * @param color The text fill color. + */ + setColor(color: string): Phaser.GameObjects.Text; + + /** + * Set the resolution used by the Text object. * - * Seeking only works if the video has a duration, so will not work for live streams. + * By default it will be set to match the resolution set in the Game Config, + * but you can override it via this method. It allows for much clearer text on High DPI devices, + * at the cost of memory because it uses larger internal Canvas textures for the Text. * - * When seeking begins, this video will emit a `seeking` event. When the video completes - * seeking (i.e. reaches its designated timestamp) it will emit a `seeked` event. + * Please use with caution, as the more high res Text you have, the more memory it uses up. + * @param value The resolution for this Text object to use. + */ + setResolution(value: number): Phaser.GameObjects.Text; + + /** + * Set the stroke settings. + * @param color The stroke color. + * @param thickness The stroke thickness. + */ + setStroke(color: string, thickness: number): Phaser.GameObjects.Text; + + /** + * Set the shadow settings. * - * If you wish to seek based on time instead, use the `Video.setCurrentTime` method. - * @param value The point in the video to seek to. A value between 0 and 1. + * Calling this method always re-measures the parent Text object, + * so only call it when you actually change the shadow settings. + * @param x The horizontal shadow offset. Default 0. + * @param y The vertical shadow offset. Default 0. + * @param color The shadow color. Default '#000'. + * @param blur The shadow blur radius. Default 0. + * @param shadowStroke Whether to stroke the shadow. Default false. + * @param shadowFill Whether to fill the shadow. Default true. */ - seekTo(value: number): this; + setShadow(x?: number, y?: number, color?: string, blur?: number, shadowStroke?: boolean, shadowFill?: boolean): Phaser.GameObjects.Text; /** - * A double-precision floating-point value indicating the current playback time in seconds. - * If the media has not started to play and has not been seeked, this value is the media's initial playback time. + * Set the shadow offset. + * @param x The horizontal shadow offset. Default 0. + * @param y The vertical shadow offset. Default 0. */ - getCurrentTime(): number; + setShadowOffset(x?: number, y?: number): Phaser.GameObjects.Text; /** - * Seeks to a given playback time in the video. The value is given in _seconds_ or as a string. + * Set the shadow color. + * @param color The shadow color. Default '#000'. + */ + setShadowColor(color?: string): Phaser.GameObjects.Text; + + /** + * Set the shadow blur radius. + * @param blur The shadow blur radius. Default 0. + */ + setShadowBlur(blur?: number): Phaser.GameObjects.Text; + + /** + * Enable or disable shadow stroke. + * @param enabled Whether shadow stroke is enabled or not. + */ + setShadowStroke(enabled: boolean): Phaser.GameObjects.Text; + + /** + * Enable or disable shadow fill. + * @param enabled Whether shadow fill is enabled or not. + */ + setShadowFill(enabled: boolean): Phaser.GameObjects.Text; + + /** + * Set the width (in pixels) to use for wrapping lines. * - * Seeking only works if the video has a duration, so will not work for live streams. + * Pass in null to remove wrapping by width. + * @param width The maximum width of a line in pixels. Set to null to remove wrapping. + * @param useAdvancedWrap Whether or not to use the advanced wrapping + * algorithm. If true, spaces are collapsed and whitespace is trimmed from lines. If false, + * spaces and whitespace are left as is. Default false. + */ + setWordWrapWidth(width: number, useAdvancedWrap?: boolean): Phaser.GameObjects.Text; + + /** + * Set a custom callback for wrapping lines. * - * When seeking begins, this video will emit a `seeking` event. When the video completes - * seeking (i.e. reaches its designated timestamp) it will emit a `seeked` event. + * Pass in null to remove wrapping by callback. + * @param callback A custom function that will be responsible for wrapping the + * text. It will receive two arguments: text (the string to wrap), textObject (this Text + * instance). It should return the wrapped lines either as an array of lines or as a string with + * newline characters in place to indicate where breaks should happen. + * @param scope The scope that will be applied when the callback is invoked. Default null. + */ + setWordWrapCallback(callback: TextStyleWordWrapCallback, scope?: object): Phaser.GameObjects.Text; + + /** + * Set the alignment of the text in this Text object. * - * You can provide a string prefixed with either a `+` or a `-`, such as `+2.5` or `-2.5`. - * In this case it will seek to +/- the value given, relative to the _current time_. + * The argument can be one of: `left`, `right`, `center` or `justify`. * - * If you wish to seek based on a duration percentage instead, use the `Video.seekTo` method. - * @param value The playback time to seek to in seconds. Can be expressed as a string, such as `+2` to seek 2 seconds ahead from the current time. + * Alignment only works if the Text object has more than one line of text. + * @param align The text alignment for multi-line text. Default 'left'. */ - setCurrentTime(value: string | number): this; + setAlign(align?: string): Phaser.GameObjects.Text; /** - * Returns a boolean indicating if this Video is currently seeking, or not. + * Set the maximum number of lines to draw. + * @param max The maximum number of lines to draw. Default 0. */ - isSeeking(): boolean; + setMaxLines(max?: number): Phaser.GameObjects.Text; /** - * Returns the current progress of the video. Progress is defined as a value between 0 (the start) - * and 1 (the end). + * Get the current text metrics. + */ + getTextMetrics(): Phaser.Types.GameObjects.Text.TextMetrics; + + /** + * Build a JSON representation of this Text Style. + */ + toJSON(): object; + + /** + * Destroy this Text Style. + */ + destroy(): void; + + } + + /** + * A TileSprite is a Sprite that has a repeating texture. + * + * The texture can be scrolled and scaled independently of the TileSprite itself. Textures will automatically wrap and + * are designed so that you can create game backdrops using seamless textures as a source. + * + * You shouldn't ever create a TileSprite any larger than your actual canvas size. If you want to create a large repeating background + * that scrolls across the whole map of your game, then you create a TileSprite that fits the canvas size and then use the `tilePosition` + * property to scroll the texture as the player moves. If you create a TileSprite that is thousands of pixels in size then it will + * consume huge amounts of memory and cause performance issues. Remember: use `tilePosition` to scroll your texture and `tileScale` to + * adjust the scale of the texture - don't resize the sprite itself or make it larger than it needs. + * + * An important note about Tile Sprites and NPOT textures: Internally, TileSprite textures use GL_REPEAT to provide + * seamless repeating of the textures. This, combined with the way in which the textures are handled in WebGL, means + * they need to be POT (power-of-two) sizes in order to wrap. If you provide a NPOT (non power-of-two) texture to a + * TileSprite it will generate a POT sized canvas and draw your texture to it, scaled up to the POT size. It's then + * scaled back down again during rendering to the original dimensions. While this works, in that it allows you to use + * any size texture for a Tile Sprite, it does mean that NPOT textures are going to appear anti-aliased when rendered, + * due to the interpolation that took place when it was resized into a POT texture. This is especially visible in + * pixel art graphics. If you notice it and it becomes an issue, the only way to avoid it is to ensure that you + * provide POT textures for Tile Sprites. + */ + class TileSprite extends Phaser.GameObjects.GameObject implements Phaser.GameObjects.Components.Alpha, Phaser.GameObjects.Components.BlendMode, Phaser.GameObjects.Components.ComputedSize, Phaser.GameObjects.Components.Crop, Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.Flip, Phaser.GameObjects.Components.GetBounds, Phaser.GameObjects.Components.Mask, Phaser.GameObjects.Components.Origin, Phaser.GameObjects.Components.Pipeline, Phaser.GameObjects.Components.ScrollFactor, Phaser.GameObjects.Components.Tint, Phaser.GameObjects.Components.Transform, Phaser.GameObjects.Components.Visible { + /** * - * Progress can only be returned if the video has a duration, otherwise it will always return zero. + * @param scene The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. + * @param x The horizontal position of this Game Object in the world. + * @param y The vertical position of this Game Object in the world. + * @param width The width of the Game Object. If zero it will use the size of the texture frame. + * @param height The height of the Game Object. If zero it will use the size of the texture frame. + * @param textureKey The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. + * @param frameKey An optional frame from the Texture this Game Object is rendering with. */ - getProgress(): number; + constructor(scene: Phaser.Scene, x: number, y: number, width: number, height: number, textureKey: string, frameKey?: string | number); /** - * A double-precision floating-point value which indicates the duration (total length) of the media in seconds, - * on the media's timeline. If no media is present on the element, or the media is not valid, the returned value is NaN. + * Whether the Tile Sprite has changed in some way, requiring an re-render of its tile texture. * - * If the media has no known end (such as for live streams of unknown duration, web radio, media incoming from WebRTC, - * and so forth), this value is +Infinity. + * Such changes include the texture frame and scroll position of the Tile Sprite. */ - getDuration(): number; + dirty: boolean; /** - * Sets the muted state of the currently playing video, if one is loaded. - * @param value The mute value. `true` if the video should be muted, otherwise `false`. Default true. + * The renderer in use by this Tile Sprite. */ - setMute(value?: boolean): this; + renderer: Phaser.Renderer.Canvas.CanvasRenderer | Phaser.Renderer.WebGL.WebGLRenderer; /** - * Returns a boolean indicating if this Video is currently muted. + * The Canvas element that the TileSprite renders its fill pattern in to. + * Only used in Canvas mode. */ - isMuted(): boolean; + canvas: HTMLCanvasElement; /** - * Sets the paused state of the currently loaded video. - * - * If the video is playing, calling this method with `true` will pause playback. - * If the video is paused, calling this method with `false` will resume playback. - * - * If no video is loaded, this method does nothing. - * @param value The paused value. `true` if the video should be paused, `false` to resume it. Default true. + * The Context of the Canvas element that the TileSprite renders its fill pattern in to. + * Only used in Canvas mode. */ - setPaused(value?: boolean): this; + context: CanvasRenderingContext2D; /** - * Returns a double indicating the audio volume, from 0.0 (silent) to 1.0 (loudest). + * The Texture this Game Object is using to render with. */ - getVolume(): number; + texture: Phaser.Textures.Texture | Phaser.Textures.CanvasTexture; /** - * Sets the volume of the currently playing video. - * - * The value given is a double indicating the audio volume, from 0.0 (silent) to 1.0 (loudest). - * @param value A double indicating the audio volume, from 0.0 (silent) to 1.0 (loudest). Default 1. + * The Texture Frame this Game Object is using to render with. */ - setVolume(value?: number): this; + frame: Phaser.Textures.Frame; /** - * Returns a double that indicates the rate at which the media is being played back. + * The next power of two value from the width of the Fill Pattern frame. */ - getPlaybackRate(): number; + potWidth: number; /** - * Sets the playback rate of the current video. - * - * The value given is a double that indicates the rate at which the media is being played back. - * @param rate A double that indicates the rate at which the media is being played back. + * The next power of two value from the height of the Fill Pattern frame. */ - setPlaybackRate(rate?: number): this; + potHeight: number; /** - * Returns a boolean which indicates whether the media element should start over when it reaches the end. + * The Canvas that the TileSprites texture is rendered to. + * This is used to create a WebGL texture from. */ - getLoop(): boolean; + fillCanvas: HTMLCanvasElement; /** - * Sets the loop state of the current video. + * The Canvas Context used to render the TileSprites texture. + */ + fillContext: CanvasRenderingContext2D; + + /** + * The texture that the Tile Sprite is rendered to, which is then rendered to a Scene. + * In WebGL this is a WebGLTexture. In Canvas it's a Canvas Fill Pattern. + */ + fillPattern: WebGLTexture | CanvasPattern; + + /** + * Sets the texture and frame this Game Object will use to render with. * - * The value given is a boolean which indicates whether the media element will start over when it reaches the end. + * Textures are referenced by their string-based keys, as stored in the Texture Manager. + * @param key The key of the texture to be used, as stored in the Texture Manager. + * @param frame The name or index of the frame within the Texture. + */ + setTexture(key: string, frame?: string | number): this; + + /** + * Sets the frame this Game Object will use to render with. * - * Not all videos can loop, for example live streams. + * The Frame has to belong to the current Texture being used. * - * Please note that not all browsers support _seamless_ video looping for all encoding formats. - * @param value A boolean which indicates whether the media element will start over when it reaches the end. Default true. + * It can be either a string or an index. + * @param frame The name or index of the frame within the Texture. */ - setLoop(value?: boolean): this; + setFrame(frame: string | number): this; /** - * Returns a boolean which indicates whether the video is currently playing. + * Sets {@link Phaser.GameObjects.TileSprite#tilePositionX} and {@link Phaser.GameObjects.TileSprite#tilePositionY}. + * @param x The x position of this sprite's tiling texture. + * @param y The y position of this sprite's tiling texture. */ - isPlaying(): boolean; + setTilePosition(x?: number, y?: number): this; /** - * Returns a boolean which indicates whether the video is currently paused. + * Sets {@link Phaser.GameObjects.TileSprite#tileScaleX} and {@link Phaser.GameObjects.TileSprite#tileScaleY}. + * @param x The horizontal scale of the tiling texture. If not given it will use the current `tileScaleX` value. + * @param y The vertical scale of the tiling texture. If not given it will use the `x` value. Default x. */ - isPaused(): boolean; + setTileScale(x?: number, y?: number): this; /** - * Stores this Video in the Texture Manager using the given key as a dynamic texture, - * which any texture-based Game Object, such as a Sprite, can use as its texture: - * - * ```javascript - * var vid = this.add.video(0, 0, 'intro'); - * - * vid.play(); - * - * vid.saveTexture('doodle'); - * - * this.add.image(400, 300, 'doodle'); - * ``` - * - * The saved texture is automatically updated as the video plays. If you pause this video, - * or change its source, then the saved texture updates instantly. - * - * Calling `saveTexture` again will not save another copy of the same texture, it will just rename the existing one. - * - * By default it will create a single base texture. You can add frames to the texture - * by using the `Texture.add` method. After doing this, you can then allow Game Objects - * to use a specific frame. - * - * If you intend to save the texture so you can use it as the input for a Shader, you may need to set the - * `flipY` parameter to `true` if you find the video renders upside down in your shader. - * @param key The unique key to store the texture as within the global Texture Manager. - * @param flipY Should the WebGL Texture set `UNPACK_MULTIPLY_FLIP_Y` during upload? Default false. + * Internal destroy handler, called as part of the destroy process. */ - saveTexture(key: string, flipY?: boolean): Phaser.Textures.Texture; + protected preDestroy(): void; /** - * Stops the video playing and clears all internal event listeners. - * - * If you only wish to pause playback of the video, and resume it a later time, use the `Video.pause` method instead. - * - * If the video hasn't finished downloading, calling this method will not abort the download. To do that you need to - * call `destroy` instead. + * The horizontal scroll position of the Tile Sprite. */ - stop(): this; + tilePositionX: number; /** - * Removes the Video element from the DOM by calling parentNode.removeChild on itself. - * - * Also removes the autoplay and src attributes and nulls the Video reference. - * - * You should not call this method if you were playing a video from the Video Cache that - * you wish to play again in your game, or if another Video object is also using the same - * video. - * - * If you loaded an external video via `Video.loadURL` then you should call this function - * to clear up once you are done with the instance. + * The vertical scroll position of the Tile Sprite. */ - removeVideoElement(): void; + tilePositionY: number; + + /** + * The horizontal scale of the Tile Sprite texture. + */ + tileScaleX: number; + + /** + * The vertical scale of the Tile Sprite texture. + */ + tileScaleY: number; /** * Clears all alpha values associated with this Game Object. @@ -37003,68 +42180,173 @@ declare namespace Phaser { setBlendMode(value: string | Phaser.BlendModes): this; /** - * The depth of this Game Object within the Scene. - * - * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order - * of Game Objects, without actually moving their position in the display list. - * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth - * value will always render in front of one with a lower value. + * The native (un-scaled) width of this Game Object. * - * Setting the depth will queue a depth sort event within the Scene. + * Changing this value will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or use + * the `displayWidth` property. */ - depth: number; + width: number; /** - * The depth of this Game Object within the Scene. - * - * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order - * of Game Objects, without actually moving their position in the display list. - * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth - * value will always render in front of one with a lower value. + * The native (un-scaled) height of this Game Object. * - * Setting the depth will queue a depth sort event within the Scene. - * @param value The depth of this Game Object. + * Changing this value will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or use + * the `displayHeight` property. */ - setDepth(value: integer): this; + height: number; /** - * The horizontally flipped state of the Game Object. + * The displayed width of this Game Object. * - * A Game Object that is flipped horizontally will render inversed on the horizontal axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * This value takes into account the scale factor. + * + * Setting this value will adjust the Game Object's scale property. */ - flipX: boolean; + displayWidth: number; /** - * Toggles the horizontal flipped state of this Game Object. + * The displayed height of this Game Object. * - * A Game Object that is flipped horizontally will render inversed on the horizontal axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * This value takes into account the scale factor. + * + * Setting this value will adjust the Game Object's scale property. */ - toggleFlipX(): this; + displayHeight: number; /** - * Toggles the vertical flipped state of this Game Object. + * Sets the internal size of this Game Object, as used for frame or physics body creation. + * + * This will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or call the + * `setDisplaySize` method, which is the same thing as changing the scale but allows you + * to do so by giving pixel values. + * + * If you have enabled this Game Object for input, changing the size will _not_ change the + * size of the hit area. To do this you should adjust the `input.hitArea` object directly. + * @param width The width of this Game Object. + * @param height The height of this Game Object. */ - toggleFlipY(): this; + setSize(width: number, height: number): this; /** - * Sets the horizontal flipped state of this Game Object. + * Sets the display size of this Game Object. * - * A Game Object that is flipped horizontally will render inversed on the horizontal axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. - * @param value The flipped state. `false` for no flip, or `true` to be flipped. + * Calling this will adjust the scale. + * @param width The width of this Game Object. + * @param height The height of this Game Object. */ - setFlipX(value: boolean): this; + setDisplaySize(width: number, height: number): this; /** - * Sets the vertical flipped state of this Game Object. - * @param value The flipped state. `false` for no flip, or `true` to be flipped. + * A boolean flag indicating if this Game Object is being cropped or not. + * You can toggle this at any time after `setCrop` has been called, to turn cropping on or off. + * Equally, calling `setCrop` with no arguments will reset the crop and disable it. + */ + isCropped: boolean; + + /** + * Applies a crop to a texture based Game Object, such as a Sprite or Image. + * + * The crop is a rectangle that limits the area of the texture frame that is visible during rendering. + * + * Cropping a Game Object does not change its size, dimensions, physics body or hit area, it just + * changes what is shown when rendered. + * + * The crop coordinates are relative to the texture frame, not the Game Object, meaning 0 x 0 is the top-left. + * + * Therefore, if you had a Game Object that had an 800x600 sized texture, and you wanted to show only the left + * half of it, you could call `setCrop(0, 0, 400, 600)`. + * + * It is also scaled to match the Game Object scale automatically. Therefore a crop rect of 100x50 would crop + * an area of 200x100 when applied to a Game Object that had a scale factor of 2. + * + * You can either pass in numeric values directly, or you can provide a single Rectangle object as the first argument. + * + * Call this method with no arguments at all to reset the crop, or toggle the property `isCropped` to `false`. + * + * You should do this if the crop rectangle becomes the same size as the frame itself, as it will allow + * the renderer to skip several internal calculations. + * @param x The x coordinate to start the crop from. Or a Phaser.Geom.Rectangle object, in which case the rest of the arguments are ignored. + * @param y The y coordinate to start the crop from. + * @param width The width of the crop rectangle in pixels. + * @param height The height of the crop rectangle in pixels. + */ + setCrop(x?: number | Phaser.Geom.Rectangle, y?: number, width?: number, height?: number): this; + + /** + * The depth of this Game Object within the Scene. + * + * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order + * of Game Objects, without actually moving their position in the display list. + * + * The default depth is zero. A Game Object with a higher depth + * value will always render in front of one with a lower value. + * + * Setting the depth will queue a depth sort event within the Scene. + */ + depth: number; + + /** + * The depth of this Game Object within the Scene. + * + * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order + * of Game Objects, without actually moving their position in the display list. + * + * The default depth is zero. A Game Object with a higher depth + * value will always render in front of one with a lower value. + * + * Setting the depth will queue a depth sort event within the Scene. + * @param value The depth of this Game Object. + */ + setDepth(value: number): this; + + /** + * The horizontally flipped state of the Game Object. + * + * A Game Object that is flipped horizontally will render inversed on the horizontal axis. + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + */ + flipX: boolean; + + /** + * The vertically flipped state of the Game Object. + * + * A Game Object that is flipped vertically will render inversed on the vertical axis (i.e. upside down) + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + */ + flipY: boolean; + + /** + * Toggles the horizontal flipped state of this Game Object. + * + * A Game Object that is flipped horizontally will render inversed on the horizontal axis. + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + */ + toggleFlipX(): this; + + /** + * Toggles the vertical flipped state of this Game Object. + */ + toggleFlipY(): this; + + /** + * Sets the horizontal flipped state of this Game Object. + * + * A Game Object that is flipped horizontally will render inversed on the horizontal axis. + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * @param value The flipped state. `false` for no flip, or `true` to be flipped. + */ + setFlipX(value: boolean): this; + + /** + * Sets the vertical flipped state of this Game Object. + * @param value The flipped state. `false` for no flip, or `true` to be flipped. */ setFlipY(value: boolean): this; @@ -37194,6 +42476,8 @@ declare namespace Phaser { * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, * including this one. * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * * To create the mask you need to pass in a reference to a renderable Game Object. * A renderable Game Object is one that uses a texture to render with, such as an * Image, Sprite, Render Texture or BitmapText. @@ -37279,6 +42563,8 @@ declare namespace Phaser { /** * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. */ defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; @@ -37287,23 +42573,109 @@ declare namespace Phaser { */ pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + /** + * Does this Game Object have any Post Pipelines set? + */ + hasPostPipeline: boolean; + + /** + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. + */ + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; + + /** + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. + */ + pipelineData: object; + /** * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + */ + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; + + /** + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. */ - initPipeline(pipelineName?: string): boolean; + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. + * Sets one, or more, Post Pipelines on this Game Object. + * + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; + + /** + * Adds an entry to the `pipelineData` object belonging to this Game Object. + * + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. */ - setPipeline(pipelineName: string): this; + setPipelineData(key: string, value?: any): this; + + /** + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. + */ + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; /** * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; + + /** + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPostPipeline(resetData?: boolean): void; + + /** + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - resetPipeline(): boolean; + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; /** * Gets the name of the WebGL Pipeline this Game Object is currently using. @@ -37370,151 +42742,38 @@ declare namespace Phaser { setScrollFactor(x: number, y?: number): this; /** - * The native (un-scaled) width of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayWidth` property. - */ - width: number; - - /** - * The native (un-scaled) height of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayHeight` property. - */ - height: number; - - /** - * The displayed width of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. - */ - displayWidth: number; - - /** - * The displayed height of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. - */ - displayHeight: number; - - /** - * Sets the size of this Game Object to be that of the given Frame. - * - * This will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or call the - * `setDisplaySize` method, which is the same thing as changing the scale but allows you - * to do so by giving pixel values. - * - * If you have enabled this Game Object for input, changing the size will _not_ change the - * size of the hit area. To do this you should adjust the `input.hitArea` object directly. - * @param frame The frame to base the size of this Game Object on. - */ - setSizeToFrame(frame: Phaser.Textures.Frame): this; - - /** - * Sets the internal size of this Game Object, as used for frame or physics body creation. - * - * This will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or call the - * `setDisplaySize` method, which is the same thing as changing the scale but allows you - * to do so by giving pixel values. - * - * If you have enabled this Game Object for input, changing the size will _not_ change the - * size of the hit area. To do this you should adjust the `input.hitArea` object directly. - * @param width The width of this Game Object. - * @param height The height of this Game Object. - */ - setSize(width: number, height: number): this; - - /** - * Sets the display size of this Game Object. - * - * Calling this will adjust the scale. - * @param width The width of this Game Object. - * @param height The height of this Game Object. - */ - setDisplaySize(width: number, height: number): this; - - /** - * The Texture this Game Object is using to render with. - */ - texture: Phaser.Textures.Texture | Phaser.Textures.CanvasTexture; - - /** - * The Texture Frame this Game Object is using to render with. + * The tint value being applied to the top-left vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. */ - frame: Phaser.Textures.Frame; + tintTopLeft: number; /** - * A boolean flag indicating if this Game Object is being cropped or not. - * You can toggle this at any time after `setCrop` has been called, to turn cropping on or off. - * Equally, calling `setCrop` with no arguments will reset the crop and disable it. + * The tint value being applied to the top-right vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. */ - isCropped: boolean; + tintTopRight: number; /** - * Applies a crop to a texture based Game Object, such as a Sprite or Image. - * - * The crop is a rectangle that limits the area of the texture frame that is visible during rendering. - * - * Cropping a Game Object does not change its size, dimensions, physics body or hit area, it just - * changes what is shown when rendered. - * - * The crop coordinates are relative to the texture frame, not the Game Object, meaning 0 x 0 is the top-left. - * - * Therefore, if you had a Game Object that had an 800x600 sized texture, and you wanted to show only the left - * half of it, you could call `setCrop(0, 0, 400, 600)`. - * - * It is also scaled to match the Game Object scale automatically. Therefore a crop rect of 100x50 would crop - * an area of 200x100 when applied to a Game Object that had a scale factor of 2. - * - * You can either pass in numeric values directly, or you can provide a single Rectangle object as the first argument. - * - * Call this method with no arguments at all to reset the crop, or toggle the property `isCropped` to `false`. - * - * You should do this if the crop rectangle becomes the same size as the frame itself, as it will allow - * the renderer to skip several internal calculations. - * @param x The x coordinate to start the crop from. Or a Phaser.Geom.Rectangle object, in which case the rest of the arguments are ignored. - * @param y The y coordinate to start the crop from. - * @param width The width of the crop rectangle in pixels. - * @param height The height of the crop rectangle in pixels. + * The tint value being applied to the bottom-left vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. */ - setCrop(x?: number | Phaser.Geom.Rectangle, y?: number, width?: number, height?: number): this; + tintBottomLeft: number; /** - * Sets the texture and frame this Game Object will use to render with. - * - * Textures are referenced by their string-based keys, as stored in the Texture Manager. - * @param key The key of the texture to be used, as stored in the Texture Manager. - * @param frame The name or index of the frame within the Texture. + * The tint value being applied to the bottom-right vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. */ - setTexture(key: string, frame?: string | integer): this; + tintBottomRight: number; /** - * Sets the frame this Game Object will use to render with. - * - * The Frame has to belong to the current Texture being used. - * - * It can be either a string or an index. + * The tint fill mode. * - * Calling `setFrame` will modify the `width` and `height` properties of your Game Object. - * It will also change the `origin` if the Frame has a custom pivot point, as exported from packages like Texture Packer. - * @param frame The name or index of the frame within the Texture. - * @param updateSize Should this call adjust the size of the Game Object? Default true. - * @param updateOrigin Should this call adjust the origin of the Game Object? Default true. - */ - setFrame(frame: string | integer, updateSize?: boolean, updateOrigin?: boolean): this; - - /** - * Fill or additive? + * `false` = An additive tint (the default), where vertices colors are blended with the texture. + * `true` = A fill tint, where the vertices colors replace the texture, but respects texture alpha. */ tintFill: boolean; @@ -37546,7 +42805,7 @@ declare namespace Phaser { * @param bottomLeft The tint being applied to the bottom-left of the Game Object. * @param bottomRight The tint being applied to the bottom-right of the Game Object. */ - setTint(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; + setTint(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; /** * Sets a fill-based tint on this Game Object. @@ -37569,40 +42828,19 @@ declare namespace Phaser { * @param bottomLeft The tint being applied to the bottom-left of the Game Object. * @param bottomRight The tint being applied to the bottom-right of the Game Object. */ - setTintFill(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; - - /** - * The tint value being applied to the top-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintTopLeft: integer; - - /** - * The tint value being applied to the top-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintTopRight: integer; - - /** - * The tint value being applied to the bottom-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintBottomLeft: integer; - - /** - * The tint value being applied to the bottom-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintBottomRight: integer; + setTintFill(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; /** * The tint value being applied to the whole of the Game Object. * This property is a setter-only. Use the properties `tintTopLeft` etc to read the current tint value. */ - tint: integer; + tint: number; /** - * Does this Game Object have a tint applied to it or not? + * Does this Game Object have a tint applied? + * + * It checks to see if the 4 tint properties are set to the value 0xffffff + * and that the `tintFill` property is `false`. This indicates that a Game Object isn't tinted. */ readonly isTinted: boolean; @@ -37656,13 +42894,13 @@ declare namespace Phaser { * * If you prefer to work in radians, see the `rotation` property instead. */ - angle: integer; + angle: number; /** * The angle of this Game Object in radians. * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. * * If you prefer to work in degrees, see the `angle` property instead. */ @@ -37677,6 +42915,12 @@ declare namespace Phaser { */ setPosition(x?: number, y?: number, z?: number, w?: number): this; + /** + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; + /** * Sets the position of this Game Object to be a random position within the confines of * the given area. @@ -37751,6 +42995,22 @@ declare namespace Phaser { */ getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. + */ + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + /** * Gets the sum total rotation of all of this Game Objects parent Containers. * @@ -37776,9470 +43036,10593 @@ declare namespace Phaser { } /** - * A Zone Game Object. + * The Update List plugin. * - * A Zone is a non-rendering rectangular Game Object that has a position and size. - * It has no texture and never displays, but does live on the display list and - * can be moved, scaled and rotated like any other Game Object. + * Update Lists belong to a Scene and maintain the list Game Objects to be updated every frame. * - * Its primary use is for creating Drop Zones and Input Hit Areas and it has a couple of helper methods - * specifically for this. It is also useful for object overlap checks, or as a base for your own - * non-displaying Game Objects. - * The default origin is 0.5, the center of the Zone, the same as with Game Objects. + * Some or all of these Game Objects may also be part of the Scene's [Display List]{@link Phaser.GameObjects.DisplayList}, for Rendering. */ - class Zone extends Phaser.GameObjects.GameObject implements Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.GetBounds, Phaser.GameObjects.Components.Origin, Phaser.GameObjects.Components.Transform, Phaser.GameObjects.Components.ScrollFactor, Phaser.GameObjects.Components.Visible { + class UpdateList extends Phaser.Structs.ProcessQueue { /** * - * @param scene The Scene to which this Game Object belongs. - * @param x The horizontal position of this Game Object in the world. - * @param y The vertical position of this Game Object in the world. - * @param width The width of the Game Object. Default 1. - * @param height The height of the Game Object. Default 1. + * @param scene The Scene that the Update List belongs to. */ - constructor(scene: Phaser.Scene, x: number, y: number, width?: number, height?: number); + constructor(scene: Phaser.Scene); /** - * The native (un-scaled) width of this Game Object. + * The Scene that the Update List belongs to. */ - width: number; + scene: Phaser.Scene; /** - * The native (un-scaled) height of this Game Object. + * The Scene's Systems. */ - height: number; + systems: Phaser.Scenes.Systems; /** - * The Blend Mode of the Game Object. - * Although a Zone never renders, it still has a blend mode to allow it to fit seamlessly into - * display lists without causing a batch flush. + * The update step. + * + * Pre-updates every active Game Object in the list. + * @param time The current timestamp. + * @param delta The delta time elapsed since the last frame. */ - blendMode: integer; + sceneUpdate(time: number, delta: number): void; /** - * The displayed width of this Game Object. - * This value takes into account the scale factor. + * The Scene that owns this plugin is shutting down. + * + * We need to kill and reset all internal properties as well as stop listening to Scene events. */ - displayWidth: number; + shutdown(): void; /** - * The displayed height of this Game Object. - * This value takes into account the scale factor. + * The Scene that owns this plugin is being destroyed. + * + * We need to shutdown and then kill off all external references. */ - displayHeight: number; + destroy(): void; + + } + /** + * A Video Game Object. + * + * This Game Object is capable of handling playback of a previously loaded video from the Phaser Video Cache, + * or playing a video based on a given URL. Videos can be either local, or streamed. + * + * ```javascript + * preload () { + * this.load.video('pixar', 'nemo.mp4'); + * } + * + * create () { + * this.add.video(400, 300, 'pixar'); + * } + * ``` + * + * To all intents and purposes, a video is a standard Game Object, just like a Sprite. And as such, you can do + * all the usual things to it, such as scaling, rotating, cropping, tinting, making interactive, giving a + * physics body, etc. + * + * Transparent videos are also possible via the WebM file format. Providing the video file has was encoded with + * an alpha channel, and providing the browser supports WebM playback (not all of them do), then it will render + * in-game with full transparency. + * + * ### Autoplaying Videos + * + * Videos can only autoplay if the browser has been unlocked with an interaction, or satisfies the MEI settings. + * The policies that control autoplaying are vast and vary between browser. + * You can, and should, read more about it here: https://developer.mozilla.org/en-US/docs/Web/Media/Autoplay_guide + * + * If your video doesn't contain any audio, then set the `noAudio` parameter to `true` when the video is _loaded_, + * and it will often allow the video to play immediately: + * + * ```javascript + * preload () { + * this.load.video('pixar', 'nemo.mp4', 'loadeddata', false, true); + * } + * ``` + * + * The 5th parameter in the load call tells Phaser that the video doesn't contain any audio tracks. Video without + * audio can autoplay without requiring a user interaction. Video with audio cannot do this unless it satisfies + * the browsers MEI settings. See the MDN Autoplay Guide for further details. + * + * Note that due to a bug in IE11 you cannot play a video texture to a Sprite in WebGL. For IE11 force Canvas mode. + * + * More details about video playback and the supported media formats can be found on MDN: + * + * https://developer.mozilla.org/en-US/docs/Web/API/HTMLVideoElement + * https://developer.mozilla.org/en-US/docs/Web/Media/Formats + */ + class Video extends Phaser.GameObjects.GameObject implements Phaser.GameObjects.Components.Alpha, Phaser.GameObjects.Components.BlendMode, Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.Flip, Phaser.GameObjects.Components.GetBounds, Phaser.GameObjects.Components.Mask, Phaser.GameObjects.Components.Origin, Phaser.GameObjects.Components.Pipeline, Phaser.GameObjects.Components.ScrollFactor, Phaser.GameObjects.Components.Size, Phaser.GameObjects.Components.TextureCrop, Phaser.GameObjects.Components.Tint, Phaser.GameObjects.Components.Transform, Phaser.GameObjects.Components.Visible { /** - * Sets the size of this Game Object. - * @param width The width of this Game Object. - * @param height The height of this Game Object. - * @param resizeInput If this Zone has a Rectangle for a hit area this argument will resize the hit area as well. Default true. + * + * @param scene The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. + * @param x The horizontal position of this Game Object in the world. + * @param y The vertical position of this Game Object in the world. + * @param key Optional key of the Video this Game Object will play, as stored in the Video Cache. */ - setSize(width: number, height: number, resizeInput?: boolean): Phaser.GameObjects.Zone; + constructor(scene: Phaser.Scene, x: number, y: number, key?: string); /** - * Sets the display size of this Game Object. - * Calling this will adjust the scale. - * @param width The width of this Game Object. - * @param height The height of this Game Object. + * A reference to the HTML Video Element this Video Game Object is playing. + * Will be `null` until a video is loaded for playback. */ - setDisplaySize(width: number, height: number): Phaser.GameObjects.Zone; + video: HTMLVideoElement; /** - * Sets this Zone to be a Circular Drop Zone. - * The circle is centered on this Zones `x` and `y` coordinates. - * @param radius The radius of the Circle that will form the Drop Zone. + * The Phaser Texture this Game Object is using to render the video to. + * Will be `null` until a video is loaded for playback. */ - setCircleDropZone(radius: number): Phaser.GameObjects.Zone; + videoTexture: Phaser.Textures.Texture; /** - * Sets this Zone to be a Rectangle Drop Zone. - * The rectangle is centered on this Zones `x` and `y` coordinates. - * @param width The width of the rectangle drop zone. - * @param height The height of the rectangle drop zone. + * A reference to the TextureSource belong to the `videoTexture` Texture object. + * Will be `null` until a video is loaded for playback. */ - setRectangleDropZone(width: number, height: number): Phaser.GameObjects.Zone; + videoTextureSource: Phaser.Textures.TextureSource; /** - * Allows you to define your own Geometry shape to be used as a Drop Zone. - * @param shape A Geometry shape instance, such as Phaser.Geom.Ellipse, or your own custom shape. - * @param callback A function that will return `true` if the given x/y coords it is sent are within the shape. + * A Phaser CanvasTexture instance that holds the most recent snapshot taken from the video. + * This will only be set if `snapshot` or `snapshotArea` have been called, and will be `null` until that point. */ - setDropZone(shape: object, callback: Phaser.Types.Input.HitAreaCallback): Phaser.GameObjects.Zone; + snapshotTexture: Phaser.Textures.CanvasTexture; /** - * The depth of this Game Object within the Scene. - * - * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order - * of Game Objects, without actually moving their position in the display list. - * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth - * value will always render in front of one with a lower value. - * - * Setting the depth will queue a depth sort event within the Scene. + * If you have saved this video to a texture via the `saveTexture` method, this controls if the video + * is rendered with `flipY` in WebGL or not. You often need to set this if you wish to use the video texture + * as the input source for a shader. If you find your video is appearing upside down within a shader or + * custom pipeline, flip this property. */ - depth: number; + flipY: boolean; /** - * The depth of this Game Object within the Scene. - * - * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order - * of Game Objects, without actually moving their position in the display list. - * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth - * value will always render in front of one with a lower value. - * - * Setting the depth will queue a depth sort event within the Scene. - * @param value The depth of this Game Object. + * An internal flag holding the current state of the video lock, should document interaction be required + * before playback can begin. */ - setDepth(value: integer): this; + touchLocked: boolean; /** - * Gets the center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. + * Should the video auto play when document interaction is required and happens? */ - getCenter(output?: O): O; + playWhenUnlocked: boolean; /** - * Gets the top-left corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * When starting playback of a video Phaser will monitor its `readyState` using a `setTimeout` call. + * The `setTimeout` happens once every `Video.retryInterval` ms. It will carry on monitoring the video + * state in this manner until the `retryLimit` is reached and then abort. */ - getTopLeft(output?: O, includeParent?: boolean): O; + retryLimit: number; /** - * Gets the top-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * The current retry attempt. */ - getTopCenter(output?: O, includeParent?: boolean): O; + retry: number; /** - * Gets the top-right corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * The number of ms between each retry while monitoring the ready state of a downloading video. */ - getTopRight(output?: O, includeParent?: boolean): O; + retryInterval: number; /** - * Gets the left-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * An object containing in and out markers for sequence playback. */ - getLeftCenter(output?: O, includeParent?: boolean): O; + markers: any; /** - * Gets the right-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * Should the Video element that this Video is using, be removed from the DOM + * when this Video is destroyed? */ - getRightCenter(output?: O, includeParent?: boolean): O; + removeVideoElementOnDestroy: boolean; /** - * Gets the bottom-left corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * Starts this video playing. + * + * If the video is already playing, or has been queued to play with `changeSource` then this method just returns. + * + * Videos can only autoplay if the browser has been unlocked. This happens if you have interacted with the browser, i.e. + * by clicking on it or pressing a key, or due to server settings. The policies that control autoplaying are vast and + * vary between browser. You can read more here: https://developer.mozilla.org/en-US/docs/Web/Media/Autoplay_guide + * + * If your video doesn't contain any audio, then set the `noAudio` parameter to `true` when the video is loaded, + * and it will often allow the video to play immediately: + * + * ```javascript + * preload () { + * this.load.video('pixar', 'nemo.mp4', 'loadeddata', false, true); + * } + * ``` + * + * The 5th parameter in the load call tells Phaser that the video doesn't contain any audio tracks. Video without + * audio can autoplay without requiring a user interaction. Video with audio cannot do this unless it satisfies + * the browsers MEI settings. See the MDN Autoplay Guide for details. + * + * If you need audio in your videos, then you'll have to consider the fact that the video cannot start playing until the + * user has interacted with the browser, into your game flow. + * @param loop Should the video loop automatically when it reaches the end? Please note that not all browsers support _seamless_ video looping for all encoding formats. Default false. + * @param markerIn Optional in marker time, in seconds, for playback of a sequence of the video. + * @param markerOut Optional out marker time, in seconds, for playback of a sequence of the video. */ - getBottomLeft(output?: O, includeParent?: boolean): O; + play(loop?: boolean, markerIn?: number, markerOut?: number): this; /** - * Gets the bottom-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * This method allows you to change the source of the current video element. It works by first stopping the + * current video, if playing. Then deleting the video texture, if one has been created. Finally, it makes a + * new video texture and starts playback of the new source through the existing video element. + * + * The reason you may wish to do this is because videos that require interaction to unlock, remain in an unlocked + * state, even if you change the source of the video. By changing the source to a new video you avoid having to + * go through the unlock process again. + * @param key The key of the Video this Game Object will swap to playing, as stored in the Video Cache. + * @param autoplay Should the video start playing immediately, once the swap is complete? Default true. + * @param loop Should the video loop automatically when it reaches the end? Please note that not all browsers support _seamless_ video looping for all encoding formats. Default false. + * @param markerIn Optional in marker time, in seconds, for playback of a sequence of the video. + * @param markerOut Optional out marker time, in seconds, for playback of a sequence of the video. */ - getBottomCenter(output?: O, includeParent?: boolean): O; + changeSource(key: string, autoplay?: boolean, loop?: boolean, markerIn?: number, markerOut?: number): this; /** - * Gets the bottom-right corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * Adds a sequence marker to this video. + * + * Markers allow you to split a video up into sequences, delineated by a start and end time, given in seconds. + * + * You can then play back specific markers via the `playMarker` method. + * + * Note that marker timing is _not_ frame-perfect. You should construct your videos in such a way that you allow for + * plenty of extra padding before and after each sequence to allow for discrepancies in browser seek and currentTime accuracy. + * + * See https://github.com/w3c/media-and-entertainment/issues/4 for more details about this issue. + * @param key A unique name to give this marker. + * @param markerIn The time, in seconds, representing the start of this marker. + * @param markerOut The time, in seconds, representing the end of this marker. */ - getBottomRight(output?: O, includeParent?: boolean): O; + addMarker(key: string, markerIn: number, markerOut: number): this; /** - * Gets the bounds of this Game Object, regardless of origin. - * The values are stored and returned in a Rectangle, or Rectangle-like, object. - * @param output An object to store the values in. If not provided a new Rectangle will be created. + * Plays a pre-defined sequence in this video. + * + * Markers allow you to split a video up into sequences, delineated by a start and end time, given in seconds and + * specified via the `addMarker` method. + * + * Note that marker timing is _not_ frame-perfect. You should construct your videos in such a way that you allow for + * plenty of extra padding before and after each sequence to allow for discrepancies in browser seek and currentTime accuracy. + * + * See https://github.com/w3c/media-and-entertainment/issues/4 for more details about this issue. + * @param key The name of the marker sequence to play. + * @param loop Should the video loop automatically when it reaches the end? Please note that not all browsers support _seamless_ video looping for all encoding formats. Default false. */ - getBounds(output?: O): O; + playMarker(key: string, loop?: boolean): this; /** - * The horizontal origin of this Game Object. - * The origin maps the relationship between the size and position of the Game Object. - * The default value is 0.5, meaning all Game Objects are positioned based on their center. - * Setting the value to 0 means the position now relates to the left of the Game Object. + * Removes a previously set marker from this video. + * + * If the marker is currently playing it will _not_ stop playback. + * @param key The name of the marker to remove. */ - originX: number; + removeMarker(key: string): this; /** - * The vertical origin of this Game Object. - * The origin maps the relationship between the size and position of the Game Object. - * The default value is 0.5, meaning all Game Objects are positioned based on their center. - * Setting the value to 0 means the position now relates to the top of the Game Object. + * Takes a snapshot of the current frame of the video and renders it to a CanvasTexture object, + * which is then returned. You can optionally resize the grab by passing a width and height. + * + * This method returns a reference to the `Video.snapshotTexture` object. Calling this method + * multiple times will overwrite the previous snapshot with the most recent one. + * @param width The width of the resulting CanvasTexture. + * @param height The height of the resulting CanvasTexture. */ - originY: number; + snapshot(width?: number, height?: number): Phaser.Textures.CanvasTexture; /** - * The horizontal display origin of this Game Object. - * The origin is a normalized value between 0 and 1. - * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. + * Takes a snapshot of the specified area of the current frame of the video and renders it to a CanvasTexture object, + * which is then returned. You can optionally resize the grab by passing a different `destWidth` and `destHeight`. + * + * This method returns a reference to the `Video.snapshotTexture` object. Calling this method + * multiple times will overwrite the previous snapshot with the most recent one. + * @param x The horizontal location of the top-left of the area to grab from. Default 0. + * @param y The vertical location of the top-left of the area to grab from. Default 0. + * @param srcWidth The width of area to grab from the video. If not given it will grab the full video dimensions. + * @param srcHeight The height of area to grab from the video. If not given it will grab the full video dimensions. + * @param destWidth The destination width of the grab, allowing you to resize it. + * @param destHeight The destination height of the grab, allowing you to resize it. */ - displayOriginX: number; + snapshotArea(x?: number, y?: number, srcWidth?: number, srcHeight?: number, destWidth?: number, destHeight?: number): Phaser.Textures.CanvasTexture; /** - * The vertical display origin of this Game Object. - * The origin is a normalized value between 0 and 1. - * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. + * Stores a copy of this Videos `snapshotTexture` in the Texture Manager using the given key. + * + * This texture is created when the `snapshot` or `snapshotArea` methods are called. + * + * After doing this, any texture based Game Object, such as a Sprite, can use the contents of the + * snapshot by using the texture key: + * + * ```javascript + * var vid = this.add.video(0, 0, 'intro'); + * + * vid.snapshot(); + * + * vid.saveSnapshotTexture('doodle'); + * + * this.add.image(400, 300, 'doodle'); + * ``` + * + * Updating the contents of the `snapshotTexture`, for example by calling `snapshot` again, + * will automatically update _any_ Game Object that is using it as a texture. + * Calling `saveSnapshotTexture` again will not save another copy of the same texture, + * it will just rename the existing one. + * + * By default it will create a single base texture. You can add frames to the texture + * by using the `Texture.add` method. After doing this, you can then allow Game Objects + * to use a specific frame. + * @param key The unique key to store the texture as within the global Texture Manager. */ - displayOriginY: number; + saveSnapshotTexture(key: string): Phaser.Textures.CanvasTexture; /** - * Sets the origin of this Game Object. + * Loads a Video from the given URL, ready for playback with the `Video.play` method. * - * The values are given in the range 0 to 1. - * @param x The horizontal origin value. Default 0.5. - * @param y The vertical origin value. If not defined it will be set to the value of `x`. Default x. + * You can control at what point the browser determines the video as being ready for playback via + * the `loadEvent` parameter. See https://developer.mozilla.org/en-US/docs/Web/API/HTMLVideoElement + * for more details. + * @param url The URL of the video to load or be streamed. + * @param loadEvent The load event to listen for. Either `loadeddata`, `canplay` or `canplaythrough`. Default 'loadeddata'. + * @param noAudio Does the video have an audio track? If not you can enable auto-playing on it. Default false. */ - setOrigin(x?: number, y?: number): this; + loadURL(url: string, loadEvent?: string, noAudio?: boolean): this; /** - * Sets the origin of this Game Object based on the Pivot values in its Frame. + * Loads a Video from the given MediaStream object, ready for playback with the `Video.play` method. + * + * You can control at what point the browser determines the video as being ready for playback via + * the `loadEvent` parameter. See https://developer.mozilla.org/en-US/docs/Web/API/HTMLVideoElement + * for more details. + * @param stream The MediaStream object. + * @param loadEvent The load event to listen for. Either `loadeddata`, `canplay` or `canplaythrough`. Default 'loadeddata'. + * @param noAudio Does the video have an audio track? If not you can enable auto-playing on it. Default false. */ - setOriginFromFrame(): this; + loadMediaStream(stream: string, loadEvent?: string, noAudio?: boolean): this; /** - * Sets the display origin of this Game Object. - * The difference between this and setting the origin is that you can use pixel values for setting the display origin. - * @param x The horizontal display origin value. Default 0. - * @param y The vertical display origin value. If not defined it will be set to the value of `x`. Default x. + * Called when the video emits a `playing` event during load. + * + * This is only listened for if the browser doesn't support Promises. */ - setDisplayOrigin(x?: number, y?: number): this; + playHandler(): void; /** - * Updates the Display Origin cached values internally stored on this Game Object. - * You don't usually call this directly, but it is exposed for edge-cases where you may. + * Called when the video completes playback, i.e. reaches an `ended` state. + * + * This will never happen if the video is coming from a live stream, where the duration is `Infinity`. */ - updateDisplayOrigin(): this; + completeHandler(): void; /** - * The x position of this Game Object. + * Called when the video emits a `timeUpdate` event during playback. + * + * This event is too slow and irregular to be used for actual video timing or texture updating, + * but we can use it to determine if a video has looped. */ - x: number; + timeUpdateHandler(): void; /** - * The y position of this Game Object. + * Internal method that is called when enough video data has been received in order to create a texture + * from it. The texture is assigned to the `Video.videoTexture` property and given a base frame that + * encompases the whole video size. */ - y: number; + updateTexture(): void; /** - * The z position of this Game Object. + * Returns the key of the currently played video, as stored in the Video Cache. + * If the video did not come from the cache this will return an empty string. + */ + getVideoKey(): string; + + /** + * Seeks to a given point in the video. The value is given as a float between 0 and 1, + * where 0 represents the start of the video and 1 represents the end. * - * Note: The z position does not control the rendering order of 2D Game Objects. Use - * {@link Phaser.GameObjects.Components.Depth#depth} instead. + * Seeking only works if the video has a duration, so will not work for live streams. + * + * When seeking begins, this video will emit a `seeking` event. When the video completes + * seeking (i.e. reaches its designated timestamp) it will emit a `seeked` event. + * + * If you wish to seek based on time instead, use the `Video.setCurrentTime` method. + * @param value The point in the video to seek to. A value between 0 and 1. */ - z: number; + seekTo(value: number): this; /** - * The w position of this Game Object. + * A double-precision floating-point value indicating the current playback time in seconds. + * If the media has not started to play and has not been seeked, this value is the media's initial playback time. */ - w: number; + getCurrentTime(): number; /** - * This is a special setter that allows you to set both the horizontal and vertical scale of this Game Object - * to the same value, at the same time. When reading this value the result returned is `(scaleX + scaleY) / 2`. + * Seeks to a given playback time in the video. The value is given in _seconds_ or as a string. * - * Use of this property implies you wish the horizontal and vertical scales to be equal to each other. If this - * isn't the case, use the `scaleX` or `scaleY` properties instead. + * Seeking only works if the video has a duration, so will not work for live streams. + * + * When seeking begins, this video will emit a `seeking` event. When the video completes + * seeking (i.e. reaches its designated timestamp) it will emit a `seeked` event. + * + * You can provide a string prefixed with either a `+` or a `-`, such as `+2.5` or `-2.5`. + * In this case it will seek to +/- the value given, relative to the _current time_. + * + * If you wish to seek based on a duration percentage instead, use the `Video.seekTo` method. + * @param value The playback time to seek to in seconds. Can be expressed as a string, such as `+2` to seek 2 seconds ahead from the current time. */ - scale: number; + setCurrentTime(value: string | number): this; /** - * The horizontal scale of this Game Object. + * Returns a boolean indicating if this Video is currently seeking, or not. */ - scaleX: number; + isSeeking(): boolean; /** - * The vertical scale of this Game Object. + * Returns the current progress of the video. Progress is defined as a value between 0 (the start) + * and 1 (the end). + * + * Progress can only be returned if the video has a duration, otherwise it will always return zero. */ - scaleY: number; + getProgress(): number; /** - * The angle of this Game Object as expressed in degrees. - * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * A double-precision floating-point value which indicates the duration (total length) of the media in seconds, + * on the media's timeline. If no media is present on the element, or the media is not valid, the returned value is NaN. * - * If you prefer to work in radians, see the `rotation` property instead. + * If the media has no known end (such as for live streams of unknown duration, web radio, media incoming from WebRTC, + * and so forth), this value is +Infinity. */ - angle: integer; + getDuration(): number; /** - * The angle of this Game Object in radians. - * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. - * - * If you prefer to work in degrees, see the `angle` property instead. + * Sets the muted state of the currently playing video, if one is loaded. + * @param value The mute value. `true` if the video should be muted, otherwise `false`. Default true. */ - rotation: number; + setMute(value?: boolean): this; /** - * Sets the position of this Game Object. - * @param x The x position of this Game Object. Default 0. - * @param y The y position of this Game Object. If not set it will use the `x` value. Default x. - * @param z The z position of this Game Object. Default 0. - * @param w The w position of this Game Object. Default 0. + * Returns a boolean indicating if this Video is currently muted. */ - setPosition(x?: number, y?: number, z?: number, w?: number): this; + isMuted(): boolean; /** - * Sets the position of this Game Object to be a random position within the confines of - * the given area. + * Sets the paused state of the currently loaded video. * - * If no area is specified a random position between 0 x 0 and the game width x height is used instead. + * If the video is playing, calling this method with `true` will pause playback. + * If the video is paused, calling this method with `false` will resume playback. * - * The position does not factor in the size of this Game Object, meaning that only the origin is - * guaranteed to be within the area. - * @param x The x position of the top-left of the random area. Default 0. - * @param y The y position of the top-left of the random area. Default 0. - * @param width The width of the random area. - * @param height The height of the random area. + * If no video is loaded, this method does nothing. + * @param value The paused value. `true` if the video should be paused, `false` to resume it. Default true. */ - setRandomPosition(x?: number, y?: number, width?: number, height?: number): this; + setPaused(value?: boolean): this; /** - * Sets the rotation of this Game Object. - * @param radians The rotation of this Game Object, in radians. Default 0. + * Returns a double indicating the audio volume, from 0.0 (silent) to 1.0 (loudest). */ - setRotation(radians?: number): this; + getVolume(): number; /** - * Sets the angle of this Game Object. - * @param degrees The rotation of this Game Object, in degrees. Default 0. + * Sets the volume of the currently playing video. + * + * The value given is a double indicating the audio volume, from 0.0 (silent) to 1.0 (loudest). + * @param value A double indicating the audio volume, from 0.0 (silent) to 1.0 (loudest). Default 1. */ - setAngle(degrees?: number): this; + setVolume(value?: number): this; /** - * Sets the scale of this Game Object. - * @param x The horizontal scale of this Game Object. - * @param y The vertical scale of this Game Object. If not set it will use the `x` value. Default x. + * Returns a double that indicates the rate at which the media is being played back. */ - setScale(x: number, y?: number): this; + getPlaybackRate(): number; /** - * Sets the x position of this Game Object. - * @param value The x position of this Game Object. Default 0. + * Sets the playback rate of the current video. + * + * The value given is a double that indicates the rate at which the media is being played back. + * @param rate A double that indicates the rate at which the media is being played back. */ - setX(value?: number): this; + setPlaybackRate(rate?: number): this; /** - * Sets the y position of this Game Object. - * @param value The y position of this Game Object. Default 0. + * Returns a boolean which indicates whether the media element should start over when it reaches the end. */ - setY(value?: number): this; + getLoop(): boolean; /** - * Sets the z position of this Game Object. + * Sets the loop state of the current video. * - * Note: The z position does not control the rendering order of 2D Game Objects. Use - * {@link Phaser.GameObjects.Components.Depth#setDepth} instead. - * @param value The z position of this Game Object. Default 0. - */ - setZ(value?: number): this; - - /** - * Sets the w position of this Game Object. - * @param value The w position of this Game Object. Default 0. + * The value given is a boolean which indicates whether the media element will start over when it reaches the end. + * + * Not all videos can loop, for example live streams. + * + * Please note that not all browsers support _seamless_ video looping for all encoding formats. + * @param value A boolean which indicates whether the media element will start over when it reaches the end. Default true. */ - setW(value?: number): this; + setLoop(value?: boolean): this; /** - * Gets the local transform matrix for this Game Object. - * @param tempMatrix The matrix to populate with the values from this Game Object. + * Returns a boolean which indicates whether the video is currently playing. */ - getLocalTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + isPlaying(): boolean; /** - * Gets the world transform matrix for this Game Object, factoring in any parent Containers. - * @param tempMatrix The matrix to populate with the values from this Game Object. - * @param parentMatrix A temporary matrix to hold parent values during the calculations. + * Returns a boolean which indicates whether the video is currently paused. */ - getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + isPaused(): boolean; /** - * Gets the sum total rotation of all of this Game Objects parent Containers. + * Stores this Video in the Texture Manager using the given key as a dynamic texture, + * which any texture-based Game Object, such as a Sprite, can use as its texture: * - * The returned value is in radians and will be zero if this Game Object has no parent container. - */ - getParentRotation(): number; - - /** - * The horizontal scroll factor of this Game Object. + * ```javascript + * var vid = this.add.video(0, 0, 'intro'); * - * The scroll factor controls the influence of the movement of a Camera upon this Game Object. + * vid.play(); * - * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. - * It does not change the Game Objects actual position values. + * vid.saveTexture('doodle'); * - * A value of 1 means it will move exactly in sync with a camera. - * A value of 0 means it will not move at all, even if the camera moves. - * Other values control the degree to which the camera movement is mapped to this Game Object. + * this.add.image(400, 300, 'doodle'); + * ``` * - * Please be aware that scroll factor values other than 1 are not taken in to consideration when - * calculating physics collisions. Bodies always collide based on their world position, but changing - * the scroll factor is a visual adjustment to where the textures are rendered, which can offset - * them from physics bodies if not accounted for in your code. + * The saved texture is automatically updated as the video plays. If you pause this video, + * or change its source, then the saved texture updates instantly. + * + * Calling `saveTexture` again will not save another copy of the same texture, it will just rename the existing one. + * + * By default it will create a single base texture. You can add frames to the texture + * by using the `Texture.add` method. After doing this, you can then allow Game Objects + * to use a specific frame. + * + * If you intend to save the texture so you can use it as the input for a Shader, you may need to set the + * `flipY` parameter to `true` if you find the video renders upside down in your shader. + * @param key The unique key to store the texture as within the global Texture Manager. + * @param flipY Should the WebGL Texture set `UNPACK_MULTIPLY_FLIP_Y` during upload? Default false. */ - scrollFactorX: number; + saveTexture(key: string, flipY?: boolean): Phaser.Textures.Texture; /** - * The vertical scroll factor of this Game Object. - * - * The scroll factor controls the influence of the movement of a Camera upon this Game Object. - * - * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. - * It does not change the Game Objects actual position values. + * Stops the video playing and clears all internal event listeners. * - * A value of 1 means it will move exactly in sync with a camera. - * A value of 0 means it will not move at all, even if the camera moves. - * Other values control the degree to which the camera movement is mapped to this Game Object. + * If you only wish to pause playback of the video, and resume it a later time, use the `Video.pause` method instead. * - * Please be aware that scroll factor values other than 1 are not taken in to consideration when - * calculating physics collisions. Bodies always collide based on their world position, but changing - * the scroll factor is a visual adjustment to where the textures are rendered, which can offset - * them from physics bodies if not accounted for in your code. + * If the video hasn't finished downloading, calling this method will not abort the download. To do that you need to + * call `destroy` instead. */ - scrollFactorY: number; + stop(): this; /** - * Sets the scroll factor of this Game Object. - * - * The scroll factor controls the influence of the movement of a Camera upon this Game Object. + * Removes the Video element from the DOM by calling parentNode.removeChild on itself. * - * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. - * It does not change the Game Objects actual position values. + * Also removes the autoplay and src attributes and nulls the Video reference. * - * A value of 1 means it will move exactly in sync with a camera. - * A value of 0 means it will not move at all, even if the camera moves. - * Other values control the degree to which the camera movement is mapped to this Game Object. + * You should not call this method if you were playing a video from the Video Cache that + * you wish to play again in your game, or if another Video object is also using the same + * video. * - * Please be aware that scroll factor values other than 1 are not taken in to consideration when - * calculating physics collisions. Bodies always collide based on their world position, but changing - * the scroll factor is a visual adjustment to where the textures are rendered, which can offset - * them from physics bodies if not accounted for in your code. - * @param x The horizontal scroll factor of this Game Object. - * @param y The vertical scroll factor of this Game Object. If not set it will use the `x` value. Default x. + * If you loaded an external video via `Video.loadURL` then you should call this function + * to clear up once you are done with the instance. */ - setScrollFactor(x: number, y?: number): this; + removeVideoElement(): void; /** - * The visible state of the Game Object. + * Clears all alpha values associated with this Game Object. * - * An invisible Game Object will skip rendering, but will still process update logic. + * Immediately sets the alpha levels back to 1 (fully opaque). */ - visible: boolean; + clearAlpha(): this; /** - * Sets the visibility of this Game Object. + * Set the Alpha level of this Game Object. The alpha controls the opacity of the Game Object as it renders. + * Alpha values are provided as a float between 0, fully transparent, and 1, fully opaque. * - * An invisible Game Object will skip rendering, but will still process update logic. - * @param value The visible state of the Game Object. + * If your game is running under WebGL you can optionally specify four different alpha values, each of which + * correspond to the four corners of the Game Object. Under Canvas only the `topLeft` value given is used. + * @param topLeft The alpha value used for the top-left of the Game Object. If this is the only value given it's applied across the whole Game Object. Default 1. + * @param topRight The alpha value used for the top-right of the Game Object. WebGL only. + * @param bottomLeft The alpha value used for the bottom-left of the Game Object. WebGL only. + * @param bottomRight The alpha value used for the bottom-right of the Game Object. WebGL only. */ - setVisible(value: boolean): this; - - } - - } + setAlpha(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; - namespace Geom { - /** - * A Circle object. - * - * This is a geometry object, containing numerical values and related methods to inspect and modify them. - * It is not a Game Object, in that you cannot add it to the display list, and it has no texture. - * To render a Circle you should look at the capabilities of the Graphics class. - */ - class Circle { /** + * The alpha value of the Game Object. * - * @param x The x position of the center of the circle. Default 0. - * @param y The y position of the center of the circle. Default 0. - * @param radius The radius of the circle. Default 0. + * This is a global value, impacting the entire Game Object, not just a region of it. */ - constructor(x?: number, y?: number, radius?: number); + alpha: number; /** - * Calculates the area of the circle. - * @param circle The Circle to get the area of. + * The alpha value starting from the top-left of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. */ - static Area(circle: Phaser.Geom.Circle): number; + alphaTopLeft: number; /** - * The geometry constant type of this object: `GEOM_CONST.CIRCLE`. - * Used for fast type comparisons. + * The alpha value starting from the top-right of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. */ - readonly type: integer; + alphaTopRight: number; /** - * The x position of the center of the circle. + * The alpha value starting from the bottom-left of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. */ - x: number; + alphaBottomLeft: number; /** - * The y position of the center of the circle. + * The alpha value starting from the bottom-right of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. */ - y: number; + alphaBottomRight: number; /** - * Check to see if the Circle contains the given x / y coordinates. - * @param x The x coordinate to check within the circle. - * @param y The y coordinate to check within the circle. + * Sets the Blend Mode being used by this Game Object. + * + * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) + * + * Under WebGL only the following Blend Modes are available: + * + * * ADD + * * MULTIPLY + * * SCREEN + * * ERASE + * + * Canvas has more available depending on browser support. + * + * You can also create your own custom Blend Modes in WebGL. + * + * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending + * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these + * reasons try to be careful about the construction of your Scene and the frequency of which blend modes + * are used. */ - contains(x: number, y: number): boolean; + blendMode: Phaser.BlendModes | string; /** - * Returns a Point object containing the coordinates of a point on the circumference of the Circle - * based on the given angle normalized to the range 0 to 1. I.e. a value of 0.5 will give the point - * at 180 degrees around the circle. - * @param position A value between 0 and 1, where 0 equals 0 degrees, 0.5 equals 180 degrees and 1 equals 360 around the circle. - * @param out An object to store the return values in. If not given a Point object will be created. + * Sets the Blend Mode being used by this Game Object. + * + * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) + * + * Under WebGL only the following Blend Modes are available: + * + * * ADD + * * MULTIPLY + * * SCREEN + * * ERASE (only works when rendering to a framebuffer, like a Render Texture) + * + * Canvas has more available depending on browser support. + * + * You can also create your own custom Blend Modes in WebGL. + * + * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending + * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these + * reasons try to be careful about the construction of your Scene and the frequency in which blend modes + * are used. + * @param value The BlendMode value. Either a string or a CONST. */ - getPoint(position: number, out?: O): O; + setBlendMode(value: string | Phaser.BlendModes): this; /** - * Returns an array of Point objects containing the coordinates of the points around the circumference of the Circle, - * based on the given quantity or stepRate values. - * @param quantity The amount of points to return. If a falsey value the quantity will be derived from the `stepRate` instead. - * @param stepRate Sets the quantity by getting the circumference of the circle and dividing it by the stepRate. - * @param output An array to insert the points in to. If not provided a new array will be created. + * The depth of this Game Object within the Scene. + * + * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order + * of Game Objects, without actually moving their position in the display list. + * + * The default depth is zero. A Game Object with a higher depth + * value will always render in front of one with a lower value. + * + * Setting the depth will queue a depth sort event within the Scene. */ - getPoints(quantity: integer, stepRate?: number, output?: O): O; + depth: number; /** - * Returns a uniformly distributed random point from anywhere within the Circle. - * @param point A Point or point-like object to set the random `x` and `y` values in. + * The depth of this Game Object within the Scene. + * + * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order + * of Game Objects, without actually moving their position in the display list. + * + * The default depth is zero. A Game Object with a higher depth + * value will always render in front of one with a lower value. + * + * Setting the depth will queue a depth sort event within the Scene. + * @param value The depth of this Game Object. */ - getRandomPoint(point?: O): O; + setDepth(value: number): this; /** - * Sets the x, y and radius of this circle. - * @param x The x position of the center of the circle. Default 0. - * @param y The y position of the center of the circle. Default 0. - * @param radius The radius of the circle. Default 0. + * The horizontally flipped state of the Game Object. + * + * A Game Object that is flipped horizontally will render inversed on the horizontal axis. + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. */ - setTo(x?: number, y?: number, radius?: number): Phaser.Geom.Circle; + flipX: boolean; /** - * Sets this Circle to be empty with a radius of zero. - * Does not change its position. + * Toggles the horizontal flipped state of this Game Object. + * + * A Game Object that is flipped horizontally will render inversed on the horizontal axis. + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. */ - setEmpty(): Phaser.Geom.Circle; + toggleFlipX(): this; /** - * Sets the position of this Circle. - * @param x The x position of the center of the circle. Default 0. - * @param y The y position of the center of the circle. Default 0. + * Toggles the vertical flipped state of this Game Object. */ - setPosition(x?: number, y?: number): Phaser.Geom.Circle; + toggleFlipY(): this; /** - * Checks to see if the Circle is empty: has a radius of zero. + * Sets the horizontal flipped state of this Game Object. + * + * A Game Object that is flipped horizontally will render inversed on the horizontal axis. + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * @param value The flipped state. `false` for no flip, or `true` to be flipped. */ - isEmpty(): boolean; + setFlipX(value: boolean): this; /** - * The radius of the Circle. + * Sets the vertical flipped state of this Game Object. + * @param value The flipped state. `false` for no flip, or `true` to be flipped. */ - radius: number; + setFlipY(value: boolean): this; /** - * The diameter of the Circle. + * Sets the horizontal and vertical flipped state of this Game Object. + * + * A Game Object that is flipped will render inversed on the flipped axis. + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * @param x The horizontal flipped state. `false` for no flip, or `true` to be flipped. + * @param y The horizontal flipped state. `false` for no flip, or `true` to be flipped. */ - diameter: number; + setFlip(x: boolean, y: boolean): this; /** - * The left position of the Circle. + * Resets the horizontal and vertical flipped state of this Game Object back to their default un-flipped state. */ - left: number; + resetFlip(): this; /** - * The right position of the Circle. + * Gets the center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. */ - right: number; + getCenter(output?: O): O; /** - * The top position of the Circle. + * Gets the top-left corner coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - top: number; + getTopLeft(output?: O, includeParent?: boolean): O; /** - * The bottom position of the Circle. + * Gets the top-center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - bottom: number; + getTopCenter(output?: O, includeParent?: boolean): O; /** - * Returns the circumference of the given Circle. - * @param circle The Circle to get the circumference of. + * Gets the top-right corner coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - static Circumference(circle: Phaser.Geom.Circle): number; + getTopRight(output?: O, includeParent?: boolean): O; /** - * Returns a Point object containing the coordinates of a point on the circumference of the Circle based on the given angle. - * @param circle The Circle to get the circumference point on. - * @param angle The angle from the center of the Circle to the circumference to return the point from. Given in radians. - * @param out A Point, or point-like object, to store the results in. If not given a Point will be created. + * Gets the left-center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - static CircumferencePoint(circle: Phaser.Geom.Circle, angle: number, out?: O): O; + getLeftCenter(output?: O, includeParent?: boolean): O; /** - * Creates a new Circle instance based on the values contained in the given source. - * @param source The Circle to be cloned. Can be an instance of a Circle or a circle-like object, with x, y and radius properties. + * Gets the right-center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - static Clone(source: Phaser.Geom.Circle | object): Phaser.Geom.Circle; + getRightCenter(output?: O, includeParent?: boolean): O; /** - * Check to see if the Circle contains the given x / y coordinates. - * @param circle The Circle to check. - * @param x The x coordinate to check within the circle. - * @param y The y coordinate to check within the circle. + * Gets the bottom-left corner coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - static Contains(circle: Phaser.Geom.Circle, x: number, y: number): boolean; + getBottomLeft(output?: O, includeParent?: boolean): O; /** - * Check to see if the Circle contains the given Point object. - * @param circle The Circle to check. - * @param point The Point object to check if it's within the Circle or not. + * Gets the bottom-center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - static ContainsPoint(circle: Phaser.Geom.Circle, point: Phaser.Geom.Point | object): boolean; + getBottomCenter(output?: O, includeParent?: boolean): O; /** - * Check to see if the Circle contains all four points of the given Rectangle object. - * @param circle The Circle to check. - * @param rect The Rectangle object to check if it's within the Circle or not. + * Gets the bottom-right corner coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - static ContainsRect(circle: Phaser.Geom.Circle, rect: Phaser.Geom.Rectangle | object): boolean; + getBottomRight(output?: O, includeParent?: boolean): O; /** - * Copies the `x`, `y` and `radius` properties from the `source` Circle - * into the given `dest` Circle, then returns the `dest` Circle. - * @param source The source Circle to copy the values from. - * @param dest The destination Circle to copy the values to. + * Gets the bounds of this Game Object, regardless of origin. + * The values are stored and returned in a Rectangle, or Rectangle-like, object. + * @param output An object to store the values in. If not provided a new Rectangle will be created. */ - static CopyFrom(source: Phaser.Geom.Circle, dest: O): O; + getBounds(output?: O): O; /** - * Compares the `x`, `y` and `radius` properties of the two given Circles. - * Returns `true` if they all match, otherwise returns `false`. - * @param circle The first Circle to compare. - * @param toCompare The second Circle to compare. + * The Mask this Game Object is using during render. */ - static Equals(circle: Phaser.Geom.Circle, toCompare: Phaser.Geom.Circle): boolean; + mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask; /** - * Returns the bounds of the Circle object. - * @param circle The Circle to get the bounds from. - * @param out A Rectangle, or rectangle-like object, to store the circle bounds in. If not given a new Rectangle will be created. + * Sets the mask that this Game Object will use to render with. + * + * The mask must have been previously created and can be either a GeometryMask or a BitmapMask. + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * + * If a mask is already set on this Game Object it will be immediately replaced. + * + * Masks are positioned in global space and are not relative to the Game Object to which they + * are applied. The reason for this is that multiple Game Objects can all share the same mask. + * + * Masks have no impact on physics or input detection. They are purely a rendering component + * that allows you to limit what is visible during the render pass. + * @param mask The mask this Game Object will use when rendering. */ - static GetBounds(circle: Phaser.Geom.Circle, out?: O): O; + setMask(mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask): this; /** - * Returns a Point object containing the coordinates of a point on the circumference of the Circle - * based on the given angle normalized to the range 0 to 1. I.e. a value of 0.5 will give the point - * at 180 degrees around the circle. - * @param circle The Circle to get the circumference point on. - * @param position A value between 0 and 1, where 0 equals 0 degrees, 0.5 equals 180 degrees and 1 equals 360 around the circle. - * @param out An object to store the return values in. If not given a Point object will be created. + * Clears the mask that this Game Object was using. + * @param destroyMask Destroy the mask before clearing it? Default false. */ - static GetPoint(circle: Phaser.Geom.Circle, position: number, out?: O): O; + clearMask(destroyMask?: boolean): this; /** - * Returns an array of Point objects containing the coordinates of the points around the circumference of the Circle, - * based on the given quantity or stepRate values. - * @param circle The Circle to get the points from. - * @param quantity The amount of points to return. If a falsey value the quantity will be derived from the `stepRate` instead. - * @param stepRate Sets the quantity by getting the circumference of the circle and dividing it by the stepRate. - * @param output An array to insert the points in to. If not provided a new array will be created. + * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, + * including this one. + * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * + * To create the mask you need to pass in a reference to a renderable Game Object. + * A renderable Game Object is one that uses a texture to render with, such as an + * Image, Sprite, Render Texture or BitmapText. + * + * If you do not provide a renderable object, and this Game Object has a texture, + * it will use itself as the object. This means you can call this method to create + * a Bitmap Mask from any renderable Game Object. + * @param renderable A renderable Game Object that uses a texture, such as a Sprite. */ - static GetPoints(circle: Phaser.Geom.Circle, quantity: integer, stepRate?: number, output?: any[]): Phaser.Geom.Point[]; + createBitmapMask(renderable?: Phaser.GameObjects.GameObject): Phaser.Display.Masks.BitmapMask; /** - * Offsets the Circle by the values given. - * @param circle The Circle to be offset (translated.) - * @param x The amount to horizontally offset the Circle by. - * @param y The amount to vertically offset the Circle by. + * Creates and returns a Geometry Mask. This mask can be used by any Game Object, + * including this one. + * + * To create the mask you need to pass in a reference to a Graphics Game Object. + * + * If you do not provide a graphics object, and this Game Object is an instance + * of a Graphics object, then it will use itself to create the mask. + * + * This means you can call this method to create a Geometry Mask from any Graphics Game Object. + * @param graphics A Graphics Game Object. The geometry within it will be used as the mask. */ - static Offset(circle: O, x: number, y: number): O; + createGeometryMask(graphics?: Phaser.GameObjects.Graphics): Phaser.Display.Masks.GeometryMask; /** - * Offsets the Circle by the values given in the `x` and `y` properties of the Point object. - * @param circle The Circle to be offset (translated.) - * @param point The Point object containing the values to offset the Circle by. + * The horizontal origin of this Game Object. + * The origin maps the relationship between the size and position of the Game Object. + * The default value is 0.5, meaning all Game Objects are positioned based on their center. + * Setting the value to 0 means the position now relates to the left of the Game Object. */ - static OffsetPoint(circle: O, point: Phaser.Geom.Point | object): O; + originX: number; /** - * Returns a uniformly distributed random point from anywhere within the given Circle. - * @param circle The Circle to get a random point from. - * @param out A Point or point-like object to set the random `x` and `y` values in. + * The vertical origin of this Game Object. + * The origin maps the relationship between the size and position of the Game Object. + * The default value is 0.5, meaning all Game Objects are positioned based on their center. + * Setting the value to 0 means the position now relates to the top of the Game Object. */ - static Random(circle: Phaser.Geom.Circle, out?: O): O; - - } + originY: number; - /** - * A Circle Geometry object type. - */ - var CIRCLE: integer; + /** + * The horizontal display origin of this Game Object. + * The origin is a normalized value between 0 and 1. + * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. + */ + displayOriginX: number; - /** - * An Ellipse Geometry object type. - */ - var ELLIPSE: integer; - - /** - * A Line Geometry object type. - */ - var LINE: integer; - - /** - * A Point Geometry object type. - */ - var POINT: integer; - - /** - * A Polygon Geometry object type. - */ - var POLYGON: integer; - - /** - * A Rectangle Geometry object type. - */ - var RECTANGLE: integer; - - /** - * A Triangle Geometry object type. - */ - var TRIANGLE: integer; + /** + * The vertical display origin of this Game Object. + * The origin is a normalized value between 0 and 1. + * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. + */ + displayOriginY: number; - /** - * An Ellipse object. - * - * This is a geometry object, containing numerical values and related methods to inspect and modify them. - * It is not a Game Object, in that you cannot add it to the display list, and it has no texture. - * To render an Ellipse you should look at the capabilities of the Graphics class. - */ - class Ellipse { /** + * Sets the origin of this Game Object. * - * @param x The x position of the center of the ellipse. Default 0. - * @param y The y position of the center of the ellipse. Default 0. - * @param width The width of the ellipse. Default 0. - * @param height The height of the ellipse. Default 0. + * The values are given in the range 0 to 1. + * @param x The horizontal origin value. Default 0.5. + * @param y The vertical origin value. If not defined it will be set to the value of `x`. Default x. */ - constructor(x?: number, y?: number, width?: number, height?: number); + setOrigin(x?: number, y?: number): this; /** - * Calculates the area of the Ellipse. - * @param ellipse The Ellipse to get the area of. + * Sets the origin of this Game Object based on the Pivot values in its Frame. */ - static Area(ellipse: Phaser.Geom.Ellipse): number; + setOriginFromFrame(): this; /** - * Returns the circumference of the given Ellipse. - * @param ellipse The Ellipse to get the circumference of. + * Sets the display origin of this Game Object. + * The difference between this and setting the origin is that you can use pixel values for setting the display origin. + * @param x The horizontal display origin value. Default 0. + * @param y The vertical display origin value. If not defined it will be set to the value of `x`. Default x. */ - static Circumference(ellipse: Phaser.Geom.Ellipse): number; + setDisplayOrigin(x?: number, y?: number): this; /** - * Returns a Point object containing the coordinates of a point on the circumference of the Ellipse based on the given angle. - * @param ellipse The Ellipse to get the circumference point on. - * @param angle The angle from the center of the Ellipse to the circumference to return the point from. Given in radians. - * @param out A Point, or point-like object, to store the results in. If not given a Point will be created. + * Updates the Display Origin cached values internally stored on this Game Object. + * You don't usually call this directly, but it is exposed for edge-cases where you may. */ - static CircumferencePoint(ellipse: Phaser.Geom.Ellipse, angle: number, out?: O): O; + updateDisplayOrigin(): this; /** - * Creates a new Ellipse instance based on the values contained in the given source. - * @param source The Ellipse to be cloned. Can be an instance of an Ellipse or a ellipse-like object, with x, y, width and height properties. + * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. */ - static Clone(source: Phaser.Geom.Ellipse): Phaser.Geom.Ellipse; + defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; /** - * Check to see if the Ellipse contains the given x / y coordinates. - * @param ellipse The Ellipse to check. - * @param x The x coordinate to check within the ellipse. - * @param y The y coordinate to check within the ellipse. + * The current WebGL pipeline of this Game Object. */ - static Contains(ellipse: Phaser.Geom.Ellipse, x: number, y: number): boolean; + pipeline: Phaser.Renderer.WebGL.WebGLPipeline; /** - * Check to see if the Ellipse contains the given Point object. - * @param ellipse The Ellipse to check. - * @param point The Point object to check if it's within the Circle or not. + * Does this Game Object have any Post Pipelines set? */ - static ContainsPoint(ellipse: Phaser.Geom.Ellipse, point: Phaser.Geom.Point | object): boolean; + hasPostPipeline: boolean; /** - * Check to see if the Ellipse contains all four points of the given Rectangle object. - * @param ellipse The Ellipse to check. - * @param rect The Rectangle object to check if it's within the Ellipse or not. + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. */ - static ContainsRect(ellipse: Phaser.Geom.Ellipse, rect: Phaser.Geom.Rectangle | object): boolean; + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; /** - * Copies the `x`, `y`, `width` and `height` properties from the `source` Ellipse - * into the given `dest` Ellipse, then returns the `dest` Ellipse. - * @param source The source Ellipse to copy the values from. - * @param dest The destination Ellipse to copy the values to. + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. */ - static CopyFrom(source: Phaser.Geom.Ellipse, dest: O): O; + pipelineData: object; /** - * The geometry constant type of this object: `GEOM_CONST.ELLIPSE`. - * Used for fast type comparisons. + * Sets the initial WebGL Pipeline of this Game Object. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. */ - readonly type: integer; + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; /** - * The x position of the center of the ellipse. + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. */ - x: number; + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; /** - * The y position of the center of the ellipse. + * Sets one, or more, Post Pipelines on this Game Object. + * + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. */ - y: number; + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; /** - * The width of the ellipse. + * Adds an entry to the `pipelineData` object belonging to this Game Object. + * + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. */ - width: number; + setPipelineData(key: string, value?: any): this; /** - * The height of the ellipse. + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - height: number; + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; /** - * Check to see if the Ellipse contains the given x / y coordinates. - * @param x The x coordinate to check within the ellipse. - * @param y The y coordinate to check within the ellipse. + * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. */ - contains(x: number, y: number): boolean; + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; /** - * Returns a Point object containing the coordinates of a point on the circumference of the Ellipse - * based on the given angle normalized to the range 0 to 1. I.e. a value of 0.5 will give the point - * at 180 degrees around the circle. - * @param position A value between 0 and 1, where 0 equals 0 degrees, 0.5 equals 180 degrees and 1 equals 360 around the ellipse. - * @param out An object to store the return values in. If not given a Point object will be created. + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. */ - getPoint(position: number, out?: O): O; + resetPostPipeline(resetData?: boolean): void; /** - * Returns an array of Point objects containing the coordinates of the points around the circumference of the Ellipse, - * based on the given quantity or stepRate values. - * @param quantity The amount of points to return. If a falsey value the quantity will be derived from the `stepRate` instead. - * @param stepRate Sets the quantity by getting the circumference of the ellipse and dividing it by the stepRate. - * @param output An array to insert the points in to. If not provided a new array will be created. + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - getPoints(quantity: integer, stepRate?: number, output?: O): O; + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; /** - * Returns a uniformly distributed random point from anywhere within the given Ellipse. - * @param point A Point or point-like object to set the random `x` and `y` values in. + * Gets the name of the WebGL Pipeline this Game Object is currently using. */ - getRandomPoint(point?: O): O; + getPipelineName(): string; /** - * Sets the x, y, width and height of this ellipse. - * @param x The x position of the center of the ellipse. - * @param y The y position of the center of the ellipse. - * @param width The width of the ellipse. - * @param height The height of the ellipse. + * The horizontal scroll factor of this Game Object. + * + * The scroll factor controls the influence of the movement of a Camera upon this Game Object. + * + * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. + * It does not change the Game Objects actual position values. + * + * A value of 1 means it will move exactly in sync with a camera. + * A value of 0 means it will not move at all, even if the camera moves. + * Other values control the degree to which the camera movement is mapped to this Game Object. + * + * Please be aware that scroll factor values other than 1 are not taken in to consideration when + * calculating physics collisions. Bodies always collide based on their world position, but changing + * the scroll factor is a visual adjustment to where the textures are rendered, which can offset + * them from physics bodies if not accounted for in your code. */ - setTo(x: number, y: number, width: number, height: number): Phaser.Geom.Ellipse; + scrollFactorX: number; /** - * Sets this Ellipse to be empty with a width and height of zero. - * Does not change its position. + * The vertical scroll factor of this Game Object. + * + * The scroll factor controls the influence of the movement of a Camera upon this Game Object. + * + * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. + * It does not change the Game Objects actual position values. + * + * A value of 1 means it will move exactly in sync with a camera. + * A value of 0 means it will not move at all, even if the camera moves. + * Other values control the degree to which the camera movement is mapped to this Game Object. + * + * Please be aware that scroll factor values other than 1 are not taken in to consideration when + * calculating physics collisions. Bodies always collide based on their world position, but changing + * the scroll factor is a visual adjustment to where the textures are rendered, which can offset + * them from physics bodies if not accounted for in your code. */ - setEmpty(): Phaser.Geom.Ellipse; + scrollFactorY: number; /** - * Sets the position of this Ellipse. - * @param x The x position of the center of the ellipse. - * @param y The y position of the center of the ellipse. + * Sets the scroll factor of this Game Object. + * + * The scroll factor controls the influence of the movement of a Camera upon this Game Object. + * + * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. + * It does not change the Game Objects actual position values. + * + * A value of 1 means it will move exactly in sync with a camera. + * A value of 0 means it will not move at all, even if the camera moves. + * Other values control the degree to which the camera movement is mapped to this Game Object. + * + * Please be aware that scroll factor values other than 1 are not taken in to consideration when + * calculating physics collisions. Bodies always collide based on their world position, but changing + * the scroll factor is a visual adjustment to where the textures are rendered, which can offset + * them from physics bodies if not accounted for in your code. + * @param x The horizontal scroll factor of this Game Object. + * @param y The vertical scroll factor of this Game Object. If not set it will use the `x` value. Default x. */ - setPosition(x: number, y: number): Phaser.Geom.Ellipse; + setScrollFactor(x: number, y?: number): this; /** - * Sets the size of this Ellipse. - * Does not change its position. - * @param width The width of the ellipse. - * @param height The height of the ellipse. Default width. + * The native (un-scaled) width of this Game Object. + * + * Changing this value will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or use + * the `displayWidth` property. */ - setSize(width: number, height?: number): Phaser.Geom.Ellipse; + width: number; /** - * Checks to see if the Ellipse is empty: has a width or height equal to zero. + * The native (un-scaled) height of this Game Object. + * + * Changing this value will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or use + * the `displayHeight` property. */ - isEmpty(): boolean; + height: number; /** - * Returns the minor radius of the ellipse. Also known as the Semi Minor Axis. + * The displayed width of this Game Object. + * + * This value takes into account the scale factor. + * + * Setting this value will adjust the Game Object's scale property. */ - getMinorRadius(): number; + displayWidth: number; /** - * Returns the major radius of the ellipse. Also known as the Semi Major Axis. + * The displayed height of this Game Object. + * + * This value takes into account the scale factor. + * + * Setting this value will adjust the Game Object's scale property. */ - getMajorRadius(): number; + displayHeight: number; /** - * The left position of the Ellipse. + * Sets the size of this Game Object to be that of the given Frame. + * + * This will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or call the + * `setDisplaySize` method, which is the same thing as changing the scale but allows you + * to do so by giving pixel values. + * + * If you have enabled this Game Object for input, changing the size will _not_ change the + * size of the hit area. To do this you should adjust the `input.hitArea` object directly. + * @param frame The frame to base the size of this Game Object on. */ - left: number; + setSizeToFrame(frame: Phaser.Textures.Frame): this; /** - * The right position of the Ellipse. + * Sets the internal size of this Game Object, as used for frame or physics body creation. + * + * This will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or call the + * `setDisplaySize` method, which is the same thing as changing the scale but allows you + * to do so by giving pixel values. + * + * If you have enabled this Game Object for input, changing the size will _not_ change the + * size of the hit area. To do this you should adjust the `input.hitArea` object directly. + * @param width The width of this Game Object. + * @param height The height of this Game Object. */ - right: number; + setSize(width: number, height: number): this; /** - * The top position of the Ellipse. + * Sets the display size of this Game Object. + * + * Calling this will adjust the scale. + * @param width The width of this Game Object. + * @param height The height of this Game Object. */ - top: number; + setDisplaySize(width: number, height: number): this; /** - * The bottom position of the Ellipse. + * The Texture this Game Object is using to render with. */ - bottom: number; + texture: Phaser.Textures.Texture | Phaser.Textures.CanvasTexture; /** - * Compares the `x`, `y`, `width` and `height` properties of the two given Ellipses. - * Returns `true` if they all match, otherwise returns `false`. - * @param ellipse The first Ellipse to compare. - * @param toCompare The second Ellipse to compare. + * The Texture Frame this Game Object is using to render with. */ - static Equals(ellipse: Phaser.Geom.Ellipse, toCompare: Phaser.Geom.Ellipse): boolean; + frame: Phaser.Textures.Frame; /** - * Returns the bounds of the Ellipse object. - * @param ellipse The Ellipse to get the bounds from. - * @param out A Rectangle, or rectangle-like object, to store the ellipse bounds in. If not given a new Rectangle will be created. + * A boolean flag indicating if this Game Object is being cropped or not. + * You can toggle this at any time after `setCrop` has been called, to turn cropping on or off. + * Equally, calling `setCrop` with no arguments will reset the crop and disable it. */ - static GetBounds(ellipse: Phaser.Geom.Ellipse, out?: O): O; + isCropped: boolean; /** - * Returns a Point object containing the coordinates of a point on the circumference of the Ellipse - * based on the given angle normalized to the range 0 to 1. I.e. a value of 0.5 will give the point - * at 180 degrees around the circle. - * @param ellipse The Ellipse to get the circumference point on. - * @param position A value between 0 and 1, where 0 equals 0 degrees, 0.5 equals 180 degrees and 1 equals 360 around the ellipse. - * @param out An object to store the return values in. If not given a Point object will be created. + * Applies a crop to a texture based Game Object, such as a Sprite or Image. + * + * The crop is a rectangle that limits the area of the texture frame that is visible during rendering. + * + * Cropping a Game Object does not change its size, dimensions, physics body or hit area, it just + * changes what is shown when rendered. + * + * The crop coordinates are relative to the texture frame, not the Game Object, meaning 0 x 0 is the top-left. + * + * Therefore, if you had a Game Object that had an 800x600 sized texture, and you wanted to show only the left + * half of it, you could call `setCrop(0, 0, 400, 600)`. + * + * It is also scaled to match the Game Object scale automatically. Therefore a crop rect of 100x50 would crop + * an area of 200x100 when applied to a Game Object that had a scale factor of 2. + * + * You can either pass in numeric values directly, or you can provide a single Rectangle object as the first argument. + * + * Call this method with no arguments at all to reset the crop, or toggle the property `isCropped` to `false`. + * + * You should do this if the crop rectangle becomes the same size as the frame itself, as it will allow + * the renderer to skip several internal calculations. + * @param x The x coordinate to start the crop from. Or a Phaser.Geom.Rectangle object, in which case the rest of the arguments are ignored. + * @param y The y coordinate to start the crop from. + * @param width The width of the crop rectangle in pixels. + * @param height The height of the crop rectangle in pixels. */ - static GetPoint(ellipse: Phaser.Geom.Ellipse, position: number, out?: O): O; + setCrop(x?: number | Phaser.Geom.Rectangle, y?: number, width?: number, height?: number): this; /** - * Returns an array of Point objects containing the coordinates of the points around the circumference of the Ellipse, - * based on the given quantity or stepRate values. - * @param ellipse The Ellipse to get the points from. - * @param quantity The amount of points to return. If a falsey value the quantity will be derived from the `stepRate` instead. - * @param stepRate Sets the quantity by getting the circumference of the ellipse and dividing it by the stepRate. - * @param out An array to insert the points in to. If not provided a new array will be created. + * Sets the texture and frame this Game Object will use to render with. + * + * Textures are referenced by their string-based keys, as stored in the Texture Manager. + * @param key The key of the texture to be used, as stored in the Texture Manager. + * @param frame The name or index of the frame within the Texture. */ - static GetPoints(ellipse: Phaser.Geom.Ellipse, quantity: integer, stepRate?: number, out?: O): O; + setTexture(key: string, frame?: string | number): this; /** - * Offsets the Ellipse by the values given. - * @param ellipse The Ellipse to be offset (translated.) - * @param x The amount to horizontally offset the Ellipse by. - * @param y The amount to vertically offset the Ellipse by. + * Sets the frame this Game Object will use to render with. + * + * The Frame has to belong to the current Texture being used. + * + * It can be either a string or an index. + * + * Calling `setFrame` will modify the `width` and `height` properties of your Game Object. + * It will also change the `origin` if the Frame has a custom pivot point, as exported from packages like Texture Packer. + * @param frame The name or index of the frame within the Texture. + * @param updateSize Should this call adjust the size of the Game Object? Default true. + * @param updateOrigin Should this call adjust the origin of the Game Object? Default true. */ - static Offset(ellipse: O, x: number, y: number): O; + setFrame(frame: string | number, updateSize?: boolean, updateOrigin?: boolean): this; /** - * Offsets the Ellipse by the values given in the `x` and `y` properties of the Point object. - * @param ellipse The Ellipse to be offset (translated.) - * @param point The Point object containing the values to offset the Ellipse by. + * The tint value being applied to the top-left vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. */ - static OffsetPoint(ellipse: O, point: Phaser.Geom.Point | object): O; + tintTopLeft: number; /** - * Returns a uniformly distributed random point from anywhere within the given Ellipse. - * @param ellipse The Ellipse to get a random point from. - * @param out A Point or point-like object to set the random `x` and `y` values in. + * The tint value being applied to the top-right vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. */ - static Random(ellipse: Phaser.Geom.Ellipse, out?: O): O; + tintTopRight: number; - } + /** + * The tint value being applied to the bottom-left vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintBottomLeft: number; - namespace Intersects { /** - * Checks if two Circles intersect. - * @param circleA The first Circle to check for intersection. - * @param circleB The second Circle to check for intersection. + * The tint value being applied to the bottom-right vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. */ - function CircleToCircle(circleA: Phaser.Geom.Circle, circleB: Phaser.Geom.Circle): boolean; + tintBottomRight: number; /** - * Checks for intersection between a circle and a rectangle. - * @param circle The circle to be checked. - * @param rect The rectangle to be checked. + * The tint fill mode. + * + * `false` = An additive tint (the default), where vertices colors are blended with the texture. + * `true` = A fill tint, where the vertices colors replace the texture, but respects texture alpha. */ - function CircleToRectangle(circle: Phaser.Geom.Circle, rect: Phaser.Geom.Rectangle): boolean; + tintFill: boolean; /** - * Checks if two Circles intersect and returns the intersection points as a Point object array. - * @param circleA The first Circle to check for intersection. - * @param circleB The second Circle to check for intersection. - * @param out An optional array in which to store the points of intersection. + * Clears all tint values associated with this Game Object. + * + * Immediately sets the color values back to 0xffffff and the tint type to 'additive', + * which results in no visible change to the texture. */ - function GetCircleToCircle(circleA: Phaser.Geom.Circle, circleB: Phaser.Geom.Circle, out?: any[]): any[]; + clearTint(): this; /** - * Checks for intersection between a circle and a rectangle, - * and returns the intersection points as a Point object array. - * @param circle The circle to be checked. - * @param rect The rectangle to be checked. - * @param out An optional array in which to store the points of intersection. + * Sets an additive tint on this Game Object. + * + * The tint works by taking the pixel color values from the Game Objects texture, and then + * multiplying it by the color value of the tint. You can provide either one color value, + * in which case the whole Game Object will be tinted in that color. Or you can provide a color + * per corner. The colors are blended together across the extent of the Game Object. + * + * To modify the tint color once set, either call this method again with new values or use the + * `tint` property to set all colors at once. Or, use the properties `tintTopLeft`, `tintTopRight, + * `tintBottomLeft` and `tintBottomRight` to set the corner color values independently. + * + * To remove a tint call `clearTint`. + * + * To swap this from being an additive tint to a fill based tint set the property `tintFill` to `true`. + * @param topLeft The tint being applied to the top-left of the Game Object. If no other values are given this value is applied evenly, tinting the whole Game Object. Default 0xffffff. + * @param topRight The tint being applied to the top-right of the Game Object. + * @param bottomLeft The tint being applied to the bottom-left of the Game Object. + * @param bottomRight The tint being applied to the bottom-right of the Game Object. */ - function GetCircleToRectangle(circle: Phaser.Geom.Circle, rect: Phaser.Geom.Rectangle, out?: any[]): any[]; + setTint(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; /** - * Checks for intersection between the line segment and circle, - * and returns the intersection points as a Point object array. - * @param line The line segment to check. - * @param circle The circle to check against the line. - * @param out An optional array in which to store the points of intersection. + * Sets a fill-based tint on this Game Object. + * + * Unlike an additive tint, a fill-tint literally replaces the pixel colors from the texture + * with those in the tint. You can use this for effects such as making a player flash 'white' + * if hit by something. You can provide either one color value, in which case the whole + * Game Object will be rendered in that color. Or you can provide a color per corner. The colors + * are blended together across the extent of the Game Object. + * + * To modify the tint color once set, either call this method again with new values or use the + * `tint` property to set all colors at once. Or, use the properties `tintTopLeft`, `tintTopRight, + * `tintBottomLeft` and `tintBottomRight` to set the corner color values independently. + * + * To remove a tint call `clearTint`. + * + * To swap this from being a fill-tint to an additive tint set the property `tintFill` to `false`. + * @param topLeft The tint being applied to the top-left of the Game Object. If not other values are given this value is applied evenly, tinting the whole Game Object. Default 0xffffff. + * @param topRight The tint being applied to the top-right of the Game Object. + * @param bottomLeft The tint being applied to the bottom-left of the Game Object. + * @param bottomRight The tint being applied to the bottom-right of the Game Object. */ - function GetLineToCircle(line: Phaser.Geom.Line, circle: Phaser.Geom.Circle, out?: any[]): any[]; + setTintFill(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; /** - * Checks for intersection between the Line and a Rectangle shape, - * and returns the intersection points as a Point object array. - * @param line The Line to check for intersection. - * @param rect The Rectangle to check for intersection. - * @param out An optional array in which to store the points of intersection. + * The tint value being applied to the whole of the Game Object. + * This property is a setter-only. Use the properties `tintTopLeft` etc to read the current tint value. */ - function GetLineToRectangle(line: Phaser.Geom.Line, rect: Phaser.Geom.Rectangle | object, out?: any[]): any[]; + tint: number; /** - * Checks if two Rectangle shapes intersect and returns the area of this intersection as Rectangle object. - * - * If optional `output` parameter is omitted, new Rectangle object is created and returned. If there is intersection, it will contain intersection area. If there is no intersection, it wil be empty Rectangle (all values set to zero). + * Does this Game Object have a tint applied? * - * If Rectangle object is passed as `output` and there is intersection, then intersection area data will be loaded into it and it will be returned. If there is no intersection, it will be returned without any change. - * @param rectA The first Rectangle object. - * @param rectB The second Rectangle object. - * @param output Optional Rectangle object. If given, the intersection data will be loaded into it (in case of no intersection, it will be left unchanged). Otherwise, new Rectangle object will be created and returned with either intersection data or empty (all values set to zero), if there is no intersection. + * It checks to see if the 4 tint properties are set to the value 0xffffff + * and that the `tintFill` property is `false`. This indicates that a Game Object isn't tinted. */ - function GetRectangleIntersection(rectA: Phaser.Geom.Rectangle, rectB: Phaser.Geom.Rectangle, output?: O): O; + readonly isTinted: boolean; /** - * Checks if two Rectangles intersect and returns the intersection points as a Point object array. - * - * A Rectangle intersects another Rectangle if any part of its bounds is within the other Rectangle's bounds. As such, the two Rectangles are considered "solid". A Rectangle with no width or no height will never intersect another Rectangle. - * @param rectA The first Rectangle to check for intersection. - * @param rectB The second Rectangle to check for intersection. - * @param out An optional array in which to store the points of intersection. + * The x position of this Game Object. */ - function GetRectangleToRectangle(rectA: Phaser.Geom.Rectangle, rectB: Phaser.Geom.Rectangle, out?: any[]): any[]; + x: number; /** - * Checks for intersection between Rectangle shape and Triangle shape, - * and returns the intersection points as a Point object array. - * @param rect Rectangle object to test. - * @param triangle Triangle object to test. - * @param out An optional array in which to store the points of intersection. + * The y position of this Game Object. */ - function GetRectangleToTriangle(rect: Phaser.Geom.Rectangle, triangle: Phaser.Geom.Triangle, out?: any[]): any[]; + y: number; /** - * Checks if a Triangle and a Circle intersect, and returns the intersection points as a Point object array. + * The z position of this Game Object. * - * A Circle intersects a Triangle if its center is located within it or if any of the Triangle's sides intersect the Circle. As such, the Triangle and the Circle are considered "solid" for the intersection. - * @param triangle The Triangle to check for intersection. - * @param circle The Circle to check for intersection. - * @param out An optional array in which to store the points of intersection. + * Note: The z position does not control the rendering order of 2D Game Objects. Use + * {@link Phaser.GameObjects.Components.Depth#depth} instead. */ - function GetTriangleToCircle(triangle: Phaser.Geom.Triangle, circle: Phaser.Geom.Circle, out?: any[]): any[]; + z: number; /** - * Checks if a Triangle and a Line intersect, and returns the intersection points as a Point object array. - * - * The Line intersects the Triangle if it starts inside of it, ends inside of it, or crosses any of the Triangle's sides. Thus, the Triangle is considered "solid". - * @param triangle The Triangle to check with. - * @param line The Line to check with. - * @param out An optional array in which to store the points of intersection. + * The w position of this Game Object. */ - function GetTriangleToLine(triangle: Phaser.Geom.Triangle, line: Phaser.Geom.Line, out?: any[]): any[]; + w: number; /** - * Checks if two Triangles intersect, and returns the intersection points as a Point object array. + * This is a special setter that allows you to set both the horizontal and vertical scale of this Game Object + * to the same value, at the same time. When reading this value the result returned is `(scaleX + scaleY) / 2`. * - * A Triangle intersects another Triangle if any pair of their lines intersects or if any point of one Triangle is within the other Triangle. Thus, the Triangles are considered "solid". - * @param triangleA The first Triangle to check for intersection. - * @param triangleB The second Triangle to check for intersection. - * @param out An optional array in which to store the points of intersection. + * Use of this property implies you wish the horizontal and vertical scales to be equal to each other. If this + * isn't the case, use the `scaleX` or `scaleY` properties instead. */ - function GetTriangleToTriangle(triangleA: Phaser.Geom.Triangle, triangleB: Phaser.Geom.Triangle, out?: any[]): any[]; + scale: number; /** - * Checks for intersection between the line segment and circle. - * - * Based on code by [Matt DesLauriers](https://github.com/mattdesl/line-circle-collision/blob/master/LICENSE.md). - * @param line The line segment to check. - * @param circle The circle to check against the line. - * @param nearest An optional Point-like object. If given the closest point on the Line where the circle intersects will be stored in this object. + * The horizontal scale of this Game Object. */ - function LineToCircle(line: Phaser.Geom.Line, circle: Phaser.Geom.Circle, nearest?: Phaser.Geom.Point | any): boolean; + scaleX: number; /** - * Checks if two Lines intersect. If the Lines are identical, they will be treated as parallel and thus non-intersecting. - * @param line1 The first Line to check. - * @param line2 The second Line to check. - * @param out A Point in which to optionally store the point of intersection. + * The vertical scale of this Game Object. */ - function LineToLine(line1: Phaser.Geom.Line, line2: Phaser.Geom.Line, out?: Phaser.Geom.Point): boolean; + scaleY: number; /** - * Checks for intersection between the Line and a Rectangle shape, or a rectangle-like - * object, with public `x`, `y`, `right` and `bottom` properties, such as a Sprite or Body. - * - * An intersection is considered valid if: + * The angle of this Game Object as expressed in degrees. * - * The line starts within, or ends within, the Rectangle. - * The line segment intersects one of the 4 rectangle edges. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left + * and -90 is up. * - * The for the purposes of this function rectangles are considered 'solid'. - * @param line The Line to check for intersection. - * @param rect The Rectangle to check for intersection. + * If you prefer to work in radians, see the `rotation` property instead. */ - function LineToRectangle(line: Phaser.Geom.Line, rect: Phaser.Geom.Rectangle | object): boolean; + angle: number; /** - * Checks if the a Point falls between the two end-points of a Line, based on the given line thickness. + * The angle of this Game Object in radians. * - * Assumes that the line end points are circular, not square. - * @param point The point, or point-like object to check. - * @param line The line segment to test for intersection on. - * @param lineThickness The line thickness. Assumes that the line end points are circular. Default 1. - */ - function PointToLine(point: Phaser.Geom.Point | any, line: Phaser.Geom.Line, lineThickness?: number): boolean; - - /** - * Checks if a Point is located on the given line segment. - * @param point The Point to check for intersection. - * @param line The line segment to check for intersection. - */ - function PointToLineSegment(point: Phaser.Geom.Point, line: Phaser.Geom.Line): boolean; - - /** - * Checks if two Rectangles intersect. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. * - * A Rectangle intersects another Rectangle if any part of its bounds is within the other Rectangle's bounds. - * As such, the two Rectangles are considered "solid". - * A Rectangle with no width or no height will never intersect another Rectangle. - * @param rectA The first Rectangle to check for intersection. - * @param rectB The second Rectangle to check for intersection. + * If you prefer to work in degrees, see the `angle` property instead. */ - function RectangleToRectangle(rectA: Phaser.Geom.Rectangle, rectB: Phaser.Geom.Rectangle): boolean; + rotation: number; /** - * Checks for intersection between Rectangle shape and Triangle shape. - * @param rect Rectangle object to test. - * @param triangle Triangle object to test. + * Sets the position of this Game Object. + * @param x The x position of this Game Object. Default 0. + * @param y The y position of this Game Object. If not set it will use the `x` value. Default x. + * @param z The z position of this Game Object. Default 0. + * @param w The w position of this Game Object. Default 0. */ - function RectangleToTriangle(rect: Phaser.Geom.Rectangle, triangle: Phaser.Geom.Triangle): boolean; + setPosition(x?: number, y?: number, z?: number, w?: number): this; /** - * Check if rectangle intersects with values. - * @param rect The rectangle object - * @param left The x coordinate of the left of the Rectangle. - * @param right The x coordinate of the right of the Rectangle. - * @param top The y coordinate of the top of the Rectangle. - * @param bottom The y coordinate of the bottom of the Rectangle. - * @param tolerance Tolerance allowed in the calculation, expressed in pixels. Default 0. + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. */ - function RectangleToValues(rect: Phaser.Geom.Rectangle, left: number, right: number, top: number, bottom: number, tolerance?: number): boolean; + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; /** - * Checks if a Triangle and a Circle intersect. + * Sets the position of this Game Object to be a random position within the confines of + * the given area. * - * A Circle intersects a Triangle if its center is located within it or if any of the Triangle's sides intersect the Circle. As such, the Triangle and the Circle are considered "solid" for the intersection. - * @param triangle The Triangle to check for intersection. - * @param circle The Circle to check for intersection. + * If no area is specified a random position between 0 x 0 and the game width x height is used instead. + * + * The position does not factor in the size of this Game Object, meaning that only the origin is + * guaranteed to be within the area. + * @param x The x position of the top-left of the random area. Default 0. + * @param y The y position of the top-left of the random area. Default 0. + * @param width The width of the random area. + * @param height The height of the random area. */ - function TriangleToCircle(triangle: Phaser.Geom.Triangle, circle: Phaser.Geom.Circle): boolean; + setRandomPosition(x?: number, y?: number, width?: number, height?: number): this; /** - * Checks if a Triangle and a Line intersect. - * - * The Line intersects the Triangle if it starts inside of it, ends inside of it, or crosses any of the Triangle's sides. Thus, the Triangle is considered "solid". - * @param triangle The Triangle to check with. - * @param line The Line to check with. + * Sets the rotation of this Game Object. + * @param radians The rotation of this Game Object, in radians. Default 0. */ - function TriangleToLine(triangle: Phaser.Geom.Triangle, line: Phaser.Geom.Line): boolean; + setRotation(radians?: number): this; /** - * Checks if two Triangles intersect. - * - * A Triangle intersects another Triangle if any pair of their lines intersects or if any point of one Triangle is within the other Triangle. Thus, the Triangles are considered "solid". - * @param triangleA The first Triangle to check for intersection. - * @param triangleB The second Triangle to check for intersection. + * Sets the angle of this Game Object. + * @param degrees The rotation of this Game Object, in degrees. Default 0. */ - function TriangleToTriangle(triangleA: Phaser.Geom.Triangle, triangleB: Phaser.Geom.Triangle): boolean; - - } + setAngle(degrees?: number): this; - /** - * Defines a Line segment, a part of a line between two endpoints. - */ - class Line { /** - * - * @param x1 The x coordinate of the lines starting point. Default 0. - * @param y1 The y coordinate of the lines starting point. Default 0. - * @param x2 The x coordinate of the lines ending point. Default 0. - * @param y2 The y coordinate of the lines ending point. Default 0. + * Sets the scale of this Game Object. + * @param x The horizontal scale of this Game Object. + * @param y The vertical scale of this Game Object. If not set it will use the `x` value. Default x. */ - constructor(x1?: number, y1?: number, x2?: number, y2?: number); + setScale(x: number, y?: number): this; /** - * Calculate the angle of the line in radians. - * @param line The line to calculate the angle of. + * Sets the x position of this Game Object. + * @param value The x position of this Game Object. Default 0. */ - static Angle(line: Phaser.Geom.Line): number; + setX(value?: number): this; /** - * Using Bresenham's line algorithm this will return an array of all coordinates on this line. - * - * The `start` and `end` points are rounded before this runs as the algorithm works on integers. - * @param line The line. - * @param stepRate The optional step rate for the points on the line. Default 1. - * @param results An optional array to push the resulting coordinates into. + * Sets the y position of this Game Object. + * @param value The y position of this Game Object. Default 0. */ - static BresenhamPoints(line: Phaser.Geom.Line, stepRate?: integer, results?: Phaser.Types.Math.Vector2Like[]): Phaser.Types.Math.Vector2Like[]; + setY(value?: number): this; /** - * Center a line on the given coordinates. - * @param line The line to center. - * @param x The horizontal coordinate to center the line on. - * @param y The vertical coordinate to center the line on. + * Sets the z position of this Game Object. + * + * Note: The z position does not control the rendering order of 2D Game Objects. Use + * {@link Phaser.GameObjects.Components.Depth#setDepth} instead. + * @param value The z position of this Game Object. Default 0. */ - static CenterOn(line: Phaser.Geom.Line, x: number, y: number): Phaser.Geom.Line; + setZ(value?: number): this; /** - * Clone the given line. - * @param source The source line to clone. + * Sets the w position of this Game Object. + * @param value The w position of this Game Object. Default 0. */ - static Clone(source: Phaser.Geom.Line): Phaser.Geom.Line; + setW(value?: number): this; /** - * Copy the values of one line to a destination line. - * @param source The source line to copy the values from. - * @param dest The destination line to copy the values to. + * Gets the local transform matrix for this Game Object. + * @param tempMatrix The matrix to populate with the values from this Game Object. */ - static CopyFrom(source: Phaser.Geom.Line, dest: O): O; + getLocalTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; /** - * Compare two lines for strict equality. - * @param line The first line to compare. - * @param toCompare The second line to compare. + * Gets the world transform matrix for this Game Object, factoring in any parent Containers. + * @param tempMatrix The matrix to populate with the values from this Game Object. + * @param parentMatrix A temporary matrix to hold parent values during the calculations. */ - static Equals(line: Phaser.Geom.Line, toCompare: Phaser.Geom.Line): boolean; + getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; /** - * Extends the start and end points of a Line by the given amounts. - * - * The amounts can be positive or negative. Positive points will increase the length of the line, - * while negative ones will decrease it. + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. * - * If no `right` value is provided it will extend the length of the line equally in both directions. + * The returned Vector2 contains the translated point in its properties. * - * Pass a value of zero to leave the start or end point unchanged. - * @param line The line instance to extend. - * @param left The amount to extend the start of the line by. - * @param right The amount to extend the end of the line by. If not given it will be set to the `left` value. + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. */ - static Extend(line: Phaser.Geom.Line, left: number, right?: number): Phaser.Geom.Line; + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; /** - * Get the midpoint of the given line. - * @param line The line to get the midpoint of. - * @param out An optional point object to store the midpoint in. + * Gets the sum total rotation of all of this Game Objects parent Containers. + * + * The returned value is in radians and will be zero if this Game Object has no parent container. */ - static GetMidPoint(line: Phaser.Geom.Line, out?: O): O; + getParentRotation(): number; /** - * Get the nearest point on a line perpendicular to the given point. - * @param line The line to get the nearest point on. - * @param point The point to get the nearest point to. - * @param out An optional point, or point-like object, to store the coordinates of the nearest point on the line. + * The visible state of the Game Object. + * + * An invisible Game Object will skip rendering, but will still process update logic. */ - static GetNearestPoint(line: Phaser.Geom.Line, point: Phaser.Geom.Point | object, out?: O): O; + visible: boolean; /** - * Calculate the normal of the given line. + * Sets the visibility of this Game Object. * - * The normal of a line is a vector that points perpendicular from it. - * @param line The line to calculate the normal of. - * @param out An optional point object to store the normal in. + * An invisible Game Object will skip rendering, but will still process update logic. + * @param value The visible state of the Game Object. */ - static GetNormal(line: Phaser.Geom.Line, out?: O): O; + setVisible(value: boolean): this; + } + + /** + * A Zone Game Object. + * + * A Zone is a non-rendering rectangular Game Object that has a position and size. + * It has no texture and never displays, but does live on the display list and + * can be moved, scaled and rotated like any other Game Object. + * + * Its primary use is for creating Drop Zones and Input Hit Areas and it has a couple of helper methods + * specifically for this. It is also useful for object overlap checks, or as a base for your own + * non-displaying Game Objects. + * The default origin is 0.5, the center of the Zone, the same as with Game Objects. + */ + class Zone extends Phaser.GameObjects.GameObject implements Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.GetBounds, Phaser.GameObjects.Components.Origin, Phaser.GameObjects.Components.Transform, Phaser.GameObjects.Components.ScrollFactor, Phaser.GameObjects.Components.Visible { /** - * Get a point on a line that's a given percentage along its length. - * @param line The line. - * @param position A value between 0 and 1, where 0 is the start, 0.5 is the middle and 1 is the end of the line. - * @param out An optional point, or point-like object, to store the coordinates of the point on the line. + * + * @param scene The Scene to which this Game Object belongs. + * @param x The horizontal position of this Game Object in the world. + * @param y The vertical position of this Game Object in the world. + * @param width The width of the Game Object. Default 1. + * @param height The height of the Game Object. Default 1. */ - static GetPoint(line: Phaser.Geom.Line, position: number, out?: O): O; + constructor(scene: Phaser.Scene, x: number, y: number, width?: number, height?: number); /** - * Get a number of points along a line's length. - * - * Provide a `quantity` to get an exact number of points along the line. - * - * Provide a `stepRate` to ensure a specific distance between each point on the line. Set `quantity` to `0` when - * providing a `stepRate`. - * @param line The line. - * @param quantity The number of points to place on the line. Set to `0` to use `stepRate` instead. - * @param stepRate The distance between each point on the line. When set, `quantity` is implied and should be set to `0`. - * @param out An optional array of Points, or point-like objects, to store the coordinates of the points on the line. + * The native (un-scaled) width of this Game Object. */ - static GetPoints(line: Phaser.Geom.Line, quantity: integer, stepRate?: number, out?: O): O; + width: number; /** - * Get the shortest distance from a Line to the given Point. - * @param line The line to get the distance from. - * @param point The point to get the shortest distance to. + * The native (un-scaled) height of this Game Object. */ - static GetShortestDistance(line: Phaser.Geom.Line, point: Phaser.Geom.Point | object): O; + height: number; /** - * Calculate the height of the given line. - * @param line The line to calculate the height of. + * The Blend Mode of the Game Object. + * Although a Zone never renders, it still has a blend mode to allow it to fit seamlessly into + * display lists without causing a batch flush. */ - static Height(line: Phaser.Geom.Line): number; + blendMode: number; /** - * Calculate the length of the given line. - * @param line The line to calculate the length of. + * The displayed width of this Game Object. + * This value takes into account the scale factor. */ - static Length(line: Phaser.Geom.Line): number; + displayWidth: number; /** - * The geometry constant type of this object: `GEOM_CONST.LINE`. - * Used for fast type comparisons. + * The displayed height of this Game Object. + * This value takes into account the scale factor. */ - readonly type: integer; + displayHeight: number; /** - * The x coordinate of the lines starting point. + * Sets the size of this Game Object. + * @param width The width of this Game Object. + * @param height The height of this Game Object. + * @param resizeInput If this Zone has a Rectangle for a hit area this argument will resize the hit area as well. Default true. */ - x1: number; + setSize(width: number, height: number, resizeInput?: boolean): this; /** - * The y coordinate of the lines starting point. + * Sets the display size of this Game Object. + * Calling this will adjust the scale. + * @param width The width of this Game Object. + * @param height The height of this Game Object. */ - y1: number; + setDisplaySize(width: number, height: number): this; /** - * The x coordinate of the lines ending point. + * Sets this Zone to be a Circular Drop Zone. + * The circle is centered on this Zones `x` and `y` coordinates. + * @param radius The radius of the Circle that will form the Drop Zone. */ - x2: number; + setCircleDropZone(radius: number): this; /** - * The y coordinate of the lines ending point. + * Sets this Zone to be a Rectangle Drop Zone. + * The rectangle is centered on this Zones `x` and `y` coordinates. + * @param width The width of the rectangle drop zone. + * @param height The height of the rectangle drop zone. */ - y2: number; + setRectangleDropZone(width: number, height: number): this; /** - * Get a point on a line that's a given percentage along its length. - * @param position A value between 0 and 1, where 0 is the start, 0.5 is the middle and 1 is the end of the line. - * @param output An optional point, or point-like object, to store the coordinates of the point on the line. + * Allows you to define your own Geometry shape to be used as a Drop Zone. + * @param hitArea A Geometry shape instance, such as Phaser.Geom.Ellipse, or your own custom shape. + * @param hitAreaCallback A function that will return `true` if the given x/y coords it is sent are within the shape. */ - getPoint(position: number, output?: O): O; + setDropZone(hitArea: object, hitAreaCallback: Phaser.Types.Input.HitAreaCallback): this; /** - * Get a number of points along a line's length. + * The depth of this Game Object within the Scene. * - * Provide a `quantity` to get an exact number of points along the line. + * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order + * of Game Objects, without actually moving their position in the display list. * - * Provide a `stepRate` to ensure a specific distance between each point on the line. Set `quantity` to `0` when - * providing a `stepRate`. - * @param quantity The number of points to place on the line. Set to `0` to use `stepRate` instead. - * @param stepRate The distance between each point on the line. When set, `quantity` is implied and should be set to `0`. - * @param output An optional array of Points, or point-like objects, to store the coordinates of the points on the line. + * The default depth is zero. A Game Object with a higher depth + * value will always render in front of one with a lower value. + * + * Setting the depth will queue a depth sort event within the Scene. */ - getPoints(quantity: integer, stepRate?: integer, output?: O): O; + depth: number; /** - * Get a random Point on the Line. - * @param point An instance of a Point to be modified. + * The depth of this Game Object within the Scene. + * + * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order + * of Game Objects, without actually moving their position in the display list. + * + * The default depth is zero. A Game Object with a higher depth + * value will always render in front of one with a lower value. + * + * Setting the depth will queue a depth sort event within the Scene. + * @param value The depth of this Game Object. */ - getRandomPoint(point?: O): O; + setDepth(value: number): this; /** - * Set new coordinates for the line endpoints. - * @param x1 The x coordinate of the lines starting point. Default 0. - * @param y1 The y coordinate of the lines starting point. Default 0. - * @param x2 The x coordinate of the lines ending point. Default 0. - * @param y2 The y coordinate of the lines ending point. Default 0. + * Gets the center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. */ - setTo(x1?: number, y1?: number, x2?: number, y2?: number): Phaser.Geom.Line; + getCenter(output?: O): O; /** - * Returns a Vector2 object that corresponds to the start of this Line. - * @param vec2 A Vector2 object to set the results in. If `undefined` a new Vector2 will be created. + * Gets the top-left corner coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - getPointA(vec2?: O): O; + getTopLeft(output?: O, includeParent?: boolean): O; /** - * Returns a Vector2 object that corresponds to the end of this Line. - * @param vec2 A Vector2 object to set the results in. If `undefined` a new Vector2 will be created. + * Gets the top-center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - getPointB(vec2?: O): O; + getTopCenter(output?: O, includeParent?: boolean): O; /** - * The left position of the Line. + * Gets the top-right corner coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - left: number; + getTopRight(output?: O, includeParent?: boolean): O; /** - * The right position of the Line. + * Gets the left-center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - right: number; + getLeftCenter(output?: O, includeParent?: boolean): O; /** - * The top position of the Line. + * Gets the right-center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - top: number; + getRightCenter(output?: O, includeParent?: boolean): O; /** - * The bottom position of the Line. + * Gets the bottom-left corner coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - bottom: number; + getBottomLeft(output?: O, includeParent?: boolean): O; /** - * Get the angle of the normal of the given line in radians. - * @param line The line to calculate the angle of the normal of. + * Gets the bottom-center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - static NormalAngle(line: Phaser.Geom.Line): number; + getBottomCenter(output?: O, includeParent?: boolean): O; /** - * [description] - * @param line The Line object to get the normal value from. + * Gets the bottom-right corner coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - static NormalX(line: Phaser.Geom.Line): number; + getBottomRight(output?: O, includeParent?: boolean): O; /** - * The Y value of the normal of the given line. - * The normal of a line is a vector that points perpendicular from it. - * @param line The line to calculate the normal of. + * Gets the bounds of this Game Object, regardless of origin. + * The values are stored and returned in a Rectangle, or Rectangle-like, object. + * @param output An object to store the values in. If not provided a new Rectangle will be created. */ - static NormalY(line: Phaser.Geom.Line): number; + getBounds(output?: O): O; /** - * Offset a line by the given amount. - * @param line The line to offset. - * @param x The horizontal offset to add to the line. - * @param y The vertical offset to add to the line. + * The horizontal origin of this Game Object. + * The origin maps the relationship between the size and position of the Game Object. + * The default value is 0.5, meaning all Game Objects are positioned based on their center. + * Setting the value to 0 means the position now relates to the left of the Game Object. */ - static Offset(line: O, x: number, y: number): O; + originX: number; /** - * Calculate the perpendicular slope of the given line. - * @param line The line to calculate the perpendicular slope of. + * The vertical origin of this Game Object. + * The origin maps the relationship between the size and position of the Game Object. + * The default value is 0.5, meaning all Game Objects are positioned based on their center. + * Setting the value to 0 means the position now relates to the top of the Game Object. */ - static PerpSlope(line: Phaser.Geom.Line): number; + originY: number; /** - * Returns a random point on a given Line. - * @param line The Line to calculate the random Point on. - * @param out An instance of a Point to be modified. + * The horizontal display origin of this Game Object. + * The origin is a normalized value between 0 and 1. + * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. */ - static Random(line: Phaser.Geom.Line, out?: O): O; + displayOriginX: number; /** - * Calculate the reflected angle between two lines. - * - * This is the outgoing angle based on the angle of Line 1 and the normalAngle of Line 2. - * @param lineA The first line. - * @param lineB The second line. + * The vertical display origin of this Game Object. + * The origin is a normalized value between 0 and 1. + * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. */ - static ReflectAngle(lineA: Phaser.Geom.Line, lineB: Phaser.Geom.Line): number; + displayOriginY: number; /** - * Rotate a line around its midpoint by the given angle in radians. - * @param line The line to rotate. - * @param angle The angle of rotation in radians. + * Sets the origin of this Game Object. + * + * The values are given in the range 0 to 1. + * @param x The horizontal origin value. Default 0.5. + * @param y The vertical origin value. If not defined it will be set to the value of `x`. Default x. */ - static Rotate(line: O, angle: number): O; + setOrigin(x?: number, y?: number): this; /** - * Rotate a line around a point by the given angle in radians. - * @param line The line to rotate. - * @param point The point to rotate the line around. - * @param angle The angle of rotation in radians. + * Sets the origin of this Game Object based on the Pivot values in its Frame. */ - static RotateAroundPoint(line: O, point: Phaser.Geom.Point | object, angle: number): O; + setOriginFromFrame(): this; /** - * Rotate a line around the given coordinates by the given angle in radians. - * @param line The line to rotate. - * @param x The horizontal coordinate to rotate the line around. - * @param y The vertical coordinate to rotate the line around. - * @param angle The angle of rotation in radians. + * Sets the display origin of this Game Object. + * The difference between this and setting the origin is that you can use pixel values for setting the display origin. + * @param x The horizontal display origin value. Default 0. + * @param y The vertical display origin value. If not defined it will be set to the value of `x`. Default x. */ - static RotateAroundXY(line: O, x: number, y: number, angle: number): O; + setDisplayOrigin(x?: number, y?: number): this; /** - * Set a line to a given position, angle and length. - * @param line The line to set. - * @param x The horizontal start position of the line. - * @param y The vertical start position of the line. - * @param angle The angle of the line in radians. - * @param length The length of the line. + * Updates the Display Origin cached values internally stored on this Game Object. + * You don't usually call this directly, but it is exposed for edge-cases where you may. */ - static SetToAngle(line: O, x: number, y: number, angle: number, length: number): O; + updateDisplayOrigin(): this; /** - * Calculate the slope of the given line. - * @param line The line to calculate the slope of. + * The x position of this Game Object. */ - static Slope(line: Phaser.Geom.Line): number; + x: number; /** - * Calculate the width of the given line. - * @param line The line to calculate the width of. + * The y position of this Game Object. */ - static Width(line: Phaser.Geom.Line): number; - - } + y: number; - /** - * Defines a Point in 2D space, with an x and y component. - */ - class Point { /** + * The z position of this Game Object. * - * @param x The x coordinate of this Point. Default 0. - * @param y The y coordinate of this Point. Default x. + * Note: The z position does not control the rendering order of 2D Game Objects. Use + * {@link Phaser.GameObjects.Components.Depth#depth} instead. */ - constructor(x?: number, y?: number); + z: number; /** - * Apply `Math.ceil()` to each coordinate of the given Point. - * @param point The Point to ceil. + * The w position of this Game Object. */ - static Ceil(point: O): O; + w: number; /** - * Clone the given Point. - * @param source The source Point to clone. + * This is a special setter that allows you to set both the horizontal and vertical scale of this Game Object + * to the same value, at the same time. When reading this value the result returned is `(scaleX + scaleY) / 2`. + * + * Use of this property implies you wish the horizontal and vertical scales to be equal to each other. If this + * isn't the case, use the `scaleX` or `scaleY` properties instead. */ - static Clone(source: Phaser.Geom.Point): Phaser.Geom.Point; + scale: number; /** - * Copy the values of one Point to a destination Point. - * @param source The source Point to copy the values from. - * @param dest The destination Point to copy the values to. + * The horizontal scale of this Game Object. */ - static CopyFrom(source: Phaser.Geom.Point, dest: O): O; + scaleX: number; /** - * A comparison of two `Point` objects to see if they are equal. - * @param point The original `Point` to compare against. - * @param toCompare The second `Point` to compare. + * The vertical scale of this Game Object. */ - static Equals(point: Phaser.Geom.Point, toCompare: Phaser.Geom.Point): boolean; + scaleY: number; /** - * Apply `Math.ceil()` to each coordinate of the given Point. - * @param point The Point to floor. - */ - static Floor(point: O): O; + * The angle of this Game Object as expressed in degrees. + * + * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left + * and -90 is up. + * + * If you prefer to work in radians, see the `rotation` property instead. + */ + angle: number; /** - * Get the centroid or geometric center of a plane figure (the arithmetic mean position of all the points in the figure). - * Informally, it is the point at which a cutout of the shape could be perfectly balanced on the tip of a pin. - * @param points [description] - * @param out [description] + * The angle of this Game Object in radians. + * + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. + * + * If you prefer to work in degrees, see the `angle` property instead. */ - static GetCentroid(points: Phaser.Geom.Point[], out?: O): O; + rotation: number; /** - * Calculate the magnitude of the point, which equivalent to the length of the line from the origin to this point. - * @param point The point to calculate the magnitude for + * Sets the position of this Game Object. + * @param x The x position of this Game Object. Default 0. + * @param y The y position of this Game Object. If not set it will use the `x` value. Default x. + * @param z The z position of this Game Object. Default 0. + * @param w The w position of this Game Object. Default 0. */ - static GetMagnitude(point: Phaser.Geom.Point): number; + setPosition(x?: number, y?: number, z?: number, w?: number): this; /** - * Calculates the square of magnitude of given point.(Can be used for fast magnitude calculation of point) - * @param point Returns square of the magnitude/length of given point. + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. */ - static GetMagnitudeSq(point: Phaser.Geom.Point): number; + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; /** - * Calculates the Axis Aligned Bounding Box (or aabb) from an array of points. - * @param points [description] - * @param out [description] + * Sets the position of this Game Object to be a random position within the confines of + * the given area. + * + * If no area is specified a random position between 0 x 0 and the game width x height is used instead. + * + * The position does not factor in the size of this Game Object, meaning that only the origin is + * guaranteed to be within the area. + * @param x The x position of the top-left of the random area. Default 0. + * @param y The y position of the top-left of the random area. Default 0. + * @param width The width of the random area. + * @param height The height of the random area. */ - static GetRectangleFromPoints(points: Phaser.Geom.Point[], out?: O): O; + setRandomPosition(x?: number, y?: number, width?: number, height?: number): this; /** - * [description] - * @param pointA The starting `Point` for the interpolation. - * @param pointB The target `Point` for the interpolation. - * @param t The amount to interpolate between the two points. Generally, a value between 0 (returns the starting `Point`) and 1 (returns the target `Point`). If omitted, 0 is used. Default 0. - * @param out An optional `Point` object whose `x` and `y` values will be set to the result of the interpolation (can also be any object with `x` and `y` properties). If omitted, a new `Point` created and returned. + * Sets the rotation of this Game Object. + * @param radians The rotation of this Game Object, in radians. Default 0. */ - static Interpolate(pointA: Phaser.Geom.Point, pointB: Phaser.Geom.Point, t?: number, out?: O): O; + setRotation(radians?: number): this; /** - * Swaps the X and the Y coordinate of a point. - * @param point The Point to modify. + * Sets the angle of this Game Object. + * @param degrees The rotation of this Game Object, in degrees. Default 0. */ - static Invert(point: O): O; + setAngle(degrees?: number): this; /** - * Inverts a Point's coordinates. - * @param point The Point to invert. - * @param out The Point to return the inverted coordinates in. + * Sets the scale of this Game Object. + * @param x The horizontal scale of this Game Object. + * @param y The vertical scale of this Game Object. If not set it will use the `x` value. Default x. */ - static Negative(point: Phaser.Geom.Point, out?: O): O; + setScale(x: number, y?: number): this; /** - * The geometry constant type of this object: `GEOM_CONST.POINT`. - * Used for fast type comparisons. + * Sets the x position of this Game Object. + * @param value The x position of this Game Object. Default 0. */ - readonly type: integer; + setX(value?: number): this; /** - * The x coordinate of this Point. + * Sets the y position of this Game Object. + * @param value The y position of this Game Object. Default 0. */ - x: number; + setY(value?: number): this; /** - * The y coordinate of this Point. + * Sets the z position of this Game Object. + * + * Note: The z position does not control the rendering order of 2D Game Objects. Use + * {@link Phaser.GameObjects.Components.Depth#setDepth} instead. + * @param value The z position of this Game Object. Default 0. */ - y: number; + setZ(value?: number): this; /** - * Set the x and y coordinates of the point to the given values. - * @param x The x coordinate of this Point. Default 0. - * @param y The y coordinate of this Point. Default x. + * Sets the w position of this Game Object. + * @param value The w position of this Game Object. Default 0. */ - setTo(x?: number, y?: number): Phaser.Geom.Point; + setW(value?: number): this; /** - * [description] - * @param pointA [description] - * @param pointB [description] - * @param out [description] + * Gets the local transform matrix for this Game Object. + * @param tempMatrix The matrix to populate with the values from this Game Object. */ - static Project(pointA: Phaser.Geom.Point, pointB: Phaser.Geom.Point, out?: O): O; + getLocalTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; /** - * [description] - * @param pointA [description] - * @param pointB [description] - * @param out [description] + * Gets the world transform matrix for this Game Object, factoring in any parent Containers. + * @param tempMatrix The matrix to populate with the values from this Game Object. + * @param parentMatrix A temporary matrix to hold parent values during the calculations. */ - static ProjectUnit(pointA: Phaser.Geom.Point, pointB: Phaser.Geom.Point, out?: O): O; + getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; /** - * Changes the magnitude (length) of a two-dimensional vector without changing its direction. - * @param point The Point to treat as the end point of the vector. - * @param magnitude The new magnitude of the vector. + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. */ - static SetMagnitude(point: O, magnitude: number): O; - - } + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; - /** - * A Polygon object - * - * The polygon is a closed shape consists of a series of connected straight lines defined by list of ordered points. - * Several formats are supported to define the list of points, check the setTo method for details. - * This is a geometry object allowing you to define and inspect the shape. - * It is not a Game Object, in that you cannot add it to the display list, and it has no texture. - * To render a Polygon you should look at the capabilities of the Graphics class. - */ - class Polygon { /** + * Gets the sum total rotation of all of this Game Objects parent Containers. * - * @param points List of points defining the perimeter of this Polygon. Several formats are supported: - * - A string containing paired x y values separated by a single space: `'40 0 40 20 100 20 100 80 40 80 40 100 0 50'` - * - An array of Point objects: `[new Phaser.Point(x1, y1), ...]` - * - An array of objects with public x y properties: `[obj1, obj2, ...]` - * - An array of paired numbers that represent point coordinates: `[x1,y1, x2,y2, ...]` - * - An array of arrays with two elements representing x/y coordinates: `[[x1, y1], [x2, y2], ...]` + * The returned value is in radians and will be zero if this Game Object has no parent container. */ - constructor(points?: Phaser.Geom.Point[]); + getParentRotation(): number; /** - * Create a new polygon which is a copy of the specified polygon - * @param polygon The polygon to create a clone of + * The horizontal scroll factor of this Game Object. + * + * The scroll factor controls the influence of the movement of a Camera upon this Game Object. + * + * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. + * It does not change the Game Objects actual position values. + * + * A value of 1 means it will move exactly in sync with a camera. + * A value of 0 means it will not move at all, even if the camera moves. + * Other values control the degree to which the camera movement is mapped to this Game Object. + * + * Please be aware that scroll factor values other than 1 are not taken in to consideration when + * calculating physics collisions. Bodies always collide based on their world position, but changing + * the scroll factor is a visual adjustment to where the textures are rendered, which can offset + * them from physics bodies if not accounted for in your code. */ - static Clone(polygon: Phaser.Geom.Polygon): Phaser.Geom.Polygon; + scrollFactorX: number; /** - * Checks if a point is within the bounds of a Polygon. - * @param polygon The Polygon to check against. - * @param x The X coordinate of the point to check. - * @param y The Y coordinate of the point to check. + * The vertical scroll factor of this Game Object. + * + * The scroll factor controls the influence of the movement of a Camera upon this Game Object. + * + * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. + * It does not change the Game Objects actual position values. + * + * A value of 1 means it will move exactly in sync with a camera. + * A value of 0 means it will not move at all, even if the camera moves. + * Other values control the degree to which the camera movement is mapped to this Game Object. + * + * Please be aware that scroll factor values other than 1 are not taken in to consideration when + * calculating physics collisions. Bodies always collide based on their world position, but changing + * the scroll factor is a visual adjustment to where the textures are rendered, which can offset + * them from physics bodies if not accounted for in your code. */ - static Contains(polygon: Phaser.Geom.Polygon, x: number, y: number): boolean; + scrollFactorY: number; /** - * [description] - * @param polygon [description] - * @param point [description] + * Sets the scroll factor of this Game Object. + * + * The scroll factor controls the influence of the movement of a Camera upon this Game Object. + * + * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. + * It does not change the Game Objects actual position values. + * + * A value of 1 means it will move exactly in sync with a camera. + * A value of 0 means it will not move at all, even if the camera moves. + * Other values control the degree to which the camera movement is mapped to this Game Object. + * + * Please be aware that scroll factor values other than 1 are not taken in to consideration when + * calculating physics collisions. Bodies always collide based on their world position, but changing + * the scroll factor is a visual adjustment to where the textures are rendered, which can offset + * them from physics bodies if not accounted for in your code. + * @param x The horizontal scroll factor of this Game Object. + * @param y The vertical scroll factor of this Game Object. If not set it will use the `x` value. Default x. */ - static ContainsPoint(polygon: Phaser.Geom.Polygon, point: Phaser.Geom.Point): boolean; + setScrollFactor(x: number, y?: number): this; /** - * Calculates the bounding AABB rectangle of a polygon. - * @param polygon The polygon that should be calculated. - * @param out The rectangle or object that has x, y, width, and height properties to store the result. Optional. + * The visible state of the Game Object. + * + * An invisible Game Object will skip rendering, but will still process update logic. */ - static GetAABB(polygon: Phaser.Geom.Polygon, out?: O): O; + visible: boolean; /** - * Stores all of the points of a Polygon into a flat array of numbers following the sequence [ x,y, x,y, x,y ], - * i.e. each point of the Polygon, in the order it's defined, corresponds to two elements of the resultant - * array for the point's X and Y coordinate. - * @param polygon The Polygon whose points to export. - * @param output An array to which the points' coordinates should be appended. + * Sets the visibility of this Game Object. + * + * An invisible Game Object will skip rendering, but will still process update logic. + * @param value The visible state of the Game Object. */ - static GetNumberArray(polygon: Phaser.Geom.Polygon, output?: O): O; + setVisible(value: boolean): this; + + } + } + + namespace Geom { + /** + * A Circle object. + * + * This is a geometry object, containing numerical values and related methods to inspect and modify them. + * It is not a Game Object, in that you cannot add it to the display list, and it has no texture. + * To render a Circle you should look at the capabilities of the Graphics class. + */ + class Circle { /** - * Returns an array of Point objects containing the coordinates of the points around the perimeter of the Polygon, - * based on the given quantity or stepRate values. - * @param polygon The Polygon to get the points from. - * @param quantity The amount of points to return. If a falsey value the quantity will be derived from the `stepRate` instead. - * @param stepRate Sets the quantity by getting the perimeter of the Polygon and dividing it by the stepRate. - * @param output An array to insert the points in to. If not provided a new array will be created. + * + * @param x The x position of the center of the circle. Default 0. + * @param y The y position of the center of the circle. Default 0. + * @param radius The radius of the circle. Default 0. */ - static GetPoints(polygon: Phaser.Geom.Polygon, quantity: integer, stepRate?: number, output?: any[]): Phaser.Geom.Point[]; + constructor(x?: number, y?: number, radius?: number); /** - * Returns the perimeter of the given Polygon. - * @param polygon The Polygon to get the perimeter of. + * Calculates the area of the circle. + * @param circle The Circle to get the area of. */ - static Perimeter(polygon: Phaser.Geom.Polygon): number; + static Area(circle: Phaser.Geom.Circle): number; /** - * The geometry constant type of this object: `GEOM_CONST.POLYGON`. + * The geometry constant type of this object: `GEOM_CONST.CIRCLE`. * Used for fast type comparisons. */ - readonly type: integer; + readonly type: number; /** - * The area of this Polygon. + * The x position of the center of the circle. */ - area: number; + x: number; /** - * An array of number pair objects that make up this polygon. I.e. [ {x,y}, {x,y}, {x,y} ] + * The y position of the center of the circle. */ - points: Phaser.Geom.Point[]; + y: number; /** - * Check to see if the Polygon contains the given x / y coordinates. - * @param x The x coordinate to check within the polygon. - * @param y The y coordinate to check within the polygon. + * Check to see if the Circle contains the given x / y coordinates. + * @param x The x coordinate to check within the circle. + * @param y The y coordinate to check within the circle. */ contains(x: number, y: number): boolean; /** - * Sets this Polygon to the given points. - * - * The points can be set from a variety of formats: - * - * - A string containing paired values separated by a single space: `'40 0 40 20 100 20 100 80 40 80 40 100 0 50'` - * - An array of Point objects: `[new Phaser.Point(x1, y1), ...]` - * - An array of objects with public x/y properties: `[obj1, obj2, ...]` - * - An array of paired numbers that represent point coordinates: `[x1,y1, x2,y2, ...]` - * - An array of arrays with two elements representing x/y coordinates: `[[x1, y1], [x2, y2], ...]` - * - * `setTo` may also be called without any arguments to remove all points. - * @param points Points defining the perimeter of this polygon. Please check function description above for the different supported formats. - */ - setTo(points: any[]): Phaser.Geom.Polygon; - - /** - * Calculates the area of the Polygon. This is available in the property Polygon.area + * Returns a Point object containing the coordinates of a point on the circumference of the Circle + * based on the given angle normalized to the range 0 to 1. I.e. a value of 0.5 will give the point + * at 180 degrees around the circle. + * @param position A value between 0 and 1, where 0 equals 0 degrees, 0.5 equals 180 degrees and 1 equals 360 around the circle. + * @param out An object to store the return values in. If not given a Point object will be created. */ - calculateArea(): number; + getPoint(position: number, out?: O): O; /** - * Returns an array of Point objects containing the coordinates of the points around the perimeter of the Polygon, + * Returns an array of Point objects containing the coordinates of the points around the circumference of the Circle, * based on the given quantity or stepRate values. * @param quantity The amount of points to return. If a falsey value the quantity will be derived from the `stepRate` instead. - * @param stepRate Sets the quantity by getting the perimeter of the Polygon and dividing it by the stepRate. + * @param stepRate Sets the quantity by getting the circumference of the circle and dividing it by the stepRate. * @param output An array to insert the points in to. If not provided a new array will be created. */ - getPoints(quantity: integer, stepRate?: number, output?: O): O; - - /** - * Reverses the order of the points of a Polygon. - * @param polygon The Polygon to modify. - */ - static Reverse(polygon: O): O; + getPoints(quantity: number, stepRate?: number, output?: O): O; /** - * Takes a Polygon object and applies Chaikin's smoothing algorithm on its points. - * @param polygon The polygon to be smoothed. The polygon will be modified in-place and returned. + * Returns a uniformly distributed random point from anywhere within the Circle. + * @param point A Point or point-like object to set the random `x` and `y` values in. */ - static Smooth(polygon: O): O; - - } + getRandomPoint(point?: O): O; - /** - * Encapsulates a 2D rectangle defined by its corner point in the top-left and its extends in x (width) and y (height) - */ - class Rectangle { /** - * - * @param x The X coordinate of the top left corner of the Rectangle. Default 0. - * @param y The Y coordinate of the top left corner of the Rectangle. Default 0. - * @param width The width of the Rectangle. Default 0. - * @param height The height of the Rectangle. Default 0. + * Sets the x, y and radius of this circle. + * @param x The x position of the center of the circle. Default 0. + * @param y The y position of the center of the circle. Default 0. + * @param radius The radius of the circle. Default 0. */ - constructor(x?: number, y?: number, width?: number, height?: number); + setTo(x?: number, y?: number, radius?: number): this; /** - * Calculates the area of the given Rectangle object. - * @param rect The rectangle to calculate the area of. + * Sets this Circle to be empty with a radius of zero. + * Does not change its position. */ - static Area(rect: Phaser.Geom.Rectangle): number; + setEmpty(): this; /** - * Rounds a Rectangle's position up to the smallest integer greater than or equal to each current coordinate. - * @param rect The Rectangle to adjust. + * Sets the position of this Circle. + * @param x The x position of the center of the circle. Default 0. + * @param y The y position of the center of the circle. Default 0. */ - static Ceil(rect: O): O; + setPosition(x?: number, y?: number): this; /** - * Rounds a Rectangle's position and size up to the smallest integer greater than or equal to each respective value. - * @param rect The Rectangle to modify. + * Checks to see if the Circle is empty: has a radius of zero. */ - static CeilAll(rect: O): O; + isEmpty(): boolean; /** - * Moves the top-left corner of a Rectangle so that its center is at the given coordinates. - * @param rect The Rectangle to be centered. - * @param x The X coordinate of the Rectangle's center. - * @param y The Y coordinate of the Rectangle's center. + * The radius of the Circle. */ - static CenterOn(rect: O, x: number, y: number): O; + radius: number; /** - * Creates a new Rectangle which is identical to the given one. - * @param source The Rectangle to clone. + * The diameter of the Circle. */ - static Clone(source: Phaser.Geom.Rectangle): Phaser.Geom.Rectangle; + diameter: number; /** - * Checks if a given point is inside a Rectangle's bounds. - * @param rect The Rectangle to check. - * @param x The X coordinate of the point to check. - * @param y The Y coordinate of the point to check. + * The left position of the Circle. */ - static Contains(rect: Phaser.Geom.Rectangle, x: number, y: number): boolean; + left: number; /** - * Determines whether the specified point is contained within the rectangular region defined by this Rectangle object. - * @param rect The Rectangle object. - * @param point The point object to be checked. Can be a Phaser Point object or any object with x and y values. + * The right position of the Circle. */ - static ContainsPoint(rect: Phaser.Geom.Rectangle, point: Phaser.Geom.Point): boolean; + right: number; /** - * Tests if one rectangle fully contains another. - * @param rectA The first rectangle. - * @param rectB The second rectangle. + * The top position of the Circle. */ - static ContainsRect(rectA: Phaser.Geom.Rectangle, rectB: Phaser.Geom.Rectangle): boolean; + top: number; /** - * Copy the values of one Rectangle to a destination Rectangle. - * @param source The source Rectangle to copy the values from. - * @param dest The destination Rectangle to copy the values to. + * The bottom position of the Circle. */ - static CopyFrom(source: Phaser.Geom.Rectangle, dest: O): O; + bottom: number; /** - * Create an array of points for each corner of a Rectangle - * If an array is specified, each point object will be added to the end of the array, otherwise a new array will be created. - * @param rect The Rectangle object to be decomposed. - * @param out If provided, each point will be added to this array. + * Returns the circumference of the given Circle. + * @param circle The Circle to get the circumference of. */ - static Decompose(rect: Phaser.Geom.Rectangle, out?: any[]): any[]; + static Circumference(circle: Phaser.Geom.Circle): number; /** - * Compares the `x`, `y`, `width` and `height` properties of two rectangles. - * @param rect Rectangle A - * @param toCompare Rectangle B + * Returns a Point object containing the coordinates of a point on the circumference of the Circle based on the given angle. + * @param circle The Circle to get the circumference point on. + * @param angle The angle from the center of the Circle to the circumference to return the point from. Given in radians. + * @param out A Point, or point-like object, to store the results in. If not given a Point will be created. */ - static Equals(rect: Phaser.Geom.Rectangle, toCompare: Phaser.Geom.Rectangle): boolean; + static CircumferencePoint(circle: Phaser.Geom.Circle, angle: number, out?: O): O; /** - * Adjusts the target rectangle, changing its width, height and position, - * so that it fits inside the area of the source rectangle, while maintaining its original - * aspect ratio. - * - * Unlike the `FitOutside` function, there may be some space inside the source area not covered. - * @param target The target rectangle to adjust. - * @param source The source rectangle to envelop the target in. + * Creates a new Circle instance based on the values contained in the given source. + * @param source The Circle to be cloned. Can be an instance of a Circle or a circle-like object, with x, y and radius properties. */ - static FitInside(target: O, source: Phaser.Geom.Rectangle): O; + static Clone(source: Phaser.Geom.Circle | object): Phaser.Geom.Circle; /** - * Adjusts the target rectangle, changing its width, height and position, - * so that it fully covers the area of the source rectangle, while maintaining its original - * aspect ratio. - * - * Unlike the `FitInside` function, the target rectangle may extend further out than the source. - * @param target The target rectangle to adjust. - * @param source The source rectangle to envelope the target in. + * Check to see if the Circle contains the given x / y coordinates. + * @param circle The Circle to check. + * @param x The x coordinate to check within the circle. + * @param y The y coordinate to check within the circle. */ - static FitOutside(target: O, source: Phaser.Geom.Rectangle): O; + static Contains(circle: Phaser.Geom.Circle, x: number, y: number): boolean; /** - * Rounds down (floors) the top left X and Y coordinates of the given Rectangle to the largest integer less than or equal to them - * @param rect The rectangle to floor the top left X and Y coordinates of + * Check to see if the Circle contains the given Point object. + * @param circle The Circle to check. + * @param point The Point object to check if it's within the Circle or not. */ - static Floor(rect: O): O; + static ContainsPoint(circle: Phaser.Geom.Circle, point: Phaser.Geom.Point | object): boolean; /** - * Rounds a Rectangle's position and size down to the largest integer less than or equal to each current coordinate or dimension. - * @param rect The Rectangle to adjust. + * Check to see if the Circle contains all four points of the given Rectangle object. + * @param circle The Circle to check. + * @param rect The Rectangle object to check if it's within the Circle or not. */ - static FloorAll(rect: O): O; + static ContainsRect(circle: Phaser.Geom.Circle, rect: Phaser.Geom.Rectangle | object): boolean; /** - * Constructs new Rectangle or repositions and resizes an existing Rectangle so that all of the given points are on or within its bounds. - * @param points An array of points (either arrays with two elements corresponding to the X and Y coordinate or an object with public `x` and `y` properties) which should be surrounded by the Rectangle. - * @param out Optional Rectangle to adjust. + * Copies the `x`, `y` and `radius` properties from the `source` Circle + * into the given `dest` Circle, then returns the `dest` Circle. + * @param source The source Circle to copy the values from. + * @param dest The destination Circle to copy the values to. */ - static FromPoints(points: any[], out?: O): O; + static CopyFrom(source: Phaser.Geom.Circle, dest: O): O; /** - * Calculates the width/height ratio of a rectangle. - * @param rect The rectangle. + * Compares the `x`, `y` and `radius` properties of the two given Circles. + * Returns `true` if they all match, otherwise returns `false`. + * @param circle The first Circle to compare. + * @param toCompare The second Circle to compare. */ - static GetAspectRatio(rect: Phaser.Geom.Rectangle): number; + static Equals(circle: Phaser.Geom.Circle, toCompare: Phaser.Geom.Circle): boolean; /** - * Returns the center of a Rectangle as a Point. - * @param rect The Rectangle to get the center of. - * @param out Optional point-like object to update with the center coordinates. + * Returns the bounds of the Circle object. + * @param circle The Circle to get the bounds from. + * @param out A Rectangle, or rectangle-like object, to store the circle bounds in. If not given a new Rectangle will be created. */ - static GetCenter(rect: Phaser.Geom.Rectangle, out?: O): O; + static GetBounds(circle: Phaser.Geom.Circle, out?: O): O; /** - * Position is a value between 0 and 1 where 0 = the top-left of the rectangle and 0.5 = the bottom right. - * @param rectangle [description] - * @param position [description] - * @param out [description] + * Returns a Point object containing the coordinates of a point on the circumference of the Circle + * based on the given angle normalized to the range 0 to 1. I.e. a value of 0.5 will give the point + * at 180 degrees around the circle. + * @param circle The Circle to get the circumference point on. + * @param position A value between 0 and 1, where 0 equals 0 degrees, 0.5 equals 180 degrees and 1 equals 360 around the circle. + * @param out An object to store the return values in. If not given a Point object will be created. */ - static GetPoint(rectangle: Phaser.Geom.Rectangle, position: number, out?: O): O; + static GetPoint(circle: Phaser.Geom.Circle, position: number, out?: O): O; /** - * Return an array of points from the perimeter of the rectangle, each spaced out based on the quantity or step required. - * @param rectangle The Rectangle object to get the points from. - * @param step Step between points. Used to calculate the number of points to return when quantity is falsey. Ignored if quantity is positive. - * @param quantity The number of evenly spaced points from the rectangles perimeter to return. If falsey, step param will be used to calculate the number of points. - * @param out An optional array to store the points in. + * Returns an array of Point objects containing the coordinates of the points around the circumference of the Circle, + * based on the given quantity or stepRate values. + * @param circle The Circle to get the points from. + * @param quantity The amount of points to return. If a falsey value the quantity will be derived from the `stepRate` instead. + * @param stepRate Sets the quantity by getting the circumference of the circle and dividing it by the stepRate. + * @param output An array to insert the points in to. If not provided a new array will be created. */ - static GetPoints(rectangle: Phaser.Geom.Rectangle, step: number, quantity: integer, out?: O): O; + static GetPoints(circle: Phaser.Geom.Circle, quantity: number, stepRate?: number, output?: any[]): Phaser.Geom.Point[]; /** - * The size of the Rectangle object, expressed as a Point object - * with the values of the width and height properties. - * @param rect [description] - * @param out [description] + * Offsets the Circle by the values given. + * @param circle The Circle to be offset (translated.) + * @param x The amount to horizontally offset the Circle by. + * @param y The amount to vertically offset the Circle by. */ - static GetSize(rect: Phaser.Geom.Rectangle, out?: O): O; + static Offset(circle: O, x: number, y: number): O; /** - * Increases the size of a Rectangle by a specified amount. - * - * The center of the Rectangle stays the same. The amounts are added to each side, so the actual increase in width or height is two times bigger than the respective argument. - * @param rect The Rectangle to inflate. - * @param x How many pixels the left and the right side should be moved by horizontally. - * @param y How many pixels the top and the bottom side should be moved by vertically. + * Offsets the Circle by the values given in the `x` and `y` properties of the Point object. + * @param circle The Circle to be offset (translated.) + * @param point The Point object containing the values to offset the Circle by. */ - static Inflate(rect: O, x: number, y: number): O; + static OffsetPoint(circle: O, point: Phaser.Geom.Point | object): O; /** - * Takes two Rectangles and first checks to see if they intersect. - * If they intersect it will return the area of intersection in the `out` Rectangle. - * If they do not intersect, the `out` Rectangle will have a width and height of zero. - * @param rectA The first Rectangle to get the intersection from. - * @param rectB The second Rectangle to get the intersection from. - * @param out A Rectangle to store the intersection results in. + * Returns a uniformly distributed random point from anywhere within the given Circle. + * @param circle The Circle to get a random point from. + * @param out A Point or point-like object to set the random `x` and `y` values in. */ - static Intersection(rectA: Phaser.Geom.Rectangle, rectB: Phaser.Geom.Rectangle, out?: Phaser.Geom.Rectangle): O; + static Random(circle: Phaser.Geom.Circle, out?: O): O; - /** - * Return an array of points from the perimeter of the rectangle - * each spaced out based on the quantity or step required - * @param rect [description] - * @param step [description] - * @param quantity [description] - * @param out [description] - */ - static MarchingAnts(rect: Phaser.Geom.Rectangle, step: number, quantity: integer, out?: O): O; + } - /** - * Merges a Rectangle with a list of points by repositioning and/or resizing it such that all points are located on or within its bounds. - * @param target The Rectangle which should be merged. - * @param points An array of Points (or any object with public `x` and `y` properties) which should be merged with the Rectangle. - */ - static MergePoints(target: O, points: Phaser.Geom.Point[]): O; + /** + * A Circle Geometry object type. + */ + var CIRCLE: number; - /** - * Merges the source rectangle into the target rectangle and returns the target. - * Neither rectangle should have a negative width or height. - * @param target Target rectangle. Will be modified to include source rectangle. - * @param source Rectangle that will be merged into target rectangle. - */ - static MergeRect(target: O, source: Phaser.Geom.Rectangle): O; + /** + * An Ellipse Geometry object type. + */ + var ELLIPSE: number; - /** - * Merges a Rectangle with a point by repositioning and/or resizing it so that the point is on or within its bounds. - * @param target The Rectangle which should be merged and modified. - * @param x The X coordinate of the point which should be merged. - * @param y The Y coordinate of the point which should be merged. - */ - static MergeXY(target: O, x: number, y: number): O; + /** + * A Line Geometry object type. + */ + var LINE: number; - /** - * Nudges (translates) the top left corner of a Rectangle by a given offset. - * @param rect The Rectangle to adjust. - * @param x The distance to move the Rectangle horizontally. - * @param y The distance to move the Rectangle vertically. + /** + * A Point Geometry object type. + */ + var POINT: number; + + /** + * A Polygon Geometry object type. + */ + var POLYGON: number; + + /** + * A Rectangle Geometry object type. + */ + var RECTANGLE: number; + + /** + * A Triangle Geometry object type. + */ + var TRIANGLE: number; + + /** + * An Ellipse object. + * + * This is a geometry object, containing numerical values and related methods to inspect and modify them. + * It is not a Game Object, in that you cannot add it to the display list, and it has no texture. + * To render an Ellipse you should look at the capabilities of the Graphics class. + */ + class Ellipse { + /** + * + * @param x The x position of the center of the ellipse. Default 0. + * @param y The y position of the center of the ellipse. Default 0. + * @param width The width of the ellipse. Default 0. + * @param height The height of the ellipse. Default 0. */ - static Offset(rect: O, x: number, y: number): O; + constructor(x?: number, y?: number, width?: number, height?: number); /** - * Nudges (translates) the top-left corner of a Rectangle by the coordinates of a point (translation vector). - * @param rect The Rectangle to adjust. - * @param point The point whose coordinates should be used as an offset. + * Calculates the area of the Ellipse. + * @param ellipse The Ellipse to get the area of. */ - static OffsetPoint(rect: O, point: Phaser.Geom.Point | Phaser.Math.Vector2): O; + static Area(ellipse: Phaser.Geom.Ellipse): number; /** - * Checks if two Rectangles overlap. If a Rectangle is within another Rectangle, the two will be considered overlapping. Thus, the Rectangles are treated as "solid". - * @param rectA The first Rectangle to check. - * @param rectB The second Rectangle to check. + * Returns the circumference of the given Ellipse. + * @param ellipse The Ellipse to get the circumference of. */ - static Overlaps(rectA: Phaser.Geom.Rectangle, rectB: Phaser.Geom.Rectangle): boolean; + static Circumference(ellipse: Phaser.Geom.Ellipse): number; /** - * Calculates the perimeter of a Rectangle. - * @param rect The Rectangle to use. + * Returns a Point object containing the coordinates of a point on the circumference of the Ellipse based on the given angle. + * @param ellipse The Ellipse to get the circumference point on. + * @param angle The angle from the center of the Ellipse to the circumference to return the point from. Given in radians. + * @param out A Point, or point-like object, to store the results in. If not given a Point will be created. */ - static Perimeter(rect: Phaser.Geom.Rectangle): number; + static CircumferencePoint(ellipse: Phaser.Geom.Ellipse, angle: number, out?: O): O; /** - * [description] - * @param rectangle [description] - * @param angle [description] - * @param out [description] + * Creates a new Ellipse instance based on the values contained in the given source. + * @param source The Ellipse to be cloned. Can be an instance of an Ellipse or a ellipse-like object, with x, y, width and height properties. */ - static PerimeterPoint(rectangle: Phaser.Geom.Rectangle, angle: integer, out?: O): O; + static Clone(source: Phaser.Geom.Ellipse): Phaser.Geom.Ellipse; /** - * Returns a random point within a Rectangle. - * @param rect The Rectangle to return a point from. - * @param out The object to update with the point's coordinates. + * Check to see if the Ellipse contains the given x / y coordinates. + * @param ellipse The Ellipse to check. + * @param x The x coordinate to check within the ellipse. + * @param y The y coordinate to check within the ellipse. */ - static Random(rect: Phaser.Geom.Rectangle, out: O): O; + static Contains(ellipse: Phaser.Geom.Ellipse, x: number, y: number): boolean; /** - * Calculates a random point that lies within the `outer` Rectangle, but outside of the `inner` Rectangle. - * The inner Rectangle must be fully contained within the outer rectangle. - * @param outer The outer Rectangle to get the random point within. - * @param inner The inner Rectangle to exclude from the returned point. - * @param out A Point, or Point-like object to store the result in. If not specified, a new Point will be created. + * Check to see if the Ellipse contains the given Point object. + * @param ellipse The Ellipse to check. + * @param point The Point object to check if it's within the Circle or not. */ - static RandomOutside(outer: Phaser.Geom.Rectangle, inner: Phaser.Geom.Rectangle, out?: O): O; + static ContainsPoint(ellipse: Phaser.Geom.Ellipse, point: Phaser.Geom.Point | object): boolean; /** - * The geometry constant type of this object: `GEOM_CONST.RECTANGLE`. + * Check to see if the Ellipse contains all four points of the given Rectangle object. + * @param ellipse The Ellipse to check. + * @param rect The Rectangle object to check if it's within the Ellipse or not. + */ + static ContainsRect(ellipse: Phaser.Geom.Ellipse, rect: Phaser.Geom.Rectangle | object): boolean; + + /** + * Copies the `x`, `y`, `width` and `height` properties from the `source` Ellipse + * into the given `dest` Ellipse, then returns the `dest` Ellipse. + * @param source The source Ellipse to copy the values from. + * @param dest The destination Ellipse to copy the values to. + */ + static CopyFrom(source: Phaser.Geom.Ellipse, dest: O): O; + + /** + * The geometry constant type of this object: `GEOM_CONST.ELLIPSE`. * Used for fast type comparisons. */ - readonly type: integer; + readonly type: number; /** - * The X coordinate of the top left corner of the Rectangle. + * The x position of the center of the ellipse. */ x: number; /** - * The Y coordinate of the top left corner of the Rectangle. + * The y position of the center of the ellipse. */ y: number; /** - * The width of the Rectangle, i.e. the distance between its left side (defined by `x`) and its right side. + * The width of the ellipse. */ width: number; /** - * The height of the Rectangle, i.e. the distance between its top side (defined by `y`) and its bottom side. + * The height of the ellipse. */ height: number; /** - * Checks if the given point is inside the Rectangle's bounds. - * @param x The X coordinate of the point to check. - * @param y The Y coordinate of the point to check. + * Check to see if the Ellipse contains the given x / y coordinates. + * @param x The x coordinate to check within the ellipse. + * @param y The y coordinate to check within the ellipse. */ contains(x: number, y: number): boolean; /** - * Calculates the coordinates of a point at a certain `position` on the Rectangle's perimeter. - * - * The `position` is a fraction between 0 and 1 which defines how far into the perimeter the point is. - * - * A value of 0 or 1 returns the point at the top left corner of the rectangle, while a value of 0.5 returns the point at the bottom right corner of the rectangle. Values between 0 and 0.5 are on the top or the right side and values between 0.5 and 1 are on the bottom or the left side. - * @param position The normalized distance into the Rectangle's perimeter to return. - * @param output An object to update with the `x` and `y` coordinates of the point. + * Returns a Point object containing the coordinates of a point on the circumference of the Ellipse + * based on the given angle normalized to the range 0 to 1. I.e. a value of 0.5 will give the point + * at 180 degrees around the circle. + * @param position A value between 0 and 1, where 0 equals 0 degrees, 0.5 equals 180 degrees and 1 equals 360 around the ellipse. + * @param out An object to store the return values in. If not given a Point object will be created. */ - getPoint(position: number, output?: O): O; + getPoint(position: number, out?: O): O; /** - * Returns an array of points from the perimeter of the Rectangle, each spaced out based on the quantity or step required. - * @param quantity The number of points to return. Set to `false` or 0 to return an arbitrary number of points (`perimeter / stepRate`) evenly spaced around the Rectangle based on the `stepRate`. - * @param stepRate If `quantity` is 0, determines the normalized distance between each returned point. - * @param output An array to which to append the points. + * Returns an array of Point objects containing the coordinates of the points around the circumference of the Ellipse, + * based on the given quantity or stepRate values. + * @param quantity The amount of points to return. If a falsey value the quantity will be derived from the `stepRate` instead. + * @param stepRate Sets the quantity by getting the circumference of the ellipse and dividing it by the stepRate. + * @param output An array to insert the points in to. If not provided a new array will be created. */ - getPoints(quantity: integer, stepRate?: number, output?: O): O; + getPoints(quantity: number, stepRate?: number, output?: O): O; /** - * Returns a random point within the Rectangle's bounds. - * @param point The object in which to store the `x` and `y` coordinates of the point. + * Returns a uniformly distributed random point from anywhere within the given Ellipse. + * @param point A Point or point-like object to set the random `x` and `y` values in. */ getRandomPoint(point?: O): O; /** - * Sets the position, width, and height of the Rectangle. - * @param x The X coordinate of the top left corner of the Rectangle. - * @param y The Y coordinate of the top left corner of the Rectangle. - * @param width The width of the Rectangle. - * @param height The height of the Rectangle. + * Sets the x, y, width and height of this ellipse. + * @param x The x position of the center of the ellipse. + * @param y The y position of the center of the ellipse. + * @param width The width of the ellipse. + * @param height The height of the ellipse. */ - setTo(x: number, y: number, width: number, height: number): Phaser.Geom.Rectangle; + setTo(x: number, y: number, width: number, height: number): this; /** - * Resets the position, width, and height of the Rectangle to 0. + * Sets this Ellipse to be empty with a width and height of zero. + * Does not change its position. */ - setEmpty(): Phaser.Geom.Rectangle; + setEmpty(): this; /** - * Sets the position of the Rectangle. - * @param x The X coordinate of the top left corner of the Rectangle. - * @param y The Y coordinate of the top left corner of the Rectangle. Default x. + * Sets the position of this Ellipse. + * @param x The x position of the center of the ellipse. + * @param y The y position of the center of the ellipse. */ - setPosition(x: number, y?: number): Phaser.Geom.Rectangle; + setPosition(x: number, y: number): this; /** - * Sets the width and height of the Rectangle. - * @param width The width to set the Rectangle to. - * @param height The height to set the Rectangle to. Default width. + * Sets the size of this Ellipse. + * Does not change its position. + * @param width The width of the ellipse. + * @param height The height of the ellipse. Default width. */ - setSize(width: number, height?: number): Phaser.Geom.Rectangle; + setSize(width: number, height?: number): this; /** - * Determines if the Rectangle is empty. A Rectangle is empty if its width or height is less than or equal to 0. + * Checks to see if the Ellipse is empty: has a width or height equal to zero. */ isEmpty(): boolean; /** - * Returns a Line object that corresponds to the top of this Rectangle. - * @param line A Line object to set the results in. If `undefined` a new Line will be created. + * Returns the minor radius of the ellipse. Also known as the Semi Minor Axis. */ - getLineA(line?: O): O; + getMinorRadius(): number; /** - * Returns a Line object that corresponds to the right of this Rectangle. - * @param line A Line object to set the results in. If `undefined` a new Line will be created. + * Returns the major radius of the ellipse. Also known as the Semi Major Axis. */ - getLineB(line?: O): O; + getMajorRadius(): number; /** - * Returns a Line object that corresponds to the bottom of this Rectangle. - * @param line A Line object to set the results in. If `undefined` a new Line will be created. + * The left position of the Ellipse. */ - getLineC(line?: O): O; + left: number; /** - * Returns a Line object that corresponds to the left of this Rectangle. - * @param line A Line object to set the results in. If `undefined` a new Line will be created. + * The right position of the Ellipse. */ - getLineD(line?: O): O; + right: number; /** - * The x coordinate of the left of the Rectangle. - * Changing the left property of a Rectangle object has no effect on the y and height properties. However it does affect the width property, whereas changing the x value does not affect the width property. + * The top position of the Ellipse. */ - left: number; + top: number; /** - * The sum of the x and width properties. - * Changing the right property of a Rectangle object has no effect on the x, y and height properties, however it does affect the width property. + * The bottom position of the Ellipse. */ - right: number; + bottom: number; /** - * The y coordinate of the top of the Rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties. - * However it does affect the height property, whereas changing the y value does not affect the height property. + * Compares the `x`, `y`, `width` and `height` properties of the two given Ellipses. + * Returns `true` if they all match, otherwise returns `false`. + * @param ellipse The first Ellipse to compare. + * @param toCompare The second Ellipse to compare. */ - top: number; + static Equals(ellipse: Phaser.Geom.Ellipse, toCompare: Phaser.Geom.Ellipse): boolean; /** - * The sum of the y and height properties. - * Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property. + * Returns the bounds of the Ellipse object. + * @param ellipse The Ellipse to get the bounds from. + * @param out A Rectangle, or rectangle-like object, to store the ellipse bounds in. If not given a new Rectangle will be created. */ - bottom: number; + static GetBounds(ellipse: Phaser.Geom.Ellipse, out?: O): O; /** - * The x coordinate of the center of the Rectangle. + * Returns a Point object containing the coordinates of a point on the circumference of the Ellipse + * based on the given angle normalized to the range 0 to 1. I.e. a value of 0.5 will give the point + * at 180 degrees around the circle. + * @param ellipse The Ellipse to get the circumference point on. + * @param position A value between 0 and 1, where 0 equals 0 degrees, 0.5 equals 180 degrees and 1 equals 360 around the ellipse. + * @param out An object to store the return values in. If not given a Point object will be created. */ - centerX: number; + static GetPoint(ellipse: Phaser.Geom.Ellipse, position: number, out?: O): O; /** - * The y coordinate of the center of the Rectangle. + * Returns an array of Point objects containing the coordinates of the points around the circumference of the Ellipse, + * based on the given quantity or stepRate values. + * @param ellipse The Ellipse to get the points from. + * @param quantity The amount of points to return. If a falsey value the quantity will be derived from the `stepRate` instead. + * @param stepRate Sets the quantity by getting the circumference of the ellipse and dividing it by the stepRate. + * @param out An array to insert the points in to. If not provided a new array will be created. */ - centerY: number; + static GetPoints(ellipse: Phaser.Geom.Ellipse, quantity: number, stepRate?: number, out?: O): O; /** - * Determines if the two objects (either Rectangles or Rectangle-like) have the same width and height values under strict equality. - * @param rect The first Rectangle object. - * @param toCompare The second Rectangle object. + * Offsets the Ellipse by the values given. + * @param ellipse The Ellipse to be offset (translated.) + * @param x The amount to horizontally offset the Ellipse by. + * @param y The amount to vertically offset the Ellipse by. */ - static SameDimensions(rect: Phaser.Geom.Rectangle, toCompare: Phaser.Geom.Rectangle): boolean; + static Offset(ellipse: O, x: number, y: number): O; /** - * Scales the width and height of this Rectangle by the given amounts. - * @param rect The `Rectangle` object that will be scaled by the specified amount(s). - * @param x The factor by which to scale the rectangle horizontally. - * @param y The amount by which to scale the rectangle vertically. If this is not specified, the rectangle will be scaled by the factor `x` in both directions. + * Offsets the Ellipse by the values given in the `x` and `y` properties of the Point object. + * @param ellipse The Ellipse to be offset (translated.) + * @param point The Point object containing the values to offset the Ellipse by. */ - static Scale(rect: O, x: number, y: number): O; + static OffsetPoint(ellipse: O, point: Phaser.Geom.Point | object): O; /** - * Creates a new Rectangle or repositions and/or resizes an existing Rectangle so that it encompasses the two given Rectangles, i.e. calculates their union. - * @param rectA The first Rectangle to use. - * @param rectB The second Rectangle to use. - * @param out The Rectangle to store the union in. + * Returns a uniformly distributed random point from anywhere within the given Ellipse. + * @param ellipse The Ellipse to get a random point from. + * @param out A Point or point-like object to set the random `x` and `y` values in. */ - static Union(rectA: Phaser.Geom.Rectangle, rectB: Phaser.Geom.Rectangle, out?: O): O; + static Random(ellipse: Phaser.Geom.Ellipse, out?: O): O; } - /** - * A triangle is a plane created by connecting three points. - * The first two arguments specify the first point, the middle two arguments - * specify the second point, and the last two arguments specify the third point. - */ - class Triangle { + namespace Intersects { /** - * - * @param x1 `x` coordinate of the first point. Default 0. - * @param y1 `y` coordinate of the first point. Default 0. - * @param x2 `x` coordinate of the second point. Default 0. - * @param y2 `y` coordinate of the second point. Default 0. - * @param x3 `x` coordinate of the third point. Default 0. - * @param y3 `y` coordinate of the third point. Default 0. + * Checks if two Circles intersect. + * @param circleA The first Circle to check for intersection. + * @param circleB The second Circle to check for intersection. */ - constructor(x1?: number, y1?: number, x2?: number, y2?: number, x3?: number, y3?: number); + function CircleToCircle(circleA: Phaser.Geom.Circle, circleB: Phaser.Geom.Circle): boolean; /** - * Returns the area of a Triangle. - * @param triangle The Triangle to use. + * Checks for intersection between a circle and a rectangle. + * @param circle The circle to be checked. + * @param rect The rectangle to be checked. */ - static Area(triangle: Phaser.Geom.Triangle): number; + function CircleToRectangle(circle: Phaser.Geom.Circle, rect: Phaser.Geom.Rectangle): boolean; /** - * Builds an equilateral triangle. In the equilateral triangle, all the sides are the same length (congruent) and all the angles are the same size (congruent). - * The x/y specifies the top-middle of the triangle (x1/y1) and length is the length of each side. - * @param x x coordinate of the top point of the triangle. - * @param y y coordinate of the top point of the triangle. - * @param length Length of each side of the triangle. + * Checks if two Circles intersect and returns the intersection points as a Point object array. + * @param circleA The first Circle to check for intersection. + * @param circleB The second Circle to check for intersection. + * @param out An optional array in which to store the points of intersection. */ - static BuildEquilateral(x: number, y: number, length: number): Phaser.Geom.Triangle; + function GetCircleToCircle(circleA: Phaser.Geom.Circle, circleB: Phaser.Geom.Circle, out?: any[]): any[]; /** - * [description] - * @param data A flat array of vertex coordinates like [x0,y0, x1,y1, x2,y2, ...] - * @param holes An array of hole indices if any (e.g. [5, 8] for a 12-vertex input would mean one hole with vertices 5–7 and another with 8–11). Default null. - * @param scaleX [description] Default 1. - * @param scaleY [description] Default 1. - * @param out [description] + * Checks for intersection between a circle and a rectangle, + * and returns the intersection points as a Point object array. + * @param circle The circle to be checked. + * @param rect The rectangle to be checked. + * @param out An optional array in which to store the points of intersection. */ - static BuildFromPolygon(data: any[], holes?: any[], scaleX?: number, scaleY?: number, out?: O): O; + function GetCircleToRectangle(circle: Phaser.Geom.Circle, rect: Phaser.Geom.Rectangle, out?: any[]): any[]; /** - * Builds a right triangle, i.e. one which has a 90-degree angle and two acute angles. - * @param x The X coordinate of the right angle, which will also be the first X coordinate of the constructed Triangle. - * @param y The Y coordinate of the right angle, which will also be the first Y coordinate of the constructed Triangle. - * @param width The length of the side which is to the left or to the right of the right angle. - * @param height The length of the side which is above or below the right angle. + * Checks for intersection between the line segment and circle, + * and returns the intersection points as a Point object array. + * @param line The line segment to check. + * @param circle The circle to check against the line. + * @param out An optional array in which to store the points of intersection. */ - static BuildRight(x: number, y: number, width: number, height: number): Phaser.Geom.Triangle; + function GetLineToCircle(line: Phaser.Geom.Line, circle: Phaser.Geom.Circle, out?: any[]): any[]; /** - * Positions the Triangle so that it is centered on the given coordinates. - * @param triangle The triangle to be positioned. - * @param x The horizontal coordinate to center on. - * @param y The vertical coordinate to center on. - * @param centerFunc The function used to center the triangle. Defaults to Centroid centering. + * Checks for intersection between the two line segments and returns the intersection point as a Vector3, + * or `null` if the lines are parallel, or do not intersect. + * + * The `z` property of the Vector3 contains the intersection distance, which can be used to find + * the closest intersecting point from a group of line segments. + * @param line1 The first line segment to check. + * @param line2 The second line segment to check. + * @param out A Vector3 to store the intersection results in. */ - static CenterOn(triangle: O, x: number, y: number, centerFunc?: CenterFunction): O; + function GetLineToLine(line1: Phaser.Geom.Line, line2: Phaser.Geom.Line, out?: Phaser.Math.Vector3): Phaser.Math.Vector3; /** - * Calculates the position of a Triangle's centroid, which is also its center of mass (center of gravity). + * Checks for the closest point of intersection between a line segment and an array of points, where each pair + * of points are converted to line segments for the intersection tests. * - * The centroid is the point in a Triangle at which its three medians (the lines drawn from the vertices to the bisectors of the opposite sides) meet. It divides each one in a 2:1 ratio. - * @param triangle The Triangle to use. - * @param out An object to store the coordinates in. + * If no intersection is found, this function returns `null`. + * + * If intersection was found, a Vector3 is returned with the following properties: + * + * The `x` and `y` components contain the point of the intersection. + * The `z` component contains the closest distance. + * @param line The line segment to check. + * @param points An array of points to check. + * @param out A Vector3 to store the intersection results in. */ - static Centroid(triangle: Phaser.Geom.Triangle, out?: O): O; + function GetLineToPoints(line: Phaser.Geom.Line, points: Phaser.Math.Vector2[] | Phaser.Geom.Point[], out?: Phaser.Math.Vector3): Phaser.Math.Vector3; /** - * Computes the circumcentre of a triangle. The circumcentre is the centre of - * the circumcircle, the smallest circle which encloses the triangle. It is also - * the common intersection point of the perpendicular bisectors of the sides of - * the triangle, and is the only point which has equal distance to all three - * vertices of the triangle. - * @param triangle [description] - * @param out [description] + * Checks for the closest point of intersection between a line segment and an array of polygons. + * + * If no intersection is found, this function returns `null`. + * + * If intersection was found, a Vector4 is returned with the following properties: + * + * The `x` and `y` components contain the point of the intersection. + * The `z` component contains the closest distance. + * The `w` component contains the index of the polygon, in the given array, that triggered the intersection. + * @param line The line segment to check. + * @param polygons A single polygon, or array of polygons, to check. + * @param out A Vector4 to store the intersection results in. */ - static CircumCenter(triangle: Phaser.Geom.Triangle, out?: O): O; + function GetLineToPolygon(line: Phaser.Geom.Line, polygons: Phaser.Geom.Polygon | Phaser.Geom.Polygon[], out?: Phaser.Math.Vector4): Phaser.Math.Vector4; /** - * Finds the circumscribed circle (circumcircle) of a Triangle object. The circumcircle is the circle which touches all of the triangle's vertices. - * @param triangle The Triangle to use as input. - * @param out An optional Circle to store the result in. + * Checks for intersection between the Line and a Rectangle shape, + * and returns the intersection points as a Point object array. + * @param line The Line to check for intersection. + * @param rect The Rectangle to check for intersection. + * @param out An optional array in which to store the points of intersection. */ - static CircumCircle(triangle: Phaser.Geom.Triangle, out?: O): O; + function GetLineToRectangle(line: Phaser.Geom.Line, rect: Phaser.Geom.Rectangle | object, out?: any[]): any[]; /** - * Clones a Triangle object. - * @param source The Triangle to clone. + * Projects rays out from the given point to each line segment of the polygons. + * + * If the rays intersect with the polygons, the points of intersection are returned in an array. + * + * If no intersections are found, the returned array will be empty. + * + * Each Vector4 intersection result has the following properties: + * + * The `x` and `y` components contain the point of the intersection. + * The `z` component contains the angle of intersection. + * The `w` component contains the index of the polygon, in the given array, that triggered the intersection. + * @param x The x coordinate to project the rays from. + * @param y The y coordinate to project the rays from. + * @param polygons A single polygon, or array of polygons, to check against the rays. */ - static Clone(source: Phaser.Geom.Triangle): Phaser.Geom.Triangle; + function GetRaysFromPointToPolygon(x: number, y: number, polygons: Phaser.Geom.Polygon | Phaser.Geom.Polygon[]): Phaser.Math.Vector4[]; /** - * Checks if a point (as a pair of coordinates) is inside a Triangle's bounds. - * @param triangle The Triangle to check. - * @param x The X coordinate of the point to check. - * @param y The Y coordinate of the point to check. + * Checks if two Rectangle shapes intersect and returns the area of this intersection as Rectangle object. + * + * If optional `output` parameter is omitted, new Rectangle object is created and returned. If there is intersection, it will contain intersection area. If there is no intersection, it wil be empty Rectangle (all values set to zero). + * + * If Rectangle object is passed as `output` and there is intersection, then intersection area data will be loaded into it and it will be returned. If there is no intersection, it will be returned without any change. + * @param rectA The first Rectangle object. + * @param rectB The second Rectangle object. + * @param output Optional Rectangle object. If given, the intersection data will be loaded into it (in case of no intersection, it will be left unchanged). Otherwise, new Rectangle object will be created and returned with either intersection data or empty (all values set to zero), if there is no intersection. */ - static Contains(triangle: Phaser.Geom.Triangle, x: number, y: number): boolean; + function GetRectangleIntersection(rectA: Phaser.Geom.Rectangle, rectB: Phaser.Geom.Rectangle, output?: O): O; /** - * Filters an array of point-like objects to only those contained within a triangle. - * If `returnFirst` is true, will return an array containing only the first point in the provided array that is within the triangle (or an empty array if there are no such points). - * @param triangle The triangle that the points are being checked in. - * @param points An array of point-like objects (objects that have an `x` and `y` property) - * @param returnFirst If `true`, return an array containing only the first point found that is within the triangle. Default false. - * @param out If provided, the points that are within the triangle will be appended to this array instead of being added to a new array. If `returnFirst` is true, only the first point found within the triangle will be appended. This array will also be returned by this function. + * Checks if two Rectangles intersect and returns the intersection points as a Point object array. + * + * A Rectangle intersects another Rectangle if any part of its bounds is within the other Rectangle's bounds. As such, the two Rectangles are considered "solid". A Rectangle with no width or no height will never intersect another Rectangle. + * @param rectA The first Rectangle to check for intersection. + * @param rectB The second Rectangle to check for intersection. + * @param out An optional array in which to store the points of intersection. */ - static ContainsArray(triangle: Phaser.Geom.Triangle, points: Phaser.Geom.Point[], returnFirst?: boolean, out?: any[]): Phaser.Geom.Point[]; + function GetRectangleToRectangle(rectA: Phaser.Geom.Rectangle, rectB: Phaser.Geom.Rectangle, out?: any[]): any[]; /** - * Tests if a triangle contains a point. - * @param triangle The triangle. - * @param point The point to test, or any point-like object with public `x` and `y` properties. + * Checks for intersection between Rectangle shape and Triangle shape, + * and returns the intersection points as a Point object array. + * @param rect Rectangle object to test. + * @param triangle Triangle object to test. + * @param out An optional array in which to store the points of intersection. */ - static ContainsPoint(triangle: Phaser.Geom.Triangle, point: Phaser.Geom.Point | Phaser.Math.Vector2 | any): boolean; + function GetRectangleToTriangle(rect: Phaser.Geom.Rectangle, triangle: Phaser.Geom.Triangle, out?: any[]): any[]; /** - * Copy the values of one Triangle to a destination Triangle. - * @param source The source Triangle to copy the values from. - * @param dest The destination Triangle to copy the values to. + * Checks if a Triangle and a Circle intersect, and returns the intersection points as a Point object array. + * + * A Circle intersects a Triangle if its center is located within it or if any of the Triangle's sides intersect the Circle. As such, the Triangle and the Circle are considered "solid" for the intersection. + * @param triangle The Triangle to check for intersection. + * @param circle The Circle to check for intersection. + * @param out An optional array in which to store the points of intersection. */ - static CopyFrom(source: Phaser.Geom.Triangle, dest: O): O; + function GetTriangleToCircle(triangle: Phaser.Geom.Triangle, circle: Phaser.Geom.Circle, out?: any[]): any[]; /** - * Decomposes a Triangle into an array of its points. - * @param triangle The Triangle to decompose. - * @param out An array to store the points into. + * Checks if a Triangle and a Line intersect, and returns the intersection points as a Point object array. + * + * The Line intersects the Triangle if it starts inside of it, ends inside of it, or crosses any of the Triangle's sides. Thus, the Triangle is considered "solid". + * @param triangle The Triangle to check with. + * @param line The Line to check with. + * @param out An optional array in which to store the points of intersection. */ - static Decompose(triangle: Phaser.Geom.Triangle, out?: any[]): any[]; + function GetTriangleToLine(triangle: Phaser.Geom.Triangle, line: Phaser.Geom.Line, out?: any[]): any[]; /** - * Returns true if two triangles have the same coordinates. - * @param triangle The first triangle to check. - * @param toCompare The second triangle to check. + * Checks if two Triangles intersect, and returns the intersection points as a Point object array. + * + * A Triangle intersects another Triangle if any pair of their lines intersects or if any point of one Triangle is within the other Triangle. Thus, the Triangles are considered "solid". + * @param triangleA The first Triangle to check for intersection. + * @param triangleB The second Triangle to check for intersection. + * @param out An optional array in which to store the points of intersection. */ - static Equals(triangle: Phaser.Geom.Triangle, toCompare: Phaser.Geom.Triangle): boolean; + function GetTriangleToTriangle(triangleA: Phaser.Geom.Triangle, triangleB: Phaser.Geom.Triangle, out?: any[]): any[]; /** - * Returns a Point from around the perimeter of a Triangle. - * @param triangle The Triangle to get the point on its perimeter from. - * @param position The position along the perimeter of the triangle. A value between 0 and 1. - * @param out An option Point, or Point-like object to store the value in. If not given a new Point will be created. + * Checks for intersection between the line segment and circle. + * + * Based on code by [Matt DesLauriers](https://github.com/mattdesl/line-circle-collision/blob/master/LICENSE.md). + * @param line The line segment to check. + * @param circle The circle to check against the line. + * @param nearest An optional Point-like object. If given the closest point on the Line where the circle intersects will be stored in this object. */ - static GetPoint(triangle: Phaser.Geom.Triangle, position: number, out?: O): O; + function LineToCircle(line: Phaser.Geom.Line, circle: Phaser.Geom.Circle, nearest?: Phaser.Geom.Point | any): boolean; /** - * Returns an array of evenly spaced points on the perimeter of a Triangle. - * @param triangle The Triangle to get the points from. - * @param quantity The number of evenly spaced points to return. Set to 0 to return an arbitrary number of points based on the `stepRate`. - * @param stepRate If `quantity` is 0, the distance between each returned point. - * @param out An array to which the points should be appended. + * Checks if two Lines intersect. If the Lines are identical, they will be treated as parallel and thus non-intersecting. + * @param line1 The first Line to check. + * @param line2 The second Line to check. + * @param out A Point in which to optionally store the point of intersection. */ - static GetPoints(triangle: Phaser.Geom.Triangle, quantity: integer, stepRate: number, out?: O): O; + function LineToLine(line1: Phaser.Geom.Line, line2: Phaser.Geom.Line, out?: Phaser.Geom.Point): boolean; /** - * Calculates the position of the incenter of a Triangle object. This is the point where its three angle bisectors meet and it's also the center of the incircle, which is the circle inscribed in the triangle. - * @param triangle The Triangle to find the incenter of. - * @param out An optional Point in which to store the coordinates. + * Checks for intersection between the Line and a Rectangle shape, or a rectangle-like + * object, with public `x`, `y`, `right` and `bottom` properties, such as a Sprite or Body. + * + * An intersection is considered valid if: + * + * The line starts within, or ends within, the Rectangle. + * The line segment intersects one of the 4 rectangle edges. + * + * The for the purposes of this function rectangles are considered 'solid'. + * @param line The Line to check for intersection. + * @param rect The Rectangle to check for intersection. */ - static InCenter(triangle: Phaser.Geom.Triangle, out?: O): O; + function LineToRectangle(line: Phaser.Geom.Line, rect: Phaser.Geom.Rectangle | object): boolean; /** - * Moves each point (vertex) of a Triangle by a given offset, thus moving the entire Triangle by that offset. - * @param triangle The Triangle to move. - * @param x The horizontal offset (distance) by which to move each point. Can be positive or negative. - * @param y The vertical offset (distance) by which to move each point. Can be positive or negative. + * Checks if the a Point falls between the two end-points of a Line, based on the given line thickness. + * + * Assumes that the line end points are circular, not square. + * @param point The point, or point-like object to check. + * @param line The line segment to test for intersection on. + * @param lineThickness The line thickness. Assumes that the line end points are circular. Default 1. */ - static Offset(triangle: O, x: number, y: number): O; + function PointToLine(point: Phaser.Geom.Point | any, line: Phaser.Geom.Line, lineThickness?: number): boolean; /** - * Gets the length of the perimeter of the given triangle. - * @param triangle [description] + * Checks if a Point is located on the given line segment. + * @param point The Point to check for intersection. + * @param line The line segment to check for intersection. */ - static Perimeter(triangle: Phaser.Geom.Triangle): number; + function PointToLineSegment(point: Phaser.Geom.Point, line: Phaser.Geom.Line): boolean; /** - * [description] - * @param triangle [description] - * @param out [description] + * Checks if two Rectangles intersect. + * + * A Rectangle intersects another Rectangle if any part of its bounds is within the other Rectangle's bounds. + * As such, the two Rectangles are considered "solid". + * A Rectangle with no width or no height will never intersect another Rectangle. + * @param rectA The first Rectangle to check for intersection. + * @param rectB The second Rectangle to check for intersection. */ - static Random(triangle: Phaser.Geom.Triangle, out?: O): O; + function RectangleToRectangle(rectA: Phaser.Geom.Rectangle, rectB: Phaser.Geom.Rectangle): boolean; /** - * Rotates a Triangle about its incenter, which is the point at which its three angle bisectors meet. - * @param triangle The Triangle to rotate. - * @param angle The angle by which to rotate the Triangle, in radians. + * Checks for intersection between Rectangle shape and Triangle shape. + * @param rect Rectangle object to test. + * @param triangle Triangle object to test. */ - static Rotate(triangle: O, angle: number): O; + function RectangleToTriangle(rect: Phaser.Geom.Rectangle, triangle: Phaser.Geom.Triangle): boolean; /** - * Rotates a Triangle at a certain angle about a given Point or object with public `x` and `y` properties. - * @param triangle The Triangle to rotate. - * @param point The Point to rotate the Triangle about. - * @param angle The angle by which to rotate the Triangle, in radians. + * Check if rectangle intersects with values. + * @param rect The rectangle object + * @param left The x coordinate of the left of the Rectangle. + * @param right The x coordinate of the right of the Rectangle. + * @param top The y coordinate of the top of the Rectangle. + * @param bottom The y coordinate of the bottom of the Rectangle. + * @param tolerance Tolerance allowed in the calculation, expressed in pixels. Default 0. */ - static RotateAroundPoint(triangle: O, point: Phaser.Geom.Point, angle: number): O; + function RectangleToValues(rect: Phaser.Geom.Rectangle, left: number, right: number, top: number, bottom: number, tolerance?: number): boolean; /** - * Rotates an entire Triangle at a given angle about a specific point. - * @param triangle The Triangle to rotate. - * @param x The X coordinate of the point to rotate the Triangle about. - * @param y The Y coordinate of the point to rotate the Triangle about. - * @param angle The angle by which to rotate the Triangle, in radians. + * Checks if a Triangle and a Circle intersect. + * + * A Circle intersects a Triangle if its center is located within it or if any of the Triangle's sides intersect the Circle. As such, the Triangle and the Circle are considered "solid" for the intersection. + * @param triangle The Triangle to check for intersection. + * @param circle The Circle to check for intersection. */ - static RotateAroundXY(triangle: O, x: number, y: number, angle: number): O; + function TriangleToCircle(triangle: Phaser.Geom.Triangle, circle: Phaser.Geom.Circle): boolean; /** - * The geometry constant type of this object: `GEOM_CONST.TRIANGLE`. - * Used for fast type comparisons. + * Checks if a Triangle and a Line intersect. + * + * The Line intersects the Triangle if it starts inside of it, ends inside of it, or crosses any of the Triangle's sides. Thus, the Triangle is considered "solid". + * @param triangle The Triangle to check with. + * @param line The Line to check with. */ - readonly type: integer; + function TriangleToLine(triangle: Phaser.Geom.Triangle, line: Phaser.Geom.Line): boolean; /** - * `x` coordinate of the first point. + * Checks if two Triangles intersect. + * + * A Triangle intersects another Triangle if any pair of their lines intersects or if any point of one Triangle is within the other Triangle. Thus, the Triangles are considered "solid". + * @param triangleA The first Triangle to check for intersection. + * @param triangleB The second Triangle to check for intersection. */ - x1: number; + function TriangleToTriangle(triangleA: Phaser.Geom.Triangle, triangleB: Phaser.Geom.Triangle): boolean; + } + + /** + * Defines a Line segment, a part of a line between two endpoints. + */ + class Line { /** - * `y` coordinate of the first point. + * + * @param x1 The x coordinate of the lines starting point. Default 0. + * @param y1 The y coordinate of the lines starting point. Default 0. + * @param x2 The x coordinate of the lines ending point. Default 0. + * @param y2 The y coordinate of the lines ending point. Default 0. */ - y1: number; + constructor(x1?: number, y1?: number, x2?: number, y2?: number); /** - * `x` coordinate of the second point. + * Calculate the angle of the line in radians. + * @param line The line to calculate the angle of. */ - x2: number; + static Angle(line: Phaser.Geom.Line): number; /** - * `y` coordinate of the second point. + * Using Bresenham's line algorithm this will return an array of all coordinates on this line. + * + * The `start` and `end` points are rounded before this runs as the algorithm works on integers. + * @param line The line. + * @param stepRate The optional step rate for the points on the line. Default 1. + * @param results An optional array to push the resulting coordinates into. */ - y2: number; + static BresenhamPoints(line: Phaser.Geom.Line, stepRate?: number, results?: Phaser.Types.Math.Vector2Like[]): Phaser.Types.Math.Vector2Like[]; /** - * `x` coordinate of the third point. + * Center a line on the given coordinates. + * @param line The line to center. + * @param x The horizontal coordinate to center the line on. + * @param y The vertical coordinate to center the line on. */ - x3: number; + static CenterOn(line: Phaser.Geom.Line, x: number, y: number): Phaser.Geom.Line; /** - * `y` coordinate of the third point. + * Clone the given line. + * @param source The source line to clone. */ - y3: number; + static Clone(source: Phaser.Geom.Line): Phaser.Geom.Line; /** - * Checks whether a given points lies within the triangle. - * @param x The x coordinate of the point to check. - * @param y The y coordinate of the point to check. + * Copy the values of one line to a destination line. + * @param source The source line to copy the values from. + * @param dest The destination line to copy the values to. */ - contains(x: number, y: number): boolean; + static CopyFrom(source: Phaser.Geom.Line, dest: O): O; /** - * Returns a specific point on the triangle. - * @param position Position as float within `0` and `1`. `0` equals the first point. - * @param output Optional Point, or point-like object, that the calculated point will be written to. + * Compare two lines for strict equality. + * @param line The first line to compare. + * @param toCompare The second line to compare. */ - getPoint(position: number, output?: O): O; + static Equals(line: Phaser.Geom.Line, toCompare: Phaser.Geom.Line): boolean; /** - * Calculates a list of evenly distributed points on the triangle. It is either possible to pass an amount of points to be generated (`quantity`) or the distance between two points (`stepRate`). - * @param quantity Number of points to be generated. Can be falsey when `stepRate` should be used. All points have the same distance along the triangle. - * @param stepRate Distance between two points. Will only be used when `quantity` is falsey. - * @param output Optional Array for writing the calculated points into. Otherwise a new array will be created. + * Extends the start and end points of a Line by the given amounts. + * + * The amounts can be positive or negative. Positive points will increase the length of the line, + * while negative ones will decrease it. + * + * If no `right` value is provided it will extend the length of the line equally in both directions. + * + * Pass a value of zero to leave the start or end point unchanged. + * @param line The line instance to extend. + * @param left The amount to extend the start of the line by. + * @param right The amount to extend the end of the line by. If not given it will be set to the `left` value. */ - getPoints(quantity: integer, stepRate?: number, output?: O): O; + static Extend(line: Phaser.Geom.Line, left: number, right?: number): Phaser.Geom.Line; /** - * Returns a random point along the triangle. - * @param point Optional `Point` that should be modified. Otherwise a new one will be created. + * Returns an array of `quantity` Points where each point is taken from the given Line, + * spaced out according to the ease function specified. + * + * ```javascript + * const line = new Phaser.Geom.Line(100, 300, 700, 300); + * const points = Phaser.Geom.Line.GetEasedPoints(line, 'sine.out', 32) + * ``` + * + * In the above example, the `points` array will contain 32 points spread-out across + * the length of `line`, where the position of each point is determined by the `Sine.out` + * ease function. + * + * You can optionally provide a collinear threshold. In this case, the resulting points + * are checked against each other, and if they are `< collinearThreshold` distance apart, + * they are dropped from the results. This can help avoid lots of clustered points at + * far ends of the line with tightly-packed eases such as Quartic. Leave the value set + * to zero to skip this check. + * + * Note that if you provide a collinear threshold, the resulting array may not always + * contain `quantity` points. + * @param line The Line object. + * @param ease The ease to use. This can be either a string from the EaseMap, or a custom function. + * @param quantity The number of points to return. Note that if you provide a `collinearThreshold`, the resulting array may not always contain this number of points. + * @param collinearThreshold An optional threshold. The final array is reduced so that each point is spaced out at least this distance apart. This helps reduce clustering in noisey eases. Default 0. + * @param easeParams An optional array of ease parameters to go with the ease. */ - getRandomPoint(point?: O): O; + static GetEasedPoints(line: Phaser.Geom.Line, ease: string | Function, quantity: number, collinearThreshold?: number, easeParams?: number[]): O; /** - * Sets all three points of the triangle. Leaving out any coordinate sets it to be `0`. - * @param x1 `x` coordinate of the first point. Default 0. - * @param y1 `y` coordinate of the first point. Default 0. - * @param x2 `x` coordinate of the second point. Default 0. - * @param y2 `y` coordinate of the second point. Default 0. - * @param x3 `x` coordinate of the third point. Default 0. - * @param y3 `y` coordinate of the third point. Default 0. + * Get the midpoint of the given line. + * @param line The line to get the midpoint of. + * @param out An optional point object to store the midpoint in. */ - setTo(x1?: number, y1?: number, x2?: number, y2?: number, x3?: number, y3?: number): Phaser.Geom.Triangle; + static GetMidPoint(line: Phaser.Geom.Line, out?: O): O; /** - * Returns a Line object that corresponds to Line A of this Triangle. - * @param line A Line object to set the results in. If `undefined` a new Line will be created. + * Get the nearest point on a line perpendicular to the given point. + * @param line The line to get the nearest point on. + * @param point The point to get the nearest point to. + * @param out An optional point, or point-like object, to store the coordinates of the nearest point on the line. */ - getLineA(line?: O): O; + static GetNearestPoint(line: Phaser.Geom.Line, point: Phaser.Geom.Point | object, out?: O): O; /** - * Returns a Line object that corresponds to Line B of this Triangle. - * @param line A Line object to set the results in. If `undefined` a new Line will be created. + * Calculate the normal of the given line. + * + * The normal of a line is a vector that points perpendicular from it. + * @param line The line to calculate the normal of. + * @param out An optional point object to store the normal in. */ - getLineB(line?: O): O; + static GetNormal(line: Phaser.Geom.Line, out?: O): O; /** - * Returns a Line object that corresponds to Line C of this Triangle. - * @param line A Line object to set the results in. If `undefined` a new Line will be created. + * Get a point on a line that's a given percentage along its length. + * @param line The line. + * @param position A value between 0 and 1, where 0 is the start, 0.5 is the middle and 1 is the end of the line. + * @param out An optional point, or point-like object, to store the coordinates of the point on the line. */ - getLineC(line?: O): O; + static GetPoint(line: Phaser.Geom.Line, position: number, out?: O): O; /** - * Left most X coordinate of the triangle. Setting it moves the triangle on the X axis accordingly. + * Get a number of points along a line's length. + * + * Provide a `quantity` to get an exact number of points along the line. + * + * Provide a `stepRate` to ensure a specific distance between each point on the line. Set `quantity` to `0` when + * providing a `stepRate`. + * @param line The line. + * @param quantity The number of points to place on the line. Set to `0` to use `stepRate` instead. + * @param stepRate The distance between each point on the line. When set, `quantity` is implied and should be set to `0`. + * @param out An optional array of Points, or point-like objects, to store the coordinates of the points on the line. */ - left: number; + static GetPoints(line: Phaser.Geom.Line, quantity: number, stepRate?: number, out?: O): O; /** - * Right most X coordinate of the triangle. Setting it moves the triangle on the X axis accordingly. + * Get the shortest distance from a Line to the given Point. + * @param line The line to get the distance from. + * @param point The point to get the shortest distance to. */ - right: number; + static GetShortestDistance(line: Phaser.Geom.Line, point: Phaser.Geom.Point | object): O; /** - * Top most Y coordinate of the triangle. Setting it moves the triangle on the Y axis accordingly. + * Calculate the height of the given line. + * @param line The line to calculate the height of. */ - top: number; + static Height(line: Phaser.Geom.Line): number; /** - * Bottom most Y coordinate of the triangle. Setting it moves the triangle on the Y axis accordingly. + * Calculate the length of the given line. + * @param line The line to calculate the length of. */ - bottom: number; - - } + static Length(line: Phaser.Geom.Line): number; - } + /** + * The geometry constant type of this object: `GEOM_CONST.LINE`. + * Used for fast type comparisons. + */ + readonly type: number; - namespace Input { - /** - * The mouse pointer is being held down. - */ - var MOUSE_DOWN: integer; + /** + * The x coordinate of the lines starting point. + */ + x1: number; - /** - * The mouse pointer is being moved. - */ - var MOUSE_MOVE: integer; + /** + * The y coordinate of the lines starting point. + */ + y1: number; - /** - * The mouse pointer is released. - */ - var MOUSE_UP: integer; + /** + * The x coordinate of the lines ending point. + */ + x2: number; - /** - * A touch pointer has been started. - */ - var TOUCH_START: integer; + /** + * The y coordinate of the lines ending point. + */ + y2: number; - /** - * A touch pointer has been started. - */ - var TOUCH_MOVE: integer; + /** + * Get a point on a line that's a given percentage along its length. + * @param position A value between 0 and 1, where 0 is the start, 0.5 is the middle and 1 is the end of the line. + * @param output An optional point, or point-like object, to store the coordinates of the point on the line. + */ + getPoint(position: number, output?: O): O; - /** - * A touch pointer has been started. - */ - var TOUCH_END: integer; + /** + * Get a number of points along a line's length. + * + * Provide a `quantity` to get an exact number of points along the line. + * + * Provide a `stepRate` to ensure a specific distance between each point on the line. Set `quantity` to `0` when + * providing a `stepRate`. + * @param quantity The number of points to place on the line. Set to `0` to use `stepRate` instead. + * @param stepRate The distance between each point on the line. When set, `quantity` is implied and should be set to `0`. + * @param output An optional array of Points, or point-like objects, to store the coordinates of the points on the line. + */ + getPoints(quantity: number, stepRate?: number, output?: O): O; - /** - * The pointer lock has changed. - */ - var POINTER_LOCK_CHANGE: integer; + /** + * Get a random Point on the Line. + * @param point An instance of a Point to be modified. + */ + getRandomPoint(point?: O): O; - /** - * A touch pointer has been been cancelled by the browser. - */ - var TOUCH_CANCEL: integer; + /** + * Set new coordinates for the line endpoints. + * @param x1 The x coordinate of the lines starting point. Default 0. + * @param y1 The y coordinate of the lines starting point. Default 0. + * @param x2 The x coordinate of the lines ending point. Default 0. + * @param y2 The y coordinate of the lines ending point. Default 0. + */ + setTo(x1?: number, y1?: number, x2?: number, y2?: number): this; - /** - * The mouse wheel changes. - */ - var MOUSE_WHEEL: integer; + /** + * Returns a Vector2 object that corresponds to the start of this Line. + * @param vec2 A Vector2 object to set the results in. If `undefined` a new Vector2 will be created. + */ + getPointA(vec2?: O): O; - /** - * Creates a new Interactive Object. - * - * This is called automatically by the Input Manager when you enable a Game Object for input. - * - * The resulting Interactive Object is mapped to the Game Object's `input` property. - * @param gameObject The Game Object to which this Interactive Object is bound. - * @param hitArea The hit area for this Interactive Object. Typically a geometry shape, like a Rectangle or Circle. - * @param hitAreaCallback The 'contains' check callback that the hit area shape will use for all hit tests. - */ - function CreateInteractiveObject(gameObject: Phaser.GameObjects.GameObject, hitArea: any, hitAreaCallback: Phaser.Types.Input.HitAreaCallback): Phaser.Types.Input.InteractiveObject; + /** + * Returns a Vector2 object that corresponds to the end of this Line. + * @param vec2 A Vector2 object to set the results in. If `undefined` a new Vector2 will be created. + */ + getPointB(vec2?: O): O; - /** - * Creates a new Pixel Perfect Handler function. - * - * Access via `InputPlugin.makePixelPerfect` rather than calling it directly. - * @param textureManager A reference to the Texture Manager. - * @param alphaTolerance The alpha level that the pixel should be above to be included as a successful interaction. - */ - function CreatePixelPerfectHandler(textureManager: Phaser.Textures.TextureManager, alphaTolerance: integer): Function; + /** + * The left position of the Line. + */ + left: number; - namespace Events { /** - * The Input Plugin Boot Event. - * - * This internal event is dispatched by the Input Plugin when it boots, signalling to all of its systems to create themselves. + * The right position of the Line. */ - const BOOT: any; + right: number; /** - * The Input Plugin Destroy Event. - * - * This internal event is dispatched by the Input Plugin when it is destroyed, signalling to all of its systems to destroy themselves. + * The top position of the Line. */ - const DESTROY: any; + top: number; /** - * The Pointer Drag End Input Event. - * - * This event is dispatched by the Input Plugin belonging to a Scene if a pointer stops dragging a Game Object. - * - * Listen to this event from within a Scene using: `this.input.on('dragend', listener)`. - * - * To listen for this event from a _specific_ Game Object, use the [GAMEOBJECT_DRAG_END]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_DRAG_END} event instead. + * The bottom position of the Line. */ - const DRAG_END: any; + bottom: number; /** - * The Pointer Drag Enter Input Event. - * - * This event is dispatched by the Input Plugin belonging to a Scene if a pointer drags a Game Object into a Drag Target. - * - * Listen to this event from within a Scene using: `this.input.on('dragenter', listener)`. - * - * A Pointer can only drag a single Game Object at once. - * - * To listen for this event from a _specific_ Game Object, use the [GAMEOBJECT_DRAG_ENTER]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_DRAG_ENTER} event instead. + * Get the angle of the normal of the given line in radians. + * @param line The line to calculate the angle of the normal of. */ - const DRAG_ENTER: any; + static NormalAngle(line: Phaser.Geom.Line): number; /** - * The Pointer Drag Input Event. - * - * This event is dispatched by the Input Plugin belonging to a Scene if a pointer moves while dragging a Game Object. - * - * Listen to this event from within a Scene using: `this.input.on('drag', listener)`. - * - * A Pointer can only drag a single Game Object at once. - * - * To listen for this event from a _specific_ Game Object, use the [GAMEOBJECT_DRAG]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_DRAG} event instead. + * Returns the x component of the normal vector of the given line. + * @param line The Line object to get the normal value from. */ - const DRAG: any; + static NormalX(line: Phaser.Geom.Line): number; /** - * The Pointer Drag Leave Input Event. - * - * This event is dispatched by the Input Plugin belonging to a Scene if a pointer drags a Game Object out of a Drag Target. - * - * Listen to this event from within a Scene using: `this.input.on('dragleave', listener)`. - * - * A Pointer can only drag a single Game Object at once. - * - * To listen for this event from a _specific_ Game Object, use the [GAMEOBJECT_DRAG_LEAVE]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_DRAG_LEAVE} event instead. + * The Y value of the normal of the given line. + * The normal of a line is a vector that points perpendicular from it. + * @param line The line to calculate the normal of. */ - const DRAG_LEAVE: any; + static NormalY(line: Phaser.Geom.Line): number; /** - * The Pointer Drag Over Input Event. - * - * This event is dispatched by the Input Plugin belonging to a Scene if a pointer drags a Game Object over a Drag Target. - * - * When the Game Object first enters the drag target it will emit a `dragenter` event. If it then moves while within - * the drag target, it will emit this event instead. - * - * Listen to this event from within a Scene using: `this.input.on('dragover', listener)`. - * - * A Pointer can only drag a single Game Object at once. - * - * To listen for this event from a _specific_ Game Object, use the [GAMEOBJECT_DRAG_OVER]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_DRAG_OVER} event instead. + * Offset a line by the given amount. + * @param line The line to offset. + * @param x The horizontal offset to add to the line. + * @param y The vertical offset to add to the line. */ - const DRAG_OVER: any; + static Offset(line: O, x: number, y: number): O; /** - * The Pointer Drag Start Input Event. - * - * This event is dispatched by the Input Plugin belonging to a Scene if a pointer starts to drag any Game Object. - * - * Listen to this event from within a Scene using: `this.input.on('dragstart', listener)`. - * - * A Pointer can only drag a single Game Object at once. - * - * To listen for this event from a _specific_ Game Object, use the [GAMEOBJECT_DRAG_START]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_DRAG_START} event instead. + * Calculate the perpendicular slope of the given line. + * @param line The line to calculate the perpendicular slope of. */ - const DRAG_START: any; + static PerpSlope(line: Phaser.Geom.Line): number; /** - * The Pointer Drop Input Event. - * - * This event is dispatched by the Input Plugin belonging to a Scene if a pointer drops a Game Object on a Drag Target. - * - * Listen to this event from within a Scene using: `this.input.on('drop', listener)`. - * - * To listen for this event from a _specific_ Game Object, use the [GAMEOBJECT_DROP]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_DROP} event instead. + * Returns a random point on a given Line. + * @param line The Line to calculate the random Point on. + * @param out An instance of a Point to be modified. */ - const DROP: any; + static Random(line: Phaser.Geom.Line, out?: O): O; /** - * The Game Object Down Input Event. - * - * This event is dispatched by the Input Plugin belonging to a Scene if a pointer is pressed down on _any_ interactive Game Object. - * - * Listen to this event from within a Scene using: `this.input.on('gameobjectdown', listener)`. - * - * To receive this event, the Game Objects must have been set as interactive. - * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. - * - * To listen for this event from a _specific_ Game Object, use the [GAMEOBJECT_POINTER_DOWN]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_DOWN} event instead. - * - * The event hierarchy is as follows: - * - * 1. [GAMEOBJECT_POINTER_DOWN]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_DOWN} - * 2. [GAMEOBJECT_DOWN]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_DOWN} - * 3. [POINTER_DOWN]{@linkcode Phaser.Input.Events#event:POINTER_DOWN} or [POINTER_DOWN_OUTSIDE]{@linkcode Phaser.Input.Events#event:POINTER_DOWN_OUTSIDE} + * Calculate the reflected angle between two lines. * - * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop - * the propagation of this event. + * This is the outgoing angle based on the angle of Line 1 and the normalAngle of Line 2. + * @param lineA The first line. + * @param lineB The second line. */ - const GAMEOBJECT_DOWN: any; + static ReflectAngle(lineA: Phaser.Geom.Line, lineB: Phaser.Geom.Line): number; /** - * The Game Object Drag End Event. - * - * This event is dispatched by an interactive Game Object if a pointer stops dragging it. - * - * Listen to this event from a Game Object using: `gameObject.on('dragend', listener)`. - * Note that the scope of the listener is automatically set to be the Game Object instance itself. - * - * To receive this event, the Game Object must have been set as interactive and enabled for drag. - * See [GameObject.setInteractive](Phaser.GameObjects.GameObject#setInteractive) for more details. + * Rotate a line around its midpoint by the given angle in radians. + * @param line The line to rotate. + * @param angle The angle of rotation in radians. */ - const GAMEOBJECT_DRAG_END: any; + static Rotate(line: O, angle: number): O; /** - * The Game Object Drag Enter Event. - * - * This event is dispatched by an interactive Game Object if a pointer drags it into a drag target. - * - * Listen to this event from a Game Object using: `gameObject.on('dragenter', listener)`. - * Note that the scope of the listener is automatically set to be the Game Object instance itself. - * - * To receive this event, the Game Object must have been set as interactive and enabled for drag. - * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. + * Rotate a line around a point by the given angle in radians. + * @param line The line to rotate. + * @param point The point to rotate the line around. + * @param angle The angle of rotation in radians. */ - const GAMEOBJECT_DRAG_ENTER: any; + static RotateAroundPoint(line: O, point: Phaser.Geom.Point | object, angle: number): O; /** - * The Game Object Drag Event. - * - * This event is dispatched by an interactive Game Object if a pointer moves while dragging it. - * - * Listen to this event from a Game Object using: `gameObject.on('drag', listener)`. - * Note that the scope of the listener is automatically set to be the Game Object instance itself. - * - * To receive this event, the Game Object must have been set as interactive and enabled for drag. - * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. + * Rotate a line around the given coordinates by the given angle in radians. + * @param line The line to rotate. + * @param x The horizontal coordinate to rotate the line around. + * @param y The vertical coordinate to rotate the line around. + * @param angle The angle of rotation in radians. */ - const GAMEOBJECT_DRAG: any; + static RotateAroundXY(line: O, x: number, y: number, angle: number): O; /** - * The Game Object Drag Leave Event. - * - * This event is dispatched by an interactive Game Object if a pointer drags it out of a drag target. - * - * Listen to this event from a Game Object using: `gameObject.on('dragleave', listener)`. - * Note that the scope of the listener is automatically set to be the Game Object instance itself. - * - * To receive this event, the Game Object must have been set as interactive and enabled for drag. - * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. + * Set a line to a given position, angle and length. + * @param line The line to set. + * @param x The horizontal start position of the line. + * @param y The vertical start position of the line. + * @param angle The angle of the line in radians. + * @param length The length of the line. */ - const GAMEOBJECT_DRAG_LEAVE: any; + static SetToAngle(line: O, x: number, y: number, angle: number, length: number): O; /** - * The Game Object Drag Over Event. - * - * This event is dispatched by an interactive Game Object if a pointer drags it over a drag target. - * - * When the Game Object first enters the drag target it will emit a `dragenter` event. If it then moves while within - * the drag target, it will emit this event instead. - * - * Listen to this event from a Game Object using: `gameObject.on('dragover', listener)`. - * Note that the scope of the listener is automatically set to be the Game Object instance itself. - * - * To receive this event, the Game Object must have been set as interactive and enabled for drag. - * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. + * Calculate the slope of the given line. + * @param line The line to calculate the slope of. */ - const GAMEOBJECT_DRAG_OVER: any; + static Slope(line: Phaser.Geom.Line): number; /** - * The Game Object Drag Start Event. - * - * This event is dispatched by an interactive Game Object if a pointer starts to drag it. - * - * Listen to this event from a Game Object using: `gameObject.on('dragstart', listener)`. - * Note that the scope of the listener is automatically set to be the Game Object instance itself. - * - * To receive this event, the Game Object must have been set as interactive and enabled for drag. - * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. - * - * There are lots of useful drag related properties that are set within the Game Object when dragging occurs. - * For example, `gameObject.input.dragStartX`, `dragStartY` and so on. + * Calculate the width of the given line. + * @param line The line to calculate the width of. */ - const GAMEOBJECT_DRAG_START: any; + static Width(line: Phaser.Geom.Line): number; + + } + namespace Mesh { /** - * The Game Object Drop Event. + * A Face Geometry Object. * - * This event is dispatched by an interactive Game Object if a pointer drops it on a Drag Target. + * A Face is used by the Mesh Game Object. A Mesh consists of one, or more, faces that are + * used to render the Mesh Game Objects in WebGL. * - * Listen to this event from a Game Object using: `gameObject.on('drop', listener)`. - * Note that the scope of the listener is automatically set to be the Game Object instance itself. - * - * To receive this event, the Game Object must have been set as interactive and enabled for drag. - * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. + * A Face consists of 3 Vertex instances, for the 3 corners of the face and methods to help + * you modify and test them. */ - const GAMEOBJECT_DROP: any; + class Face { + /** + * + * @param vertex1 The first vertex of the Face. + * @param vertex2 The second vertex of the Face. + * @param vertex3 The third vertex of the Face. + */ + constructor(vertex1: Phaser.Geom.Mesh.Vertex, vertex2: Phaser.Geom.Mesh.Vertex, vertex3: Phaser.Geom.Mesh.Vertex); - /** - * The Game Object Move Input Event. - * - * This event is dispatched by the Input Plugin belonging to a Scene if a pointer is moved across _any_ interactive Game Object. - * - * Listen to this event from within a Scene using: `this.input.on('gameobjectmove', listener)`. - * - * To receive this event, the Game Objects must have been set as interactive. - * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. - * - * To listen for this event from a _specific_ Game Object, use the [GAMEOBJECT_POINTER_MOVE]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_MOVE} event instead. - * - * The event hierarchy is as follows: - * - * 1. [GAMEOBJECT_POINTER_MOVE]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_MOVE} - * 2. [GAMEOBJECT_MOVE]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_MOVE} - * 3. [POINTER_MOVE]{@linkcode Phaser.Input.Events#event:POINTER_MOVE} - * - * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop - * the propagation of this event. - */ - const GAMEOBJECT_MOVE: any; + /** + * The first vertex in this Face. + */ + vertex1: Phaser.Geom.Mesh.Vertex; - /** - * The Game Object Out Input Event. - * - * This event is dispatched by the Input Plugin belonging to a Scene if a pointer moves out of _any_ interactive Game Object. - * - * Listen to this event from within a Scene using: `this.input.on('gameobjectout', listener)`. - * - * To receive this event, the Game Objects must have been set as interactive. - * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. - * - * To listen for this event from a _specific_ Game Object, use the [GAMEOBJECT_POINTER_OUT]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_OUT} event instead. - * - * The event hierarchy is as follows: - * - * 1. [GAMEOBJECT_POINTER_OUT]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_OUT} - * 2. [GAMEOBJECT_OUT]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_OUT} - * 3. [POINTER_OUT]{@linkcode Phaser.Input.Events#event:POINTER_OUT} - * - * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop - * the propagation of this event. - */ - const GAMEOBJECT_OUT: any; + /** + * The second vertex in this Face. + */ + vertex2: Phaser.Geom.Mesh.Vertex; - /** - * The Game Object Over Input Event. - * - * This event is dispatched by the Input Plugin belonging to a Scene if a pointer moves over _any_ interactive Game Object. - * - * Listen to this event from within a Scene using: `this.input.on('gameobjectover', listener)`. - * - * To receive this event, the Game Objects must have been set as interactive. - * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. - * - * To listen for this event from a _specific_ Game Object, use the [GAMEOBJECT_POINTER_OVER]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_OVER} event instead. - * - * The event hierarchy is as follows: - * - * 1. [GAMEOBJECT_POINTER_OVER]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_OVER} - * 2. [GAMEOBJECT_OVER]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_OVER} - * 3. [POINTER_OVER]{@linkcode Phaser.Input.Events#event:POINTER_OVER} - * - * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop - * the propagation of this event. - */ - const GAMEOBJECT_OVER: any; + /** + * The third vertex in this Face. + */ + vertex3: Phaser.Geom.Mesh.Vertex; - /** - * The Game Object Pointer Down Event. - * - * This event is dispatched by an interactive Game Object if a pointer is pressed down on it. - * - * Listen to this event from a Game Object using: `gameObject.on('pointerdown', listener)`. - * Note that the scope of the listener is automatically set to be the Game Object instance itself. - * - * To receive this event, the Game Object must have been set as interactive. - * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. - * - * The event hierarchy is as follows: - * - * 1. [GAMEOBJECT_POINTER_DOWN]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_DOWN} - * 2. [GAMEOBJECT_DOWN]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_DOWN} - * 3. [POINTER_DOWN]{@linkcode Phaser.Input.Events#event:POINTER_DOWN} or [POINTER_DOWN_OUTSIDE]{@linkcode Phaser.Input.Events#event:POINTER_DOWN_OUTSIDE} - * - * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop - * the propagation of this event. - */ - const GAMEOBJECT_POINTER_DOWN: any; + /** + * The bounds of this Face. + * + * Be sure to call the `Face.updateBounds` method _before_ using this property. + */ + bounds: Phaser.Geom.Rectangle; - /** - * The Game Object Pointer Move Event. - * - * This event is dispatched by an interactive Game Object if a pointer is moved while over it. - * - * Listen to this event from a Game Object using: `gameObject.on('pointermove', listener)`. - * Note that the scope of the listener is automatically set to be the Game Object instance itself. - * - * To receive this event, the Game Object must have been set as interactive. - * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. - * - * The event hierarchy is as follows: - * - * 1. [GAMEOBJECT_POINTER_MOVE]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_MOVE} - * 2. [GAMEOBJECT_MOVE]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_MOVE} - * 3. [POINTER_MOVE]{@linkcode Phaser.Input.Events#event:POINTER_MOVE} - * - * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop - * the propagation of this event. - */ - const GAMEOBJECT_POINTER_MOVE: any; + /** + * Calculates and returns the in-center position of this Face. + * @param local Return the in center from the un-transformed vertex positions (`true`), or transformed? (`false`) Default true. + */ + getInCenter(local?: boolean): Phaser.Math.Vector2; - /** - * The Game Object Pointer Out Event. - * - * This event is dispatched by an interactive Game Object if a pointer moves out of it. - * - * Listen to this event from a Game Object using: `gameObject.on('pointerout', listener)`. - * Note that the scope of the listener is automatically set to be the Game Object instance itself. - * - * To receive this event, the Game Object must have been set as interactive. - * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. - * - * The event hierarchy is as follows: - * - * 1. [GAMEOBJECT_POINTER_OUT]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_OUT} - * 2. [GAMEOBJECT_OUT]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_OUT} - * 3. [POINTER_OUT]{@linkcode Phaser.Input.Events#event:POINTER_OUT} - * - * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop - * the propagation of this event. - */ - const GAMEOBJECT_POINTER_OUT: any; + /** + * Checks if the given coordinates are within this Face. + * + * You can optionally provide a transform matrix. If given, the Face vertices + * will be transformed first, before being checked against the coordinates. + * @param x The horizontal position to check. + * @param y The vertical position to check. + * @param calcMatrix Optional transform matrix to apply to the vertices before comparison. + */ + contains(x: number, y: number, calcMatrix?: Phaser.GameObjects.Components.TransformMatrix): boolean; - /** - * The Game Object Pointer Over Event. - * - * This event is dispatched by an interactive Game Object if a pointer moves over it. - * - * Listen to this event from a Game Object using: `gameObject.on('pointerover', listener)`. - * Note that the scope of the listener is automatically set to be the Game Object instance itself. - * - * To receive this event, the Game Object must have been set as interactive. - * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. - * - * The event hierarchy is as follows: - * - * 1. [GAMEOBJECT_POINTER_OVER]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_OVER} - * 2. [GAMEOBJECT_OVER]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_OVER} - * 3. [POINTER_OVER]{@linkcode Phaser.Input.Events#event:POINTER_OVER} - * - * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop - * the propagation of this event. - */ - const GAMEOBJECT_POINTER_OVER: any; + /** + * Checks if the vertices in this Face are orientated counter-clockwise, or not. + * + * It checks the transformed position of the vertices, not the local one. + * @param z The z-axis value to test against. Typically the `Mesh.modelPosition.z`. + */ + isCounterClockwise(z: number): boolean; - /** - * The Game Object Pointer Up Event. - * - * This event is dispatched by an interactive Game Object if a pointer is released while over it. - * - * Listen to this event from a Game Object using: `gameObject.on('pointerup', listener)`. - * Note that the scope of the listener is automatically set to be the Game Object instance itself. - * - * To receive this event, the Game Object must have been set as interactive. - * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. - * - * The event hierarchy is as follows: - * - * 1. [GAMEOBJECT_POINTER_UP]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_UP} - * 2. [GAMEOBJECT_UP]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_UP} - * 3. [POINTER_UP]{@linkcode Phaser.Input.Events#event:POINTER_UP} or [POINTER_UP_OUTSIDE]{@linkcode Phaser.Input.Events#event:POINTER_UP_OUTSIDE} - * - * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop - * the propagation of this event. - */ - const GAMEOBJECT_POINTER_UP: any; + /** + * Loads the data from this Vertex into the given Typed Arrays. + * @param F32 A Float32 Array to insert the position, UV and unit data in to. + * @param U32 A Uint32 Array to insert the color and alpha data in to. + * @param offset The index of the array to insert this Vertex to. + * @param textureUnit The texture unit currently in use. + * @param alpha The alpha of the parent object. + * @param a The parent transform matrix data a component. + * @param b The parent transform matrix data b component. + * @param c The parent transform matrix data c component. + * @param d The parent transform matrix data d component. + * @param e The parent transform matrix data e component. + * @param f The parent transform matrix data f component. + * @param roundPixels Round the vertex position or not? + */ + load(F32: Float32Array, U32: Uint32Array, offset: number, textureUnit: number, alpha: number, a: number, b: number, c: number, d: number, e: number, f: number, roundPixels: boolean): number; - /** - * The Game Object Pointer Wheel Event. - * - * This event is dispatched by an interactive Game Object if a pointer has its wheel moved while over it. - * - * Listen to this event from a Game Object using: `gameObject.on('wheel', listener)`. - * Note that the scope of the listener is automatically set to be the Game Object instance itself. - * - * To receive this event, the Game Object must have been set as interactive. - * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. - * - * The event hierarchy is as follows: - * - * 1. [GAMEOBJECT_POINTER_WHEEL]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_WHEEL} - * 2. [GAMEOBJECT_WHEEL]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_WHEEL} - * 3. [POINTER_WHEEL]{@linkcode Phaser.Input.Events#event:POINTER_WHEEL} - * - * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop - * the propagation of this event. - */ - const GAMEOBJECT_POINTER_WHEEL: any; + /** + * Transforms all Face vertices by the given matrix, storing the results in their `vx`, `vy` and `vz` properties. + * @param transformMatrix The transform matrix to apply to this vertex. + * @param width The width of the parent Mesh. + * @param height The height of the parent Mesh. + * @param cameraZ The z position of the MeshCamera. + */ + transformCoordinatesLocal(transformMatrix: Phaser.Math.Matrix4, width: number, height: number, cameraZ: number): this; - /** - * The Game Object Up Input Event. - * - * This event is dispatched by the Input Plugin belonging to a Scene if a pointer is released while over _any_ interactive Game Object. - * - * Listen to this event from within a Scene using: `this.input.on('gameobjectup', listener)`. - * - * To receive this event, the Game Objects must have been set as interactive. - * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. - * - * To listen for this event from a _specific_ Game Object, use the [GAMEOBJECT_POINTER_UP]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_UP} event instead. - * - * The event hierarchy is as follows: - * - * 1. [GAMEOBJECT_POINTER_UP]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_UP} - * 2. [GAMEOBJECT_UP]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_UP} - * 3. [POINTER_UP]{@linkcode Phaser.Input.Events#event:POINTER_UP} or [POINTER_UP_OUTSIDE]{@linkcode Phaser.Input.Events#event:POINTER_UP_OUTSIDE} - * - * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop - * the propagation of this event. - */ - const GAMEOBJECT_UP: any; + /** + * Updates the bounds of this Face, based on the translated values of the vertices. + * + * Call this method prior to accessing the `Face.bounds` property. + */ + updateBounds(): this; - /** - * The Game Object Wheel Input Event. - * - * This event is dispatched by the Input Plugin belonging to a Scene if a pointer has its wheel moved while over _any_ interactive Game Object. - * - * Listen to this event from within a Scene using: `this.input.on('gameobjectwheel', listener)`. - * - * To receive this event, the Game Objects must have been set as interactive. - * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. - * - * To listen for this event from a _specific_ Game Object, use the [GAMEOBJECT_POINTER_WHEEL]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_WHEEL} event instead. - * - * The event hierarchy is as follows: - * - * 1. [GAMEOBJECT_POINTER_WHEEL]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_WHEEL} - * 2. [GAMEOBJECT_WHEEL]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_WHEEL} - * 3. [POINTER_WHEEL]{@linkcode Phaser.Input.Events#event:POINTER_WHEEL} - * - * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop - * the propagation of this event. - */ - const GAMEOBJECT_WHEEL: any; + /** + * Checks if this Face is within the view of the given Camera. + * + * This method is called in the `MeshWebGLRenderer` function. It performs the following tasks: + * + * First, the `Vertex.update` method is called on each of the vertices. This populates them + * with the new translated values, updating their `tx`, `ty` and `ta` properties. + * + * Then it tests to see if this face is visible due to the alpha values, if not, it returns. + * + * After this, if `hideCCW` is set, it calls `isCounterClockwise` and returns if not. + * + * Finally, it will update the `Face.bounds` based on the newly translated vertex values + * and return the results of an intersection test between the bounds and the camera world view + * rectangle. + * @param camera The Camera to check against. + * @param hideCCW Test the counter-clockwise orientation of the verts? + * @param z The Cameras z position, used in the CCW test. + * @param alpha The alpha of the parent object. + * @param a The parent transform matrix data a component. + * @param b The parent transform matrix data b component. + * @param c The parent transform matrix data c component. + * @param d The parent transform matrix data d component. + * @param e The parent transform matrix data e component. + * @param f The parent transform matrix data f component. + * @param roundPixels Round the vertex position or not? + */ + isInView(camera: Phaser.Cameras.Scene2D.Camera, hideCCW: boolean, z: number, alpha: number, a: number, b: number, c: number, d: number, e: number, f: number, roundPixels: boolean): boolean; - /** - * The Input Plugin Game Out Event. - * - * This event is dispatched by the Input Plugin if the active pointer leaves the game canvas and is now - * outside of it, elsewhere on the web page. - * - * Listen to this event from within a Scene using: `this.input.on('gameout', listener)`. - */ - const GAME_OUT: any; + /** + * Translates the vertices of this Face by the given amounts. + * + * The actual vertex positions are adjusted, not their transformed position. + * + * Therefore, this updates the vertex data directly. + * @param x The amount to horizontally translate by. + * @param y The amount to vertically translate by. Default 0. + */ + translate(x: number, y?: number): this; - /** - * The Input Plugin Game Over Event. - * - * This event is dispatched by the Input Plugin if the active pointer enters the game canvas and is now - * over of it, having previously been elsewhere on the web page. - * - * Listen to this event from within a Scene using: `this.input.on('gameover', listener)`. - */ - const GAME_OVER: any; + /** + * The x coordinate of this Face, based on the in center position of the Face. + */ + x: number; - /** - * The Input Manager Boot Event. - * - * This internal event is dispatched by the Input Manager when it boots. - */ - const MANAGER_BOOT: any; + /** + * The y coordinate of this Face, based on the in center position of the Face. + */ + y: number; - /** - * The Input Manager Process Event. - * - * This internal event is dispatched by the Input Manager when not using the legacy queue system, - * and it wants the Input Plugins to update themselves. - */ - const MANAGER_PROCESS: any; + /** + * Set the alpha value of this Face. + * + * Each vertex is given the same value. If you need to adjust the alpha on a per-vertex basis + * then use the `Vertex.alpha` property instead. + * + * When getting the alpha of this Face, it will return an average of the alpha + * component of all three vertices. + */ + alpha: number; - /** - * The Input Manager Update Event. - * - * This internal event is dispatched by the Input Manager as part of its update step. - */ - const MANAGER_UPDATE: any; + /** + * The depth of this Face, which is an average of the z component of all three vertices. + * + * The depth is calculated based on the transformed z value, not the local one. + */ + readonly depth: number; - /** - * The Input Manager Pointer Lock Change Event. - * - * This event is dispatched by the Input Manager when it is processing a native Pointer Lock Change DOM Event. - */ - const POINTERLOCK_CHANGE: any; + /** + * Destroys this Face and nulls the references to the vertices. + */ + destroy(): void; - /** - * The Pointer Down Input Event. - * - * This event is dispatched by the Input Plugin belonging to a Scene if a pointer is pressed down anywhere. - * - * Listen to this event from within a Scene using: `this.input.on('pointerdown', listener)`. - * - * The event hierarchy is as follows: - * - * 1. [GAMEOBJECT_POINTER_DOWN]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_DOWN} - * 2. [GAMEOBJECT_DOWN]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_DOWN} - * 3. [POINTER_DOWN]{@linkcode Phaser.Input.Events#event:POINTER_DOWN} or [POINTER_DOWN_OUTSIDE]{@linkcode Phaser.Input.Events#event:POINTER_DOWN_OUTSIDE} - * - * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop - * the propagation of this event. - */ - const POINTER_DOWN: any; + } /** - * The Pointer Down Outside Input Event. - * - * This event is dispatched by the Input Plugin belonging to a Scene if a pointer is pressed down anywhere outside of the game canvas. - * - * Listen to this event from within a Scene using: `this.input.on('pointerdownoutside', listener)`. - * - * The event hierarchy is as follows: + * Creates a grid of vertices based on the given configuration object and optionally adds it to a Mesh. * - * 1. [GAMEOBJECT_POINTER_DOWN]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_DOWN} - * 2. [GAMEOBJECT_DOWN]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_DOWN} - * 3. [POINTER_DOWN]{@linkcode Phaser.Input.Events#event:POINTER_DOWN} or [POINTER_DOWN_OUTSIDE]{@linkcode Phaser.Input.Events#event:POINTER_DOWN_OUTSIDE} + * The size of the grid is given in pixels. An example configuration may be: * - * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop - * the propagation of this event. - */ - const POINTER_DOWN_OUTSIDE: any; - - /** - * The Pointer Move Input Event. + * `{ width: 256, height: 256, widthSegments: 2, heightSegments: 2, tile: true }` * - * This event is dispatched by the Input Plugin belonging to a Scene if a pointer is moved anywhere. + * This will create a grid 256 x 256 pixels in size, split into 2 x 2 segments, with + * the texture tiling across the cells. * - * Listen to this event from within a Scene using: `this.input.on('pointermove', listener)`. + * You can split the grid into segments both vertically and horizontally. This will + * generate two faces per grid segment as a result. * - * The event hierarchy is as follows: + * The `tile` parameter allows you to control if the tile will repeat across the grid + * segments, or be displayed in full. * - * 1. [GAMEOBJECT_POINTER_MOVE]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_MOVE} - * 2. [GAMEOBJECT_MOVE]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_MOVE} - * 3. [POINTER_MOVE]{@linkcode Phaser.Input.Events#event:POINTER_MOVE} + * If adding this grid to a Mesh you can offset the grid via the `x` and `y` properties. * - * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop - * the propagation of this event. + * UV coordinates are generated based on the given texture and frame in the config. For + * example, no frame is given, the UVs will be in the range 0 to 1. If a frame is given, + * such as from a texture atlas, the UVs will be generated within the range of that frame. + * @param config A Grid configuration object. */ - const POINTER_MOVE: any; + function GenerateGridVerts(config: Phaser.Types.Geom.Mesh.GenerateGridConfig): Phaser.Types.Geom.Mesh.GenerateGridVertsResult; /** - * The Pointer Out Input Event. - * - * This event is dispatched by the Input Plugin belonging to a Scene if a pointer moves out of any interactive Game Object. + * This method will return an object containing Face and Vertex instances, generated + * from the parsed triangulated OBJ Model data given to this function. * - * Listen to this event from within a Scene using: `this.input.on('pointerout', listener)`. + * The obj data should have been parsed in advance via the ParseObj function: * - * The event hierarchy is as follows: + * ```javascript + * var data = Phaser.Geom.Mesh.ParseObj(rawData, flipUV); * - * 1. [GAMEOBJECT_POINTER_OUT]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_OUT} - * 2. [GAMEOBJECT_OUT]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_OUT} - * 3. [POINTER_OUT]{@linkcode Phaser.Input.Events#event:POINTER_OUT} + * var results = GenerateObjVerts(data); + * ``` * - * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop - * the propagation of this event. - */ - const POINTER_OUT: any; - - /** - * The Pointer Over Input Event. + * Alternatively, you can parse obj files loaded via the OBJFile loader: * - * This event is dispatched by the Input Plugin belonging to a Scene if a pointer moves over any interactive Game Object. + * ```javascript + * preload () + * { + * this.load.obj('alien', 'assets/3d/alien.obj); + * } * - * Listen to this event from within a Scene using: `this.input.on('pointerover', listener)`. + * var results = GenerateObjVerts(this.cache.obj.get('alien)); + * ``` * - * The event hierarchy is as follows: + * Make sure your 3D package has triangulated the model data prior to exporting it. * - * 1. [GAMEOBJECT_POINTER_OVER]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_OVER} - * 2. [GAMEOBJECT_OVER]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_OVER} - * 3. [POINTER_OVER]{@linkcode Phaser.Input.Events#event:POINTER_OVER} + * You can use the data returned by this function to populate the vertices of a Mesh Game Object. * - * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop - * the propagation of this event. + * You may add multiple models to a single Mesh, although they will act as one when + * moved or rotated. You can scale the model data, should it be too small (or large) to visualize. + * You can also offset the model via the `x`, `y` and `z` parameters. + * @param data The parsed OBJ model data. + * @param mesh An optional Mesh Game Object. If given, the generated Faces will be automatically added to this Mesh. Set to `null` to skip. + * @param scale An amount to scale the model data by. Use this if the model has exported too small, or large, to see. Default 1. + * @param x Translate the model x position by this amount. Default 0. + * @param y Translate the model y position by this amount. Default 0. + * @param z Translate the model z position by this amount. Default 0. + * @param rotateX Rotate the model on the x axis by this amount, in radians. Default 0. + * @param rotateY Rotate the model on the y axis by this amount, in radians. Default 0. + * @param rotateZ Rotate the model on the z axis by this amount, in radians. Default 0. + * @param zIsUp Is the z axis up (true), or is y axis up (false)? Default true. */ - const POINTER_OVER: any; + function GenerateObjVerts(data: Phaser.Types.Geom.Mesh.OBJData, mesh?: Phaser.GameObjects.Mesh, scale?: number, x?: number, y?: number, z?: number, rotateX?: number, rotateY?: number, rotateZ?: number, zIsUp?: boolean): Phaser.Types.Geom.Mesh.GenerateVertsResult; /** - * The Pointer Up Input Event. + * Generates a set of Face and Vertex objects by parsing the given data. * - * This event is dispatched by the Input Plugin belonging to a Scene if a pointer is released anywhere. - * - * Listen to this event from within a Scene using: `this.input.on('pointerup', listener)`. - * - * The event hierarchy is as follows: - * - * 1. [GAMEOBJECT_POINTER_UP]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_UP} - * 2. [GAMEOBJECT_UP]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_UP} - * 3. [POINTER_UP]{@linkcode Phaser.Input.Events#event:POINTER_UP} or [POINTER_UP_OUTSIDE]{@linkcode Phaser.Input.Events#event:POINTER_UP_OUTSIDE} + * This method will take vertex data in one of two formats, based on the `containsZ` parameter. * - * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop - * the propagation of this event. - */ - const POINTER_UP: any; - - /** - * The Pointer Up Outside Input Event. + * If your vertex data are `x`, `y` pairs, then `containsZ` should be `false` (this is the default) * - * This event is dispatched by the Input Plugin belonging to a Scene if a pointer is released anywhere outside of the game canvas. + * If your vertex data is groups of `x`, `y` and `z` values, then the `containsZ` parameter must be true. * - * Listen to this event from within a Scene using: `this.input.on('pointerupoutside', listener)`. + * The `uvs` parameter is a numeric array consisting of `u` and `v` pairs. * - * The event hierarchy is as follows: + * The `normals` parameter is a numeric array consisting of `x`, `y` vertex normal values and, if `containsZ` is true, `z` values as well. * - * 1. [GAMEOBJECT_POINTER_UP]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_UP} - * 2. [GAMEOBJECT_UP]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_UP} - * 3. [POINTER_UP]{@linkcode Phaser.Input.Events#event:POINTER_UP} or [POINTER_UP_OUTSIDE]{@linkcode Phaser.Input.Events#event:POINTER_UP_OUTSIDE} + * The `indicies` parameter is an optional array that, if given, is an indexed list of vertices to be added. * - * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop - * the propagation of this event. - */ - const POINTER_UP_OUTSIDE: any; - - /** - * The Pointer Wheel Input Event. + * The `colors` parameter is an optional array, or single value, that if given sets the color of each vertex created. * - * This event is dispatched by the Input Plugin belonging to a Scene if a pointer has its wheel updated. + * The `alphas` parameter is an optional array, or single value, that if given sets the alpha of each vertex created. * - * Listen to this event from within a Scene using: `this.input.on('wheel', listener)`. + * When providing indexed data it is assumed that _all_ of the arrays are indexed, not just the vertices. * - * The event hierarchy is as follows: + * The following example will create a 256 x 256 sized quad using an index array: * - * 1. [GAMEOBJECT_POINTER_WHEEL]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_WHEEL} - * 2. [GAMEOBJECT_WHEEL]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_WHEEL} - * 3. [POINTER_WHEEL]{@linkcode Phaser.Input.Events#event:POINTER_WHEEL} + * ```javascript + * const vertices = [ + * -128, 128, + * 128, 128, + * -128, -128, + * 128, -128 + * ]; + * + * const uvs = [ + * 0, 1, + * 1, 1, + * 0, 0, + * 1, 0 + * ]; + * + * const indices = [ 0, 2, 1, 2, 3, 1 ]; + * + * GenerateVerts(vertices, uvs, indicies); + * ``` * - * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop - * the propagation of this event. + * If the data is not indexed, it's assumed that the arrays all contain sequential data. + * @param vertices The vertices array. Either `xy` pairs, or `xyz` if the `containsZ` parameter is `true`. + * @param uvs The UVs pairs array. + * @param indicies Optional vertex indicies array. If you don't have one, pass `null` or an empty array. + * @param containsZ Does the vertices data include a `z` component? Default false. + * @param normals Optional vertex normals array. If you don't have one, pass `null` or an empty array. + * @param colors An array of colors, one per vertex, or a single color value applied to all vertices. Default 0xffffff. + * @param alphas An array of alpha values, one per vertex, or a single alpha value applied to all vertices. Default 1. */ - const POINTER_WHEEL: any; + function GenerateVerts(vertices: number[], uvs: number[], indicies?: number[], containsZ?: boolean, normals?: number[], colors?: number | number[], alphas?: number | number[]): Phaser.Types.Geom.Mesh.GenerateVertsResult; /** - * The Input Plugin Pre-Update Event. + * Parses a Wavefront OBJ File, extracting the models from it and returning them in an array. * - * This internal event is dispatched by the Input Plugin at the start of its `preUpdate` method. - * This hook is designed specifically for input plugins, but can also be listened to from user-land code. + * The model data *must* be triangulated for a Mesh Game Object to be able to render it. + * @param data The OBJ File data as a raw string. + * @param flipUV Flip the UV coordinates? Default true. */ - const PRE_UPDATE: any; + function ParseObj(data: string, flipUV?: boolean): Phaser.Types.Geom.Mesh.OBJData; /** - * The Input Plugin Shutdown Event. + * Takes a Wavefront Material file and extracts the diffuse reflectivity of the named + * materials, converts them to integer color values and returns them. * - * This internal event is dispatched by the Input Plugin when it shuts down, signalling to all of its systems to shut themselves down. - */ - const SHUTDOWN: any; - - /** - * The Input Plugin Start Event. + * This is used internally by the `addOBJ` and `addModel` methods, but is exposed for + * public consumption as well. * - * This internal event is dispatched by the Input Plugin when it has finished setting-up, - * signalling to all of its internal systems to start. + * Note this only works with diffuse values, specified in the `Kd r g b` format, where + * `g` and `b` are optional, but `r` is required. It does not support spectral rfl files, + * or any other material statement (such as `Ka` or `Ks`) + * @param mtl The OBJ MTL file as a raw string, i.e. loaded via `this.load.text`. */ - const START: any; + function ParseObjMaterial(mtl: string): object; /** - * The Input Plugin Update Event. + * Rotates the vertices of a Face to the given angle. * - * This internal event is dispatched by the Input Plugin at the start of its `update` method. - * This hook is designed specifically for input plugins, but can also be listened to from user-land code. + * The actual vertex positions are adjusted, not their transformed positions. + * + * Therefore, this updates the vertex data directly. + * @param face The Face to rotate. + * @param angle The angle to rotate to, in radians. + * @param cx An optional center of rotation. If not given, the Face in-center is used. + * @param cy An optional center of rotation. If not given, the Face in-center is used. */ - const UPDATE: any; - - } + function RotateFace(face: Phaser.Geom.Mesh.Face, angle: number, cx?: number, cy?: number): void; - namespace Gamepad { /** - * Contains information about a specific Gamepad Axis. - * Axis objects are created automatically by the Gamepad as they are needed. + * A Vertex Geometry Object. + * + * This class consists of all the information required for a single vertex within a Face Geometry Object. + * + * Faces, and thus Vertex objects, are used by the Mesh Game Object in order to render objects in WebGL. */ - class Axis { + class Vertex extends Phaser.Math.Vector3 { /** * - * @param pad A reference to the Gamepad that this Axis belongs to. - * @param index The index of this Axis. + * @param x The x position of the vertex. + * @param y The y position of the vertex. + * @param z The z position of the vertex. + * @param u The UV u coordinate of the vertex. + * @param v The UV v coordinate of the vertex. + * @param color The color value of the vertex. Default 0xffffff. + * @param alpha The alpha value of the vertex. Default 1. + * @param nx The x normal value of the vertex. Default 0. + * @param ny The y normal value of the vertex. Default 0. + * @param nz The z normal value of the vertex. Default 0. */ - constructor(pad: Phaser.Input.Gamepad.Gamepad, index: integer); + constructor(x: number, y: number, z: number, u: number, v: number, color?: number, alpha?: number, nx?: number, ny?: number, nz?: number); /** - * A reference to the Gamepad that this Axis belongs to. + * The projected x coordinate of this vertex. */ - pad: Phaser.Input.Gamepad.Gamepad; + vx: number; /** - * An event emitter to use to emit the axis events. + * The projected y coordinate of this vertex. */ - events: Phaser.Events.EventEmitter; + vy: number; /** - * The index of this Axis. + * The projected z coordinate of this vertex. */ - index: integer; + vz: number; /** - * The raw axis value, between -1 and 1 with 0 being dead center. - * Use the method `getValue` to get a normalized value with the threshold applied. + * The projected x coordinate of this vertex. */ - value: number; + nx: number; /** - * Movement tolerance threshold below which axis values are ignored in `getValue`. + * The projected y coordinate of this vertex. */ - threshold: number; + ny: number; /** - * Applies the `threshold` value to the axis and returns it. + * The projected z coordinate of this vertex. */ - getValue(): number; + nz: number; /** - * Destroys this Axis instance and releases external references it holds. + * UV u coordinate of this vertex. */ - destroy(): void; - - } + u: number; - /** - * Contains information about a specific button on a Gamepad. - * Button objects are created automatically by the Gamepad as they are needed. - */ - class Button { /** - * - * @param pad A reference to the Gamepad that this Button belongs to. - * @param index The index of this Button. + * UV v coordinate of this vertex. */ - constructor(pad: Phaser.Input.Gamepad.Gamepad, index: integer); + v: number; /** - * A reference to the Gamepad that this Button belongs to. + * The color value of this vertex. */ - pad: Phaser.Input.Gamepad.Gamepad; + color: number; /** - * An event emitter to use to emit the button events. - */ - events: Phaser.Events.EventEmitter; - - /** - * The index of this Button. + * The alpha value of this vertex. */ - index: integer; + alpha: number; /** - * Between 0 and 1. + * The translated x coordinate of this vertex. */ - value: number; + tx: number; /** - * Can be set for analogue buttons to enable a 'pressure' threshold, - * before a button is considered as being 'pressed'. + * The translated y coordinate of this vertex. */ - threshold: number; + ty: number; /** - * Is the Button being pressed down or not? + * The translated alpha value of this vertex. */ - pressed: boolean; + ta: number; /** - * Destroys this Button instance and releases external references it holds. + * Sets the U and V properties. + * @param u The UV u coordinate of the vertex. + * @param v The UV v coordinate of the vertex. */ - destroy(): void; - - } + setUVs(u: number, v: number): this; - namespace Configs { /** - * Tatar SNES USB Controller Gamepad Configuration. - * USB Gamepad (STANDARD GAMEPAD Vendor: 0079 Product: 0011) + * Transforms this vertex by the given matrix, storing the results in `vx`, `vy` and `vz`. + * @param transformMatrix The transform matrix to apply to this vertex. + * @param width The width of the parent Mesh. + * @param height The height of the parent Mesh. + * @param cameraZ The z position of the MeshCamera. */ - var SNES_USB: object; + transformCoordinatesLocal(transformMatrix: Phaser.Math.Matrix4, width: number, height: number, cameraZ: number): void; /** - * PlayStation DualShock 4 Gamepad Configuration. - * Sony PlayStation DualShock 4 (v2) wireless controller + * Updates this Vertex based on the given transform. + * @param a The parent transform matrix data a component. + * @param b The parent transform matrix data b component. + * @param c The parent transform matrix data c component. + * @param d The parent transform matrix data d component. + * @param e The parent transform matrix data e component. + * @param f The parent transform matrix data f component. + * @param roundPixels Round the vertex position or not? + * @param alpha The alpha of the parent object. */ - var DUALSHOCK_4: object; + update(a: number, b: number, c: number, d: number, e: number, f: number, roundPixels: boolean, alpha: number): this; /** - * XBox 360 Gamepad Configuration. + * Loads the data from this Vertex into the given Typed Arrays. + * @param F32 A Float32 Array to insert the position, UV and unit data in to. + * @param U32 A Uint32 Array to insert the color and alpha data in to. + * @param offset The index of the array to insert this Vertex to. + * @param textureUnit The texture unit currently in use. */ - var XBOX_360: object; + load(F32: Float32Array, U32: Uint32Array, offset: number, textureUnit: number): number; } - namespace Events { - /** - * The Gamepad Button Down Event. - * - * This event is dispatched by the Gamepad Plugin when a button has been pressed on any active Gamepad. - * - * Listen to this event from within a Scene using: `this.input.gamepad.on('down', listener)`. - * - * You can also listen for a DOWN event from a Gamepad instance. See the [GAMEPAD_BUTTON_DOWN]{@linkcode Phaser.Input.Gamepad.Events#event:GAMEPAD_BUTTON_DOWN} event for details. - */ - const BUTTON_DOWN: any; - - /** - * The Gamepad Button Up Event. - * - * This event is dispatched by the Gamepad Plugin when a button has been released on any active Gamepad. - * - * Listen to this event from within a Scene using: `this.input.gamepad.on('up', listener)`. - * - * You can also listen for an UP event from a Gamepad instance. See the [GAMEPAD_BUTTON_UP]{@linkcode Phaser.Input.Gamepad.Events#event:GAMEPAD_BUTTON_UP} event for details. - */ - const BUTTON_UP: any; - - /** - * The Gamepad Connected Event. - * - * This event is dispatched by the Gamepad Plugin when a Gamepad has been connected. - * - * Listen to this event from within a Scene using: `this.input.gamepad.once('connected', listener)`. - * - * Note that the browser may require you to press a button on a gamepad before it will allow you to access it, - * this is for security reasons. However, it may also trust the page already, in which case you won't get the - * 'connected' event and instead should check `GamepadPlugin.total` to see if it thinks there are any gamepads - * already connected. - */ - const CONNECTED: any; - - /** - * The Gamepad Disconnected Event. - * - * This event is dispatched by the Gamepad Plugin when a Gamepad has been disconnected. - * - * Listen to this event from within a Scene using: `this.input.gamepad.once('disconnected', listener)`. - */ - const DISCONNECTED: any; - - /** - * The Gamepad Button Down Event. - * - * This event is dispatched by a Gamepad instance when a button has been pressed on it. - * - * Listen to this event from a Gamepad instance. Once way to get this is from the `pad1`, `pad2`, etc properties on the Gamepad Plugin: - * `this.input.gamepad.pad1.on('down', listener)`. - * - * Note that you will not receive any Gamepad button events until the browser considers the Gamepad as being 'connected'. - * - * You can also listen for a DOWN event from the Gamepad Plugin. See the [BUTTON_DOWN]{@linkcode Phaser.Input.Gamepad.Events#event:BUTTON_DOWN} event for details. - */ - const GAMEPAD_BUTTON_DOWN: any; - - /** - * The Gamepad Button Up Event. - * - * This event is dispatched by a Gamepad instance when a button has been released on it. - * - * Listen to this event from a Gamepad instance. Once way to get this is from the `pad1`, `pad2`, etc properties on the Gamepad Plugin: - * `this.input.gamepad.pad1.on('up', listener)`. - * - * Note that you will not receive any Gamepad button events until the browser considers the Gamepad as being 'connected'. - * - * You can also listen for an UP event from the Gamepad Plugin. See the [BUTTON_UP]{@linkcode Phaser.Input.Gamepad.Events#event:BUTTON_UP} event for details. - */ - const GAMEPAD_BUTTON_UP: any; - - } + } + /** + * Defines a Point in 2D space, with an x and y component. + */ + class Point { /** - * A single Gamepad. * - * These are created, updated and managed by the Gamepad Plugin. + * @param x The x coordinate of this Point. Default 0. + * @param y The y coordinate of this Point. Default x. */ - class Gamepad extends Phaser.Events.EventEmitter { - /** - * - * @param manager A reference to the Gamepad Plugin. - * @param pad The Gamepad object, as extracted from GamepadEvent. - */ - constructor(manager: Phaser.Input.Gamepad.GamepadPlugin, pad: Phaser.Types.Input.Gamepad.Pad); - - /** - * A reference to the Gamepad Plugin. - */ - manager: Phaser.Input.Gamepad.GamepadPlugin; - - /** - * A reference to the native Gamepad object that is connected to the browser. - */ - pad: any; - - /** - * A string containing some information about the controller. - * - * This is not strictly specified, but in Firefox it will contain three pieces of information - * separated by dashes (-): two 4-digit hexadecimal strings containing the USB vendor and - * product id of the controller, and the name of the controller as provided by the driver. - * In Chrome it will contain the name of the controller as provided by the driver, - * followed by vendor and product 4-digit hexadecimal strings. - */ - id: string; - - /** - * An integer that is unique for each Gamepad currently connected to the system. - * This can be used to distinguish multiple controllers. - * Note that disconnecting a device and then connecting a new device may reuse the previous index. - */ - index: number; - - /** - * An array of Gamepad Button objects, corresponding to the different buttons available on the Gamepad. - */ - buttons: Phaser.Input.Gamepad.Button[]; - - /** - * An array of Gamepad Axis objects, corresponding to the different axes available on the Gamepad, if any. - */ - axes: Phaser.Input.Gamepad.Axis[]; - - /** - * The Gamepad's Haptic Actuator (Vibration / Rumble support). - * This is highly experimental and only set if both present on the device, - * and exposed by both the hardware and browser. - */ - vibration: GamepadHapticActuator; + constructor(x?: number, y?: number); - /** - * A Vector2 containing the most recent values from the Gamepad's left axis stick. - * This is updated automatically as part of the Gamepad.update cycle. - * The H Axis is mapped to the `Vector2.x` property, and the V Axis to the `Vector2.y` property. - * The values are based on the Axis thresholds. - * If the Gamepad does not have a left axis stick, the values will always be zero. - */ - leftStick: Phaser.Math.Vector2; + /** + * Apply `Math.ceil()` to each coordinate of the given Point. + * @param point The Point to ceil. + */ + static Ceil(point: O): O; - /** - * A Vector2 containing the most recent values from the Gamepad's right axis stick. - * This is updated automatically as part of the Gamepad.update cycle. - * The H Axis is mapped to the `Vector2.x` property, and the V Axis to the `Vector2.y` property. - * The values are based on the Axis thresholds. - * If the Gamepad does not have a right axis stick, the values will always be zero. - */ - rightStick: Phaser.Math.Vector2; + /** + * Clone the given Point. + * @param source The source Point to clone. + */ + static Clone(source: Phaser.Geom.Point): Phaser.Geom.Point; - /** - * Gets the total number of axis this Gamepad claims to support. - */ - getAxisTotal(): integer; + /** + * Copy the values of one Point to a destination Point. + * @param source The source Point to copy the values from. + * @param dest The destination Point to copy the values to. + */ + static CopyFrom(source: Phaser.Geom.Point, dest: O): O; - /** - * Gets the value of an axis based on the given index. - * The index must be valid within the range of axes supported by this Gamepad. - * The return value will be a float between 0 and 1. - * @param index The index of the axes to get the value for. - */ - getAxisValue(index: integer): number; + /** + * A comparison of two `Point` objects to see if they are equal. + * @param point The original `Point` to compare against. + * @param toCompare The second `Point` to compare. + */ + static Equals(point: Phaser.Geom.Point, toCompare: Phaser.Geom.Point): boolean; - /** - * Sets the threshold value of all axis on this Gamepad. - * The value is a float between 0 and 1 and is the amount below which the axis is considered as not having been moved. - * @param value A value between 0 and 1. - */ - setAxisThreshold(value: number): void; + /** + * Apply `Math.ceil()` to each coordinate of the given Point. + * @param point The Point to floor. + */ + static Floor(point: O): O; - /** - * Gets the total number of buttons this Gamepad claims to have. - */ - getButtonTotal(): integer; + /** + * Get the centroid or geometric center of a plane figure (the arithmetic mean position of all the points in the figure). + * Informally, it is the point at which a cutout of the shape could be perfectly balanced on the tip of a pin. + * @param points An array of Vector2Like objects to get the geometric center of. + * @param out A Point object to store the output coordinates in. If not given, a new Point instance is created. + */ + static GetCentroid(points: Phaser.Types.Math.Vector2Like[], out?: O): O; - /** - * Gets the value of a button based on the given index. - * The index must be valid within the range of buttons supported by this Gamepad. - * - * The return value will be either 0 or 1 for an analogue button, or a float between 0 and 1 - * for a pressure-sensitive digital button, such as the shoulder buttons on a Dual Shock. - * @param index The index of the button to get the value for. - */ - getButtonValue(index: integer): number; + /** + * Calculate the magnitude of the point, which equivalent to the length of the line from the origin to this point. + * @param point The point to calculate the magnitude for + */ + static GetMagnitude(point: Phaser.Geom.Point): number; - /** - * Returns if the button is pressed down or not. - * The index must be valid within the range of buttons supported by this Gamepad. - * @param index The index of the button to get the value for. - */ - isButtonDown(index: integer): boolean; + /** + * Calculates the square of magnitude of given point.(Can be used for fast magnitude calculation of point) + * @param point Returns square of the magnitude/length of given point. + */ + static GetMagnitudeSq(point: Phaser.Geom.Point): number; - /** - * Destroys this Gamepad instance, its buttons and axes, and releases external references it holds. - */ - destroy(): void; + /** + * Calculates the Axis Aligned Bounding Box (or aabb) from an array of points. + * @param points An array of Vector2Like objects to get the AABB from. + * @param out A Rectangle object to store the results in. If not given, a new Rectangle instance is created. + */ + static GetRectangleFromPoints(points: Phaser.Types.Math.Vector2Like[], out?: O): O; - /** - * Is this Gamepad currently connected or not? - */ - connected: boolean; + /** + * Returns the linear interpolation point between the two given points, based on `t`. + * @param pointA The starting `Point` for the interpolation. + * @param pointB The target `Point` for the interpolation. + * @param t The amount to interpolate between the two points. Generally, a value between 0 (returns the starting `Point`) and 1 (returns the target `Point`). If omitted, 0 is used. Default 0. + * @param out An optional `Point` object whose `x` and `y` values will be set to the result of the interpolation (can also be any object with `x` and `y` properties). If omitted, a new `Point` created and returned. + */ + static Interpolate(pointA: Phaser.Geom.Point, pointB: Phaser.Geom.Point, t?: number, out?: O): O; - /** - * A timestamp containing the most recent time this Gamepad was updated. - */ - timestamp: number; + /** + * Swaps the X and the Y coordinate of a point. + * @param point The Point to modify. + */ + static Invert(point: O): O; - /** - * Is the Gamepad's Left button being pressed? - * If the Gamepad doesn't have this button it will always return false. - * This is the d-pad left button under standard Gamepad mapping. - */ - left: boolean; + /** + * Inverts a Point's coordinates. + * @param point The Point to invert. + * @param out The Point to return the inverted coordinates in. + */ + static Negative(point: Phaser.Geom.Point, out?: O): O; - /** - * Is the Gamepad's Right button being pressed? - * If the Gamepad doesn't have this button it will always return false. - * This is the d-pad right button under standard Gamepad mapping. - */ - right: boolean; + /** + * The geometry constant type of this object: `GEOM_CONST.POINT`. + * Used for fast type comparisons. + */ + readonly type: number; - /** - * Is the Gamepad's Up button being pressed? - * If the Gamepad doesn't have this button it will always return false. - * This is the d-pad up button under standard Gamepad mapping. - */ - up: boolean; + /** + * The x coordinate of this Point. + */ + x: number; - /** - * Is the Gamepad's Down button being pressed? - * If the Gamepad doesn't have this button it will always return false. - * This is the d-pad down button under standard Gamepad mapping. - */ - down: boolean; + /** + * The y coordinate of this Point. + */ + y: number; - /** - * Is the Gamepad's bottom button in the right button cluster being pressed? - * If the Gamepad doesn't have this button it will always return false. - * On a Dual Shock controller it's the X button. - * On an XBox controller it's the A button. - */ - A: boolean; + /** + * Set the x and y coordinates of the point to the given values. + * @param x The x coordinate of this Point. Default 0. + * @param y The y coordinate of this Point. Default x. + */ + setTo(x?: number, y?: number): this; - /** - * Is the Gamepad's top button in the right button cluster being pressed? - * If the Gamepad doesn't have this button it will always return false. - * On a Dual Shock controller it's the Triangle button. - * On an XBox controller it's the Y button. - */ - Y: boolean; + /** + * Calculates the vector projection of `pointA` onto the nonzero `pointB`. This is the + * orthogonal projection of `pointA` onto a straight line paralle to `pointB`. + * @param pointA Point A, to be projected onto Point B. + * @param pointB Point B, to have Point A projected upon it. + * @param out The Point object to store the position in. If not given, a new Point instance is created. + */ + static Project(pointA: Phaser.Geom.Point, pointB: Phaser.Geom.Point, out?: O): O; - /** - * Is the Gamepad's left button in the right button cluster being pressed? - * If the Gamepad doesn't have this button it will always return false. - * On a Dual Shock controller it's the Square button. - * On an XBox controller it's the X button. - */ - X: boolean; + /** + * Calculates the vector projection of `pointA` onto the nonzero `pointB`. This is the + * orthogonal projection of `pointA` onto a straight line paralle to `pointB`. + * @param pointA Point A, to be projected onto Point B. Must be a normalized point with a magnitude of 1. + * @param pointB Point B, to have Point A projected upon it. + * @param out The Point object to store the position in. If not given, a new Point instance is created. + */ + static ProjectUnit(pointA: Phaser.Geom.Point, pointB: Phaser.Geom.Point, out?: O): O; - /** - * Is the Gamepad's right button in the right button cluster being pressed? - * If the Gamepad doesn't have this button it will always return false. - * On a Dual Shock controller it's the Circle button. - * On an XBox controller it's the B button. - */ - B: boolean; + /** + * Changes the magnitude (length) of a two-dimensional vector without changing its direction. + * @param point The Point to treat as the end point of the vector. + * @param magnitude The new magnitude of the vector. + */ + static SetMagnitude(point: O, magnitude: number): O; - /** - * Returns the value of the Gamepad's top left shoulder button. - * If the Gamepad doesn't have this button it will always return zero. - * The value is a float between 0 and 1, corresponding to how depressed the button is. - * On a Dual Shock controller it's the L1 button. - * On an XBox controller it's the LB button. - */ - L1: number; + } - /** - * Returns the value of the Gamepad's bottom left shoulder button. - * If the Gamepad doesn't have this button it will always return zero. - * The value is a float between 0 and 1, corresponding to how depressed the button is. - * On a Dual Shock controller it's the L2 button. - * On an XBox controller it's the LT button. - */ - L2: number; + /** + * A Polygon object + * + * The polygon is a closed shape consists of a series of connected straight lines defined by list of ordered points. + * Several formats are supported to define the list of points, check the setTo method for details. + * This is a geometry object allowing you to define and inspect the shape. + * It is not a Game Object, in that you cannot add it to the display list, and it has no texture. + * To render a Polygon you should look at the capabilities of the Graphics class. + */ + class Polygon { + /** + * + * @param points List of points defining the perimeter of this Polygon. Several formats are supported: + * - A string containing paired x y values separated by a single space: `'40 0 40 20 100 20 100 80 40 80 40 100 0 50'` + * - An array of Point objects: `[new Phaser.Point(x1, y1), ...]` + * - An array of objects with public x y properties: `[obj1, obj2, ...]` + * - An array of paired numbers that represent point coordinates: `[x1,y1, x2,y2, ...]` + * - An array of arrays with two elements representing x/y coordinates: `[[x1, y1], [x2, y2], ...]` + */ + constructor(points?: string | number[] | Phaser.Types.Math.Vector2Like[]); - /** - * Returns the value of the Gamepad's top right shoulder button. - * If the Gamepad doesn't have this button it will always return zero. - * The value is a float between 0 and 1, corresponding to how depressed the button is. - * On a Dual Shock controller it's the R1 button. - * On an XBox controller it's the RB button. - */ - R1: number; + /** + * Create a new polygon which is a copy of the specified polygon + * @param polygon The polygon to create a clone of + */ + static Clone(polygon: Phaser.Geom.Polygon): Phaser.Geom.Polygon; - /** - * Returns the value of the Gamepad's bottom right shoulder button. - * If the Gamepad doesn't have this button it will always return zero. - * The value is a float between 0 and 1, corresponding to how depressed the button is. - * On a Dual Shock controller it's the R2 button. - * On an XBox controller it's the RT button. - */ - R2: number; + /** + * Checks if a point is within the bounds of a Polygon. + * @param polygon The Polygon to check against. + * @param x The X coordinate of the point to check. + * @param y The Y coordinate of the point to check. + */ + static Contains(polygon: Phaser.Geom.Polygon, x: number, y: number): boolean; - } + /** + * Checks the given Point again the Polygon to see if the Point lays within its vertices. + * @param polygon The Polygon to check. + * @param point The Point to check if it's within the Polygon. + */ + static ContainsPoint(polygon: Phaser.Geom.Polygon, point: Phaser.Geom.Point): boolean; /** - * The Gamepad Plugin is an input plugin that belongs to the Scene-owned Input system. - * - * Its role is to listen for native DOM Gamepad Events and then process them. + * This module implements a modified ear slicing algorithm, optimized by z-order curve hashing and extended to + * handle holes, twisted polygons, degeneracies and self-intersections in a way that doesn't guarantee correctness + * of triangulation, but attempts to always produce acceptable results for practical data. * - * You do not need to create this class directly, the Input system will create an instance of it automatically. + * Example: * - * You can access it from within a Scene using `this.input.gamepad`. + * ```javascript + * const triangles = Phaser.Geom.Polygon.Earcut([10,0, 0,50, 60,60, 70,10]); // returns [1,0,3, 3,2,1] + * ``` * - * To listen for a gamepad being connected: + * Each group of three vertex indices in the resulting array forms a triangle. * * ```javascript - * this.input.gamepad.once('connected', function (pad) { - * // 'pad' is a reference to the gamepad that was just connected - * }); + * // triangulating a polygon with a hole + * earcut([0,0, 100,0, 100,100, 0,100, 20,20, 80,20, 80,80, 20,80], [4]); + * // [3,0,4, 5,4,0, 3,4,7, 5,0,1, 2,3,7, 6,5,1, 2,7,6, 6,1,2] + * + * // triangulating a polygon with 3d coords + * earcut([10,0,1, 0,50,2, 60,60,3, 70,10,4], null, 3); + * // [1,0,3, 3,2,1] * ``` * - * Note that the browser may require you to press a button on a gamepad before it will allow you to access it, - * this is for security reasons. However, it may also trust the page already, in which case you won't get the - * 'connected' event and instead should check `GamepadPlugin.total` to see if it thinks there are any gamepads - * already connected. + * If you pass a single vertex as a hole, Earcut treats it as a Steiner point. * - * Once you have received the connected event, or polled the gamepads and found them enabled, you can access - * them via the built-in properties `GamepadPlugin.pad1` to `pad4`, for up to 4 game pads. With a reference - * to the gamepads you can poll its buttons and axis sticks. See the properties and methods available on - * the `Gamepad` class for more details. + * If your input is a multi-dimensional array (e.g. GeoJSON Polygon), you can convert it to the format + * expected by Earcut with `Phaser.Geom.Polygon.Earcut.flatten`: * - * For more information about Gamepad support in browsers see the following resources: + * ```javascript + * var data = earcut.flatten(geojson.geometry.coordinates); + * var triangles = earcut(data.vertices, data.holes, data.dimensions); + * ``` * - * https://developer.mozilla.org/en-US/docs/Web/API/Gamepad_API - * https://developer.mozilla.org/en-US/docs/Web/API/Gamepad_API/Using_the_Gamepad_API - * https://www.smashingmagazine.com/2015/11/gamepad-api-in-web-games/ - * http://html5gamepad.com/ + * After getting a triangulation, you can verify its correctness with `Phaser.Geom.Polygon.Earcut.deviation`: + * + * ```javascript + * var deviation = earcut.deviation(vertices, holes, dimensions, triangles); + * ``` + * Returns the relative difference between the total area of triangles and the area of the input polygon. + * 0 means the triangulation is fully correct. + * + * For more information see https://github.com/mapbox/earcut + * @param data A flat array of vertex coordinate, like [x0,y0, x1,y1, x2,y2, ...] + * @param holeIndices An array of hole indices if any (e.g. [5, 8] for a 12-vertex input would mean one hole with vertices 5–7 and another with 8–11). + * @param dimensions The number of coordinates per vertex in the input array (2 by default). Default 2. */ - class GamepadPlugin extends Phaser.Events.EventEmitter { - /** - * - * @param sceneInputPlugin A reference to the Scene Input Plugin that the KeyboardPlugin belongs to. - */ - constructor(sceneInputPlugin: Phaser.Input.InputPlugin); - - /** - * A reference to the Scene that this Input Plugin is responsible for. - */ - scene: Phaser.Scene; + static Earcut(data: number[], holeIndices?: number[], dimensions?: number): number[]; - /** - * A reference to the Scene Systems Settings. - */ - settings: Phaser.Types.Scenes.SettingsObject; + /** + * Calculates the bounding AABB rectangle of a polygon. + * @param polygon The polygon that should be calculated. + * @param out The rectangle or object that has x, y, width, and height properties to store the result. Optional. + */ + static GetAABB(polygon: Phaser.Geom.Polygon, out?: O): O; - /** - * A reference to the Scene Input Plugin that created this Keyboard Plugin. - */ - sceneInputPlugin: Phaser.Input.InputPlugin; + /** + * Stores all of the points of a Polygon into a flat array of numbers following the sequence [ x,y, x,y, x,y ], + * i.e. each point of the Polygon, in the order it's defined, corresponds to two elements of the resultant + * array for the point's X and Y coordinate. + * @param polygon The Polygon whose points to export. + * @param output An array to which the points' coordinates should be appended. + */ + static GetNumberArray(polygon: Phaser.Geom.Polygon, output?: O): O; - /** - * A boolean that controls if the Gamepad Manager is enabled or not. - * Can be toggled on the fly. - */ - enabled: boolean; + /** + * Returns an array of Point objects containing the coordinates of the points around the perimeter of the Polygon, + * based on the given quantity or stepRate values. + * @param polygon The Polygon to get the points from. + * @param quantity The amount of points to return. If a falsey value the quantity will be derived from the `stepRate` instead. + * @param stepRate Sets the quantity by getting the perimeter of the Polygon and dividing it by the stepRate. + * @param output An array to insert the points in to. If not provided a new array will be created. + */ + static GetPoints(polygon: Phaser.Geom.Polygon, quantity: number, stepRate?: number, output?: any[]): Phaser.Geom.Point[]; - /** - * The Gamepad Event target, as defined in the Game Config. - * Typically the browser window, but can be any interactive DOM element. - */ - target: any; + /** + * Returns the perimeter of the given Polygon. + * @param polygon The Polygon to get the perimeter of. + */ + static Perimeter(polygon: Phaser.Geom.Polygon): number; - /** - * An array of the connected Gamepads. - */ - gamepads: Phaser.Input.Gamepad.Gamepad[]; + /** + * The geometry constant type of this object: `GEOM_CONST.POLYGON`. + * Used for fast type comparisons. + */ + readonly type: number; - /** - * Checks to see if both this plugin and the Scene to which it belongs is active. - */ - isActive(): boolean; + /** + * The area of this Polygon. + */ + area: number; - /** - * Disconnects all current Gamepads. - */ - disconnectAll(): void; + /** + * An array of number pair objects that make up this polygon. I.e. [ {x,y}, {x,y}, {x,y} ] + */ + points: Phaser.Geom.Point[]; - /** - * Returns an array of all currently connected Gamepads. - */ - getAll(): Phaser.Input.Gamepad.Gamepad[]; + /** + * Check to see if the Polygon contains the given x / y coordinates. + * @param x The x coordinate to check within the polygon. + * @param y The y coordinate to check within the polygon. + */ + contains(x: number, y: number): boolean; - /** - * Looks-up a single Gamepad based on the given index value. - * @param index The index of the Gamepad to get. - */ - getPad(index: number): Phaser.Input.Gamepad.Gamepad; + /** + * Sets this Polygon to the given points. + * + * The points can be set from a variety of formats: + * + * - A string containing paired values separated by a single space: `'40 0 40 20 100 20 100 80 40 80 40 100 0 50'` + * - An array of Point objects: `[new Phaser.Point(x1, y1), ...]` + * - An array of objects with public x/y properties: `[obj1, obj2, ...]` + * - An array of paired numbers that represent point coordinates: `[x1,y1, x2,y2, ...]` + * - An array of arrays with two elements representing x/y coordinates: `[[x1, y1], [x2, y2], ...]` + * + * `setTo` may also be called without any arguments to remove all points. + * @param points Points defining the perimeter of this polygon. Please check function description above for the different supported formats. + */ + setTo(points?: string | number[] | Phaser.Types.Math.Vector2Like[]): this; - /** - * The total number of connected game pads. - */ - total: integer; + /** + * Calculates the area of the Polygon. This is available in the property Polygon.area + */ + calculateArea(): number; - /** - * A reference to the first connected Gamepad. - * - * This will be undefined if either no pads are connected, or the browser - * has not yet issued a gamepadconnect, which can happen even if a Gamepad - * is plugged in, but hasn't yet had any buttons pressed on it. - */ - pad1: Phaser.Input.Gamepad.Gamepad; + /** + * Returns an array of Point objects containing the coordinates of the points around the perimeter of the Polygon, + * based on the given quantity or stepRate values. + * @param quantity The amount of points to return. If a falsey value the quantity will be derived from the `stepRate` instead. + * @param stepRate Sets the quantity by getting the perimeter of the Polygon and dividing it by the stepRate. + * @param output An array to insert the points in to. If not provided a new array will be created. + */ + getPoints(quantity: number, stepRate?: number, output?: O): O; - /** - * A reference to the second connected Gamepad. - * - * This will be undefined if either no pads are connected, or the browser - * has not yet issued a gamepadconnect, which can happen even if a Gamepad - * is plugged in, but hasn't yet had any buttons pressed on it. - */ - pad2: Phaser.Input.Gamepad.Gamepad; + /** + * Reverses the order of the points of a Polygon. + * @param polygon The Polygon to modify. + */ + static Reverse(polygon: O): O; - /** - * A reference to the third connected Gamepad. - * - * This will be undefined if either no pads are connected, or the browser - * has not yet issued a gamepadconnect, which can happen even if a Gamepad - * is plugged in, but hasn't yet had any buttons pressed on it. - */ - pad3: Phaser.Input.Gamepad.Gamepad; + /** + * Takes a Polygon object and simplifies the points by running them through a combination of + * Douglas-Peucker and Radial Distance algorithms. Simplification dramatically reduces the number of + * points in a polygon while retaining its shape, giving a huge performance boost when processing + * it and also reducing visual noise. + * @param polygon The polygon to be simplified. The polygon will be modified in-place and returned. + * @param tolerance Affects the amount of simplification (in the same metric as the point coordinates). Default 1. + * @param highestQuality Excludes distance-based preprocessing step which leads to highest quality simplification but runs ~10-20 times slower. Default false. + */ + static Simplify(polygon: O, tolerance?: number, highestQuality?: boolean): O; - /** - * A reference to the fourth connected Gamepad. - * - * This will be undefined if either no pads are connected, or the browser - * has not yet issued a gamepadconnect, which can happen even if a Gamepad - * is plugged in, but hasn't yet had any buttons pressed on it. - */ - pad4: Phaser.Input.Gamepad.Gamepad; + /** + * Takes a Polygon object and applies Chaikin's smoothing algorithm on its points. + * @param polygon The polygon to be smoothed. The polygon will be modified in-place and returned. + */ + static Smooth(polygon: O): O; - } + /** + * Tranlates the points of the given Polygon. + * @param polygon The Polygon to modify. + * @param x The amount to horizontally translate the points by. + * @param y The amount to vertically translate the points by. + */ + static Translate(polygon: O, x: number, y: number): O; } /** - * The Input Manager is responsible for handling the pointer related systems in a single Phaser Game instance. - * - * Based on the Game Config it will create handlers for mouse and touch support. - * - * Keyboard and Gamepad are plugins, handled directly by the InputPlugin class. - * - * It then manages the events, pointer creation and general hit test related operations. - * - * You rarely need to interact with the Input Manager directly, and as such, all of its properties and methods - * should be considered private. Instead, you should use the Input Plugin, which is a Scene level system, responsible - * for dealing with all input events for a Scene. + * Encapsulates a 2D rectangle defined by its corner point in the top-left and its extends in x (width) and y (height) */ - class InputManager { + class Rectangle { /** * - * @param game The Game instance that owns the Input Manager. - * @param config The Input Configuration object, as set in the Game Config. + * @param x The X coordinate of the top left corner of the Rectangle. Default 0. + * @param y The Y coordinate of the top left corner of the Rectangle. Default 0. + * @param width The width of the Rectangle. Default 0. + * @param height The height of the Rectangle. Default 0. */ - constructor(game: Phaser.Game, config: object); + constructor(x?: number, y?: number, width?: number, height?: number); /** - * The Game instance that owns the Input Manager. - * A Game only maintains on instance of the Input Manager at any time. + * Calculates the area of the given Rectangle object. + * @param rect The rectangle to calculate the area of. */ - readonly game: Phaser.Game; + static Area(rect: Phaser.Geom.Rectangle): number; /** - * A reference to the global Game Scale Manager. - * Used for all bounds checks and pointer scaling. + * Rounds a Rectangle's position up to the smallest integer greater than or equal to each current coordinate. + * @param rect The Rectangle to adjust. */ - scaleManager: Phaser.Scale.ScaleManager; + static Ceil(rect: O): O; /** - * The Canvas that is used for all DOM event input listeners. + * Rounds a Rectangle's position and size up to the smallest integer greater than or equal to each respective value. + * @param rect The Rectangle to modify. */ - canvas: HTMLCanvasElement; + static CeilAll(rect: O): O; /** - * The Game Configuration object, as set during the game boot. + * Moves the top-left corner of a Rectangle so that its center is at the given coordinates. + * @param rect The Rectangle to be centered. + * @param x The X coordinate of the Rectangle's center. + * @param y The Y coordinate of the Rectangle's center. */ - config: Phaser.Core.Config; + static CenterOn(rect: O, x: number, y: number): O; /** - * If set, the Input Manager will run its update loop every frame. + * Creates a new Rectangle which is identical to the given one. + * @param source The Rectangle to clone. */ - enabled: boolean; + static Clone(source: Phaser.Geom.Rectangle): Phaser.Geom.Rectangle; /** - * The Event Emitter instance that the Input Manager uses to emit events from. + * Checks if a given point is inside a Rectangle's bounds. + * @param rect The Rectangle to check. + * @param x The X coordinate of the point to check. + * @param y The Y coordinate of the point to check. */ - events: Phaser.Events.EventEmitter; + static Contains(rect: Phaser.Geom.Rectangle, x: number, y: number): boolean; /** - * Are any mouse or touch pointers currently over the game canvas? - * This is updated automatically by the canvas over and out handlers. + * Determines whether the specified point is contained within the rectangular region defined by this Rectangle object. + * @param rect The Rectangle object. + * @param point The point object to be checked. Can be a Phaser Point object or any object with x and y values. */ - readonly isOver: boolean; + static ContainsPoint(rect: Phaser.Geom.Rectangle, point: Phaser.Geom.Point): boolean; /** - * The default CSS cursor to be used when interacting with your game. - * - * See the `setDefaultCursor` method for more details. + * Tests if one rectangle fully contains another. + * @param rectA The first rectangle. + * @param rectB The second rectangle. */ - defaultCursor: string; + static ContainsRect(rectA: Phaser.Geom.Rectangle, rectB: Phaser.Geom.Rectangle): boolean; /** - * A reference to the Keyboard Manager class, if enabled via the `input.keyboard` Game Config property. + * Copy the values of one Rectangle to a destination Rectangle. + * @param source The source Rectangle to copy the values from. + * @param dest The destination Rectangle to copy the values to. */ - keyboard: Phaser.Input.Keyboard.KeyboardManager; + static CopyFrom(source: Phaser.Geom.Rectangle, dest: O): O; /** - * A reference to the Mouse Manager class, if enabled via the `input.mouse` Game Config property. + * Create an array of points for each corner of a Rectangle + * If an array is specified, each point object will be added to the end of the array, otherwise a new array will be created. + * @param rect The Rectangle object to be decomposed. + * @param out If provided, each point will be added to this array. */ - mouse: Phaser.Input.Mouse.MouseManager; + static Decompose(rect: Phaser.Geom.Rectangle, out?: any[]): any[]; /** - * A reference to the Touch Manager class, if enabled via the `input.touch` Game Config property. + * Compares the `x`, `y`, `width` and `height` properties of two rectangles. + * @param rect Rectangle A + * @param toCompare Rectangle B */ - touch: Phaser.Input.Touch.TouchManager; + static Equals(rect: Phaser.Geom.Rectangle, toCompare: Phaser.Geom.Rectangle): boolean; /** - * An array of Pointers that have been added to the game. - * The first entry is reserved for the Mouse Pointer, the rest are Touch Pointers. + * Adjusts the target rectangle, changing its width, height and position, + * so that it fits inside the area of the source rectangle, while maintaining its original + * aspect ratio. * - * By default there is 1 touch pointer enabled. If you need more use the `addPointer` method to start them, - * or set the `input.activePointers` property in the Game Config. + * Unlike the `FitOutside` function, there may be some space inside the source area not covered. + * @param target The target rectangle to adjust. + * @param source The source rectangle to envelop the target in. */ - pointers: Phaser.Input.Pointer[]; + static FitInside(target: O, source: Phaser.Geom.Rectangle): O; /** - * The number of touch objects activated and being processed each update. + * Adjusts the target rectangle, changing its width, height and position, + * so that it fully covers the area of the source rectangle, while maintaining its original + * aspect ratio. * - * You can change this by either calling `addPointer` at run-time, or by - * setting the `input.activePointers` property in the Game Config. + * Unlike the `FitInside` function, the target rectangle may extend further out than the source. + * @param target The target rectangle to adjust. + * @param source The source rectangle to envelope the target in. */ - readonly pointersTotal: integer; + static FitOutside(target: O, source: Phaser.Geom.Rectangle): O; /** - * The mouse has its own unique Pointer object, which you can reference directly if making a _desktop specific game_. - * If you are supporting both desktop and touch devices then do not use this property, instead use `activePointer` - * which will always map to the most recently interacted pointer. + * Rounds down (floors) the top left X and Y coordinates of the given Rectangle to the largest integer less than or equal to them + * @param rect The rectangle to floor the top left X and Y coordinates of */ - mousePointer: Phaser.Input.Pointer; + static Floor(rect: O): O; /** - * The most recently active Pointer object. - * - * If you've only 1 Pointer in your game then this will accurately be either the first finger touched, or the mouse. - * - * If your game doesn't need to support multi-touch then you can safely use this property in all of your game - * code and it will adapt to be either the mouse or the touch, based on device. + * Rounds a Rectangle's position and size down to the largest integer less than or equal to each current coordinate or dimension. + * @param rect The Rectangle to adjust. */ - activePointer: Phaser.Input.Pointer; + static FloorAll(rect: O): O; /** - * If the top-most Scene in the Scene List receives an input it will stop input from - * propagating any lower down the scene list, i.e. if you have a UI Scene at the top - * and click something on it, that click will not then be passed down to any other - * Scene below. Disable this to have input events passed through all Scenes, all the time. + * Constructs new Rectangle or repositions and resizes an existing Rectangle so that all of the given points are on or within its bounds. + * @param points An array of points (either arrays with two elements corresponding to the X and Y coordinate or an object with public `x` and `y` properties) which should be surrounded by the Rectangle. + * @param out Optional Rectangle to adjust. */ - globalTopOnly: boolean; + static FromPoints(points: any[], out?: O): O; /** - * The time this Input Manager was last updated. - * This value is populated by the Game Step each frame. + * Create the smallest Rectangle containing two coordinate pairs. + * @param x1 The X coordinate of the first point. + * @param y1 The Y coordinate of the first point. + * @param x2 The X coordinate of the second point. + * @param y2 The Y coordinate of the second point. + * @param out Optional Rectangle to adjust. */ - readonly time: number; + static FromXY(x1: number, y1: number, x2: number, y2: number, out?: O): O; /** - * The Boot handler is called by Phaser.Game when it first starts up. - * The renderer is available by now. + * Calculates the width/height ratio of a rectangle. + * @param rect The rectangle. */ - protected boot(): void; + static GetAspectRatio(rect: Phaser.Geom.Rectangle): number; /** - * Tells the Input system to set a custom cursor. - * - * This cursor will be the default cursor used when interacting with the game canvas. - * - * If an Interactive Object also sets a custom cursor, this is the cursor that is reset after its use. - * - * Any valid CSS cursor value is allowed, including paths to image files, i.e.: - * - * ```javascript - * this.input.setDefaultCursor('url(assets/cursors/sword.cur), pointer'); - * ``` - * - * Please read about the differences between browsers when it comes to the file formats and sizes they support: - * - * https://developer.mozilla.org/en-US/docs/Web/CSS/cursor - * https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_User_Interface/Using_URL_values_for_the_cursor_property - * - * It's up to you to pick a suitable cursor format that works across the range of browsers you need to support. - * @param cursor The CSS to be used when setting the default cursor. + * Returns the center of a Rectangle as a Point. + * @param rect The Rectangle to get the center of. + * @param out Optional point-like object to update with the center coordinates. */ - setDefaultCursor(cursor: string): void; + static GetCenter(rect: Phaser.Geom.Rectangle, out?: O): O; /** - * Adds new Pointer objects to the Input Manager. - * - * By default Phaser creates 2 pointer objects: `mousePointer` and `pointer1`. + * Calculates the coordinates of a point at a certain `position` on the Rectangle's perimeter. * - * You can create more either by calling this method, or by setting the `input.activePointers` property - * in the Game Config, up to a maximum of 10 pointers. + * The `position` is a fraction between 0 and 1 which defines how far into the perimeter the point is. * - * The first 10 pointers are available via the `InputPlugin.pointerX` properties, once they have been added - * via this method. - * @param quantity The number of new Pointers to create. A maximum of 10 is allowed in total. Default 1. + * A value of 0 or 1 returns the point at the top left corner of the rectangle, while a value of 0.5 returns the point at the bottom right corner of the rectangle. Values between 0 and 0.5 are on the top or the right side and values between 0.5 and 1 are on the bottom or the left side. + * @param rectangle The Rectangle to get the perimeter point from. + * @param position The normalized distance into the Rectangle's perimeter to return. + * @param out An object to update with the `x` and `y` coordinates of the point. */ - addPointer(quantity?: integer): Phaser.Input.Pointer[]; + static GetPoint(rectangle: Phaser.Geom.Rectangle, position: number, out?: O): O; /** - * Internal method that gets a list of all the active Input Plugins in the game - * and updates each of them in turn, in reverse order (top to bottom), to allow - * for DOM top-level event handling simulation. - * @param type The type of event to process. - * @param pointers An array of Pointers on which the event occurred. + * Return an array of points from the perimeter of the rectangle, each spaced out based on the quantity or step required. + * @param rectangle The Rectangle object to get the points from. + * @param step Step between points. Used to calculate the number of points to return when quantity is falsey. Ignored if quantity is positive. + * @param quantity The number of evenly spaced points from the rectangles perimeter to return. If falsey, step param will be used to calculate the number of points. + * @param out An optional array to store the points in. */ - updateInputPlugins(type: integer, pointers: Phaser.Input.Pointer[]): void; + static GetPoints(rectangle: Phaser.Geom.Rectangle, step: number, quantity: number, out?: O): O; /** - * Performs a hit test using the given Pointer and camera, against an array of interactive Game Objects. - * - * The Game Objects are culled against the camera, and then the coordinates are translated into the local camera space - * and used to determine if they fall within the remaining Game Objects hit areas or not. - * - * If nothing is matched an empty array is returned. - * - * This method is called automatically by InputPlugin.hitTestPointer and doesn't usually need to be invoked directly. - * @param pointer The Pointer to test against. - * @param gameObjects An array of interactive Game Objects to check. - * @param camera The Camera which is being tested against. - * @param output An array to store the results in. If not given, a new empty array is created. + * Returns the size of the Rectangle, expressed as a Point object. + * With the value of the `width` as the `x` property and the `height` as the `y` property. + * @param rect The Rectangle to get the size from. + * @param out The Point object to store the size in. If not given, a new Point instance is created. */ - hitTest(pointer: Phaser.Input.Pointer, gameObjects: any[], camera: Phaser.Cameras.Scene2D.Camera, output?: any[]): any[]; + static GetSize(rect: Phaser.Geom.Rectangle, out?: O): O; /** - * Checks if the given x and y coordinate are within the hit area of the Game Object. - * - * This method assumes that the coordinate values have already been translated into the space of the Game Object. + * Increases the size of a Rectangle by a specified amount. * - * If the coordinates are within the hit area they are set into the Game Objects Input `localX` and `localY` properties. - * @param gameObject The interactive Game Object to check against. - * @param x The translated x coordinate for the hit test. - * @param y The translated y coordinate for the hit test. + * The center of the Rectangle stays the same. The amounts are added to each side, so the actual increase in width or height is two times bigger than the respective argument. + * @param rect The Rectangle to inflate. + * @param x How many pixels the left and the right side should be moved by horizontally. + * @param y How many pixels the top and the bottom side should be moved by vertically. */ - pointWithinHitArea(gameObject: Phaser.GameObjects.GameObject, x: number, y: number): boolean; + static Inflate(rect: O, x: number, y: number): O; /** - * Checks if the given x and y coordinate are within the hit area of the Interactive Object. - * - * This method assumes that the coordinate values have already been translated into the space of the Interactive Object. - * - * If the coordinates are within the hit area they are set into the Interactive Objects Input `localX` and `localY` properties. - * @param object The Interactive Object to check against. - * @param x The translated x coordinate for the hit test. - * @param y The translated y coordinate for the hit test. + * Takes two Rectangles and first checks to see if they intersect. + * If they intersect it will return the area of intersection in the `out` Rectangle. + * If they do not intersect, the `out` Rectangle will have a width and height of zero. + * @param rectA The first Rectangle to get the intersection from. + * @param rectB The second Rectangle to get the intersection from. + * @param out A Rectangle to store the intersection results in. */ - pointWithinInteractiveObject(object: Phaser.Types.Input.InteractiveObject, x: number, y: number): boolean; + static Intersection(rectA: Phaser.Geom.Rectangle, rectB: Phaser.Geom.Rectangle, out?: Phaser.Geom.Rectangle): O; /** - * Transforms the pageX and pageY values of a Pointer into the scaled coordinate space of the Input Manager. - * @param pointer The Pointer to transform the values for. - * @param pageX The Page X value. - * @param pageY The Page Y value. - * @param wasMove Are we transforming the Pointer from a move event, or an up / down event? + * Returns an array of points from the perimeter of the Rectangle, where each point is spaced out based + * on either the `step` value, or the `quantity`. + * @param rect The Rectangle to get the perimeter points from. + * @param step The distance between each point of the perimeter. Set to `null` if you wish to use the `quantity` parameter instead. + * @param quantity The total number of points to return. The step is then calculated based on the length of the Rectangle, divided by this value. + * @param out An array in which the perimeter points will be stored. If not given, a new array instance is created. */ - transformPointer(pointer: Phaser.Input.Pointer, pageX: number, pageY: number, wasMove: boolean): void; + static MarchingAnts(rect: Phaser.Geom.Rectangle, step?: number, quantity?: number, out?: O): O; /** - * Destroys the Input Manager and all of its systems. - * - * There is no way to recover from doing this. + * Merges a Rectangle with a list of points by repositioning and/or resizing it such that all points are located on or within its bounds. + * @param target The Rectangle which should be merged. + * @param points An array of Points (or any object with public `x` and `y` properties) which should be merged with the Rectangle. */ - destroy(): void; - - } + static MergePoints(target: O, points: Phaser.Geom.Point[]): O; - /** - * The Input Plugin belongs to a Scene and handles all input related events and operations for it. - * - * You can access it from within a Scene using `this.input`. - * - * It emits events directly. For example, you can do: - * - * ```javascript - * this.input.on('pointerdown', callback, context); - * ``` - * - * To listen for a pointer down event anywhere on the game canvas. - * - * Game Objects can be enabled for input by calling their `setInteractive` method. After which they - * will directly emit input events: - * - * ```javascript - * var sprite = this.add.sprite(x, y, texture); - * sprite.setInteractive(); - * sprite.on('pointerdown', callback, context); - * ``` - * - * There are lots of game configuration options available relating to input. - * See the [Input Config object]{@linkcode Phaser.Types.Core.InputConfig} for more details, including how to deal with Phaser - * listening for input events outside of the canvas, how to set a default number of pointers, input - * capture settings and more. - * - * Please also see the Input examples and tutorials for further information. - */ - class InputPlugin extends Phaser.Events.EventEmitter { /** - * - * @param scene A reference to the Scene that this Input Plugin is responsible for. + * Merges the source rectangle into the target rectangle and returns the target. + * Neither rectangle should have a negative width or height. + * @param target Target rectangle. Will be modified to include source rectangle. + * @param source Rectangle that will be merged into target rectangle. */ - constructor(scene: Phaser.Scene); + static MergeRect(target: O, source: Phaser.Geom.Rectangle): O; /** - * An instance of the Gamepad Plugin class, if enabled via the `input.gamepad` Scene or Game Config property. - * Use this to create access Gamepads connected to the browser and respond to gamepad buttons. + * Merges a Rectangle with a point by repositioning and/or resizing it so that the point is on or within its bounds. + * @param target The Rectangle which should be merged and modified. + * @param x The X coordinate of the point which should be merged. + * @param y The Y coordinate of the point which should be merged. */ - gamepad: Phaser.Input.Gamepad.GamepadPlugin; + static MergeXY(target: O, x: number, y: number): O; /** - * A reference to the Scene that this Input Plugin is responsible for. + * Nudges (translates) the top left corner of a Rectangle by a given offset. + * @param rect The Rectangle to adjust. + * @param x The distance to move the Rectangle horizontally. + * @param y The distance to move the Rectangle vertically. */ - scene: Phaser.Scene; + static Offset(rect: O, x: number, y: number): O; /** - * A reference to the Scene Systems class. + * Nudges (translates) the top-left corner of a Rectangle by the coordinates of a point (translation vector). + * @param rect The Rectangle to adjust. + * @param point The point whose coordinates should be used as an offset. */ - systems: Phaser.Scenes.Systems; + static OffsetPoint(rect: O, point: Phaser.Geom.Point | Phaser.Math.Vector2): O; /** - * A reference to the Scene Systems Settings. + * Checks if two Rectangles overlap. If a Rectangle is within another Rectangle, the two will be considered overlapping. Thus, the Rectangles are treated as "solid". + * @param rectA The first Rectangle to check. + * @param rectB The second Rectangle to check. */ - settings: Phaser.Types.Scenes.SettingsObject; + static Overlaps(rectA: Phaser.Geom.Rectangle, rectB: Phaser.Geom.Rectangle): boolean; /** - * A reference to the Game Input Manager. + * Calculates the perimeter of a Rectangle. + * @param rect The Rectangle to use. */ - manager: Phaser.Input.InputManager; + static Perimeter(rect: Phaser.Geom.Rectangle): number; /** - * If `true` this Input Plugin will process DOM input events. + * Returns a Point from the perimeter of a Rectangle based on the given angle. + * @param rectangle The Rectangle to get the perimeter point from. + * @param angle The angle of the point, in degrees. + * @param out The Point object to store the position in. If not given, a new Point instance is created. */ - enabled: boolean; + static PerimeterPoint(rectangle: Phaser.Geom.Rectangle, angle: number, out?: O): O; /** - * A reference to the Scene Display List. This property is set during the `boot` method. + * Returns a random point within a Rectangle. + * @param rect The Rectangle to return a point from. + * @param out The object to update with the point's coordinates. */ - displayList: Phaser.GameObjects.DisplayList; + static Random(rect: Phaser.Geom.Rectangle, out: O): O; /** - * A reference to the Scene Cameras Manager. This property is set during the `boot` method. + * Calculates a random point that lies within the `outer` Rectangle, but outside of the `inner` Rectangle. + * The inner Rectangle must be fully contained within the outer rectangle. + * @param outer The outer Rectangle to get the random point within. + * @param inner The inner Rectangle to exclude from the returned point. + * @param out A Point, or Point-like object to store the result in. If not specified, a new Point will be created. */ - cameras: Phaser.Cameras.Scene2D.CameraManager; + static RandomOutside(outer: Phaser.Geom.Rectangle, inner: Phaser.Geom.Rectangle, out?: O): O; /** - * A reference to the Mouse Manager. - * - * This property is only set if Mouse support has been enabled in your Game Configuration file. - * - * If you just wish to get access to the mouse pointer, use the `mousePointer` property instead. + * The geometry constant type of this object: `GEOM_CONST.RECTANGLE`. + * Used for fast type comparisons. */ - mouse: Phaser.Input.Mouse.MouseManager; + readonly type: number; /** - * When set to `true` (the default) the Input Plugin will emulate DOM behavior by only emitting events from - * the top-most Game Objects in the Display List. - * - * If set to `false` it will emit events from all Game Objects below a Pointer, not just the top one. + * The X coordinate of the top left corner of the Rectangle. */ - topOnly: boolean; + x: number; /** - * How often should the Pointers be checked? - * - * The value is a time, given in ms, and is the time that must have elapsed between game steps before - * the Pointers will be polled again. When a pointer is polled it runs a hit test to see which Game - * Objects are currently below it, or being interacted with it. - * - * Pointers will *always* be checked if they have been moved by the user, or press or released. - * - * This property only controls how often they will be polled if they have not been updated. - * You should set this if you want to have Game Objects constantly check against the pointers, even - * if the pointer didn't itself move. - * - * Set to 0 to poll constantly. Set to -1 to only poll on user movement. + * The Y coordinate of the top left corner of the Rectangle. */ - pollRate: integer; + y: number; /** - * The distance, in pixels, a pointer has to move while being held down, before it thinks it is being dragged. + * The width of the Rectangle, i.e. the distance between its left side (defined by `x`) and its right side. */ - dragDistanceThreshold: number; + width: number; /** - * The amount of time, in ms, a pointer has to be held down before it thinks it is dragging. - * - * The default polling rate is to poll only on move so once the time threshold is reached the - * drag event will not start until you move the mouse. If you want it to start immediately - * when the time threshold is reached, you must increase the polling rate by calling - * [setPollAlways]{@linkcode Phaser.Input.InputPlugin#setPollAlways} or - * [setPollRate]{@linkcode Phaser.Input.InputPlugin#setPollRate}. + * The height of the Rectangle, i.e. the distance between its top side (defined by `y`) and its bottom side. */ - dragTimeThreshold: number; + height: number; /** - * Checks to see if both this plugin and the Scene to which it belongs is active. + * Checks if the given point is inside the Rectangle's bounds. + * @param x The X coordinate of the point to check. + * @param y The Y coordinate of the point to check. */ - isActive(): boolean; + contains(x: number, y: number): boolean; /** - * This is called automatically by the Input Manager. - * It emits events for plugins to listen to and also handles polling updates, if enabled. - * @param time The current time. Either a High Resolution Timer value if it comes from Request Animation Frame, or Date.now if using SetTimeout. - * @param delta The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate. + * Calculates the coordinates of a point at a certain `position` on the Rectangle's perimeter. + * + * The `position` is a fraction between 0 and 1 which defines how far into the perimeter the point is. + * + * A value of 0 or 1 returns the point at the top left corner of the rectangle, while a value of 0.5 returns the point at the bottom right corner of the rectangle. Values between 0 and 0.5 are on the top or the right side and values between 0.5 and 1 are on the bottom or the left side. + * @param position The normalized distance into the Rectangle's perimeter to return. + * @param output An object to update with the `x` and `y` coordinates of the point. */ - updatePoll(time: number, delta: number): boolean; + getPoint(position: number, output?: O): O; /** - * Clears a Game Object so it no longer has an Interactive Object associated with it. - * The Game Object is then queued for removal from the Input Plugin on the next update. - * @param gameObject The Game Object that will have its Interactive Object removed. - * @param skipQueue Skip adding this Game Object into the removal queue? Default false. + * Returns an array of points from the perimeter of the Rectangle, each spaced out based on the quantity or step required. + * @param quantity The number of points to return. Set to `false` or 0 to return an arbitrary number of points (`perimeter / stepRate`) evenly spaced around the Rectangle based on the `stepRate`. + * @param stepRate If `quantity` is 0, determines the normalized distance between each returned point. + * @param output An array to which to append the points. */ - clear(gameObject: Phaser.GameObjects.GameObject, skipQueue?: boolean): Phaser.GameObjects.GameObject; + getPoints(quantity: number, stepRate?: number, output?: O): O; /** - * Disables Input on a single Game Object. - * - * An input disabled Game Object still retains its Interactive Object component and can be re-enabled - * at any time, by passing it to `InputPlugin.enable`. - * @param gameObject The Game Object to have its input system disabled. + * Returns a random point within the Rectangle's bounds. + * @param point The object in which to store the `x` and `y` coordinates of the point. */ - disable(gameObject: Phaser.GameObjects.GameObject): void; + getRandomPoint(point?: O): O; /** - * Enable a Game Object for interaction. - * - * If the Game Object already has an Interactive Object component, it is enabled and returned. - * - * Otherwise, a new Interactive Object component is created and assigned to the Game Object's `input` property. - * - * Input works by using hit areas, these are nearly always geometric shapes, such as rectangles or circles, that act as the hit area - * for the Game Object. However, you can provide your own hit area shape and callback, should you wish to handle some more advanced - * input detection. - * - * If no arguments are provided it will try and create a rectangle hit area based on the texture frame the Game Object is using. If - * this isn't a texture-bound object, such as a Graphics or BitmapText object, this will fail, and you'll need to provide a specific - * shape for it to use. - * - * You can also provide an Input Configuration Object as the only argument to this method. - * @param gameObject The Game Object to be enabled for input. - * @param shape 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. - * @param callback The 'contains' function to invoke to check if the pointer is within the hit area. - * @param dropZone Is this Game Object a drop zone or not? Default false. + * Sets the position, width, and height of the Rectangle. + * @param x The X coordinate of the top left corner of the Rectangle. + * @param y The Y coordinate of the top left corner of the Rectangle. + * @param width The width of the Rectangle. + * @param height The height of the Rectangle. */ - enable(gameObject: Phaser.GameObjects.GameObject, shape?: Phaser.Types.Input.InputConfiguration | any, callback?: Phaser.Types.Input.HitAreaCallback, dropZone?: boolean): Phaser.Input.InputPlugin; + setTo(x: number, y: number, width: number, height: number): this; /** - * Takes the given Pointer and performs a hit test against it, to see which interactive Game Objects - * it is currently above. - * - * The hit test is performed against which-ever Camera the Pointer is over. If it is over multiple - * cameras, it starts checking the camera at the top of the camera list, and if nothing is found, iterates down the list. - * @param pointer The Pointer to check against the Game Objects. + * Resets the position, width, and height of the Rectangle to 0. */ - hitTestPointer(pointer: Phaser.Input.Pointer): Phaser.GameObjects.GameObject[]; + setEmpty(): this; /** - * Returns the drag state of the given Pointer for this Input Plugin. - * - * The state will be one of the following: - * - * 0 = Not dragging anything - * 1 = Primary button down and objects below, so collect a draglist - * 2 = Pointer being checked if meets drag criteria - * 3 = Pointer meets criteria, notify the draglist - * 4 = Pointer actively dragging the draglist and has moved - * 5 = Pointer actively dragging but has been released, notify draglist - * @param pointer The Pointer to get the drag state for. + * Sets the position of the Rectangle. + * @param x The X coordinate of the top left corner of the Rectangle. + * @param y The Y coordinate of the top left corner of the Rectangle. Default x. */ - getDragState(pointer: Phaser.Input.Pointer): integer; + setPosition(x: number, y?: number): this; /** - * Sets the drag state of the given Pointer for this Input Plugin. - * - * The state must be one of the following values: - * - * 0 = Not dragging anything - * 1 = Primary button down and objects below, so collect a draglist - * 2 = Pointer being checked if meets drag criteria - * 3 = Pointer meets criteria, notify the draglist - * 4 = Pointer actively dragging the draglist and has moved - * 5 = Pointer actively dragging but has been released, notify draglist - * @param pointer The Pointer to set the drag state for. - * @param state The drag state value. An integer between 0 and 5. + * Sets the width and height of the Rectangle. + * @param width The width to set the Rectangle to. + * @param height The height to set the Rectangle to. Default width. */ - setDragState(pointer: Phaser.Input.Pointer, state: integer): void; + setSize(width: number, height?: number): this; /** - * Sets the draggable state of the given array of Game Objects. - * - * They can either be set to be draggable, or can have their draggable state removed by passing `false`. - * - * A Game Object will not fire drag events unless it has been specifically enabled for drag. - * @param gameObjects An array of Game Objects to change the draggable state on. - * @param value Set to `true` if the Game Objects should be made draggable, `false` if they should be unset. Default true. + * Determines if the Rectangle is empty. A Rectangle is empty if its width or height is less than or equal to 0. */ - setDraggable(gameObjects: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[], value?: boolean): Phaser.Input.InputPlugin; + isEmpty(): boolean; /** - * Creates a function that can be passed to `setInteractive`, `enable` or `setHitArea` that will handle - * pixel-perfect input detection on an Image or Sprite based Game Object, or any custom class that extends them. - * - * The following will create a sprite that is clickable on any pixel that has an alpha value >= 1. - * - * ```javascript - * this.add.sprite(x, y, key).setInteractive(this.input.makePixelPerfect()); - * ``` - * - * The following will create a sprite that is clickable on any pixel that has an alpha value >= 150. - * - * ```javascript - * this.add.sprite(x, y, key).setInteractive(this.input.makePixelPerfect(150)); - * ``` - * - * Once you have made an Interactive Object pixel perfect it impacts all input related events for it: down, up, - * dragstart, drag, etc. - * - * As a pointer interacts with the Game Object it will constantly poll the texture, extracting a single pixel from - * the given coordinates and checking its color values. This is an expensive process, so should only be enabled on - * Game Objects that really need it. - * - * You cannot make non-texture based Game Objects pixel perfect. So this will not work on Graphics, BitmapText, - * Render Textures, Text, Tilemaps, Containers or Particles. - * @param alphaTolerance The alpha level that the pixel should be above to be included as a successful interaction. Default 1. + * Returns a Line object that corresponds to the top of this Rectangle. + * @param line A Line object to set the results in. If `undefined` a new Line will be created. */ - makePixelPerfect(alphaTolerance?: integer): Function; + getLineA(line?: O): O; /** - * Sets the hit area for the given array of Game Objects. - * - * A hit area is typically one of the geometric shapes Phaser provides, such as a `Phaser.Geom.Rectangle` - * or `Phaser.Geom.Circle`. However, it can be any object as long as it works with the provided callback. - * - * If no hit area is provided a Rectangle is created based on the size of the Game Object, if possible - * to calculate. - * - * The hit area callback is the function that takes an `x` and `y` coordinate and returns a boolean if - * those values fall within the area of the shape or not. All of the Phaser geometry objects provide this, - * such as `Phaser.Geom.Rectangle.Contains`. - * @param gameObjects An array of Game Objects to set the hit area on. - * @param shape 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. - * @param callback The 'contains' function to invoke to check if the pointer is within the hit area. + * Returns a Line object that corresponds to the right of this Rectangle. + * @param line A Line object to set the results in. If `undefined` a new Line will be created. */ - setHitArea(gameObjects: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[], shape?: Phaser.Types.Input.InputConfiguration | any, callback?: Phaser.Types.Input.HitAreaCallback): Phaser.Input.InputPlugin; + getLineB(line?: O): O; /** - * Sets the hit area for an array of Game Objects to be a `Phaser.Geom.Circle` shape, using - * the given coordinates and radius to control its position and size. - * @param gameObjects An array of Game Objects to set as having a circle hit area. - * @param x The center of the circle. - * @param y The center of the circle. - * @param radius The radius of the circle. - * @param callback The hit area callback. If undefined it uses Circle.Contains. + * Returns a Line object that corresponds to the bottom of this Rectangle. + * @param line A Line object to set the results in. If `undefined` a new Line will be created. */ - setHitAreaCircle(gameObjects: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[], x: number, y: number, radius: number, callback?: Phaser.Types.Input.HitAreaCallback): Phaser.Input.InputPlugin; + getLineC(line?: O): O; /** - * Sets the hit area for an array of Game Objects to be a `Phaser.Geom.Ellipse` shape, using - * the given coordinates and dimensions to control its position and size. - * @param gameObjects An array of Game Objects to set as having an ellipse hit area. - * @param x The center of the ellipse. - * @param y The center of the ellipse. - * @param width The width of the ellipse. - * @param height The height of the ellipse. - * @param callback The hit area callback. If undefined it uses Ellipse.Contains. + * Returns a Line object that corresponds to the left of this Rectangle. + * @param line A Line object to set the results in. If `undefined` a new Line will be created. */ - setHitAreaEllipse(gameObjects: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[], x: number, y: number, width: number, height: number, callback?: Phaser.Types.Input.HitAreaCallback): Phaser.Input.InputPlugin; + getLineD(line?: O): O; /** - * Sets the hit area for an array of Game Objects to be a `Phaser.Geom.Rectangle` shape, using - * the Game Objects texture frame to define the position and size of the hit area. - * @param gameObjects An array of Game Objects to set as having an ellipse hit area. - * @param callback The hit area callback. If undefined it uses Rectangle.Contains. + * The x coordinate of the left of the Rectangle. + * Changing the left property of a Rectangle object has no effect on the y and height properties. However it does affect the width property, whereas changing the x value does not affect the width property. */ - setHitAreaFromTexture(gameObjects: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[], callback?: Phaser.Types.Input.HitAreaCallback): Phaser.Input.InputPlugin; + left: number; /** - * Sets the hit area for an array of Game Objects to be a `Phaser.Geom.Rectangle` shape, using - * the given coordinates and dimensions to control its position and size. - * @param gameObjects An array of Game Objects to set as having a rectangular hit area. - * @param x The top-left of the rectangle. - * @param y The top-left of the rectangle. - * @param width The width of the rectangle. - * @param height The height of the rectangle. - * @param callback The hit area callback. If undefined it uses Rectangle.Contains. + * The sum of the x and width properties. + * Changing the right property of a Rectangle object has no effect on the x, y and height properties, however it does affect the width property. */ - setHitAreaRectangle(gameObjects: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[], x: number, y: number, width: number, height: number, callback?: Phaser.Types.Input.HitAreaCallback): Phaser.Input.InputPlugin; + right: number; /** - * Sets the hit area for an array of Game Objects to be a `Phaser.Geom.Triangle` shape, using - * the given coordinates to control the position of its points. - * @param gameObjects An array of Game Objects to set as having a triangular hit area. - * @param x1 The x coordinate of the first point of the triangle. - * @param y1 The y coordinate of the first point of the triangle. - * @param x2 The x coordinate of the second point of the triangle. - * @param y2 The y coordinate of the second point of the triangle. - * @param x3 The x coordinate of the third point of the triangle. - * @param y3 The y coordinate of the third point of the triangle. - * @param callback The hit area callback. If undefined it uses Triangle.Contains. + * The y coordinate of the top of the Rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties. + * However it does affect the height property, whereas changing the y value does not affect the height property. */ - setHitAreaTriangle(gameObjects: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[], x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, callback?: Phaser.Types.Input.HitAreaCallback): Phaser.Input.InputPlugin; + top: number; /** - * Creates an Input Debug Shape for the given Game Object. - * - * The Game Object must have _already_ been enabled for input prior to calling this method. - * - * This is intended to assist you during development and debugging. - * - * Debug Shapes can only be created for Game Objects that are using standard Phaser Geometry for input, - * including: Circle, Ellipse, Line, Polygon, Rectangle and Triangle. - * - * Game Objects that are using their automatic hit areas are using Rectangles by default, so will also work. - * - * The Debug Shape is created and added to the display list and is then kept in sync with the Game Object - * it is connected with. Should you need to modify it yourself, such as to hide it, you can access it via - * the Game Object property: `GameObject.input.hitAreaDebug`. - * - * Calling this method on a Game Object that already has a Debug Shape will first destroy the old shape, - * before creating a new one. If you wish to remove the Debug Shape entirely, you should call the - * method `InputPlugin.removeDebug`. - * - * Note that the debug shape will only show the outline of the input area. If the input test is using a - * pixel perfect check, for example, then this is not displayed. If you are using a custom shape, that - * doesn't extend one of the base Phaser Geometry objects, as your hit area, then this method will not - * work. - * @param gameObject The Game Object to create the input debug shape for. - * @param color The outline color of the debug shape. Default 0x00ff00. + * The sum of the y and height properties. + * Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property. */ - enableDebug(gameObject: Phaser.GameObjects.GameObject, color?: number): Phaser.Input.InputPlugin; + bottom: number; /** - * Removes an Input Debug Shape from the given Game Object. - * - * The shape is destroyed immediately and the `hitAreaDebug` property is set to `null`. - * @param gameObject The Game Object to remove the input debug shape from. + * The x coordinate of the center of the Rectangle. */ - removeDebug(gameObject: Phaser.GameObjects.GameObject): Phaser.Input.InputPlugin; + centerX: number; /** - * Sets the Pointers to always poll. - * - * When a pointer is polled it runs a hit test to see which Game Objects are currently below it, - * or being interacted with it, regardless if the Pointer has actually moved or not. - * - * You should enable this if you want objects in your game to fire over / out events, and the objects - * are constantly moving, but the pointer may not have. Polling every frame has additional computation - * costs, especially if there are a large number of interactive objects in your game. + * The y coordinate of the center of the Rectangle. */ - setPollAlways(): Phaser.Input.InputPlugin; + centerY: number; /** - * Sets the Pointers to only poll when they are moved or updated. - * - * When a pointer is polled it runs a hit test to see which Game Objects are currently below it, - * or being interacted with it. + * Determines if the two objects (either Rectangles or Rectangle-like) have the same width and height values under strict equality. + * @param rect The first Rectangle object. + * @param toCompare The second Rectangle object. */ - setPollOnMove(): Phaser.Input.InputPlugin; + static SameDimensions(rect: Phaser.Geom.Rectangle, toCompare: Phaser.Geom.Rectangle): boolean; /** - * Sets the poll rate value. This is the amount of time that should have elapsed before a pointer - * will be polled again. See the `setPollAlways` and `setPollOnMove` methods. - * @param value The amount of time, in ms, that should elapsed before re-polling the pointers. + * Scales the width and height of this Rectangle by the given amounts. + * @param rect The `Rectangle` object that will be scaled by the specified amount(s). + * @param x The factor by which to scale the rectangle horizontally. + * @param y The amount by which to scale the rectangle vertically. If this is not specified, the rectangle will be scaled by the factor `x` in both directions. */ - setPollRate(value: number): Phaser.Input.InputPlugin; + static Scale(rect: O, x: number, y: number): O; /** - * When set to `true` the global Input Manager will emulate DOM behavior by only emitting events from - * the top-most Scene in the Scene List. By default, if a Scene receives an input event it will then stop the event - * from flowing down to any Scenes below it in the Scene list. To disable this behavior call this method with `false`. - * @param value Set to `true` to stop processing input events on the Scene that receives it, or `false` to let the event continue down the Scene list. + * Creates a new Rectangle or repositions and/or resizes an existing Rectangle so that it encompasses the two given Rectangles, i.e. calculates their union. + * @param rectA The first Rectangle to use. + * @param rectB The second Rectangle to use. + * @param out The Rectangle to store the union in. */ - setGlobalTopOnly(value: boolean): Phaser.Input.InputPlugin; + static Union(rectA: Phaser.Geom.Rectangle, rectB: Phaser.Geom.Rectangle, out?: O): O; + } + + /** + * A triangle is a plane created by connecting three points. + * The first two arguments specify the first point, the middle two arguments + * specify the second point, and the last two arguments specify the third point. + */ + class Triangle { /** - * When set to `true` this Input Plugin will emulate DOM behavior by only emitting events from - * the top-most Game Objects in the Display List. * - * If set to `false` it will emit events from all Game Objects below a Pointer, not just the top one. - * @param value `true` to only include the top-most Game Object, or `false` to include all Game Objects in a hit test. + * @param x1 `x` coordinate of the first point. Default 0. + * @param y1 `y` coordinate of the first point. Default 0. + * @param x2 `x` coordinate of the second point. Default 0. + * @param y2 `y` coordinate of the second point. Default 0. + * @param x3 `x` coordinate of the third point. Default 0. + * @param y3 `y` coordinate of the third point. Default 0. */ - setTopOnly(value: boolean): Phaser.Input.InputPlugin; + constructor(x1?: number, y1?: number, x2?: number, y2?: number, x3?: number, y3?: number); /** - * Given an array of Game Objects, sort the array and return it, so that the objects are in depth index order - * with the lowest at the bottom. - * @param gameObjects An array of Game Objects to be sorted. + * Returns the area of a Triangle. + * @param triangle The Triangle to use. */ - sortGameObjects(gameObjects: Phaser.GameObjects.GameObject[]): Phaser.GameObjects.GameObject[]; + static Area(triangle: Phaser.Geom.Triangle): number; /** - * This method should be called from within an input event handler, such as `pointerdown`. - * - * When called, it stops the Input Manager from allowing _this specific event_ to be processed by any other Scene - * not yet handled in the scene list. + * Builds an equilateral triangle. In the equilateral triangle, all the sides are the same length (congruent) and all the angles are the same size (congruent). + * The x/y specifies the top-middle of the triangle (x1/y1) and length is the length of each side. + * @param x x coordinate of the top point of the triangle. + * @param y y coordinate of the top point of the triangle. + * @param length Length of each side of the triangle. */ - stopPropagation(): Phaser.Input.InputPlugin; + static BuildEquilateral(x: number, y: number, length: number): Phaser.Geom.Triangle; /** - * Adds new Pointer objects to the Input Manager. - * - * By default Phaser creates 2 pointer objects: `mousePointer` and `pointer1`. - * - * You can create more either by calling this method, or by setting the `input.activePointers` property - * in the Game Config, up to a maximum of 10 pointers. - * - * The first 10 pointers are available via the `InputPlugin.pointerX` properties, once they have been added - * via this method. - * @param quantity The number of new Pointers to create. A maximum of 10 is allowed in total. Default 1. + * Takes an array of vertex coordinates, and optionally an array of hole indices, then returns an array + * of Triangle instances, where the given vertices have been decomposed into a series of triangles. + * @param data A flat array of vertex coordinates like [x0,y0, x1,y1, x2,y2, ...] + * @param holes An array of hole indices if any (e.g. [5, 8] for a 12-vertex input would mean one hole with vertices 5–7 and another with 8–11). Default null. + * @param scaleX Horizontal scale factor to multiply the resulting points by. Default 1. + * @param scaleY Vertical scale factor to multiply the resulting points by. Default 1. + * @param out An array to store the resulting Triangle instances in. If not provided, a new array is created. */ - addPointer(quantity?: integer): Phaser.Input.Pointer[]; + static BuildFromPolygon(data: any[], holes?: any[], scaleX?: number, scaleY?: number, out?: O): O; /** - * Tells the Input system to set a custom cursor. - * - * This cursor will be the default cursor used when interacting with the game canvas. - * - * If an Interactive Object also sets a custom cursor, this is the cursor that is reset after its use. - * - * Any valid CSS cursor value is allowed, including paths to image files, i.e.: - * - * ```javascript - * this.input.setDefaultCursor('url(assets/cursors/sword.cur), pointer'); - * ``` - * - * Please read about the differences between browsers when it comes to the file formats and sizes they support: - * - * https://developer.mozilla.org/en-US/docs/Web/CSS/cursor - * https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_User_Interface/Using_URL_values_for_the_cursor_property - * - * It's up to you to pick a suitable cursor format that works across the range of browsers you need to support. - * @param cursor The CSS to be used when setting the default cursor. + * Builds a right triangle, i.e. one which has a 90-degree angle and two acute angles. + * @param x The X coordinate of the right angle, which will also be the first X coordinate of the constructed Triangle. + * @param y The Y coordinate of the right angle, which will also be the first Y coordinate of the constructed Triangle. + * @param width The length of the side which is to the left or to the right of the right angle. + * @param height The length of the side which is above or below the right angle. */ - setDefaultCursor(cursor: string): Phaser.Input.InputPlugin; + static BuildRight(x: number, y: number, width: number, height: number): Phaser.Geom.Triangle; /** - * The x coordinates of the ActivePointer based on the first camera in the camera list. - * This is only safe to use if your game has just 1 non-transformed camera and doesn't use multi-touch. + * Positions the Triangle so that it is centered on the given coordinates. + * @param triangle The triangle to be positioned. + * @param x The horizontal coordinate to center on. + * @param y The vertical coordinate to center on. + * @param centerFunc The function used to center the triangle. Defaults to Centroid centering. */ - readonly x: number; + static CenterOn(triangle: O, x: number, y: number, centerFunc?: CenterFunction): O; /** - * The y coordinates of the ActivePointer based on the first camera in the camera list. - * This is only safe to use if your game has just 1 non-transformed camera and doesn't use multi-touch. + * Calculates the position of a Triangle's centroid, which is also its center of mass (center of gravity). + * + * The centroid is the point in a Triangle at which its three medians (the lines drawn from the vertices to the bisectors of the opposite sides) meet. It divides each one in a 2:1 ratio. + * @param triangle The Triangle to use. + * @param out An object to store the coordinates in. */ - readonly y: number; + static Centroid(triangle: Phaser.Geom.Triangle, out?: O): O; /** - * Are any mouse or touch pointers currently over the game canvas? + * Computes the circumcentre of a triangle. The circumcentre is the centre of + * the circumcircle, the smallest circle which encloses the triangle. It is also + * the common intersection point of the perpendicular bisectors of the sides of + * the triangle, and is the only point which has equal distance to all three + * vertices of the triangle. + * @param triangle The Triangle to get the circumcenter of. + * @param out The Vector2 object to store the position in. If not given, a new Vector2 instance is created. */ - readonly isOver: boolean; + static CircumCenter(triangle: Phaser.Geom.Triangle, out?: O): O; /** - * The mouse has its own unique Pointer object, which you can reference directly if making a _desktop specific game_. - * If you are supporting both desktop and touch devices then do not use this property, instead use `activePointer` - * which will always map to the most recently interacted pointer. + * Finds the circumscribed circle (circumcircle) of a Triangle object. The circumcircle is the circle which touches all of the triangle's vertices. + * @param triangle The Triangle to use as input. + * @param out An optional Circle to store the result in. */ - readonly mousePointer: Phaser.Input.Pointer; + static CircumCircle(triangle: Phaser.Geom.Triangle, out?: O): O; /** - * The current active input Pointer. + * Clones a Triangle object. + * @param source The Triangle to clone. */ - readonly activePointer: Phaser.Input.Pointer; + static Clone(source: Phaser.Geom.Triangle): Phaser.Geom.Triangle; /** - * A touch-based Pointer object. - * This will be `undefined` by default unless you add a new Pointer using `addPointer`. + * Checks if a point (as a pair of coordinates) is inside a Triangle's bounds. + * @param triangle The Triangle to check. + * @param x The X coordinate of the point to check. + * @param y The Y coordinate of the point to check. */ - readonly pointer1: Phaser.Input.Pointer; + static Contains(triangle: Phaser.Geom.Triangle, x: number, y: number): boolean; /** - * A touch-based Pointer object. - * This will be `undefined` by default unless you add a new Pointer using `addPointer`. + * Filters an array of point-like objects to only those contained within a triangle. + * If `returnFirst` is true, will return an array containing only the first point in the provided array that is within the triangle (or an empty array if there are no such points). + * @param triangle The triangle that the points are being checked in. + * @param points An array of point-like objects (objects that have an `x` and `y` property) + * @param returnFirst If `true`, return an array containing only the first point found that is within the triangle. Default false. + * @param out If provided, the points that are within the triangle will be appended to this array instead of being added to a new array. If `returnFirst` is true, only the first point found within the triangle will be appended. This array will also be returned by this function. */ - readonly pointer2: Phaser.Input.Pointer; + static ContainsArray(triangle: Phaser.Geom.Triangle, points: Phaser.Geom.Point[], returnFirst?: boolean, out?: any[]): Phaser.Geom.Point[]; /** - * A touch-based Pointer object. - * This will be `undefined` by default unless you add a new Pointer using `addPointer`. + * Tests if a triangle contains a point. + * @param triangle The triangle. + * @param point The point to test, or any point-like object with public `x` and `y` properties. */ - readonly pointer3: Phaser.Input.Pointer; + static ContainsPoint(triangle: Phaser.Geom.Triangle, point: Phaser.Geom.Point | Phaser.Math.Vector2 | any): boolean; /** - * A touch-based Pointer object. - * This will be `undefined` by default unless you add a new Pointer using `addPointer`. + * Copy the values of one Triangle to a destination Triangle. + * @param source The source Triangle to copy the values from. + * @param dest The destination Triangle to copy the values to. */ - readonly pointer4: Phaser.Input.Pointer; + static CopyFrom(source: Phaser.Geom.Triangle, dest: O): O; /** - * A touch-based Pointer object. - * This will be `undefined` by default unless you add a new Pointer using `addPointer`. + * Decomposes a Triangle into an array of its points. + * @param triangle The Triangle to decompose. + * @param out An array to store the points into. */ - readonly pointer5: Phaser.Input.Pointer; + static Decompose(triangle: Phaser.Geom.Triangle, out?: any[]): any[]; /** - * A touch-based Pointer object. - * This will be `undefined` by default unless you add a new Pointer using `addPointer`. + * Returns true if two triangles have the same coordinates. + * @param triangle The first triangle to check. + * @param toCompare The second triangle to check. */ - readonly pointer6: Phaser.Input.Pointer; + static Equals(triangle: Phaser.Geom.Triangle, toCompare: Phaser.Geom.Triangle): boolean; /** - * A touch-based Pointer object. - * This will be `undefined` by default unless you add a new Pointer using `addPointer`. + * Returns a Point from around the perimeter of a Triangle. + * @param triangle The Triangle to get the point on its perimeter from. + * @param position The position along the perimeter of the triangle. A value between 0 and 1. + * @param out An option Point, or Point-like object to store the value in. If not given a new Point will be created. */ - readonly pointer7: Phaser.Input.Pointer; + static GetPoint(triangle: Phaser.Geom.Triangle, position: number, out?: O): O; /** - * A touch-based Pointer object. - * This will be `undefined` by default unless you add a new Pointer using `addPointer`. + * Returns an array of evenly spaced points on the perimeter of a Triangle. + * @param triangle The Triangle to get the points from. + * @param quantity The number of evenly spaced points to return. Set to 0 to return an arbitrary number of points based on the `stepRate`. + * @param stepRate If `quantity` is 0, the distance between each returned point. + * @param out An array to which the points should be appended. */ - readonly pointer8: Phaser.Input.Pointer; + static GetPoints(triangle: Phaser.Geom.Triangle, quantity: number, stepRate: number, out?: O): O; /** - * A touch-based Pointer object. - * This will be `undefined` by default unless you add a new Pointer using `addPointer`. + * Calculates the position of the incenter of a Triangle object. This is the point where its three angle bisectors meet and it's also the center of the incircle, which is the circle inscribed in the triangle. + * @param triangle The Triangle to find the incenter of. + * @param out An optional Point in which to store the coordinates. */ - readonly pointer9: Phaser.Input.Pointer; + static InCenter(triangle: Phaser.Geom.Triangle, out?: O): O; /** - * A touch-based Pointer object. - * This will be `undefined` by default unless you add a new Pointer using `addPointer`. + * Moves each point (vertex) of a Triangle by a given offset, thus moving the entire Triangle by that offset. + * @param triangle The Triangle to move. + * @param x The horizontal offset (distance) by which to move each point. Can be positive or negative. + * @param y The vertical offset (distance) by which to move each point. Can be positive or negative. */ - readonly pointer10: Phaser.Input.Pointer; + static Offset(triangle: O, x: number, y: number): O; /** - * An instance of the Keyboard Plugin class, if enabled via the `input.keyboard` Scene or Game Config property. - * Use this to create Key objects and listen for keyboard specific events. + * Gets the length of the perimeter of the given triangle. + * Calculated by adding together the length of each of the three sides. + * @param triangle The Triangle to get the length from. */ - keyboard: Phaser.Input.Keyboard.KeyboardPlugin; + static Perimeter(triangle: Phaser.Geom.Triangle): number; - } + /** + * Returns a random Point from within the area of the given Triangle. + * @param triangle The Triangle to get a random point from. + * @param out The Point object to store the position in. If not given, a new Point instance is created. + */ + static Random(triangle: Phaser.Geom.Triangle, out?: O): O; - namespace InputPluginCache { /** - * Static method called directly by the Core internal Plugins. - * Key is a reference used to get the plugin from the plugins object (i.e. InputPlugin) - * Plugin is the object to instantiate to create the plugin - * Mapping is what the plugin is injected into the Scene.Systems as (i.e. input) - * @param key A reference used to get this plugin from the plugin cache. - * @param plugin The plugin to be stored. Should be the core object, not instantiated. - * @param mapping If this plugin is to be injected into the Input Plugin, this is the property key used. - * @param settingsKey The key in the Scene Settings to check to see if this plugin should install or not. - * @param configKey The key in the Game Config to check to see if this plugin should install or not. + * Rotates a Triangle about its incenter, which is the point at which its three angle bisectors meet. + * @param triangle The Triangle to rotate. + * @param angle The angle by which to rotate the Triangle, in radians. */ - function register(key: string, plugin: Function, mapping: string, settingsKey: string, configKey: string): void; + static Rotate(triangle: O, angle: number): O; /** - * Returns the input plugin object from the cache based on the given key. - * @param key The key of the input plugin to get. + * Rotates a Triangle at a certain angle about a given Point or object with public `x` and `y` properties. + * @param triangle The Triangle to rotate. + * @param point The Point to rotate the Triangle about. + * @param angle The angle by which to rotate the Triangle, in radians. */ - function getCore(key: string): Phaser.Types.Input.InputPluginContainer; + static RotateAroundPoint(triangle: O, point: Phaser.Geom.Point, angle: number): O; /** - * Installs all of the registered Input Plugins into the given target. - * @param target The target InputPlugin to install the plugins into. + * Rotates an entire Triangle at a given angle about a specific point. + * @param triangle The Triangle to rotate. + * @param x The X coordinate of the point to rotate the Triangle about. + * @param y The Y coordinate of the point to rotate the Triangle about. + * @param angle The angle by which to rotate the Triangle, in radians. */ - function install(target: Phaser.Input.InputPlugin): void; + static RotateAroundXY(triangle: O, x: number, y: number, angle: number): O; /** - * Removes an input plugin based on the given key. - * @param key The key of the input plugin to remove. + * The geometry constant type of this object: `GEOM_CONST.TRIANGLE`. + * Used for fast type comparisons. */ - function remove(key: string): void; + readonly type: number; - } + /** + * `x` coordinate of the first point. + */ + x1: number; - namespace Keyboard { /** - * A KeyCombo will listen for a specific string of keys from the Keyboard, and when it receives them - * it will emit a `keycombomatch` event from the Keyboard Manager. - * - * The keys to be listened for can be defined as: - * - * A string (i.e. 'ATARI') - * An array of either integers (key codes) or strings, or a mixture of both - * An array of objects (such as Key objects) with a public 'keyCode' property - * - * For example, to listen for the Konami code (up, up, down, down, left, right, left, right, b, a, enter) - * you could pass the following array of key codes: - * - * ```javascript - * this.input.keyboard.createCombo([ 38, 38, 40, 40, 37, 39, 37, 39, 66, 65, 13 ], { resetOnMatch: true }); - * - * this.input.keyboard.on('keycombomatch', function (event) { - * console.log('Konami Code entered!'); - * }); - * ``` - * - * Or, to listen for the user entering the word PHASER: - * - * ```javascript - * this.input.keyboard.createCombo('PHASER'); - * ``` + * `y` coordinate of the first point. */ - class KeyCombo { - /** - * - * @param keyboardPlugin A reference to the Keyboard Plugin. - * @param keys The keys that comprise this combo. - * @param config A Key Combo configuration object. - */ - constructor(keyboardPlugin: Phaser.Input.Keyboard.KeyboardPlugin, keys: string | integer[] | object[], config?: Phaser.Types.Input.Keyboard.KeyComboConfig); + y1: number; - /** - * A reference to the Keyboard Manager - */ - manager: Phaser.Input.Keyboard.KeyboardPlugin; + /** + * `x` coordinate of the second point. + */ + x2: number; - /** - * A flag that controls if this Key Combo is actively processing keys or not. - */ - enabled: boolean; + /** + * `y` coordinate of the second point. + */ + y2: number; - /** - * An array of the keycodes that comprise this combo. - */ - keyCodes: any[]; + /** + * `x` coordinate of the third point. + */ + x3: number; - /** - * The current keyCode the combo is waiting for. - */ - current: integer; + /** + * `y` coordinate of the third point. + */ + y3: number; - /** - * The current index of the key being waited for in the 'keys' string. - */ - index: integer; + /** + * Checks whether a given points lies within the triangle. + * @param x The x coordinate of the point to check. + * @param y The y coordinate of the point to check. + */ + contains(x: number, y: number): boolean; - /** - * The length of this combo (in keycodes) - */ - size: number; + /** + * Returns a specific point on the triangle. + * @param position Position as float within `0` and `1`. `0` equals the first point. + * @param output Optional Point, or point-like object, that the calculated point will be written to. + */ + getPoint(position: number, output?: O): O; - /** - * The time the previous key in the combo was matched. - */ - timeLastMatched: number; + /** + * Calculates a list of evenly distributed points on the triangle. It is either possible to pass an amount of points to be generated (`quantity`) or the distance between two points (`stepRate`). + * @param quantity Number of points to be generated. Can be falsey when `stepRate` should be used. All points have the same distance along the triangle. + * @param stepRate Distance between two points. Will only be used when `quantity` is falsey. + * @param output Optional Array for writing the calculated points into. Otherwise a new array will be created. + */ + getPoints(quantity: number, stepRate?: number, output?: O): O; - /** - * Has this Key Combo been matched yet? - */ - matched: boolean; + /** + * Returns a random point along the triangle. + * @param point Optional `Point` that should be modified. Otherwise a new one will be created. + */ + getRandomPoint(point?: O): O; - /** - * The time the entire combo was matched. - */ - timeMatched: number; + /** + * Sets all three points of the triangle. Leaving out any coordinate sets it to be `0`. + * @param x1 `x` coordinate of the first point. Default 0. + * @param y1 `y` coordinate of the first point. Default 0. + * @param x2 `x` coordinate of the second point. Default 0. + * @param y2 `y` coordinate of the second point. Default 0. + * @param x3 `x` coordinate of the third point. Default 0. + * @param y3 `y` coordinate of the third point. Default 0. + */ + setTo(x1?: number, y1?: number, x2?: number, y2?: number, x3?: number, y3?: number): this; - /** - * If they press the wrong key do we reset the combo? - */ - resetOnWrongKey: boolean; + /** + * Returns a Line object that corresponds to Line A of this Triangle. + * @param line A Line object to set the results in. If `undefined` a new Line will be created. + */ + getLineA(line?: O): O; - /** - * The max delay in ms between each key press. Above this the combo is reset. 0 means disabled. - */ - maxKeyDelay: integer; + /** + * Returns a Line object that corresponds to Line B of this Triangle. + * @param line A Line object to set the results in. If `undefined` a new Line will be created. + */ + getLineB(line?: O): O; - /** - * If previously matched and they press the first key of the combo again, will it reset? - */ - resetOnMatch: boolean; + /** + * Returns a Line object that corresponds to Line C of this Triangle. + * @param line A Line object to set the results in. If `undefined` a new Line will be created. + */ + getLineC(line?: O): O; - /** - * If the combo matches, will it delete itself? - */ - deleteOnMatch: boolean; + /** + * Left most X coordinate of the triangle. Setting it moves the triangle on the X axis accordingly. + */ + left: number; - /** - * How far complete is this combo? A value between 0 and 1. - */ - readonly progress: number; + /** + * Right most X coordinate of the triangle. Setting it moves the triangle on the X axis accordingly. + */ + right: number; - /** - * Destroys this Key Combo and all of its references. - */ - destroy(): void; + /** + * Top most Y coordinate of the triangle. Setting it moves the triangle on the Y axis accordingly. + */ + top: number; - } + /** + * Bottom most Y coordinate of the triangle. Setting it moves the triangle on the Y axis accordingly. + */ + bottom: number; - namespace Events { - /** - * The Global Key Down Event. - * - * This event is dispatched by the Keyboard Plugin when any key on the keyboard is pressed down. - * - * Listen to this event from within a Scene using: `this.input.keyboard.on('keydown', listener)`. - * - * You can also listen for a specific key being pressed. See [Keyboard.Events.KEY_DOWN]{@linkcode Phaser.Input.Keyboard.Events#event:KEY_DOWN} for details. - * - * Finally, you can create Key objects, which you can also listen for events from. See [Keyboard.Events.DOWN]{@linkcode Phaser.Input.Keyboard.Events#event:DOWN} for details. - * - * _Note_: Many keyboards are unable to process certain combinations of keys due to hardware limitations known as ghosting. - * Read [this article on ghosting]{@link http://www.html5gamedevs.com/topic/4876-impossible-to-use-more-than-2-keyboard-input-buttons-at-the-same-time/} for details. - * - * Also, please be aware that some browser extensions can disable or override Phaser keyboard handling. - * For example, the Chrome extension vimium is known to disable Phaser from using the D key, while EverNote disables the backtick key. - * There are others. So, please check your extensions if you find you have specific keys that don't work. - */ - const ANY_KEY_DOWN: any; + } - /** - * The Global Key Up Event. - * - * This event is dispatched by the Keyboard Plugin when any key on the keyboard is released. - * - * Listen to this event from within a Scene using: `this.input.keyboard.on('keyup', listener)`. - * - * You can also listen for a specific key being released. See [Keyboard.Events.KEY_UP]{@linkcode Phaser.Input.Keyboard.Events#event:KEY_UP} for details. - * - * Finally, you can create Key objects, which you can also listen for events from. See [Keyboard.Events.UP]{@linkcode Phaser.Input.Keyboard.Events#event:UP} for details. - */ - const ANY_KEY_UP: any; + } - /** - * The Key Combo Match Event. - * - * This event is dispatched by the Keyboard Plugin when a [Key Combo]{@link Phaser.Input.Keyboard.KeyCombo} is matched. - * - * Listen for this event from the Key Plugin after a combo has been created: - * - * ```javascript - * this.input.keyboard.createCombo([ 38, 38, 40, 40, 37, 39, 37, 39, 66, 65, 13 ], { resetOnMatch: true }); - * - * this.input.keyboard.on('keycombomatch', function (event) { - * console.log('Konami Code entered!'); - * }); - * ``` - */ - const COMBO_MATCH: any; + namespace Input { + /** + * The mouse pointer is being held down. + */ + var MOUSE_DOWN: number; - /** - * The Key Down Event. - * - * This event is dispatched by a [Key]{@link Phaser.Input.Keyboard.Key} object when it is pressed. - * - * Listen for this event from the Key object instance directly: - * - * ```javascript - * var spaceBar = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.SPACE); - * - * spaceBar.on('down', listener) - * ``` - * - * You can also create a generic 'global' listener. See [Keyboard.Events.ANY_KEY_DOWN]{@linkcode Phaser.Input.Keyboard.Events#event:ANY_KEY_DOWN} for details. - */ - const DOWN: any; + /** + * The mouse pointer is being moved. + */ + var MOUSE_MOVE: number; - /** - * The Key Down Event. - * - * This event is dispatched by the Keyboard Plugin when any key on the keyboard is pressed down. - * - * Unlike the `ANY_KEY_DOWN` event, this one has a special dynamic event name. For example, to listen for the `A` key being pressed - * use the following from within a Scene: `this.input.keyboard.on('keydown-A', listener)`. You can replace the `-A` part of the event - * name with any valid [Key Code string]{@link Phaser.Input.Keyboard.KeyCodes}. For example, this will listen for the space bar: - * `this.input.keyboard.on('keydown-SPACE', listener)`. - * - * You can also create a generic 'global' listener. See [Keyboard.Events.ANY_KEY_DOWN]{@linkcode Phaser.Input.Keyboard.Events#event:ANY_KEY_DOWN} for details. - * - * Finally, you can create Key objects, which you can also listen for events from. See [Keyboard.Events.DOWN]{@linkcode Phaser.Input.Keyboard.Events#event:DOWN} for details. - * - * _Note_: Many keyboards are unable to process certain combinations of keys due to hardware limitations known as ghosting. - * Read [this article on ghosting]{@link http://www.html5gamedevs.com/topic/4876-impossible-to-use-more-than-2-keyboard-input-buttons-at-the-same-time/} for details. - * - * Also, please be aware that some browser extensions can disable or override Phaser keyboard handling. - * For example, the Chrome extension vimium is known to disable Phaser from using the D key, while EverNote disables the backtick key. - * There are others. So, please check your extensions if you find you have specific keys that don't work. - */ - const KEY_DOWN: any; + /** + * The mouse pointer is released. + */ + var MOUSE_UP: number; - /** - * The Key Up Event. - * - * This event is dispatched by the Keyboard Plugin when any key on the keyboard is released. - * - * Unlike the `ANY_KEY_UP` event, this one has a special dynamic event name. For example, to listen for the `A` key being released - * use the following from within a Scene: `this.input.keyboard.on('keyup-A', listener)`. You can replace the `-A` part of the event - * name with any valid [Key Code string]{@link Phaser.Input.Keyboard.KeyCodes}. For example, this will listen for the space bar: - * `this.input.keyboard.on('keyup-SPACE', listener)`. - * - * You can also create a generic 'global' listener. See [Keyboard.Events.ANY_KEY_UP]{@linkcode Phaser.Input.Keyboard.Events#event:ANY_KEY_UP} for details. - * - * Finally, you can create Key objects, which you can also listen for events from. See [Keyboard.Events.UP]{@linkcode Phaser.Input.Keyboard.Events#event:UP} for details. - */ - const KEY_UP: any; + /** + * A touch pointer has been started. + */ + var TOUCH_START: number; - /** - * The Key Up Event. - * - * This event is dispatched by a [Key]{@link Phaser.Input.Keyboard.Key} object when it is released. - * - * Listen for this event from the Key object instance directly: - * - * ```javascript - * var spaceBar = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.SPACE); - * - * spaceBar.on('up', listener) - * ``` - * - * You can also create a generic 'global' listener. See [Keyboard.Events.ANY_KEY_UP]{@linkcode Phaser.Input.Keyboard.Events#event:ANY_KEY_UP} for details. - */ - const UP: any; + /** + * A touch pointer has been started. + */ + var TOUCH_MOVE: number; - } + /** + * A touch pointer has been started. + */ + var TOUCH_END: number; + + /** + * The pointer lock has changed. + */ + var POINTER_LOCK_CHANGE: number; + + /** + * A touch pointer has been been cancelled by the browser. + */ + var TOUCH_CANCEL: number; + + /** + * The mouse wheel changes. + */ + var MOUSE_WHEEL: number; + /** + * Creates a new Interactive Object. + * + * This is called automatically by the Input Manager when you enable a Game Object for input. + * + * The resulting Interactive Object is mapped to the Game Object's `input` property. + * @param gameObject The Game Object to which this Interactive Object is bound. + * @param hitArea The hit area for this Interactive Object. Typically a geometry shape, like a Rectangle or Circle. + * @param hitAreaCallback The 'contains' check callback that the hit area shape will use for all hit tests. + */ + function CreateInteractiveObject(gameObject: Phaser.GameObjects.GameObject, hitArea: any, hitAreaCallback: Phaser.Types.Input.HitAreaCallback): Phaser.Types.Input.InteractiveObject; + + /** + * Creates a new Pixel Perfect Handler function. + * + * Access via `InputPlugin.makePixelPerfect` rather than calling it directly. + * @param textureManager A reference to the Texture Manager. + * @param alphaTolerance The alpha level that the pixel should be above to be included as a successful interaction. + */ + function CreatePixelPerfectHandler(textureManager: Phaser.Textures.TextureManager, alphaTolerance: number): Function; + + namespace Events { /** - * The Keyboard Manager is a helper class that belongs to the global Input Manager. - * - * Its role is to listen for native DOM Keyboard Events and then store them for further processing by the Keyboard Plugin. + * The Input Plugin Boot Event. * - * You do not need to create this class directly, the Input Manager will create an instance of it automatically if keyboard - * input has been enabled in the Game Config. + * This internal event is dispatched by the Input Plugin when it boots, signalling to all of its systems to create themselves. */ - class KeyboardManager { - /** - * - * @param inputManager A reference to the Input Manager. - */ - constructor(inputManager: Phaser.Input.InputManager); + const BOOT: any; - /** - * A reference to the Input Manager. - */ - manager: Phaser.Input.InputManager; + /** + * The Input Plugin Destroy Event. + * + * This internal event is dispatched by the Input Plugin when it is destroyed, signalling to all of its systems to destroy themselves. + */ + const DESTROY: any; - /** - * A flag that controls if the non-modified keys, matching those stored in the `captures` array, - * have `preventDefault` called on them or not. - * - * A non-modified key is one that doesn't have a modifier key held down with it. The modifier keys are - * shift, control, alt and the meta key (Command on a Mac, the Windows Key on Windows). - * Therefore, if the user presses shift + r, it won't prevent this combination, because of the modifier. - * However, if the user presses just the r key on its own, it will have its event prevented. - * - * If you wish to stop capturing the keys, for example switching out to a DOM based element, then - * you can toggle this property at run-time. - */ - preventDefault: boolean; + /** + * The Pointer Drag End Input Event. + * + * This event is dispatched by the Input Plugin belonging to a Scene if a pointer stops dragging a Game Object. + * + * Listen to this event from within a Scene using: `this.input.on('dragend', listener)`. + * + * To listen for this event from a _specific_ Game Object, use the [GAMEOBJECT_DRAG_END]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_DRAG_END} event instead. + */ + const DRAG_END: any; - /** - * An array of Key Code values that will automatically have `preventDefault` called on them, - * as long as the `KeyboardManager.preventDefault` boolean is set to `true`. - * - * By default the array is empty. - * - * The key must be non-modified when pressed in order to be captured. - * - * A non-modified key is one that doesn't have a modifier key held down with it. The modifier keys are - * shift, control, alt and the meta key (Command on a Mac, the Windows Key on Windows). - * Therefore, if the user presses shift + r, it won't prevent this combination, because of the modifier. - * However, if the user presses just the r key on its own, it will have its event prevented. - * - * If you wish to stop capturing the keys, for example switching out to a DOM based element, then - * you can toggle the `KeyboardManager.preventDefault` boolean at run-time. - * - * If you need more specific control, you can create Key objects and set the flag on each of those instead. - * - * This array can be populated via the Game Config by setting the `input.keyboard.capture` array, or you - * can call the `addCapture` method. See also `removeCapture` and `clearCaptures`. - */ - captures: integer[]; + /** + * The Pointer Drag Enter Input Event. + * + * This event is dispatched by the Input Plugin belonging to a Scene if a pointer drags a Game Object into a Drag Target. + * + * Listen to this event from within a Scene using: `this.input.on('dragenter', listener)`. + * + * A Pointer can only drag a single Game Object at once. + * + * To listen for this event from a _specific_ Game Object, use the [GAMEOBJECT_DRAG_ENTER]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_DRAG_ENTER} event instead. + */ + const DRAG_ENTER: any; - /** - * A boolean that controls if the Keyboard Manager is enabled or not. - * Can be toggled on the fly. - */ - enabled: boolean; + /** + * The Pointer Drag Input Event. + * + * This event is dispatched by the Input Plugin belonging to a Scene if a pointer moves while dragging a Game Object. + * + * Listen to this event from within a Scene using: `this.input.on('drag', listener)`. + * + * A Pointer can only drag a single Game Object at once. + * + * To listen for this event from a _specific_ Game Object, use the [GAMEOBJECT_DRAG]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_DRAG} event instead. + */ + const DRAG: any; - /** - * The Keyboard Event target, as defined in the Game Config. - * Typically the window in which the game is rendering, but can be any interactive DOM element. - */ - target: any; + /** + * The Pointer Drag Leave Input Event. + * + * This event is dispatched by the Input Plugin belonging to a Scene if a pointer drags a Game Object out of a Drag Target. + * + * Listen to this event from within a Scene using: `this.input.on('dragleave', listener)`. + * + * A Pointer can only drag a single Game Object at once. + * + * To listen for this event from a _specific_ Game Object, use the [GAMEOBJECT_DRAG_LEAVE]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_DRAG_LEAVE} event instead. + */ + const DRAG_LEAVE: any; - /** - * The Key Down Event handler. - * This function is sent the native DOM KeyEvent. - * Initially empty and bound in the `startListeners` method. - */ - onKeyDown: Function; + /** + * The Pointer Drag Over Input Event. + * + * This event is dispatched by the Input Plugin belonging to a Scene if a pointer drags a Game Object over a Drag Target. + * + * When the Game Object first enters the drag target it will emit a `dragenter` event. If it then moves while within + * the drag target, it will emit this event instead. + * + * Listen to this event from within a Scene using: `this.input.on('dragover', listener)`. + * + * A Pointer can only drag a single Game Object at once. + * + * To listen for this event from a _specific_ Game Object, use the [GAMEOBJECT_DRAG_OVER]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_DRAG_OVER} event instead. + */ + const DRAG_OVER: any; - /** - * The Key Up Event handler. - * This function is sent the native DOM KeyEvent. - * Initially empty and bound in the `startListeners` method. - */ - onKeyUp: Function; + /** + * The Pointer Drag Start Input Event. + * + * This event is dispatched by the Input Plugin belonging to a Scene if a pointer starts to drag any Game Object. + * + * Listen to this event from within a Scene using: `this.input.on('dragstart', listener)`. + * + * A Pointer can only drag a single Game Object at once. + * + * To listen for this event from a _specific_ Game Object, use the [GAMEOBJECT_DRAG_START]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_DRAG_START} event instead. + */ + const DRAG_START: any; - /** - * Starts the Keyboard Event listeners running. - * This is called automatically and does not need to be manually invoked. - */ - startListeners(): void; - - /** - * Stops the Key Event listeners. - * This is called automatically and does not need to be manually invoked. - */ - stopListeners(): void; - - /** - * By default when a key is pressed Phaser will not stop the event from propagating up to the browser. - * There are some keys this can be annoying for, like the arrow keys or space bar, which make the browser window scroll. - * - * This `addCapture` method enables consuming keyboard event for specific keys so it doesn't bubble up to the the browser - * and cause the default browser behavior. - * - * Please note that keyboard captures are global. This means that if you call this method from within a Scene, to say prevent - * the SPACE BAR from triggering a page scroll, then it will prevent it for any Scene in your game, not just the calling one. - * - * You can pass in a single key code value, or an array of key codes, or a string: - * - * ```javascript - * this.input.keyboard.addCapture(62); - * ``` - * - * An array of key codes: - * - * ```javascript - * this.input.keyboard.addCapture([ 62, 63, 64 ]); - * ``` - * - * Or a string: - * - * ```javascript - * this.input.keyboard.addCapture('W,S,A,D'); - * ``` - * - * To use non-alpha numeric keys, use a string, such as 'UP', 'SPACE' or 'LEFT'. - * - * You can also provide an array mixing both strings and key code integers. - * - * If there are active captures after calling this method, the `preventDefault` property is set to `true`. - * @param keycode The Key Codes to enable capture for, preventing them reaching the browser. - */ - addCapture(keycode: string | integer | integer[] | any[]): void; - - /** - * Removes an existing key capture. - * - * Please note that keyboard captures are global. This means that if you call this method from within a Scene, to remove - * the capture of a key, then it will remove it for any Scene in your game, not just the calling one. - * - * You can pass in a single key code value, or an array of key codes, or a string: - * - * ```javascript - * this.input.keyboard.removeCapture(62); - * ``` - * - * An array of key codes: - * - * ```javascript - * this.input.keyboard.removeCapture([ 62, 63, 64 ]); - * ``` - * - * Or a string: - * - * ```javascript - * this.input.keyboard.removeCapture('W,S,A,D'); - * ``` - * - * To use non-alpha numeric keys, use a string, such as 'UP', 'SPACE' or 'LEFT'. - * - * You can also provide an array mixing both strings and key code integers. - * - * If there are no captures left after calling this method, the `preventDefault` property is set to `false`. - * @param keycode The Key Codes to disable capture for, allowing them reaching the browser again. - */ - removeCapture(keycode: string | integer | integer[] | any[]): void; - - /** - * Removes all keyboard captures and sets the `preventDefault` property to `false`. - */ - clearCaptures(): void; - - /** - * Destroys this Keyboard Manager instance. - */ - destroy(): void; - - } + /** + * The Pointer Drop Input Event. + * + * This event is dispatched by the Input Plugin belonging to a Scene if a pointer drops a Game Object on a Drag Target. + * + * Listen to this event from within a Scene using: `this.input.on('drop', listener)`. + * + * To listen for this event from a _specific_ Game Object, use the [GAMEOBJECT_DROP]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_DROP} event instead. + */ + const DROP: any; /** - * The Keyboard Plugin is an input plugin that belongs to the Scene-owned Input system. - * - * Its role is to listen for native DOM Keyboard Events and then process them. + * The Game Object Down Input Event. * - * You do not need to create this class directly, the Input system will create an instance of it automatically. + * This event is dispatched by the Input Plugin belonging to a Scene if a pointer is pressed down on _any_ interactive Game Object. * - * You can access it from within a Scene using `this.input.keyboard`. For example, you can do: + * Listen to this event from within a Scene using: `this.input.on('gameobjectdown', listener)`. * - * ```javascript - * this.input.keyboard.on('keydown', callback, context); - * ``` + * To receive this event, the Game Objects must have been set as interactive. + * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. * - * Or, to listen for a specific key: + * To listen for this event from a _specific_ Game Object, use the [GAMEOBJECT_POINTER_DOWN]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_DOWN} event instead. * - * ```javascript - * this.input.keyboard.on('keydown-A', callback, context); - * ``` + * The event hierarchy is as follows: * - * You can also create Key objects, which you can then poll in your game loop: + * 1. [GAMEOBJECT_POINTER_DOWN]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_DOWN} + * 2. [GAMEOBJECT_DOWN]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_DOWN} + * 3. [POINTER_DOWN]{@linkcode Phaser.Input.Events#event:POINTER_DOWN} or [POINTER_DOWN_OUTSIDE]{@linkcode Phaser.Input.Events#event:POINTER_DOWN_OUTSIDE} * - * ```javascript - * var spaceBar = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.SPACE); - * ``` + * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop + * the propagation of this event. + */ + const GAMEOBJECT_DOWN: any; + + /** + * The Game Object Drag End Event. * - * If you have multiple parallel Scenes, each trying to get keyboard input, be sure to disable capture on them to stop them from - * stealing input from another Scene in the list. You can do this with `this.input.keyboard.enabled = false` within the - * Scene to stop all input, or `this.input.keyboard.preventDefault = false` to stop a Scene halting input on another Scene. + * This event is dispatched by an interactive Game Object if a pointer stops dragging it. * - * _Note_: Many keyboards are unable to process certain combinations of keys due to hardware limitations known as ghosting. - * See http://www.html5gamedevs.com/topic/4876-impossible-to-use-more-than-2-keyboard-input-buttons-at-the-same-time/ for more details. + * Listen to this event from a Game Object using: `gameObject.on('dragend', listener)`. + * Note that the scope of the listener is automatically set to be the Game Object instance itself. * - * Also please be aware that certain browser extensions can disable or override Phaser keyboard handling. - * For example the Chrome extension vimium is known to disable Phaser from using the D key, while EverNote disables the backtick key. - * And there are others. So, please check your extensions before opening Phaser issues about keys that don't work. + * To receive this event, the Game Object must have been set as interactive and enabled for drag. + * See [GameObject.setInteractive](Phaser.GameObjects.GameObject#setInteractive) for more details. */ - class KeyboardPlugin extends Phaser.Events.EventEmitter { - /** - * - * @param sceneInputPlugin A reference to the Scene Input Plugin that the KeyboardPlugin belongs to. - */ - constructor(sceneInputPlugin: Phaser.Input.InputPlugin); - - /** - * A reference to the core game, so we can listen for visibility events. - */ - game: Phaser.Game; - - /** - * A reference to the Scene that this Input Plugin is responsible for. - */ - scene: Phaser.Scene; - - /** - * A reference to the Scene Systems Settings. - */ - settings: Phaser.Types.Scenes.SettingsObject; - - /** - * A reference to the Scene Input Plugin that created this Keyboard Plugin. - */ - sceneInputPlugin: Phaser.Input.InputPlugin; - - /** - * A reference to the global Keyboard Manager. - */ - manager: Phaser.Input.InputPlugin; - - /** - * A boolean that controls if this Keyboard Plugin is enabled or not. - * Can be toggled on the fly. - */ - enabled: boolean; - - /** - * An array of Key objects to process. - */ - keys: Phaser.Input.Keyboard.Key[]; - - /** - * An array of KeyCombo objects to process. - */ - combos: Phaser.Input.Keyboard.KeyCombo[]; - - /** - * Checks to see if both this plugin and the Scene to which it belongs is active. - */ - isActive(): boolean; - - /** - * By default when a key is pressed Phaser will not stop the event from propagating up to the browser. - * There are some keys this can be annoying for, like the arrow keys or space bar, which make the browser window scroll. - * - * This `addCapture` method enables consuming keyboard events for specific keys, so they don't bubble up the browser - * and cause the default behaviors. - * - * Please note that keyboard captures are global. This means that if you call this method from within a Scene, to say prevent - * the SPACE BAR from triggering a page scroll, then it will prevent it for any Scene in your game, not just the calling one. - * - * You can pass a single key code value: - * - * ```javascript - * this.input.keyboard.addCapture(62); - * ``` - * - * An array of key codes: - * - * ```javascript - * this.input.keyboard.addCapture([ 62, 63, 64 ]); - * ``` - * - * Or, a comma-delimited string: - * - * ```javascript - * this.input.keyboard.addCapture('W,S,A,D'); - * ``` - * - * To use non-alpha numeric keys, use a string, such as 'UP', 'SPACE' or 'LEFT'. - * - * You can also provide an array mixing both strings and key code integers. - * @param keycode The Key Codes to enable event capture for. - */ - addCapture(keycode: string | integer | integer[] | any[]): Phaser.Input.Keyboard.KeyboardPlugin; - - /** - * Removes an existing key capture. - * - * Please note that keyboard captures are global. This means that if you call this method from within a Scene, to remove - * the capture of a key, then it will remove it for any Scene in your game, not just the calling one. - * - * You can pass a single key code value: - * - * ```javascript - * this.input.keyboard.removeCapture(62); - * ``` - * - * An array of key codes: - * - * ```javascript - * this.input.keyboard.removeCapture([ 62, 63, 64 ]); - * ``` - * - * Or, a comma-delimited string: - * - * ```javascript - * this.input.keyboard.removeCapture('W,S,A,D'); - * ``` - * - * To use non-alpha numeric keys, use a string, such as 'UP', 'SPACE' or 'LEFT'. - * - * You can also provide an array mixing both strings and key code integers. - * @param keycode The Key Codes to disable event capture for. - */ - removeCapture(keycode: string | integer | integer[] | any[]): Phaser.Input.Keyboard.KeyboardPlugin; - - /** - * Returns an array that contains all of the keyboard captures currently enabled. - */ - getCaptures(): integer[]; - - /** - * Allows Phaser to prevent any key captures you may have defined from bubbling up the browser. - * You can use this to re-enable event capturing if you had paused it via `disableGlobalCapture`. - */ - enableGlobalCapture(): Phaser.Input.Keyboard.KeyboardPlugin; - - /** - * Disables Phaser from preventing any key captures you may have defined, without actually removing them. - * You can use this to temporarily disable event capturing if, for example, you swap to a DOM element. - */ - disableGlobalCapture(): Phaser.Input.Keyboard.KeyboardPlugin; - - /** - * Removes all keyboard captures. - * - * Note that this is a global change. It will clear all event captures across your game, not just for this specific Scene. - */ - clearCaptures(): Phaser.Input.Keyboard.KeyboardPlugin; - - /** - * Creates and returns an object containing 4 hotkeys for Up, Down, Left and Right, and also Space Bar and shift. - */ - createCursorKeys(): Phaser.Types.Input.Keyboard.CursorKeys; - - /** - * A practical way to create an object containing user selected hotkeys. - * - * For example: - * - * ```javascript - * this.input.keyboard.addKeys({ 'up': Phaser.Input.Keyboard.KeyCodes.W, 'down': Phaser.Input.Keyboard.KeyCodes.S }); - * ``` - * - * would return an object containing the properties (`up` and `down`) mapped to W and S {@link Phaser.Input.Keyboard.Key} objects. - * - * You can also pass in a comma-separated string: - * - * ```javascript - * this.input.keyboard.addKeys('W,S,A,D'); - * ``` - * - * Which will return an object with the properties W, S, A and D mapped to the relevant Key objects. - * - * To use non-alpha numeric keys, use a string, such as 'UP', 'SPACE' or 'LEFT'. - * @param keys An object containing Key Codes, or a comma-separated string. - * @param enableCapture Automatically call `preventDefault` on the native DOM browser event for the key codes being added. Default true. - * @param emitOnRepeat Controls if the Key will continuously emit a 'down' event while being held down (true), or emit the event just once (false, the default). Default false. - */ - addKeys(keys: object | string, enableCapture?: boolean, emitOnRepeat?: boolean): object; - - /** - * Adds a Key object to this Keyboard Plugin. - * - * The given argument can be either an existing Key object, a string, such as `A` or `SPACE`, or a key code value. - * - * If a Key object is given, and one already exists matching the same key code, the existing one is replaced with the new one. - * @param key Either a Key object, a string, such as `A` or `SPACE`, or a key code value. - * @param enableCapture Automatically call `preventDefault` on the native DOM browser event for the key codes being added. Default true. - * @param emitOnRepeat Controls if the Key will continuously emit a 'down' event while being held down (true), or emit the event just once (false, the default). Default false. - */ - addKey(key: Phaser.Input.Keyboard.Key | string | integer, enableCapture?: boolean, emitOnRepeat?: boolean): Phaser.Input.Keyboard.Key; - - /** - * Removes a Key object from this Keyboard Plugin. - * - * The given argument can be either a Key object, a string, such as `A` or `SPACE`, or a key code value. - * @param key Either a Key object, a string, such as `A` or `SPACE`, or a key code value. - * @param destroy Call `Key.destroy` on the removed Key object? Default false. - */ - removeKey(key: Phaser.Input.Keyboard.Key | string | integer, destroy?: boolean): Phaser.Input.Keyboard.KeyboardPlugin; - - /** - * Creates a new KeyCombo. - * - * A KeyCombo will listen for a specific string of keys from the Keyboard, and when it receives them - * it will emit a `keycombomatch` event from this Keyboard Plugin. - * - * The keys to be listened for can be defined as: - * - * A string (i.e. 'ATARI') - * An array of either integers (key codes) or strings, or a mixture of both - * An array of objects (such as Key objects) with a public 'keyCode' property - * - * For example, to listen for the Konami code (up, up, down, down, left, right, left, right, b, a, enter) - * you could pass the following array of key codes: - * - * ```javascript - * this.input.keyboard.createCombo([ 38, 38, 40, 40, 37, 39, 37, 39, 66, 65, 13 ], { resetOnMatch: true }); - * - * this.input.keyboard.on('keycombomatch', function (event) { - * console.log('Konami Code entered!'); - * }); - * ``` - * - * Or, to listen for the user entering the word PHASER: - * - * ```javascript - * this.input.keyboard.createCombo('PHASER'); - * ``` - * @param keys The keys that comprise this combo. - * @param config A Key Combo configuration object. - */ - createCombo(keys: string | integer[] | object[], config?: Phaser.Types.Input.Keyboard.KeyComboConfig): Phaser.Input.Keyboard.KeyCombo; - - /** - * Checks if the given Key object is currently being held down. - * - * The difference between this method and checking the `Key.isDown` property directly is that you can provide - * a duration to this method. For example, if you wanted a key press to fire a bullet, but you only wanted - * it to be able to fire every 100ms, then you can call this method with a `duration` of 100 and it - * will only return `true` every 100ms. - * - * If the Keyboard Plugin has been disabled, this method will always return `false`. - * @param key A Key object. - * @param duration The duration which must have elapsed before this Key is considered as being down. Default 0. - */ - checkDown(key: Phaser.Input.Keyboard.Key, duration?: number): boolean; + const GAMEOBJECT_DRAG_END: any; - /** - * Resets all Key objects created by _this_ Keyboard Plugin back to their default un-pressed states. - * This can only reset keys created via the `addKey`, `addKeys` or `createCursorKeys` methods. - * If you have created a Key object directly you'll need to reset it yourself. - * - * This method is called automatically when the Keyboard Plugin shuts down, but can be - * invoked directly at any time you require. - */ - resetKeys(): Phaser.Input.Keyboard.KeyboardPlugin; + /** + * The Game Object Drag Enter Event. + * + * This event is dispatched by an interactive Game Object if a pointer drags it into a drag target. + * + * Listen to this event from a Game Object using: `gameObject.on('dragenter', listener)`. + * Note that the scope of the listener is automatically set to be the Game Object instance itself. + * + * To receive this event, the Game Object must have been set as interactive and enabled for drag. + * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. + */ + const GAMEOBJECT_DRAG_ENTER: any; - } + /** + * The Game Object Drag Event. + * + * This event is dispatched by an interactive Game Object if a pointer moves while dragging it. + * + * Listen to this event from a Game Object using: `gameObject.on('drag', listener)`. + * Note that the scope of the listener is automatically set to be the Game Object instance itself. + * + * To receive this event, the Game Object must have been set as interactive and enabled for drag. + * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. + */ + const GAMEOBJECT_DRAG: any; /** - * Returns `true` if the Key was pressed down within the `duration` value given, based on the current - * game clock time. Or `false` if it either isn't down, or was pressed down longer ago than the given duration. - * @param key The Key object to test. - * @param duration The duration, in ms, within which the key must have been pressed down. Default 50. + * The Game Object Drag Leave Event. + * + * This event is dispatched by an interactive Game Object if a pointer drags it out of a drag target. + * + * Listen to this event from a Game Object using: `gameObject.on('dragleave', listener)`. + * Note that the scope of the listener is automatically set to be the Game Object instance itself. + * + * To receive this event, the Game Object must have been set as interactive and enabled for drag. + * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. */ - function DownDuration(key: Phaser.Input.Keyboard.Key, duration?: integer): boolean; + const GAMEOBJECT_DRAG_LEAVE: any; /** - * The justDown value allows you to test if this Key has just been pressed down or not. + * The Game Object Drag Over Event. * - * When you check this value it will return `true` if the Key is down, otherwise `false`. + * This event is dispatched by an interactive Game Object if a pointer drags it over a drag target. * - * You can only call justDown once per key press. It will only return `true` once, until the Key is released and pressed down again. - * This allows you to use it in situations where you want to check if this key is down without using an event, such as in a core game loop. - * @param key The Key to check to see if it's just down or not. + * When the Game Object first enters the drag target it will emit a `dragenter` event. If it then moves while within + * the drag target, it will emit this event instead. + * + * Listen to this event from a Game Object using: `gameObject.on('dragover', listener)`. + * Note that the scope of the listener is automatically set to be the Game Object instance itself. + * + * To receive this event, the Game Object must have been set as interactive and enabled for drag. + * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. */ - function JustDown(key: Phaser.Input.Keyboard.Key): boolean; + const GAMEOBJECT_DRAG_OVER: any; /** - * The justUp value allows you to test if this Key has just been released or not. + * The Game Object Drag Start Event. * - * When you check this value it will return `true` if the Key is up, otherwise `false`. + * This event is dispatched by an interactive Game Object if a pointer starts to drag it. * - * You can only call JustUp once per key release. It will only return `true` once, until the Key is pressed down and released again. - * This allows you to use it in situations where you want to check if this key is up without using an event, such as in a core game loop. - * @param key The Key to check to see if it's just up or not. + * Listen to this event from a Game Object using: `gameObject.on('dragstart', listener)`. + * Note that the scope of the listener is automatically set to be the Game Object instance itself. + * + * To receive this event, the Game Object must have been set as interactive and enabled for drag. + * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. + * + * There are lots of useful drag related properties that are set within the Game Object when dragging occurs. + * For example, `gameObject.input.dragStartX`, `dragStartY` and so on. */ - function JustUp(key: Phaser.Input.Keyboard.Key): boolean; + const GAMEOBJECT_DRAG_START: any; /** - * A generic Key object which can be passed to the Process functions (and so on) - * keycode must be an integer + * The Game Object Drop Event. + * + * This event is dispatched by an interactive Game Object if a pointer drops it on a Drag Target. + * + * Listen to this event from a Game Object using: `gameObject.on('drop', listener)`. + * Note that the scope of the listener is automatically set to be the Game Object instance itself. + * + * To receive this event, the Game Object must have been set as interactive and enabled for drag. + * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. */ - class Key extends Phaser.Events.EventEmitter { - /** - * - * @param plugin The Keyboard Plugin instance that owns this Key object. - * @param keyCode The keycode of this key. - */ - constructor(plugin: Phaser.Input.Keyboard.KeyboardPlugin, keyCode: integer); + const GAMEOBJECT_DROP: any; - /** - * The Keyboard Plugin instance that owns this Key object. - */ - plugin: Phaser.Input.Keyboard.KeyboardPlugin; + /** + * The Game Object Move Input Event. + * + * This event is dispatched by the Input Plugin belonging to a Scene if a pointer is moved across _any_ interactive Game Object. + * + * Listen to this event from within a Scene using: `this.input.on('gameobjectmove', listener)`. + * + * To receive this event, the Game Objects must have been set as interactive. + * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. + * + * To listen for this event from a _specific_ Game Object, use the [GAMEOBJECT_POINTER_MOVE]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_MOVE} event instead. + * + * The event hierarchy is as follows: + * + * 1. [GAMEOBJECT_POINTER_MOVE]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_MOVE} + * 2. [GAMEOBJECT_MOVE]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_MOVE} + * 3. [POINTER_MOVE]{@linkcode Phaser.Input.Events#event:POINTER_MOVE} + * + * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop + * the propagation of this event. + */ + const GAMEOBJECT_MOVE: any; - /** - * The keycode of this key. - */ - keyCode: integer; + /** + * The Game Object Out Input Event. + * + * This event is dispatched by the Input Plugin belonging to a Scene if a pointer moves out of _any_ interactive Game Object. + * + * Listen to this event from within a Scene using: `this.input.on('gameobjectout', listener)`. + * + * To receive this event, the Game Objects must have been set as interactive. + * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. + * + * To listen for this event from a _specific_ Game Object, use the [GAMEOBJECT_POINTER_OUT]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_OUT} event instead. + * + * The event hierarchy is as follows: + * + * 1. [GAMEOBJECT_POINTER_OUT]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_OUT} + * 2. [GAMEOBJECT_OUT]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_OUT} + * 3. [POINTER_OUT]{@linkcode Phaser.Input.Events#event:POINTER_OUT} + * + * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop + * the propagation of this event. + */ + const GAMEOBJECT_OUT: any; + /** + * The Game Object Over Input Event. + * + * This event is dispatched by the Input Plugin belonging to a Scene if a pointer moves over _any_ interactive Game Object. + * + * Listen to this event from within a Scene using: `this.input.on('gameobjectover', listener)`. + * + * To receive this event, the Game Objects must have been set as interactive. + * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. + * + * To listen for this event from a _specific_ Game Object, use the [GAMEOBJECT_POINTER_OVER]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_OVER} event instead. + * + * The event hierarchy is as follows: + * + * 1. [GAMEOBJECT_POINTER_OVER]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_OVER} + * 2. [GAMEOBJECT_OVER]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_OVER} + * 3. [POINTER_OVER]{@linkcode Phaser.Input.Events#event:POINTER_OVER} + * + * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop + * the propagation of this event. + */ + const GAMEOBJECT_OVER: any; + + /** + * The Game Object Pointer Down Event. + * + * This event is dispatched by an interactive Game Object if a pointer is pressed down on it. + * + * Listen to this event from a Game Object using: `gameObject.on('pointerdown', listener)`. + * Note that the scope of the listener is automatically set to be the Game Object instance itself. + * + * To receive this event, the Game Object must have been set as interactive. + * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. + * + * The event hierarchy is as follows: + * + * 1. [GAMEOBJECT_POINTER_DOWN]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_DOWN} + * 2. [GAMEOBJECT_DOWN]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_DOWN} + * 3. [POINTER_DOWN]{@linkcode Phaser.Input.Events#event:POINTER_DOWN} or [POINTER_DOWN_OUTSIDE]{@linkcode Phaser.Input.Events#event:POINTER_DOWN_OUTSIDE} + * + * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop + * the propagation of this event. + */ + const GAMEOBJECT_POINTER_DOWN: any; + + /** + * The Game Object Pointer Move Event. + * + * This event is dispatched by an interactive Game Object if a pointer is moved while over it. + * + * Listen to this event from a Game Object using: `gameObject.on('pointermove', listener)`. + * Note that the scope of the listener is automatically set to be the Game Object instance itself. + * + * To receive this event, the Game Object must have been set as interactive. + * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. + * + * The event hierarchy is as follows: + * + * 1. [GAMEOBJECT_POINTER_MOVE]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_MOVE} + * 2. [GAMEOBJECT_MOVE]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_MOVE} + * 3. [POINTER_MOVE]{@linkcode Phaser.Input.Events#event:POINTER_MOVE} + * + * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop + * the propagation of this event. + */ + const GAMEOBJECT_POINTER_MOVE: any; + + /** + * The Game Object Pointer Out Event. + * + * This event is dispatched by an interactive Game Object if a pointer moves out of it. + * + * Listen to this event from a Game Object using: `gameObject.on('pointerout', listener)`. + * Note that the scope of the listener is automatically set to be the Game Object instance itself. + * + * To receive this event, the Game Object must have been set as interactive. + * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. + * + * The event hierarchy is as follows: + * + * 1. [GAMEOBJECT_POINTER_OUT]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_OUT} + * 2. [GAMEOBJECT_OUT]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_OUT} + * 3. [POINTER_OUT]{@linkcode Phaser.Input.Events#event:POINTER_OUT} + * + * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop + * the propagation of this event. + */ + const GAMEOBJECT_POINTER_OUT: any; + + /** + * The Game Object Pointer Over Event. + * + * This event is dispatched by an interactive Game Object if a pointer moves over it. + * + * Listen to this event from a Game Object using: `gameObject.on('pointerover', listener)`. + * Note that the scope of the listener is automatically set to be the Game Object instance itself. + * + * To receive this event, the Game Object must have been set as interactive. + * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. + * + * The event hierarchy is as follows: + * + * 1. [GAMEOBJECT_POINTER_OVER]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_OVER} + * 2. [GAMEOBJECT_OVER]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_OVER} + * 3. [POINTER_OVER]{@linkcode Phaser.Input.Events#event:POINTER_OVER} + * + * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop + * the propagation of this event. + */ + const GAMEOBJECT_POINTER_OVER: any; + + /** + * The Game Object Pointer Up Event. + * + * This event is dispatched by an interactive Game Object if a pointer is released while over it. + * + * Listen to this event from a Game Object using: `gameObject.on('pointerup', listener)`. + * Note that the scope of the listener is automatically set to be the Game Object instance itself. + * + * To receive this event, the Game Object must have been set as interactive. + * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. + * + * The event hierarchy is as follows: + * + * 1. [GAMEOBJECT_POINTER_UP]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_UP} + * 2. [GAMEOBJECT_UP]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_UP} + * 3. [POINTER_UP]{@linkcode Phaser.Input.Events#event:POINTER_UP} or [POINTER_UP_OUTSIDE]{@linkcode Phaser.Input.Events#event:POINTER_UP_OUTSIDE} + * + * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop + * the propagation of this event. + */ + const GAMEOBJECT_POINTER_UP: any; + + /** + * The Game Object Pointer Wheel Event. + * + * This event is dispatched by an interactive Game Object if a pointer has its wheel moved while over it. + * + * Listen to this event from a Game Object using: `gameObject.on('wheel', listener)`. + * Note that the scope of the listener is automatically set to be the Game Object instance itself. + * + * To receive this event, the Game Object must have been set as interactive. + * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. + * + * The event hierarchy is as follows: + * + * 1. [GAMEOBJECT_POINTER_WHEEL]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_WHEEL} + * 2. [GAMEOBJECT_WHEEL]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_WHEEL} + * 3. [POINTER_WHEEL]{@linkcode Phaser.Input.Events#event:POINTER_WHEEL} + * + * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop + * the propagation of this event. + */ + const GAMEOBJECT_POINTER_WHEEL: any; + + /** + * The Game Object Up Input Event. + * + * This event is dispatched by the Input Plugin belonging to a Scene if a pointer is released while over _any_ interactive Game Object. + * + * Listen to this event from within a Scene using: `this.input.on('gameobjectup', listener)`. + * + * To receive this event, the Game Objects must have been set as interactive. + * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. + * + * To listen for this event from a _specific_ Game Object, use the [GAMEOBJECT_POINTER_UP]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_UP} event instead. + * + * The event hierarchy is as follows: + * + * 1. [GAMEOBJECT_POINTER_UP]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_UP} + * 2. [GAMEOBJECT_UP]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_UP} + * 3. [POINTER_UP]{@linkcode Phaser.Input.Events#event:POINTER_UP} or [POINTER_UP_OUTSIDE]{@linkcode Phaser.Input.Events#event:POINTER_UP_OUTSIDE} + * + * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop + * the propagation of this event. + */ + const GAMEOBJECT_UP: any; + + /** + * The Game Object Wheel Input Event. + * + * This event is dispatched by the Input Plugin belonging to a Scene if a pointer has its wheel moved while over _any_ interactive Game Object. + * + * Listen to this event from within a Scene using: `this.input.on('gameobjectwheel', listener)`. + * + * To receive this event, the Game Objects must have been set as interactive. + * See [GameObject.setInteractive]{@link Phaser.GameObjects.GameObject#setInteractive} for more details. + * + * To listen for this event from a _specific_ Game Object, use the [GAMEOBJECT_POINTER_WHEEL]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_WHEEL} event instead. + * + * The event hierarchy is as follows: + * + * 1. [GAMEOBJECT_POINTER_WHEEL]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_WHEEL} + * 2. [GAMEOBJECT_WHEEL]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_WHEEL} + * 3. [POINTER_WHEEL]{@linkcode Phaser.Input.Events#event:POINTER_WHEEL} + * + * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop + * the propagation of this event. + */ + const GAMEOBJECT_WHEEL: any; + + /** + * The Input Plugin Game Out Event. + * + * This event is dispatched by the Input Plugin if the active pointer leaves the game canvas and is now + * outside of it, elsewhere on the web page. + * + * Listen to this event from within a Scene using: `this.input.on('gameout', listener)`. + */ + const GAME_OUT: any; + + /** + * The Input Plugin Game Over Event. + * + * This event is dispatched by the Input Plugin if the active pointer enters the game canvas and is now + * over of it, having previously been elsewhere on the web page. + * + * Listen to this event from within a Scene using: `this.input.on('gameover', listener)`. + */ + const GAME_OVER: any; + + /** + * The Input Manager Boot Event. + * + * This internal event is dispatched by the Input Manager when it boots. + */ + const MANAGER_BOOT: any; + + /** + * The Input Manager Process Event. + * + * This internal event is dispatched by the Input Manager when not using the legacy queue system, + * and it wants the Input Plugins to update themselves. + */ + const MANAGER_PROCESS: any; + + /** + * The Input Manager Update Event. + * + * This internal event is dispatched by the Input Manager as part of its update step. + */ + const MANAGER_UPDATE: any; + + /** + * The Input Manager Pointer Lock Change Event. + * + * This event is dispatched by the Input Manager when it is processing a native Pointer Lock Change DOM Event. + */ + const POINTERLOCK_CHANGE: any; + + /** + * The Pointer Down Input Event. + * + * This event is dispatched by the Input Plugin belonging to a Scene if a pointer is pressed down anywhere. + * + * Listen to this event from within a Scene using: `this.input.on('pointerdown', listener)`. + * + * The event hierarchy is as follows: + * + * 1. [GAMEOBJECT_POINTER_DOWN]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_DOWN} + * 2. [GAMEOBJECT_DOWN]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_DOWN} + * 3. [POINTER_DOWN]{@linkcode Phaser.Input.Events#event:POINTER_DOWN} or [POINTER_DOWN_OUTSIDE]{@linkcode Phaser.Input.Events#event:POINTER_DOWN_OUTSIDE} + * + * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop + * the propagation of this event. + */ + const POINTER_DOWN: any; + + /** + * The Pointer Down Outside Input Event. + * + * This event is dispatched by the Input Plugin belonging to a Scene if a pointer is pressed down anywhere outside of the game canvas. + * + * Listen to this event from within a Scene using: `this.input.on('pointerdownoutside', listener)`. + * + * The event hierarchy is as follows: + * + * 1. [GAMEOBJECT_POINTER_DOWN]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_DOWN} + * 2. [GAMEOBJECT_DOWN]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_DOWN} + * 3. [POINTER_DOWN]{@linkcode Phaser.Input.Events#event:POINTER_DOWN} or [POINTER_DOWN_OUTSIDE]{@linkcode Phaser.Input.Events#event:POINTER_DOWN_OUTSIDE} + * + * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop + * the propagation of this event. + */ + const POINTER_DOWN_OUTSIDE: any; + + /** + * The Pointer Move Input Event. + * + * This event is dispatched by the Input Plugin belonging to a Scene if a pointer is moved anywhere. + * + * Listen to this event from within a Scene using: `this.input.on('pointermove', listener)`. + * + * The event hierarchy is as follows: + * + * 1. [GAMEOBJECT_POINTER_MOVE]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_MOVE} + * 2. [GAMEOBJECT_MOVE]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_MOVE} + * 3. [POINTER_MOVE]{@linkcode Phaser.Input.Events#event:POINTER_MOVE} + * + * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop + * the propagation of this event. + */ + const POINTER_MOVE: any; + + /** + * The Pointer Out Input Event. + * + * This event is dispatched by the Input Plugin belonging to a Scene if a pointer moves out of any interactive Game Object. + * + * Listen to this event from within a Scene using: `this.input.on('pointerout', listener)`. + * + * The event hierarchy is as follows: + * + * 1. [GAMEOBJECT_POINTER_OUT]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_OUT} + * 2. [GAMEOBJECT_OUT]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_OUT} + * 3. [POINTER_OUT]{@linkcode Phaser.Input.Events#event:POINTER_OUT} + * + * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop + * the propagation of this event. + */ + const POINTER_OUT: any; + + /** + * The Pointer Over Input Event. + * + * This event is dispatched by the Input Plugin belonging to a Scene if a pointer moves over any interactive Game Object. + * + * Listen to this event from within a Scene using: `this.input.on('pointerover', listener)`. + * + * The event hierarchy is as follows: + * + * 1. [GAMEOBJECT_POINTER_OVER]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_OVER} + * 2. [GAMEOBJECT_OVER]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_OVER} + * 3. [POINTER_OVER]{@linkcode Phaser.Input.Events#event:POINTER_OVER} + * + * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop + * the propagation of this event. + */ + const POINTER_OVER: any; + + /** + * The Pointer Up Input Event. + * + * This event is dispatched by the Input Plugin belonging to a Scene if a pointer is released anywhere. + * + * Listen to this event from within a Scene using: `this.input.on('pointerup', listener)`. + * + * The event hierarchy is as follows: + * + * 1. [GAMEOBJECT_POINTER_UP]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_UP} + * 2. [GAMEOBJECT_UP]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_UP} + * 3. [POINTER_UP]{@linkcode Phaser.Input.Events#event:POINTER_UP} or [POINTER_UP_OUTSIDE]{@linkcode Phaser.Input.Events#event:POINTER_UP_OUTSIDE} + * + * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop + * the propagation of this event. + */ + const POINTER_UP: any; + + /** + * The Pointer Up Outside Input Event. + * + * This event is dispatched by the Input Plugin belonging to a Scene if a pointer is released anywhere outside of the game canvas. + * + * Listen to this event from within a Scene using: `this.input.on('pointerupoutside', listener)`. + * + * The event hierarchy is as follows: + * + * 1. [GAMEOBJECT_POINTER_UP]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_UP} + * 2. [GAMEOBJECT_UP]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_UP} + * 3. [POINTER_UP]{@linkcode Phaser.Input.Events#event:POINTER_UP} or [POINTER_UP_OUTSIDE]{@linkcode Phaser.Input.Events#event:POINTER_UP_OUTSIDE} + * + * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop + * the propagation of this event. + */ + const POINTER_UP_OUTSIDE: any; + + /** + * The Pointer Wheel Input Event. + * + * This event is dispatched by the Input Plugin belonging to a Scene if a pointer has its wheel updated. + * + * Listen to this event from within a Scene using: `this.input.on('wheel', listener)`. + * + * The event hierarchy is as follows: + * + * 1. [GAMEOBJECT_POINTER_WHEEL]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_POINTER_WHEEL} + * 2. [GAMEOBJECT_WHEEL]{@linkcode Phaser.Input.Events#event:GAMEOBJECT_WHEEL} + * 3. [POINTER_WHEEL]{@linkcode Phaser.Input.Events#event:POINTER_WHEEL} + * + * With the top event being dispatched first and then flowing down the list. Note that higher-up event handlers can stop + * the propagation of this event. + */ + const POINTER_WHEEL: any; + + /** + * The Input Plugin Pre-Update Event. + * + * This internal event is dispatched by the Input Plugin at the start of its `preUpdate` method. + * This hook is designed specifically for input plugins, but can also be listened to from user-land code. + */ + const PRE_UPDATE: any; + + /** + * The Input Plugin Shutdown Event. + * + * This internal event is dispatched by the Input Plugin when it shuts down, signalling to all of its systems to shut themselves down. + */ + const SHUTDOWN: any; + + /** + * The Input Plugin Start Event. + * + * This internal event is dispatched by the Input Plugin when it has finished setting-up, + * signalling to all of its internal systems to start. + */ + const START: any; + + /** + * The Input Plugin Update Event. + * + * This internal event is dispatched by the Input Plugin at the start of its `update` method. + * This hook is designed specifically for input plugins, but can also be listened to from user-land code. + */ + const UPDATE: any; + + } + + namespace Gamepad { + /** + * Contains information about a specific Gamepad Axis. + * Axis objects are created automatically by the Gamepad as they are needed. + */ + class Axis { /** - * The original DOM event. + * + * @param pad A reference to the Gamepad that this Axis belongs to. + * @param index The index of this Axis. */ - originalEvent: KeyboardEvent; + constructor(pad: Phaser.Input.Gamepad.Gamepad, index: number); /** - * Can this Key be processed? + * A reference to the Gamepad that this Axis belongs to. */ - enabled: boolean; + pad: Phaser.Input.Gamepad.Gamepad; /** - * The "down" state of the key. This will remain `true` for as long as the keyboard thinks this key is held down. + * An event emitter to use to emit the axis events. */ - isDown: boolean; + events: Phaser.Events.EventEmitter; /** - * The "up" state of the key. This will remain `true` for as long as the keyboard thinks this key is up. + * The index of this Axis. */ - isUp: boolean; + index: number; /** - * The down state of the ALT key, if pressed at the same time as this key. + * The raw axis value, between -1 and 1 with 0 being dead center. + * Use the method `getValue` to get a normalized value with the threshold applied. */ - altKey: boolean; + value: number; /** - * The down state of the CTRL key, if pressed at the same time as this key. + * Movement tolerance threshold below which axis values are ignored in `getValue`. */ - ctrlKey: boolean; + threshold: number; /** - * The down state of the SHIFT key, if pressed at the same time as this key. + * Applies the `threshold` value to the axis and returns it. */ - shiftKey: boolean; + getValue(): number; /** - * The down state of the Meta key, if pressed at the same time as this key. - * On a Mac the Meta Key is the Command key. On Windows keyboards, it's the Windows key. + * Destroys this Axis instance and releases external references it holds. */ - metaKey: boolean; + destroy(): void; + } + + /** + * Contains information about a specific button on a Gamepad. + * Button objects are created automatically by the Gamepad as they are needed. + */ + class Button { /** - * The location of the modifier key. 0 for standard (or unknown), 1 for left, 2 for right, 3 for numpad. + * + * @param pad A reference to the Gamepad that this Button belongs to. + * @param index The index of this Button. */ - location: number; + constructor(pad: Phaser.Input.Gamepad.Gamepad, index: number); /** - * The timestamp when the key was last pressed down. + * A reference to the Gamepad that this Button belongs to. */ - timeDown: number; + pad: Phaser.Input.Gamepad.Gamepad; /** - * The number of milliseconds this key was held down for in the previous down - up sequence. - * This value isn't updated every game step, only when the Key changes state. - * To get the current duration use the `getDuration` method. + * An event emitter to use to emit the button events. */ - duration: number; + events: Phaser.Events.EventEmitter; /** - * The timestamp when the key was last released. + * The index of this Button. */ - timeUp: number; + index: number; /** - * When a key is held down should it continuously fire the `down` event each time it repeats? - * - * By default it will emit the `down` event just once, but if you wish to receive the event - * for each repeat as well, enable this property. + * Between 0 and 1. */ - emitOnRepeat: boolean; + value: number; /** - * If a key is held down this holds down the number of times the key has 'repeated'. + * Can be set for analogue buttons to enable a 'pressure' threshold, + * before a button is considered as being 'pressed'. */ - repeats: number; + threshold: number; /** - * Controls if this Key will continuously emit a `down` event while being held down (true), - * or emit the event just once, on first press, and then skip future events (false). - * @param value Emit `down` events on repeated key down actions, or just once? + * Is the Button being pressed down or not? */ - setEmitOnRepeat(value: boolean): Phaser.Input.Keyboard.Key; + pressed: boolean; /** - * Processes the Key Down action for this Key. - * Called automatically by the Keyboard Plugin. - * @param event The native DOM Keyboard event. + * Destroys this Button instance and releases external references it holds. */ - onDown(event: KeyboardEvent): void; + destroy(): void; - /** - * Processes the Key Up action for this Key. - * Called automatically by the Keyboard Plugin. - * @param event The native DOM Keyboard event. - */ - onUp(event: KeyboardEvent): void; + } + namespace Configs { /** - * Resets this Key object back to its default un-pressed state. + * Tatar SNES USB Controller Gamepad Configuration. + * USB Gamepad (STANDARD GAMEPAD Vendor: 0079 Product: 0011) */ - reset(): Phaser.Input.Keyboard.Key; + var SNES_USB: object; /** - * Returns the duration, in ms, that the Key has been held down for. - * - * If the key is not currently down it will return zero. - * - * The get the duration the Key was held down for in the previous up-down cycle, - * use the `Key.duration` property value instead. + * PlayStation DualShock 4 Gamepad Configuration. + * Sony PlayStation DualShock 4 (v2) wireless controller */ - getDuration(): number; + var DUALSHOCK_4: object; /** - * Removes any bound event handlers and removes local references. + * XBox 360 Gamepad Configuration. */ - destroy(): void; + var XBOX_360: object; } - /** - * Keyboard Codes. - */ - namespace KeyCodes { + namespace Events { /** - * The BACKSPACE key. + * The Gamepad Button Down Event. + * + * This event is dispatched by the Gamepad Plugin when a button has been pressed on any active Gamepad. + * + * Listen to this event from within a Scene using: `this.input.gamepad.on('down', listener)`. + * + * You can also listen for a DOWN event from a Gamepad instance. See the [GAMEPAD_BUTTON_DOWN]{@linkcode Phaser.Input.Gamepad.Events#event:GAMEPAD_BUTTON_DOWN} event for details. */ - var BACKSPACE: integer; + const BUTTON_DOWN: any; /** - * The TAB key. + * The Gamepad Button Up Event. + * + * This event is dispatched by the Gamepad Plugin when a button has been released on any active Gamepad. + * + * Listen to this event from within a Scene using: `this.input.gamepad.on('up', listener)`. + * + * You can also listen for an UP event from a Gamepad instance. See the [GAMEPAD_BUTTON_UP]{@linkcode Phaser.Input.Gamepad.Events#event:GAMEPAD_BUTTON_UP} event for details. */ - var TAB: integer; + const BUTTON_UP: any; /** - * The ENTER key. + * The Gamepad Connected Event. + * + * This event is dispatched by the Gamepad Plugin when a Gamepad has been connected. + * + * Listen to this event from within a Scene using: `this.input.gamepad.once('connected', listener)`. + * + * Note that the browser may require you to press a button on a gamepad before it will allow you to access it, + * this is for security reasons. However, it may also trust the page already, in which case you won't get the + * 'connected' event and instead should check `GamepadPlugin.total` to see if it thinks there are any gamepads + * already connected. */ - var ENTER: integer; + const CONNECTED: any; /** - * The SHIFT key. + * The Gamepad Disconnected Event. + * + * This event is dispatched by the Gamepad Plugin when a Gamepad has been disconnected. + * + * Listen to this event from within a Scene using: `this.input.gamepad.once('disconnected', listener)`. */ - var SHIFT: integer; + const DISCONNECTED: any; /** - * The CTRL key. + * The Gamepad Button Down Event. + * + * This event is dispatched by a Gamepad instance when a button has been pressed on it. + * + * Listen to this event from a Gamepad instance. Once way to get this is from the `pad1`, `pad2`, etc properties on the Gamepad Plugin: + * `this.input.gamepad.pad1.on('down', listener)`. + * + * Note that you will not receive any Gamepad button events until the browser considers the Gamepad as being 'connected'. + * + * You can also listen for a DOWN event from the Gamepad Plugin. See the [BUTTON_DOWN]{@linkcode Phaser.Input.Gamepad.Events#event:BUTTON_DOWN} event for details. */ - var CTRL: integer; + const GAMEPAD_BUTTON_DOWN: any; /** - * The ALT key. + * The Gamepad Button Up Event. + * + * This event is dispatched by a Gamepad instance when a button has been released on it. + * + * Listen to this event from a Gamepad instance. Once way to get this is from the `pad1`, `pad2`, etc properties on the Gamepad Plugin: + * `this.input.gamepad.pad1.on('up', listener)`. + * + * Note that you will not receive any Gamepad button events until the browser considers the Gamepad as being 'connected'. + * + * You can also listen for an UP event from the Gamepad Plugin. See the [BUTTON_UP]{@linkcode Phaser.Input.Gamepad.Events#event:BUTTON_UP} event for details. */ - var ALT: integer; + const GAMEPAD_BUTTON_UP: any; - /** - * The PAUSE key. - */ - var PAUSE: integer; + } + /** + * A single Gamepad. + * + * These are created, updated and managed by the Gamepad Plugin. + */ + class Gamepad extends Phaser.Events.EventEmitter { /** - * The CAPS_LOCK key. + * + * @param manager A reference to the Gamepad Plugin. + * @param pad The Gamepad object, as extracted from GamepadEvent. */ - var CAPS_LOCK: integer; + constructor(manager: Phaser.Input.Gamepad.GamepadPlugin, pad: Phaser.Types.Input.Gamepad.Pad); /** - * The ESC key. + * A reference to the Gamepad Plugin. */ - var ESC: integer; + manager: Phaser.Input.Gamepad.GamepadPlugin; /** - * The SPACE key. + * A reference to the native Gamepad object that is connected to the browser. */ - var SPACE: integer; + pad: any; /** - * The PAGE_UP key. + * A string containing some information about the controller. + * + * This is not strictly specified, but in Firefox it will contain three pieces of information + * separated by dashes (-): two 4-digit hexadecimal strings containing the USB vendor and + * product id of the controller, and the name of the controller as provided by the driver. + * In Chrome it will contain the name of the controller as provided by the driver, + * followed by vendor and product 4-digit hexadecimal strings. */ - var PAGE_UP: integer; + id: string; /** - * The PAGE_DOWN key. + * An integer that is unique for each Gamepad currently connected to the system. + * This can be used to distinguish multiple controllers. + * Note that disconnecting a device and then connecting a new device may reuse the previous index. */ - var PAGE_DOWN: integer; + index: number; /** - * The END key. + * An array of Gamepad Button objects, corresponding to the different buttons available on the Gamepad. */ - var END: integer; + buttons: Phaser.Input.Gamepad.Button[]; /** - * The HOME key. + * An array of Gamepad Axis objects, corresponding to the different axes available on the Gamepad, if any. */ - var HOME: integer; + axes: Phaser.Input.Gamepad.Axis[]; /** - * The LEFT key. + * The Gamepad's Haptic Actuator (Vibration / Rumble support). + * This is highly experimental and only set if both present on the device, + * and exposed by both the hardware and browser. */ - var LEFT: integer; + vibration: GamepadHapticActuator; /** - * The UP key. + * A Vector2 containing the most recent values from the Gamepad's left axis stick. + * This is updated automatically as part of the Gamepad.update cycle. + * The H Axis is mapped to the `Vector2.x` property, and the V Axis to the `Vector2.y` property. + * The values are based on the Axis thresholds. + * If the Gamepad does not have a left axis stick, the values will always be zero. */ - var UP: integer; + leftStick: Phaser.Math.Vector2; /** - * The RIGHT key. + * A Vector2 containing the most recent values from the Gamepad's right axis stick. + * This is updated automatically as part of the Gamepad.update cycle. + * The H Axis is mapped to the `Vector2.x` property, and the V Axis to the `Vector2.y` property. + * The values are based on the Axis thresholds. + * If the Gamepad does not have a right axis stick, the values will always be zero. */ - var RIGHT: integer; + rightStick: Phaser.Math.Vector2; /** - * The DOWN key. + * Gets the total number of axis this Gamepad claims to support. */ - var DOWN: integer; + getAxisTotal(): number; /** - * The PRINT_SCREEN key. + * Gets the value of an axis based on the given index. + * The index must be valid within the range of axes supported by this Gamepad. + * The return value will be a float between 0 and 1. + * @param index The index of the axes to get the value for. */ - var PRINT_SCREEN: integer; + getAxisValue(index: number): number; /** - * The INSERT key. + * Sets the threshold value of all axis on this Gamepad. + * The value is a float between 0 and 1 and is the amount below which the axis is considered as not having been moved. + * @param value A value between 0 and 1. */ - var INSERT: integer; + setAxisThreshold(value: number): void; /** - * The DELETE key. + * Gets the total number of buttons this Gamepad claims to have. */ - var DELETE: integer; + getButtonTotal(): number; /** - * The ZERO key. + * Gets the value of a button based on the given index. + * The index must be valid within the range of buttons supported by this Gamepad. + * + * The return value will be either 0 or 1 for an analogue button, or a float between 0 and 1 + * for a pressure-sensitive digital button, such as the shoulder buttons on a Dual Shock. + * @param index The index of the button to get the value for. */ - var ZERO: integer; + getButtonValue(index: number): number; /** - * The ONE key. + * Returns if the button is pressed down or not. + * The index must be valid within the range of buttons supported by this Gamepad. + * @param index The index of the button to get the value for. */ - var ONE: integer; + isButtonDown(index: number): boolean; /** - * The TWO key. + * Destroys this Gamepad instance, its buttons and axes, and releases external references it holds. */ - var TWO: integer; + destroy(): void; /** - * The THREE key. + * Is this Gamepad currently connected or not? */ - var THREE: integer; + connected: boolean; /** - * The FOUR key. + * A timestamp containing the most recent time this Gamepad was updated. */ - var FOUR: integer; + timestamp: number; /** - * The FIVE key. + * Is the Gamepad's Left button being pressed? + * If the Gamepad doesn't have this button it will always return false. + * This is the d-pad left button under standard Gamepad mapping. */ - var FIVE: integer; + left: boolean; /** - * The SIX key. + * Is the Gamepad's Right button being pressed? + * If the Gamepad doesn't have this button it will always return false. + * This is the d-pad right button under standard Gamepad mapping. */ - var SIX: integer; + right: boolean; /** - * The SEVEN key. + * Is the Gamepad's Up button being pressed? + * If the Gamepad doesn't have this button it will always return false. + * This is the d-pad up button under standard Gamepad mapping. */ - var SEVEN: integer; + up: boolean; /** - * The EIGHT key. + * Is the Gamepad's Down button being pressed? + * If the Gamepad doesn't have this button it will always return false. + * This is the d-pad down button under standard Gamepad mapping. */ - var EIGHT: integer; + down: boolean; /** - * The NINE key. + * Is the Gamepad's bottom button in the right button cluster being pressed? + * If the Gamepad doesn't have this button it will always return false. + * On a Dual Shock controller it's the X button. + * On an XBox controller it's the A button. */ - var NINE: integer; + A: boolean; /** - * The NUMPAD_ZERO key. + * Is the Gamepad's top button in the right button cluster being pressed? + * If the Gamepad doesn't have this button it will always return false. + * On a Dual Shock controller it's the Triangle button. + * On an XBox controller it's the Y button. */ - var NUMPAD_ZERO: integer; + Y: boolean; /** - * The NUMPAD_ONE key. + * Is the Gamepad's left button in the right button cluster being pressed? + * If the Gamepad doesn't have this button it will always return false. + * On a Dual Shock controller it's the Square button. + * On an XBox controller it's the X button. */ - var NUMPAD_ONE: integer; + X: boolean; /** - * The NUMPAD_TWO key. + * Is the Gamepad's right button in the right button cluster being pressed? + * If the Gamepad doesn't have this button it will always return false. + * On a Dual Shock controller it's the Circle button. + * On an XBox controller it's the B button. */ - var NUMPAD_TWO: integer; + B: boolean; /** - * The NUMPAD_THREE key. + * Returns the value of the Gamepad's top left shoulder button. + * If the Gamepad doesn't have this button it will always return zero. + * The value is a float between 0 and 1, corresponding to how depressed the button is. + * On a Dual Shock controller it's the L1 button. + * On an XBox controller it's the LB button. */ - var NUMPAD_THREE: integer; + L1: number; /** - * The NUMPAD_FOUR key. + * Returns the value of the Gamepad's bottom left shoulder button. + * If the Gamepad doesn't have this button it will always return zero. + * The value is a float between 0 and 1, corresponding to how depressed the button is. + * On a Dual Shock controller it's the L2 button. + * On an XBox controller it's the LT button. */ - var NUMPAD_FOUR: integer; + L2: number; /** - * The NUMPAD_FIVE key. + * Returns the value of the Gamepad's top right shoulder button. + * If the Gamepad doesn't have this button it will always return zero. + * The value is a float between 0 and 1, corresponding to how depressed the button is. + * On a Dual Shock controller it's the R1 button. + * On an XBox controller it's the RB button. */ - var NUMPAD_FIVE: integer; + R1: number; /** - * The NUMPAD_SIX key. + * Returns the value of the Gamepad's bottom right shoulder button. + * If the Gamepad doesn't have this button it will always return zero. + * The value is a float between 0 and 1, corresponding to how depressed the button is. + * On a Dual Shock controller it's the R2 button. + * On an XBox controller it's the RT button. */ - var NUMPAD_SIX: integer; + R2: number; - /** - * The NUMPAD_SEVEN key. - */ - var NUMPAD_SEVEN: integer; + } + /** + * The Gamepad Plugin is an input plugin that belongs to the Scene-owned Input system. + * + * Its role is to listen for native DOM Gamepad Events and then process them. + * + * You do not need to create this class directly, the Input system will create an instance of it automatically. + * + * You can access it from within a Scene using `this.input.gamepad`. + * + * To listen for a gamepad being connected: + * + * ```javascript + * this.input.gamepad.once('connected', function (pad) { + * // 'pad' is a reference to the gamepad that was just connected + * }); + * ``` + * + * Note that the browser may require you to press a button on a gamepad before it will allow you to access it, + * this is for security reasons. However, it may also trust the page already, in which case you won't get the + * 'connected' event and instead should check `GamepadPlugin.total` to see if it thinks there are any gamepads + * already connected. + * + * Once you have received the connected event, or polled the gamepads and found them enabled, you can access + * them via the built-in properties `GamepadPlugin.pad1` to `pad4`, for up to 4 game pads. With a reference + * to the gamepads you can poll its buttons and axis sticks. See the properties and methods available on + * the `Gamepad` class for more details. + * + * As of September 2020 Chrome, and likely other browsers, will soon start to require that games requesting + * access to the Gamepad API are running under SSL. They will actively block API access if they are not. + * + * For more information about Gamepad support in browsers see the following resources: + * + * https://developer.mozilla.org/en-US/docs/Web/API/Gamepad_API + * https://developer.mozilla.org/en-US/docs/Web/API/Gamepad_API/Using_the_Gamepad_API + * https://www.smashingmagazine.com/2015/11/gamepad-api-in-web-games/ + * http://html5gamepad.com/ + */ + class GamepadPlugin extends Phaser.Events.EventEmitter { /** - * The NUMPAD_EIGHT key. + * + * @param sceneInputPlugin A reference to the Scene Input Plugin that the KeyboardPlugin belongs to. */ - var NUMPAD_EIGHT: integer; + constructor(sceneInputPlugin: Phaser.Input.InputPlugin); /** - * The NUMPAD_NINE key. + * A reference to the Scene that this Input Plugin is responsible for. */ - var NUMPAD_NINE: integer; + scene: Phaser.Scene; /** - * The Numpad Addition (+) key. + * A reference to the Scene Systems Settings. */ - var NUMPAD_ADD: integer; + settings: Phaser.Types.Scenes.SettingsObject; /** - * The Numpad Subtraction (-) key. + * A reference to the Scene Input Plugin that created this Keyboard Plugin. */ - var NUMPAD_SUBTRACT: integer; + sceneInputPlugin: Phaser.Input.InputPlugin; /** - * The A key. + * A boolean that controls if the Gamepad Manager is enabled or not. + * Can be toggled on the fly. */ - var A: integer; + enabled: boolean; /** - * The B key. + * The Gamepad Event target, as defined in the Game Config. + * Typically the browser window, but can be any interactive DOM element. */ - var B: integer; + target: any; /** - * The C key. + * An array of the connected Gamepads. */ - var C: integer; + gamepads: Phaser.Input.Gamepad.Gamepad[]; /** - * The D key. + * Checks to see if both this plugin and the Scene to which it belongs is active. */ - var D: integer; + isActive(): boolean; /** - * The E key. + * Disconnects all current Gamepads. */ - var E: integer; + disconnectAll(): void; /** - * The F key. + * Returns an array of all currently connected Gamepads. */ - var F: integer; + getAll(): Phaser.Input.Gamepad.Gamepad[]; /** - * The G key. + * Looks-up a single Gamepad based on the given index value. + * @param index The index of the Gamepad to get. */ - var G: integer; + getPad(index: number): Phaser.Input.Gamepad.Gamepad; /** - * The H key. + * The total number of connected game pads. */ - var H: integer; + total: number; /** - * The I key. + * A reference to the first connected Gamepad. + * + * This will be undefined if either no pads are connected, or the browser + * has not yet issued a gamepadconnect, which can happen even if a Gamepad + * is plugged in, but hasn't yet had any buttons pressed on it. */ - var I: integer; + pad1: Phaser.Input.Gamepad.Gamepad; /** - * The J key. + * A reference to the second connected Gamepad. + * + * This will be undefined if either no pads are connected, or the browser + * has not yet issued a gamepadconnect, which can happen even if a Gamepad + * is plugged in, but hasn't yet had any buttons pressed on it. */ - var J: integer; + pad2: Phaser.Input.Gamepad.Gamepad; /** - * The K key. + * A reference to the third connected Gamepad. + * + * This will be undefined if either no pads are connected, or the browser + * has not yet issued a gamepadconnect, which can happen even if a Gamepad + * is plugged in, but hasn't yet had any buttons pressed on it. */ - var K: integer; + pad3: Phaser.Input.Gamepad.Gamepad; /** - * The L key. + * A reference to the fourth connected Gamepad. + * + * This will be undefined if either no pads are connected, or the browser + * has not yet issued a gamepadconnect, which can happen even if a Gamepad + * is plugged in, but hasn't yet had any buttons pressed on it. */ - var L: integer; + pad4: Phaser.Input.Gamepad.Gamepad; - /** - * The M key. - */ - var M: integer; + } - /** - * The N key. - */ - var N: integer; + } - /** - * The O key. - */ - var O: integer; + /** + * The Input Manager is responsible for handling the pointer related systems in a single Phaser Game instance. + * + * Based on the Game Config it will create handlers for mouse and touch support. + * + * Keyboard and Gamepad are plugins, handled directly by the InputPlugin class. + * + * It then manages the events, pointer creation and general hit test related operations. + * + * You rarely need to interact with the Input Manager directly, and as such, all of its properties and methods + * should be considered private. Instead, you should use the Input Plugin, which is a Scene level system, responsible + * for dealing with all input events for a Scene. + */ + class InputManager { + /** + * + * @param game The Game instance that owns the Input Manager. + * @param config The Input Configuration object, as set in the Game Config. + */ + constructor(game: Phaser.Game, config: object); - /** - * The P key. - */ - var P: integer; + /** + * The Game instance that owns the Input Manager. + * A Game only maintains on instance of the Input Manager at any time. + */ + readonly game: Phaser.Game; - /** - * The Q key. - */ - var Q: integer; + /** + * A reference to the global Game Scale Manager. + * Used for all bounds checks and pointer scaling. + */ + scaleManager: Phaser.Scale.ScaleManager; - /** - * The R key. - */ - var R: integer; + /** + * The Canvas that is used for all DOM event input listeners. + */ + canvas: HTMLCanvasElement; - /** - * The S key. - */ - var S: integer; + /** + * The Game Configuration object, as set during the game boot. + */ + config: Phaser.Core.Config; - /** - * The T key. - */ - var T: integer; + /** + * If set, the Input Manager will run its update loop every frame. + */ + enabled: boolean; - /** - * The U key. - */ - var U: integer; + /** + * The Event Emitter instance that the Input Manager uses to emit events from. + */ + events: Phaser.Events.EventEmitter; - /** - * The V key. - */ - var V: integer; + /** + * Are any mouse or touch pointers currently over the game canvas? + * This is updated automatically by the canvas over and out handlers. + */ + readonly isOver: boolean; - /** - * The W key. - */ - var W: integer; + /** + * The default CSS cursor to be used when interacting with your game. + * + * See the `setDefaultCursor` method for more details. + */ + defaultCursor: string; - /** - * The X key. - */ - var X: integer; + /** + * A reference to the Keyboard Manager class, if enabled via the `input.keyboard` Game Config property. + */ + keyboard: Phaser.Input.Keyboard.KeyboardManager; - /** - * The Y key. - */ - var Y: integer; + /** + * A reference to the Mouse Manager class, if enabled via the `input.mouse` Game Config property. + */ + mouse: Phaser.Input.Mouse.MouseManager; - /** - * The Z key. - */ - var Z: integer; + /** + * A reference to the Touch Manager class, if enabled via the `input.touch` Game Config property. + */ + touch: Phaser.Input.Touch.TouchManager; - /** - * The F1 key. - */ - var F1: integer; + /** + * An array of Pointers that have been added to the game. + * The first entry is reserved for the Mouse Pointer, the rest are Touch Pointers. + * + * By default there is 1 touch pointer enabled. If you need more use the `addPointer` method to start them, + * or set the `input.activePointers` property in the Game Config. + */ + pointers: Phaser.Input.Pointer[]; - /** - * The F2 key. - */ - var F2: integer; + /** + * The number of touch objects activated and being processed each update. + * + * You can change this by either calling `addPointer` at run-time, or by + * setting the `input.activePointers` property in the Game Config. + */ + readonly pointersTotal: number; - /** - * The F3 key. - */ - var F3: integer; + /** + * The mouse has its own unique Pointer object, which you can reference directly if making a _desktop specific game_. + * If you are supporting both desktop and touch devices then do not use this property, instead use `activePointer` + * which will always map to the most recently interacted pointer. + */ + mousePointer: Phaser.Input.Pointer; - /** - * The F4 key. - */ - var F4: integer; - - /** - * The F5 key. - */ - var F5: integer; - - /** - * The F6 key. - */ - var F6: integer; - - /** - * The F7 key. - */ - var F7: integer; - - /** - * The F8 key. - */ - var F8: integer; - - /** - * The F9 key. - */ - var F9: integer; - - /** - * The F10 key. - */ - var F10: integer; - - /** - * The F11 key. - */ - var F11: integer; - - /** - * The F12 key. - */ - var F12: integer; - - /** - * The SEMICOLON key. - */ - var SEMICOLON: integer; - - /** - * The PLUS key. - */ - var PLUS: integer; - - /** - * The COMMA key. - */ - var COMMA: integer; - - /** - * The MINUS key. - */ - var MINUS: integer; - - /** - * The PERIOD key. - */ - var PERIOD: integer; - - /** - * The FORWARD_SLASH key. - */ - var FORWARD_SLASH: integer; - - /** - * The BACK_SLASH key. - */ - var BACK_SLASH: integer; - - /** - * The QUOTES key. - */ - var QUOTES: integer; - - /** - * The BACKTICK key. - */ - var BACKTICK: integer; - - /** - * The OPEN_BRACKET key. - */ - var OPEN_BRACKET: integer; - - /** - * The CLOSED_BRACKET key. - */ - var CLOSED_BRACKET: integer; - - /** - * The SEMICOLON_FIREFOX key. - */ - var SEMICOLON_FIREFOX: integer; - - /** - * The COLON key. - */ - var COLON: integer; - - /** - * The COMMA_FIREFOX_WINDOWS key. - */ - var COMMA_FIREFOX_WINDOWS: integer; - - /** - * The COMMA_FIREFOX key. - */ - var COMMA_FIREFOX: integer; - - /** - * The BRACKET_RIGHT_FIREFOX key. - */ - var BRACKET_RIGHT_FIREFOX: integer; - - /** - * The BRACKET_LEFT_FIREFOX key. - */ - var BRACKET_LEFT_FIREFOX: integer; + /** + * The most recently active Pointer object. + * + * If you've only 1 Pointer in your game then this will accurately be either the first finger touched, or the mouse. + * + * If your game doesn't need to support multi-touch then you can safely use this property in all of your game + * code and it will adapt to be either the mouse or the touch, based on device. + */ + activePointer: Phaser.Input.Pointer; - } + /** + * If the top-most Scene in the Scene List receives an input it will stop input from + * propagating any lower down the scene list, i.e. if you have a UI Scene at the top + * and click something on it, that click will not then be passed down to any other + * Scene below. Disable this to have input events passed through all Scenes, all the time. + */ + globalTopOnly: boolean; /** - * Returns `true` if the Key was released within the `duration` value given, based on the current - * game clock time. Or returns `false` if it either isn't up, or was released longer ago than the given duration. - * @param key The Key object to test. - * @param duration The duration, in ms, within which the key must have been released. Default 50. + * The time this Input Manager was last updated. + * This value is populated by the Game Step each frame. */ - function UpDuration(key: Phaser.Input.Keyboard.Key, duration?: integer): boolean; + readonly time: number; - } + /** + * The Boot handler is called by Phaser.Game when it first starts up. + * The renderer is available by now. + */ + protected boot(): void; - namespace Mouse { /** - * The Mouse Manager is a helper class that belongs to the Input Manager. + * Tells the Input system to set a custom cursor. * - * Its role is to listen for native DOM Mouse Events and then pass them onto the Input Manager for further processing. + * This cursor will be the default cursor used when interacting with the game canvas. * - * You do not need to create this class directly, the Input Manager will create an instance of it automatically. + * If an Interactive Object also sets a custom cursor, this is the cursor that is reset after its use. + * + * Any valid CSS cursor value is allowed, including paths to image files, i.e.: + * + * ```javascript + * this.input.setDefaultCursor('url(assets/cursors/sword.cur), pointer'); + * ``` + * + * Please read about the differences between browsers when it comes to the file formats and sizes they support: + * + * https://developer.mozilla.org/en-US/docs/Web/CSS/cursor + * https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_User_Interface/Using_URL_values_for_the_cursor_property + * + * It's up to you to pick a suitable cursor format that works across the range of browsers you need to support. + * @param cursor The CSS to be used when setting the default cursor. */ - class MouseManager { - /** - * - * @param inputManager A reference to the Input Manager. - */ - constructor(inputManager: Phaser.Input.InputManager); - - /** - * A reference to the Input Manager. - */ - manager: Phaser.Input.InputManager; - - /** - * If true the DOM mouse events will have event.preventDefault applied to them, if false they will propagate fully. - */ - capture: boolean; - - /** - * A boolean that controls if the Mouse Manager is enabled or not. - * Can be toggled on the fly. - */ - enabled: boolean; - - /** - * The Mouse target, as defined in the Game Config. - * Typically the canvas to which the game is rendering, but can be any interactive DOM element. - */ - target: any; - - /** - * If the mouse has been pointer locked successfully this will be set to true. - */ - locked: boolean; - - /** - * The Mouse Move Event handler. - * This function is sent the native DOM MouseEvent. - * Initially empty and bound in the `startListeners` method. - */ - onMouseMove: Function; - - /** - * The Mouse Down Event handler. - * This function is sent the native DOM MouseEvent. - * Initially empty and bound in the `startListeners` method. - */ - onMouseDown: Function; - - /** - * The Mouse Up Event handler. - * This function is sent the native DOM MouseEvent. - * Initially empty and bound in the `startListeners` method. - */ - onMouseUp: Function; - - /** - * The Mouse Down Event handler specifically for events on the Window. - * This function is sent the native DOM MouseEvent. - * Initially empty and bound in the `startListeners` method. - */ - onMouseDownWindow: Function; - - /** - * The Mouse Up Event handler specifically for events on the Window. - * This function is sent the native DOM MouseEvent. - * Initially empty and bound in the `startListeners` method. - */ - onMouseUpWindow: Function; - - /** - * The Mouse Over Event handler. - * This function is sent the native DOM MouseEvent. - * Initially empty and bound in the `startListeners` method. - */ - onMouseOver: Function; - - /** - * The Mouse Out Event handler. - * This function is sent the native DOM MouseEvent. - * Initially empty and bound in the `startListeners` method. - */ - onMouseOut: Function; - - /** - * The Mouse Wheel Event handler. - * This function is sent the native DOM MouseEvent. - * Initially empty and bound in the `startListeners` method. - */ - onMouseWheel: Function; - - /** - * Internal pointerLockChange handler. - * This function is sent the native DOM MouseEvent. - * Initially empty and bound in the `startListeners` method. - */ - pointerLockChange: Function; + setDefaultCursor(cursor: string): void; - /** - * Attempts to disable the context menu from appearing if you right-click on the browser. - * - * Works by listening for the `contextmenu` event and prevent defaulting it. - * - * Use this if you need to enable right-button mouse support in your game, and the browser - * menu keeps getting in the way. - */ - disableContextMenu(): Phaser.Input.Mouse.MouseManager; + /** + * Adds new Pointer objects to the Input Manager. + * + * By default Phaser creates 2 pointer objects: `mousePointer` and `pointer1`. + * + * You can create more either by calling this method, or by setting the `input.activePointers` property + * in the Game Config, up to a maximum of 10 pointers. + * + * The first 10 pointers are available via the `InputPlugin.pointerX` properties, once they have been added + * via this method. + * @param quantity The number of new Pointers to create. A maximum of 10 is allowed in total. Default 1. + */ + addPointer(quantity?: number): Phaser.Input.Pointer[]; - /** - * If the browser supports it, you can request that the pointer be locked to the browser window. - * - * This is classically known as 'FPS controls', where the pointer can't leave the browser until - * the user presses an exit key. - * - * If the browser successfully enters a locked state, a `POINTER_LOCK_CHANGE_EVENT` will be dispatched, - * from the games Input Manager, with an `isPointerLocked` property. - * - * It is important to note that pointer lock can only be enabled after an 'engagement gesture', - * see: https://w3c.github.io/pointerlock/#dfn-engagement-gesture. - */ - requestPointerLock(): void; + /** + * Internal method that gets a list of all the active Input Plugins in the game + * and updates each of them in turn, in reverse order (top to bottom), to allow + * for DOM top-level event handling simulation. + * @param type The type of event to process. + * @param pointers An array of Pointers on which the event occurred. + */ + updateInputPlugins(type: number, pointers: Phaser.Input.Pointer[]): void; - /** - * If the browser supports pointer lock, this will request that the pointer lock is released. If - * the browser successfully enters a locked state, a 'POINTER_LOCK_CHANGE_EVENT' will be - * dispatched - from the game's input manager - with an `isPointerLocked` property. - */ - releasePointerLock(): void; + /** + * Performs a hit test using the given Pointer and camera, against an array of interactive Game Objects. + * + * The Game Objects are culled against the camera, and then the coordinates are translated into the local camera space + * and used to determine if they fall within the remaining Game Objects hit areas or not. + * + * If nothing is matched an empty array is returned. + * + * This method is called automatically by InputPlugin.hitTestPointer and doesn't usually need to be invoked directly. + * @param pointer The Pointer to test against. + * @param gameObjects An array of interactive Game Objects to check. + * @param camera The Camera which is being tested against. + * @param output An array to store the results in. If not given, a new empty array is created. + */ + hitTest(pointer: Phaser.Input.Pointer, gameObjects: any[], camera: Phaser.Cameras.Scene2D.Camera, output?: any[]): any[]; - /** - * Starts the Mouse Event listeners running. - * This is called automatically and does not need to be manually invoked. - */ - startListeners(): void; + /** + * Checks if the given x and y coordinate are within the hit area of the Game Object. + * + * This method assumes that the coordinate values have already been translated into the space of the Game Object. + * + * If the coordinates are within the hit area they are set into the Game Objects Input `localX` and `localY` properties. + * @param gameObject The interactive Game Object to check against. + * @param x The translated x coordinate for the hit test. + * @param y The translated y coordinate for the hit test. + */ + pointWithinHitArea(gameObject: Phaser.GameObjects.GameObject, x: number, y: number): boolean; - /** - * Stops the Mouse Event listeners. - * This is called automatically and does not need to be manually invoked. - */ - stopListeners(): void; + /** + * Checks if the given x and y coordinate are within the hit area of the Interactive Object. + * + * This method assumes that the coordinate values have already been translated into the space of the Interactive Object. + * + * If the coordinates are within the hit area they are set into the Interactive Objects Input `localX` and `localY` properties. + * @param object The Interactive Object to check against. + * @param x The translated x coordinate for the hit test. + * @param y The translated y coordinate for the hit test. + */ + pointWithinInteractiveObject(object: Phaser.Types.Input.InteractiveObject, x: number, y: number): boolean; - /** - * Destroys this Mouse Manager instance. - */ - destroy(): void; + /** + * Transforms the pageX and pageY values of a Pointer into the scaled coordinate space of the Input Manager. + * @param pointer The Pointer to transform the values for. + * @param pageX The Page X value. + * @param pageY The Page Y value. + * @param wasMove Are we transforming the Pointer from a move event, or an up / down event? + */ + transformPointer(pointer: Phaser.Input.Pointer, pageX: number, pageY: number, wasMove: boolean): void; - } + /** + * Destroys the Input Manager and all of its systems. + * + * There is no way to recover from doing this. + */ + destroy(): void; } /** - * A Pointer object encapsulates both mouse and touch input within Phaser. + * The Input Plugin belongs to a Scene and handles all input related events and operations for it. * - * By default, Phaser will create 2 pointers for your game to use. If you require more, i.e. for a multi-touch - * game, then use the `InputPlugin.addPointer` method to do so, rather than instantiating this class directly, - * otherwise it won't be managed by the input system. + * You can access it from within a Scene using `this.input`. * - * You can reference the current active pointer via `InputPlugin.activePointer`. You can also use the properties - * `InputPlugin.pointer1` through to `pointer10`, for each pointer you have enabled in your game. + * It emits events directly. For example, you can do: * - * The properties of this object are set by the Input Plugin during processing. This object is then sent in all - * input related events that the Input Plugin emits, so you can reference properties from it directly in your - * callbacks. + * ```javascript + * this.input.on('pointerdown', callback, context); + * ``` + * + * To listen for a pointer down event anywhere on the game canvas. + * + * Game Objects can be enabled for input by calling their `setInteractive` method. After which they + * will directly emit input events: + * + * ```javascript + * var sprite = this.add.sprite(x, y, texture); + * sprite.setInteractive(); + * sprite.on('pointerdown', callback, context); + * ``` + * + * There are lots of game configuration options available relating to input. + * See the [Input Config object]{@linkcode Phaser.Types.Core.InputConfig} for more details, including how to deal with Phaser + * listening for input events outside of the canvas, how to set a default number of pointers, input + * capture settings and more. + * + * Please also see the Input examples and tutorials for further information. + * + * **Incorrect input coordinates with Angular** + * + * If you are using Phaser within Angular, and use nglf or the router, to make the component in which the Phaser game resides + * change state (i.e. appear or disappear) then you'll need to notify the Scale Manager about this, as Angular will mess with + * the DOM in a way in which Phaser can't detect directly. Call `this.scale.updateBounds()` as part of your game init in order + * to refresh the canvas DOM bounds values, which Phaser uses for input point position calculations. */ - class Pointer { + class InputPlugin extends Phaser.Events.EventEmitter { /** * - * @param manager A reference to the Input Manager. - * @param id The internal ID of this Pointer. + * @param scene A reference to the Scene that this Input Plugin is responsible for. */ - constructor(manager: Phaser.Input.InputManager, id: integer); + constructor(scene: Phaser.Scene); /** - * A reference to the Input Manager. + * An instance of the Gamepad Plugin class, if enabled via the `input.gamepad` Scene or Game Config property. + * Use this to create access Gamepads connected to the browser and respond to gamepad buttons. */ - manager: Phaser.Input.InputManager; + gamepad: Phaser.Input.Gamepad.GamepadPlugin; /** - * The internal ID of this Pointer. + * A reference to the Scene that this Input Plugin is responsible for. */ - readonly id: integer; + scene: Phaser.Scene; /** - * The most recent native DOM Event this Pointer has processed. + * A reference to the Scene Systems class. */ - event: TouchEvent | MouseEvent; + systems: Phaser.Scenes.Systems; /** - * The DOM element the Pointer was pressed down on, taken from the DOM event. - * In a default set-up this will be the Canvas that Phaser is rendering to, or the Window element. + * A reference to the Scene Systems Settings. */ - readonly downElement: any; + settings: Phaser.Types.Scenes.SettingsObject; /** - * The DOM element the Pointer was released on, taken from the DOM event. - * In a default set-up this will be the Canvas that Phaser is rendering to, or the Window element. + * A reference to the Game Input Manager. */ - readonly upElement: any; + manager: Phaser.Input.InputManager; /** - * The camera the Pointer interacted with during its last update. - * - * A Pointer can only ever interact with one camera at once, which will be the top-most camera - * in the list should multiple cameras be positioned on-top of each other. + * If `true` this Input Plugin will process DOM input events. */ - camera: Phaser.Cameras.Scene2D.Camera; + enabled: boolean; /** - * A read-only property that indicates which button was pressed, or released, on the pointer - * during the most recent event. It is only set during `up` and `down` events. - * - * On Touch devices the value is always 0. - * - * Users may change the configuration of buttons on their pointing device so that if an event's button property - * is zero, it may not have been caused by the button that is physically left–most on the pointing device; - * however, it should behave as if the left button was clicked in the standard button layout. + * A reference to the Scene Display List. This property is set during the `boot` method. */ - readonly button: integer; + displayList: Phaser.GameObjects.DisplayList; /** - * 0: No button or un-initialized - * 1: Left button - * 2: Right button - * 4: Wheel button or middle button - * 8: 4th button (typically the "Browser Back" button) - * 16: 5th button (typically the "Browser Forward" button) - * - * For a mouse configured for left-handed use, the button actions are reversed. - * In this case, the values are read from right to left. + * A reference to the Scene Cameras Manager. This property is set during the `boot` method. */ - buttons: integer; + cameras: Phaser.Cameras.Scene2D.CameraManager; /** - * The position of the Pointer in screen space. + * A reference to the Mouse Manager. + * + * This property is only set if Mouse support has been enabled in your Game Configuration file. + * + * If you just wish to get access to the mouse pointer, use the `mousePointer` property instead. */ - readonly position: Phaser.Math.Vector2; + mouse: Phaser.Input.Mouse.MouseManager; /** - * The previous position of the Pointer in screen space. - * - * The old x and y values are stored in here during the InputManager.transformPointer call. + * When set to `true` (the default) the Input Plugin will emulate DOM behavior by only emitting events from + * the top-most Game Objects in the Display List. * - * Use the properties `velocity`, `angle` and `distance` to create your own gesture recognition. + * If set to `false` it will emit events from all Game Objects below a Pointer, not just the top one. */ - readonly prevPosition: Phaser.Math.Vector2; + topOnly: boolean; /** - * The current velocity of the Pointer, based on its current and previous positions. + * How often should the Pointers be checked? * - * This value is smoothed out each frame, according to the `motionFactor` property. + * The value is a time, given in ms, and is the time that must have elapsed between game steps before + * the Pointers will be polled again. When a pointer is polled it runs a hit test to see which Game + * Objects are currently below it, or being interacted with it. * - * This property is updated whenever the Pointer moves, regardless of any button states. In other words, - * it changes based on movement alone - a button doesn't have to be pressed first. + * Pointers will *always* be checked if they have been moved by the user, or press or released. + * + * This property only controls how often they will be polled if they have not been updated. + * You should set this if you want to have Game Objects constantly check against the pointers, even + * if the pointer didn't itself move. + * + * Set to 0 to poll constantly. Set to -1 to only poll on user movement. */ - readonly velocity: Phaser.Math.Vector2; + pollRate: number; /** - * The current angle the Pointer is moving, in radians, based on its previous and current position. - * - * The angle is based on the old position facing to the current position. - * - * This property is updated whenever the Pointer moves, regardless of any button states. In other words, - * it changes based on movement alone - a button doesn't have to be pressed first. + * The distance, in pixels, a pointer has to move while being held down, before it thinks it is being dragged. */ - readonly angle: number; + dragDistanceThreshold: number; /** - * The distance the Pointer has moved, based on its previous and current position. - * - * This value is smoothed out each frame, according to the `motionFactor` property. - * - * This property is updated whenever the Pointer moves, regardless of any button states. In other words, - * it changes based on movement alone - a button doesn't have to be pressed first. + * The amount of time, in ms, a pointer has to be held down before it thinks it is dragging. * - * If you need the total distance travelled since the primary buttons was pressed down, - * then use the `Pointer.getDistance` method. + * The default polling rate is to poll only on move so once the time threshold is reached the + * drag event will not start until you move the mouse. If you want it to start immediately + * when the time threshold is reached, you must increase the polling rate by calling + * [setPollAlways]{@linkcode Phaser.Input.InputPlugin#setPollAlways} or + * [setPollRate]{@linkcode Phaser.Input.InputPlugin#setPollRate}. */ - readonly distance: number; + dragTimeThreshold: number; /** - * The smoothing factor to apply to the Pointer position. - * - * Due to their nature, pointer positions are inherently noisy. While this is fine for lots of games, if you need cleaner positions - * then you can set this value to apply an automatic smoothing to the positions as they are recorded. - * - * The default value of zero means 'no smoothing'. - * Set to a small value, such as 0.2, to apply an average level of smoothing between positions. You can do this by changing this - * value directly, or by setting the `input.smoothFactor` property in the Game Config. - * - * Positions are only smoothed when the pointer moves. If the primary button on this Pointer enters an Up or Down state, then the position - * is always precise, and not smoothed. + * Checks to see if both this plugin and the Scene to which it belongs is active. */ - smoothFactor: number; + isActive(): boolean; /** - * The factor applied to the motion smoothing each frame. - * - * This value is passed to the Smooth Step Interpolation that is used to calculate the velocity, - * angle and distance of the Pointer. It's applied every frame, until the midPoint reaches the current - * position of the Pointer. 0.2 provides a good average but can be increased if you need a - * quicker update and are working in a high performance environment. Never set this value to - * zero. + * This is called automatically by the Input Manager. + * It emits events for plugins to listen to and also handles polling updates, if enabled. + * @param time The current time. Either a High Resolution Timer value if it comes from Request Animation Frame, or Date.now if using SetTimeout. + * @param delta The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate. */ - motionFactor: number; + updatePoll(time: number, delta: number): boolean; /** - * The x position of this Pointer, translated into the coordinate space of the most recent Camera it interacted with. - * - * If you wish to use this value _outside_ of an input event handler then you should update it first by calling - * the `Pointer.updateWorldPoint` method. + * Clears a Game Object so it no longer has an Interactive Object associated with it. + * The Game Object is then queued for removal from the Input Plugin on the next update. + * @param gameObject The Game Object that will have its Interactive Object removed. + * @param skipQueue Skip adding this Game Object into the removal queue? Default false. */ - worldX: number; + clear(gameObject: Phaser.GameObjects.GameObject, skipQueue?: boolean): Phaser.GameObjects.GameObject; /** - * The y position of this Pointer, translated into the coordinate space of the most recent Camera it interacted with. + * Disables Input on a single Game Object. * - * If you wish to use this value _outside_ of an input event handler then you should update it first by calling - * the `Pointer.updateWorldPoint` method. + * An input disabled Game Object still retains its Interactive Object component and can be re-enabled + * at any time, by passing it to `InputPlugin.enable`. + * @param gameObject The Game Object to have its input system disabled. */ - worldY: number; + disable(gameObject: Phaser.GameObjects.GameObject): void; /** - * Time when this Pointer was most recently moved (regardless of the state of its buttons, if any) + * Enable a Game Object for interaction. + * + * If the Game Object already has an Interactive Object component, it is enabled and returned. + * + * Otherwise, a new Interactive Object component is created and assigned to the Game Object's `input` property. + * + * Input works by using hit areas, these are nearly always geometric shapes, such as rectangles or circles, that act as the hit area + * for the Game Object. However, you can provide your own hit area shape and callback, should you wish to handle some more advanced + * input detection. + * + * If no arguments are provided it will try and create a rectangle hit area based on the texture frame the Game Object is using. If + * this isn't a texture-bound object, such as a Graphics or BitmapText object, this will fail, and you'll need to provide a specific + * shape for it to use. + * + * You can also provide an Input Configuration Object as the only argument to this method. + * @param gameObject The Game Object to be enabled for input. + * @param hitArea 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. + * @param hitAreaCallback The 'contains' function to invoke to check if the pointer is within the hit area. + * @param dropZone Is this Game Object a drop zone or not? Default false. */ - moveTime: number; + enable(gameObject: Phaser.GameObjects.GameObject, hitArea?: Phaser.Types.Input.InputConfiguration | any, hitAreaCallback?: Phaser.Types.Input.HitAreaCallback, dropZone?: boolean): this; /** - * X coordinate of the Pointer when Button 1 (left button), or Touch, was pressed, used for dragging objects. + * Takes the given Pointer and performs a hit test against it, to see which interactive Game Objects + * it is currently above. + * + * The hit test is performed against which-ever Camera the Pointer is over. If it is over multiple + * cameras, it starts checking the camera at the top of the camera list, and if nothing is found, iterates down the list. + * @param pointer The Pointer to check against the Game Objects. */ - downX: number; + hitTestPointer(pointer: Phaser.Input.Pointer): Phaser.GameObjects.GameObject[]; /** - * Y coordinate of the Pointer when Button 1 (left button), or Touch, was pressed, used for dragging objects. + * Returns the drag state of the given Pointer for this Input Plugin. + * + * The state will be one of the following: + * + * 0 = Not dragging anything + * 1 = Primary button down and objects below, so collect a draglist + * 2 = Pointer being checked if meets drag criteria + * 3 = Pointer meets criteria, notify the draglist + * 4 = Pointer actively dragging the draglist and has moved + * 5 = Pointer actively dragging but has been released, notify draglist + * @param pointer The Pointer to get the drag state for. */ - downY: number; + getDragState(pointer: Phaser.Input.Pointer): number; /** - * Time when Button 1 (left button), or Touch, was pressed, used for dragging objects. + * Sets the drag state of the given Pointer for this Input Plugin. + * + * The state must be one of the following values: + * + * 0 = Not dragging anything + * 1 = Primary button down and objects below, so collect a draglist + * 2 = Pointer being checked if meets drag criteria + * 3 = Pointer meets criteria, notify the draglist + * 4 = Pointer actively dragging the draglist and has moved + * 5 = Pointer actively dragging but has been released, notify draglist + * @param pointer The Pointer to set the drag state for. + * @param state The drag state value. An integer between 0 and 5. */ - downTime: number; + setDragState(pointer: Phaser.Input.Pointer, state: number): void; /** - * X coordinate of the Pointer when Button 1 (left button), or Touch, was released, used for dragging objects. + * Sets the draggable state of the given array of Game Objects. + * + * They can either be set to be draggable, or can have their draggable state removed by passing `false`. + * + * A Game Object will not fire drag events unless it has been specifically enabled for drag. + * @param gameObjects An array of Game Objects to change the draggable state on. + * @param value Set to `true` if the Game Objects should be made draggable, `false` if they should be unset. Default true. */ - upX: number; + setDraggable(gameObjects: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[], value?: boolean): this; /** - * Y coordinate of the Pointer when Button 1 (left button), or Touch, was released, used for dragging objects. + * Creates a function that can be passed to `setInteractive`, `enable` or `setHitArea` that will handle + * pixel-perfect input detection on an Image or Sprite based Game Object, or any custom class that extends them. + * + * The following will create a sprite that is clickable on any pixel that has an alpha value >= 1. + * + * ```javascript + * this.add.sprite(x, y, key).setInteractive(this.input.makePixelPerfect()); + * ``` + * + * The following will create a sprite that is clickable on any pixel that has an alpha value >= 150. + * + * ```javascript + * this.add.sprite(x, y, key).setInteractive(this.input.makePixelPerfect(150)); + * ``` + * + * Once you have made an Interactive Object pixel perfect it impacts all input related events for it: down, up, + * dragstart, drag, etc. + * + * As a pointer interacts with the Game Object it will constantly poll the texture, extracting a single pixel from + * the given coordinates and checking its color values. This is an expensive process, so should only be enabled on + * Game Objects that really need it. + * + * You cannot make non-texture based Game Objects pixel perfect. So this will not work on Graphics, BitmapText, + * Render Textures, Text, Tilemaps, Containers or Particles. + * @param alphaTolerance The alpha level that the pixel should be above to be included as a successful interaction. Default 1. */ - upY: number; + makePixelPerfect(alphaTolerance?: number): Function; /** - * Time when Button 1 (left button), or Touch, was released, used for dragging objects. + * Sets the hit area for the given array of Game Objects. + * + * A hit area is typically one of the geometric shapes Phaser provides, such as a `Phaser.Geom.Rectangle` + * or `Phaser.Geom.Circle`. However, it can be any object as long as it works with the provided callback. + * + * If no hit area is provided a Rectangle is created based on the size of the Game Object, if possible + * to calculate. + * + * The hit area callback is the function that takes an `x` and `y` coordinate and returns a boolean if + * those values fall within the area of the shape or not. All of the Phaser geometry objects provide this, + * such as `Phaser.Geom.Rectangle.Contains`. + * @param gameObjects An array of Game Objects to set the hit area on. + * @param hitArea 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. + * @param hitAreaCallback The 'contains' function to invoke to check if the pointer is within the hit area. */ - upTime: number; + setHitArea(gameObjects: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[], hitArea?: Phaser.Types.Input.InputConfiguration | any, hitAreaCallback?: Phaser.Types.Input.HitAreaCallback): this; /** - * Is the primary button down? (usually button 0, the left mouse button) + * Sets the hit area for an array of Game Objects to be a `Phaser.Geom.Circle` shape, using + * the given coordinates and radius to control its position and size. + * @param gameObjects An array of Game Objects to set as having a circle hit area. + * @param x The center of the circle. + * @param y The center of the circle. + * @param radius The radius of the circle. + * @param callback The hit area callback. If undefined it uses Circle.Contains. */ - primaryDown: boolean; + setHitAreaCircle(gameObjects: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[], x: number, y: number, radius: number, callback?: Phaser.Types.Input.HitAreaCallback): this; /** - * Is _any_ button on this pointer considered as being down? + * Sets the hit area for an array of Game Objects to be a `Phaser.Geom.Ellipse` shape, using + * the given coordinates and dimensions to control its position and size. + * @param gameObjects An array of Game Objects to set as having an ellipse hit area. + * @param x The center of the ellipse. + * @param y The center of the ellipse. + * @param width The width of the ellipse. + * @param height The height of the ellipse. + * @param callback The hit area callback. If undefined it uses Ellipse.Contains. */ - isDown: boolean; + setHitAreaEllipse(gameObjects: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[], x: number, y: number, width: number, height: number, callback?: Phaser.Types.Input.HitAreaCallback): this; /** - * Did the previous input event come from a Touch input (true) or Mouse? (false) + * Sets the hit area for an array of Game Objects to be a `Phaser.Geom.Rectangle` shape, using + * the Game Objects texture frame to define the position and size of the hit area. + * @param gameObjects An array of Game Objects to set as having an ellipse hit area. + * @param callback The hit area callback. If undefined it uses Rectangle.Contains. */ - wasTouch: boolean; + setHitAreaFromTexture(gameObjects: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[], callback?: Phaser.Types.Input.HitAreaCallback): this; /** - * Did this Pointer get canceled by a touchcancel event? - * - * Note: "canceled" is the American-English spelling of "cancelled". Please don't submit PRs correcting it! + * Sets the hit area for an array of Game Objects to be a `Phaser.Geom.Rectangle` shape, using + * the given coordinates and dimensions to control its position and size. + * @param gameObjects An array of Game Objects to set as having a rectangular hit area. + * @param x The top-left of the rectangle. + * @param y The top-left of the rectangle. + * @param width The width of the rectangle. + * @param height The height of the rectangle. + * @param callback The hit area callback. If undefined it uses Rectangle.Contains. */ - wasCanceled: boolean; + setHitAreaRectangle(gameObjects: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[], x: number, y: number, width: number, height: number, callback?: Phaser.Types.Input.HitAreaCallback): this; /** - * If the mouse is locked, the horizontal relative movement of the Pointer in pixels since last frame. + * Sets the hit area for an array of Game Objects to be a `Phaser.Geom.Triangle` shape, using + * the given coordinates to control the position of its points. + * @param gameObjects An array of Game Objects to set as having a triangular hit area. + * @param x1 The x coordinate of the first point of the triangle. + * @param y1 The y coordinate of the first point of the triangle. + * @param x2 The x coordinate of the second point of the triangle. + * @param y2 The y coordinate of the second point of the triangle. + * @param x3 The x coordinate of the third point of the triangle. + * @param y3 The y coordinate of the third point of the triangle. + * @param callback The hit area callback. If undefined it uses Triangle.Contains. */ - movementX: number; + setHitAreaTriangle(gameObjects: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[], x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, callback?: Phaser.Types.Input.HitAreaCallback): this; /** - * If the mouse is locked, the vertical relative movement of the Pointer in pixels since last frame. + * Creates an Input Debug Shape for the given Game Object. + * + * The Game Object must have _already_ been enabled for input prior to calling this method. + * + * This is intended to assist you during development and debugging. + * + * Debug Shapes can only be created for Game Objects that are using standard Phaser Geometry for input, + * including: Circle, Ellipse, Line, Polygon, Rectangle and Triangle. + * + * Game Objects that are using their automatic hit areas are using Rectangles by default, so will also work. + * + * The Debug Shape is created and added to the display list and is then kept in sync with the Game Object + * it is connected with. Should you need to modify it yourself, such as to hide it, you can access it via + * the Game Object property: `GameObject.input.hitAreaDebug`. + * + * Calling this method on a Game Object that already has a Debug Shape will first destroy the old shape, + * before creating a new one. If you wish to remove the Debug Shape entirely, you should call the + * method `InputPlugin.removeDebug`. + * + * Note that the debug shape will only show the outline of the input area. If the input test is using a + * pixel perfect check, for example, then this is not displayed. If you are using a custom shape, that + * doesn't extend one of the base Phaser Geometry objects, as your hit area, then this method will not + * work. + * @param gameObject The Game Object to create the input debug shape for. + * @param color The outline color of the debug shape. Default 0x00ff00. */ - movementY: number; + enableDebug(gameObject: Phaser.GameObjects.GameObject, color?: number): this; /** - * The identifier property of the Pointer as set by the DOM event when this Pointer is started. + * Removes an Input Debug Shape from the given Game Object. + * + * The shape is destroyed immediately and the `hitAreaDebug` property is set to `null`. + * @param gameObject The Game Object to remove the input debug shape from. */ - identifier: number; + removeDebug(gameObject: Phaser.GameObjects.GameObject): this; /** - * The pointerId property of the Pointer as set by the DOM event when this Pointer is started. - * The browser can and will recycle this value. + * Sets the Pointers to always poll. + * + * When a pointer is polled it runs a hit test to see which Game Objects are currently below it, + * or being interacted with it, regardless if the Pointer has actually moved or not. + * + * You should enable this if you want objects in your game to fire over / out events, and the objects + * are constantly moving, but the pointer may not have. Polling every frame has additional computation + * costs, especially if there are a large number of interactive objects in your game. */ - pointerId: number; + setPollAlways(): this; /** - * An active Pointer is one that is currently pressed down on the display. - * A Mouse is always considered as active. + * Sets the Pointers to only poll when they are moved or updated. + * + * When a pointer is polled it runs a hit test to see which Game Objects are currently below it, + * or being interacted with it. */ - active: boolean; + setPollOnMove(): this; /** - * Is this pointer Pointer Locked? - * - * Only a mouse pointer can be locked and it only becomes locked when requested via - * the browsers Pointer Lock API. - * - * You can request this by calling the `this.input.mouse.requestPointerLock()` method from - * a `pointerdown` or `pointerup` event handler. + * Sets the poll rate value. This is the amount of time that should have elapsed before a pointer + * will be polled again. See the `setPollAlways` and `setPollOnMove` methods. + * @param value The amount of time, in ms, that should elapsed before re-polling the pointers. */ - readonly locked: boolean; + setPollRate(value: number): this; /** - * The horizontal scroll amount that occurred due to the user moving a mouse wheel or similar input device. + * When set to `true` the global Input Manager will emulate DOM behavior by only emitting events from + * the top-most Scene in the Scene List. By default, if a Scene receives an input event it will then stop the event + * from flowing down to any Scenes below it in the Scene list. To disable this behavior call this method with `false`. + * @param value Set to `true` to stop processing input events on the Scene that receives it, or `false` to let the event continue down the Scene list. */ - deltaX: number; + setGlobalTopOnly(value: boolean): this; /** - * The vertical scroll amount that occurred due to the user moving a mouse wheel or similar input device. - * This value will typically be less than 0 if the user scrolls up and greater than zero if scrolling down. + * When set to `true` this Input Plugin will emulate DOM behavior by only emitting events from + * the top-most Game Objects in the Display List. + * + * If set to `false` it will emit events from all Game Objects below a Pointer, not just the top one. + * @param value `true` to only include the top-most Game Object, or `false` to include all Game Objects in a hit test. */ - deltaY: number; + setTopOnly(value: boolean): this; /** - * The z-axis scroll amount that occurred due to the user moving a mouse wheel or similar input device. + * Given an array of Game Objects, sort the array and return it, so that the objects are in depth index order + * with the lowest at the bottom. + * @param gameObjects An array of Game Objects to be sorted. */ - deltaZ: number; + sortGameObjects(gameObjects: Phaser.GameObjects.GameObject[]): Phaser.GameObjects.GameObject[]; /** - * Takes a Camera and updates this Pointer's `worldX` and `worldY` values so they are - * the result of a translation through the given Camera. + * This method should be called from within an input event handler, such as `pointerdown`. * - * Note that the values will be automatically replaced the moment the Pointer is - * updated by an input event, such as a mouse move, so should be used immediately. - * @param camera The Camera which is being tested against. + * When called, it stops the Input Manager from allowing _this specific event_ to be processed by any other Scene + * not yet handled in the scene list. */ - updateWorldPoint(camera: Phaser.Cameras.Scene2D.Camera): this; + stopPropagation(): this; /** - * Takes a Camera and returns a Vector2 containing the translated position of this Pointer - * within that Camera. This can be used to convert this Pointers position into camera space. - * @param camera The Camera to use for the translation. - * @param output A Vector2-like object in which to store the translated position. + * Adds new Pointer objects to the Input Manager. + * + * By default Phaser creates 2 pointer objects: `mousePointer` and `pointer1`. + * + * You can create more either by calling this method, or by setting the `input.activePointers` property + * in the Game Config, up to a maximum of 10 pointers. + * + * The first 10 pointers are available via the `InputPlugin.pointerX` properties, once they have been added + * via this method. + * @param quantity The number of new Pointers to create. A maximum of 10 is allowed in total. Default 1. */ - positionToCamera(camera: Phaser.Cameras.Scene2D.Camera, output?: Phaser.Math.Vector2 | object): Phaser.Math.Vector2 | object; + addPointer(quantity?: number): Phaser.Input.Pointer[]; /** - * Checks to see if any buttons are being held down on this Pointer. + * Tells the Input system to set a custom cursor. + * + * This cursor will be the default cursor used when interacting with the game canvas. + * + * If an Interactive Object also sets a custom cursor, this is the cursor that is reset after its use. + * + * Any valid CSS cursor value is allowed, including paths to image files, i.e.: + * + * ```javascript + * this.input.setDefaultCursor('url(assets/cursors/sword.cur), pointer'); + * ``` + * + * Please read about the differences between browsers when it comes to the file formats and sizes they support: + * + * https://developer.mozilla.org/en-US/docs/Web/CSS/cursor + * https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_User_Interface/Using_URL_values_for_the_cursor_property + * + * It's up to you to pick a suitable cursor format that works across the range of browsers you need to support. + * @param cursor The CSS to be used when setting the default cursor. */ - noButtonDown(): boolean; + setDefaultCursor(cursor: string): this; /** - * Checks to see if the left button is being held down on this Pointer. + * The x coordinates of the ActivePointer based on the first camera in the camera list. + * This is only safe to use if your game has just 1 non-transformed camera and doesn't use multi-touch. */ - leftButtonDown(): boolean; + readonly x: number; /** - * Checks to see if the right button is being held down on this Pointer. + * The y coordinates of the ActivePointer based on the first camera in the camera list. + * This is only safe to use if your game has just 1 non-transformed camera and doesn't use multi-touch. */ - rightButtonDown(): boolean; + readonly y: number; /** - * Checks to see if the middle button is being held down on this Pointer. + * Are any mouse or touch pointers currently over the game canvas? */ - middleButtonDown(): boolean; + readonly isOver: boolean; /** - * Checks to see if the back button is being held down on this Pointer. + * The mouse has its own unique Pointer object, which you can reference directly if making a _desktop specific game_. + * If you are supporting both desktop and touch devices then do not use this property, instead use `activePointer` + * which will always map to the most recently interacted pointer. */ - backButtonDown(): boolean; + readonly mousePointer: Phaser.Input.Pointer; /** - * Checks to see if the forward button is being held down on this Pointer. + * The current active input Pointer. */ - forwardButtonDown(): boolean; + readonly activePointer: Phaser.Input.Pointer; /** - * Checks to see if the left button was just released on this Pointer. + * A touch-based Pointer object. + * This will be `undefined` by default unless you add a new Pointer using `addPointer`. */ - leftButtonReleased(): boolean; + readonly pointer1: Phaser.Input.Pointer; /** - * Checks to see if the right button was just released on this Pointer. + * A touch-based Pointer object. + * This will be `undefined` by default unless you add a new Pointer using `addPointer`. */ - rightButtonReleased(): boolean; + readonly pointer2: Phaser.Input.Pointer; /** - * Checks to see if the middle button was just released on this Pointer. + * A touch-based Pointer object. + * This will be `undefined` by default unless you add a new Pointer using `addPointer`. */ - middleButtonReleased(): boolean; + readonly pointer3: Phaser.Input.Pointer; /** - * Checks to see if the back button was just released on this Pointer. + * A touch-based Pointer object. + * This will be `undefined` by default unless you add a new Pointer using `addPointer`. */ - backButtonReleased(): boolean; + readonly pointer4: Phaser.Input.Pointer; /** - * Checks to see if the forward button was just released on this Pointer. + * A touch-based Pointer object. + * This will be `undefined` by default unless you add a new Pointer using `addPointer`. */ - forwardButtonReleased(): boolean; + readonly pointer5: Phaser.Input.Pointer; /** - * If the Pointer has a button pressed down at the time this method is called, it will return the - * distance between the Pointer's `downX` and `downY` values and the current position. - * - * If no button is held down, it will return the last recorded distance, based on where - * the Pointer was when the button was released. - * - * If you wish to get the distance being travelled currently, based on the velocity of the Pointer, - * then see the `Pointer.distance` property. + * A touch-based Pointer object. + * This will be `undefined` by default unless you add a new Pointer using `addPointer`. */ - getDistance(): number; + readonly pointer6: Phaser.Input.Pointer; /** - * If the Pointer has a button pressed down at the time this method is called, it will return the - * horizontal distance between the Pointer's `downX` and `downY` values and the current position. - * - * If no button is held down, it will return the last recorded horizontal distance, based on where - * the Pointer was when the button was released. + * A touch-based Pointer object. + * This will be `undefined` by default unless you add a new Pointer using `addPointer`. */ - getDistanceX(): number; + readonly pointer7: Phaser.Input.Pointer; /** - * If the Pointer has a button pressed down at the time this method is called, it will return the - * vertical distance between the Pointer's `downX` and `downY` values and the current position. - * - * If no button is held down, it will return the last recorded vertical distance, based on where - * the Pointer was when the button was released. + * A touch-based Pointer object. + * This will be `undefined` by default unless you add a new Pointer using `addPointer`. */ - getDistanceY(): number; + readonly pointer8: Phaser.Input.Pointer; /** - * If the Pointer has a button pressed down at the time this method is called, it will return the - * duration since the button was pressed down. - * - * If no button is held down, it will return the last recorded duration, based on the time - * the Pointer button was released. + * A touch-based Pointer object. + * This will be `undefined` by default unless you add a new Pointer using `addPointer`. */ - getDuration(): number; + readonly pointer9: Phaser.Input.Pointer; /** - * If the Pointer has a button pressed down at the time this method is called, it will return the - * angle between the Pointer's `downX` and `downY` values and the current position. - * - * If no button is held down, it will return the last recorded angle, based on where - * the Pointer was when the button was released. - * - * The angle is based on the old position facing to the current position. - * - * If you wish to get the current angle, based on the velocity of the Pointer, then - * see the `Pointer.angle` property. + * A touch-based Pointer object. + * This will be `undefined` by default unless you add a new Pointer using `addPointer`. */ - getAngle(): number; + readonly pointer10: Phaser.Input.Pointer; /** - * Takes the previous and current Pointer positions and then generates an array of interpolated values between - * the two. The array will be populated up to the size of the `steps` argument. - * - * ```javaScript - * var points = pointer.getInterpolatedPosition(4); - * - * // points[0] = { x: 0, y: 0 } - * // points[1] = { x: 2, y: 1 } - * // points[2] = { x: 3, y: 2 } - * // points[3] = { x: 6, y: 3 } - * ``` - * - * Use this if you need to get smoothed values between the previous and current pointer positions. DOM pointer - * events can often fire faster than the main browser loop, and this will help you avoid janky movement - * especially if you have an object following a Pointer. - * - * Note that if you provide an output array it will only be populated up to the number of steps provided. - * It will not clear any previous data that may have existed beyond the range of the steps count. - * - * Internally it uses the Smooth Step interpolation calculation. - * @param steps The number of interpolation steps to use. Default 10. - * @param out An array to store the results in. If not provided a new one will be created. + * An instance of the Keyboard Plugin class, if enabled via the `input.keyboard` Scene or Game Config property. + * Use this to create Key objects and listen for keyboard specific events. */ - getInterpolatedPosition(steps?: integer, out?: any[]): any[]; + keyboard: Phaser.Input.Keyboard.KeyboardPlugin; + } + + namespace InputPluginCache { /** - * Destroys this Pointer instance and resets its external references. + * Static method called directly by the Core internal Plugins. + * Key is a reference used to get the plugin from the plugins object (i.e. InputPlugin) + * Plugin is the object to instantiate to create the plugin + * Mapping is what the plugin is injected into the Scene.Systems as (i.e. input) + * @param key A reference used to get this plugin from the plugin cache. + * @param plugin The plugin to be stored. Should be the core object, not instantiated. + * @param mapping If this plugin is to be injected into the Input Plugin, this is the property key used. + * @param settingsKey The key in the Scene Settings to check to see if this plugin should install or not. + * @param configKey The key in the Game Config to check to see if this plugin should install or not. */ - destroy(): void; + function register(key: string, plugin: Function, mapping: string, settingsKey: string, configKey: string): void; /** - * The x position of this Pointer. - * The value is in screen space. - * See `worldX` to get a camera converted position. + * Returns the input plugin object from the cache based on the given key. + * @param key The key of the input plugin to get. */ - x: number; + function getPlugin(key: string): Phaser.Types.Input.InputPluginContainer; /** - * The y position of this Pointer. - * The value is in screen space. - * See `worldY` to get a camera converted position. + * Installs all of the registered Input Plugins into the given target. + * @param target The target InputPlugin to install the plugins into. */ - y: number; + function install(target: Phaser.Input.InputPlugin): void; /** - * Time when this Pointer was most recently updated by a DOM Event. - * This comes directly from the `event.timeStamp` property. - * If no event has yet taken place, it will return zero. + * Removes an input plugin based on the given key. + * @param key The key of the input plugin to remove. */ - readonly time: number; + function remove(key: string): void; } - namespace Touch { + namespace Keyboard { /** - * The Touch Manager is a helper class that belongs to the Input Manager. + * A KeyCombo will listen for a specific string of keys from the Keyboard, and when it receives them + * it will emit a `keycombomatch` event from the Keyboard Manager. * - * Its role is to listen for native DOM Touch Events and then pass them onto the Input Manager for further processing. + * The keys to be listened for can be defined as: * - * You do not need to create this class directly, the Input Manager will create an instance of it automatically. - */ - class TouchManager { - /** - * - * @param inputManager A reference to the Input Manager. - */ - constructor(inputManager: Phaser.Input.InputManager); - - /** - * A reference to the Input Manager. - */ - manager: Phaser.Input.InputManager; - - /** - * If true the DOM events will have event.preventDefault applied to them, if false they will propagate fully. - */ - capture: boolean; + * A string (i.e. 'ATARI') + * An array of either integers (key codes) or strings, or a mixture of both + * An array of objects (such as Key objects) with a public 'keyCode' property + * + * For example, to listen for the Konami code (up, up, down, down, left, right, left, right, b, a, enter) + * you could pass the following array of key codes: + * + * ```javascript + * this.input.keyboard.createCombo([ 38, 38, 40, 40, 37, 39, 37, 39, 66, 65, 13 ], { resetOnMatch: true }); + * + * this.input.keyboard.on('keycombomatch', function (event) { + * console.log('Konami Code entered!'); + * }); + * ``` + * + * Or, to listen for the user entering the word PHASER: + * + * ```javascript + * this.input.keyboard.createCombo('PHASER'); + * ``` + */ + class KeyCombo { + /** + * + * @param keyboardPlugin A reference to the Keyboard Plugin. + * @param keys The keys that comprise this combo. + * @param config A Key Combo configuration object. + */ + constructor(keyboardPlugin: Phaser.Input.Keyboard.KeyboardPlugin, keys: string | number[] | object[], config?: Phaser.Types.Input.Keyboard.KeyComboConfig); /** - * A boolean that controls if the Touch Manager is enabled or not. - * Can be toggled on the fly. + * A reference to the Keyboard Manager */ - enabled: boolean; + manager: Phaser.Input.Keyboard.KeyboardPlugin; /** - * The Touch Event target, as defined in the Game Config. - * Typically the canvas to which the game is rendering, but can be any interactive DOM element. + * A flag that controls if this Key Combo is actively processing keys or not. */ - target: any; + enabled: boolean; /** - * The Touch Start event handler function. - * Initially empty and bound in the `startListeners` method. + * An array of the keycodes that comprise this combo. */ - onTouchStart: Function; + keyCodes: any[]; /** - * The Touch Start event handler function specifically for events on the Window. - * Initially empty and bound in the `startListeners` method. + * The current keyCode the combo is waiting for. */ - onTouchStartWindow: Function; + current: number; /** - * The Touch Move event handler function. - * Initially empty and bound in the `startListeners` method. + * The current index of the key being waited for in the 'keys' string. */ - onTouchMove: Function; + index: number; /** - * The Touch End event handler function. - * Initially empty and bound in the `startListeners` method. + * The length of this combo (in keycodes) */ - onTouchEnd: Function; + size: number; /** - * The Touch End event handler function specifically for events on the Window. - * Initially empty and bound in the `startListeners` method. + * The time the previous key in the combo was matched. */ - onTouchEndWindow: Function; + timeLastMatched: number; /** - * The Touch Cancel event handler function. - * Initially empty and bound in the `startListeners` method. + * Has this Key Combo been matched yet? */ - onTouchCancel: Function; + matched: boolean; /** - * The Touch Cancel event handler function specifically for events on the Window. - * Initially empty and bound in the `startListeners` method. + * The time the entire combo was matched. */ - onTouchCancelWindow: Function; + timeMatched: number; /** - * The Touch Over event handler function. - * Initially empty and bound in the `startListeners` method. + * If they press the wrong key do we reset the combo? */ - onTouchOver: Function; + resetOnWrongKey: boolean; /** - * The Touch Out event handler function. - * Initially empty and bound in the `startListeners` method. + * The max delay in ms between each key press. Above this the combo is reset. 0 means disabled. */ - onTouchOut: Function; + maxKeyDelay: number; /** - * Attempts to disable the context menu from appearing if you touch-hold on the browser. - * - * Works by listening for the `contextmenu` event and prevent defaulting it. - * - * Use this if you need to disable the OS context menu on mobile. + * If previously matched and they press the first key of the combo again, will it reset? */ - disableContextMenu(): Phaser.Input.Touch.TouchManager; + resetOnMatch: boolean; /** - * Starts the Touch Event listeners running as long as an input target is set. - * - * This method is called automatically if Touch Input is enabled in the game config, - * which it is by default. However, you can call it manually should you need to - * delay input capturing until later in the game. + * If the combo matches, will it delete itself? */ - startListeners(): void; + deleteOnMatch: boolean; /** - * Stops the Touch Event listeners. - * This is called automatically and does not need to be manually invoked. + * How far complete is this combo? A value between 0 and 1. */ - stopListeners(): void; + readonly progress: number; /** - * Destroys this Touch Manager instance. + * Destroys this Key Combo and all of its references. */ destroy(): void; } - } + namespace Events { + /** + * The Global Key Down Event. + * + * This event is dispatched by the Keyboard Plugin when any key on the keyboard is pressed down. + * + * Listen to this event from within a Scene using: `this.input.keyboard.on('keydown', listener)`. + * + * You can also listen for a specific key being pressed. See [Keyboard.Events.KEY_DOWN]{@linkcode Phaser.Input.Keyboard.Events#event:KEY_DOWN} for details. + * + * Finally, you can create Key objects, which you can also listen for events from. See [Keyboard.Events.DOWN]{@linkcode Phaser.Input.Keyboard.Events#event:DOWN} for details. + * + * _Note_: Many keyboards are unable to process certain combinations of keys due to hardware limitations known as ghosting. + * Read [this article on ghosting]{@link http://www.html5gamedevs.com/topic/4876-impossible-to-use-more-than-2-keyboard-input-buttons-at-the-same-time/} for details. + * + * Also, please be aware that some browser extensions can disable or override Phaser keyboard handling. + * For example, the Chrome extension vimium is known to disable Phaser from using the D key, while EverNote disables the backtick key. + * There are others. So, please check your extensions if you find you have specific keys that don't work. + */ + const ANY_KEY_DOWN: any; - } + /** + * The Global Key Up Event. + * + * This event is dispatched by the Keyboard Plugin when any key on the keyboard is released. + * + * Listen to this event from within a Scene using: `this.input.keyboard.on('keyup', listener)`. + * + * You can also listen for a specific key being released. See [Keyboard.Events.KEY_UP]{@linkcode Phaser.Input.Keyboard.Events#event:KEY_UP} for details. + * + * Finally, you can create Key objects, which you can also listen for events from. See [Keyboard.Events.UP]{@linkcode Phaser.Input.Keyboard.Events#event:UP} for details. + */ + const ANY_KEY_UP: any; - namespace Loader { - /** - * The Loader is idle. - */ - var LOADER_IDLE: integer; + /** + * The Key Combo Match Event. + * + * This event is dispatched by the Keyboard Plugin when a [Key Combo]{@link Phaser.Input.Keyboard.KeyCombo} is matched. + * + * Listen for this event from the Key Plugin after a combo has been created: + * + * ```javascript + * this.input.keyboard.createCombo([ 38, 38, 40, 40, 37, 39, 37, 39, 66, 65, 13 ], { resetOnMatch: true }); + * + * this.input.keyboard.on('keycombomatch', function (event) { + * console.log('Konami Code entered!'); + * }); + * ``` + */ + const COMBO_MATCH: any; - /** - * The Loader is actively loading. - */ - var LOADER_LOADING: integer; + /** + * The Key Down Event. + * + * This event is dispatched by a [Key]{@link Phaser.Input.Keyboard.Key} object when it is pressed. + * + * Listen for this event from the Key object instance directly: + * + * ```javascript + * var spaceBar = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.SPACE); + * + * spaceBar.on('down', listener) + * ``` + * + * You can also create a generic 'global' listener. See [Keyboard.Events.ANY_KEY_DOWN]{@linkcode Phaser.Input.Keyboard.Events#event:ANY_KEY_DOWN} for details. + */ + const DOWN: any; - /** - * The Loader is processing files is has loaded. - */ - var LOADER_PROCESSING: integer; + /** + * The Key Down Event. + * + * This event is dispatched by the Keyboard Plugin when any key on the keyboard is pressed down. + * + * Unlike the `ANY_KEY_DOWN` event, this one has a special dynamic event name. For example, to listen for the `A` key being pressed + * use the following from within a Scene: `this.input.keyboard.on('keydown-A', listener)`. You can replace the `-A` part of the event + * name with any valid [Key Code string]{@link Phaser.Input.Keyboard.KeyCodes}. For example, this will listen for the space bar: + * `this.input.keyboard.on('keydown-SPACE', listener)`. + * + * You can also create a generic 'global' listener. See [Keyboard.Events.ANY_KEY_DOWN]{@linkcode Phaser.Input.Keyboard.Events#event:ANY_KEY_DOWN} for details. + * + * Finally, you can create Key objects, which you can also listen for events from. See [Keyboard.Events.DOWN]{@linkcode Phaser.Input.Keyboard.Events#event:DOWN} for details. + * + * _Note_: Many keyboards are unable to process certain combinations of keys due to hardware limitations known as ghosting. + * Read [this article on ghosting]{@link http://www.html5gamedevs.com/topic/4876-impossible-to-use-more-than-2-keyboard-input-buttons-at-the-same-time/} for details. + * + * Also, please be aware that some browser extensions can disable or override Phaser keyboard handling. + * For example, the Chrome extension vimium is known to disable Phaser from using the D key, while EverNote disables the backtick key. + * There are others. So, please check your extensions if you find you have specific keys that don't work. + */ + const KEY_DOWN: any; - /** - * The Loader has completed loading and processing. - */ - var LOADER_COMPLETE: integer; + /** + * The Key Up Event. + * + * This event is dispatched by the Keyboard Plugin when any key on the keyboard is released. + * + * Unlike the `ANY_KEY_UP` event, this one has a special dynamic event name. For example, to listen for the `A` key being released + * use the following from within a Scene: `this.input.keyboard.on('keyup-A', listener)`. You can replace the `-A` part of the event + * name with any valid [Key Code string]{@link Phaser.Input.Keyboard.KeyCodes}. For example, this will listen for the space bar: + * `this.input.keyboard.on('keyup-SPACE', listener)`. + * + * You can also create a generic 'global' listener. See [Keyboard.Events.ANY_KEY_UP]{@linkcode Phaser.Input.Keyboard.Events#event:ANY_KEY_UP} for details. + * + * Finally, you can create Key objects, which you can also listen for events from. See [Keyboard.Events.UP]{@linkcode Phaser.Input.Keyboard.Events#event:UP} for details. + */ + const KEY_UP: any; - /** - * The Loader is shutting down. - */ - var LOADER_SHUTDOWN: integer; + /** + * The Key Up Event. + * + * This event is dispatched by a [Key]{@link Phaser.Input.Keyboard.Key} object when it is released. + * + * Listen for this event from the Key object instance directly: + * + * ```javascript + * var spaceBar = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.SPACE); + * + * spaceBar.on('up', listener) + * ``` + * + * You can also create a generic 'global' listener. See [Keyboard.Events.ANY_KEY_UP]{@linkcode Phaser.Input.Keyboard.Events#event:ANY_KEY_UP} for details. + */ + const UP: any; - /** - * The Loader has been destroyed. - */ - var LOADER_DESTROYED: integer; + } - /** - * File is in the load queue but not yet started - */ - var FILE_PENDING: integer; + /** + * The Keyboard Manager is a helper class that belongs to the global Input Manager. + * + * Its role is to listen for native DOM Keyboard Events and then store them for further processing by the Keyboard Plugin. + * + * You do not need to create this class directly, the Input Manager will create an instance of it automatically if keyboard + * input has been enabled in the Game Config. + */ + class KeyboardManager { + /** + * + * @param inputManager A reference to the Input Manager. + */ + constructor(inputManager: Phaser.Input.InputManager); - /** - * File has been started to load by the loader (onLoad called) - */ - var FILE_LOADING: integer; + /** + * A reference to the Input Manager. + */ + manager: Phaser.Input.InputManager; - /** - * File has loaded successfully, awaiting processing - */ - var FILE_LOADED: integer; + /** + * A flag that controls if the non-modified keys, matching those stored in the `captures` array, + * have `preventDefault` called on them or not. + * + * A non-modified key is one that doesn't have a modifier key held down with it. The modifier keys are + * shift, control, alt and the meta key (Command on a Mac, the Windows Key on Windows). + * Therefore, if the user presses shift + r, it won't prevent this combination, because of the modifier. + * However, if the user presses just the r key on its own, it will have its event prevented. + * + * If you wish to stop capturing the keys, for example switching out to a DOM based element, then + * you can toggle this property at run-time. + */ + preventDefault: boolean; - /** - * File failed to load - */ - var FILE_FAILED: integer; + /** + * An array of Key Code values that will automatically have `preventDefault` called on them, + * as long as the `KeyboardManager.preventDefault` boolean is set to `true`. + * + * By default the array is empty. + * + * The key must be non-modified when pressed in order to be captured. + * + * A non-modified key is one that doesn't have a modifier key held down with it. The modifier keys are + * shift, control, alt and the meta key (Command on a Mac, the Windows Key on Windows). + * Therefore, if the user presses shift + r, it won't prevent this combination, because of the modifier. + * However, if the user presses just the r key on its own, it will have its event prevented. + * + * If you wish to stop capturing the keys, for example switching out to a DOM based element, then + * you can toggle the `KeyboardManager.preventDefault` boolean at run-time. + * + * If you need more specific control, you can create Key objects and set the flag on each of those instead. + * + * This array can be populated via the Game Config by setting the `input.keyboard.capture` array, or you + * can call the `addCapture` method. See also `removeCapture` and `clearCaptures`. + */ + captures: number[]; - /** - * File is being processed (onProcess callback) - */ - var FILE_PROCESSING: integer; + /** + * A boolean that controls if the Keyboard Manager is enabled or not. + * Can be toggled on the fly. + */ + enabled: boolean; - /** - * The File has errored somehow during processing. - */ - var FILE_ERRORED: integer; + /** + * The Keyboard Event target, as defined in the Game Config. + * Typically the window in which the game is rendering, but can be any interactive DOM element. + */ + target: any; - /** - * File has finished processing. - */ - var FILE_COMPLETE: integer; + /** + * The Key Down Event handler. + * This function is sent the native DOM KeyEvent. + * Initially empty and bound in the `startListeners` method. + */ + onKeyDown: Function; - /** - * File has been destroyed - */ - var FILE_DESTROYED: integer; + /** + * The Key Up Event handler. + * This function is sent the native DOM KeyEvent. + * Initially empty and bound in the `startListeners` method. + */ + onKeyUp: Function; - /** - * File was populated from local data and doesn't need an HTTP request - */ - var FILE_POPULATED: integer; + /** + * Starts the Keyboard Event listeners running. + * This is called automatically and does not need to be manually invoked. + */ + startListeners(): void; - namespace Events { - /** - * The Loader Plugin Add File Event. - * - * This event is dispatched when a new file is successfully added to the Loader and placed into the load queue. - * - * Listen to it from a Scene using: `this.load.on('addfile', listener)`. - * - * If you add lots of files to a Loader from a `preload` method, it will dispatch this event for each one of them. - */ - const ADD: any; + /** + * Stops the Key Event listeners. + * This is called automatically and does not need to be manually invoked. + */ + stopListeners(): void; - /** - * The Loader Plugin Complete Event. - * - * This event is dispatched when the Loader has fully processed everything in the load queue. - * By this point every loaded file will now be in its associated cache and ready for use. - * - * Listen to it from a Scene using: `this.load.on('complete', listener)`. - */ - const COMPLETE: any; + /** + * By default when a key is pressed Phaser will not stop the event from propagating up to the browser. + * There are some keys this can be annoying for, like the arrow keys or space bar, which make the browser window scroll. + * + * This `addCapture` method enables consuming keyboard event for specific keys so it doesn't bubble up to the the browser + * and cause the default browser behavior. + * + * Please note that keyboard captures are global. This means that if you call this method from within a Scene, to say prevent + * the SPACE BAR from triggering a page scroll, then it will prevent it for any Scene in your game, not just the calling one. + * + * You can pass in a single key code value, or an array of key codes, or a string: + * + * ```javascript + * this.input.keyboard.addCapture(62); + * ``` + * + * An array of key codes: + * + * ```javascript + * this.input.keyboard.addCapture([ 62, 63, 64 ]); + * ``` + * + * Or a string: + * + * ```javascript + * this.input.keyboard.addCapture('W,S,A,D'); + * ``` + * + * To use non-alpha numeric keys, use a string, such as 'UP', 'SPACE' or 'LEFT'. + * + * You can also provide an array mixing both strings and key code integers. + * + * If there are active captures after calling this method, the `preventDefault` property is set to `true`. + * @param keycode The Key Codes to enable capture for, preventing them reaching the browser. + */ + addCapture(keycode: string | number | number[] | any[]): void; - /** - * The File Load Complete Event. - * - * This event is dispatched by the Loader Plugin when any file in the queue finishes loading. - * - * Listen to it from a Scene using: `this.load.on('filecomplete', listener)`. - * - * You can also listen for the completion of a specific file. See the [FILE_KEY_COMPLETE]{@linkcode Phaser.Loader.Events#event:FILE_KEY_COMPLETE} event. - */ - const FILE_COMPLETE: any; + /** + * Removes an existing key capture. + * + * Please note that keyboard captures are global. This means that if you call this method from within a Scene, to remove + * the capture of a key, then it will remove it for any Scene in your game, not just the calling one. + * + * You can pass in a single key code value, or an array of key codes, or a string: + * + * ```javascript + * this.input.keyboard.removeCapture(62); + * ``` + * + * An array of key codes: + * + * ```javascript + * this.input.keyboard.removeCapture([ 62, 63, 64 ]); + * ``` + * + * Or a string: + * + * ```javascript + * this.input.keyboard.removeCapture('W,S,A,D'); + * ``` + * + * To use non-alpha numeric keys, use a string, such as 'UP', 'SPACE' or 'LEFT'. + * + * You can also provide an array mixing both strings and key code integers. + * + * If there are no captures left after calling this method, the `preventDefault` property is set to `false`. + * @param keycode The Key Codes to disable capture for, allowing them reaching the browser again. + */ + removeCapture(keycode: string | number | number[] | any[]): void; + + /** + * Removes all keyboard captures and sets the `preventDefault` property to `false`. + */ + clearCaptures(): void; + + /** + * Destroys this Keyboard Manager instance. + */ + destroy(): void; + + } /** - * The File Load Complete Event. + * The Keyboard Plugin is an input plugin that belongs to the Scene-owned Input system. * - * This event is dispatched by the Loader Plugin when any file in the queue finishes loading. + * Its role is to listen for native DOM Keyboard Events and then process them. * - * It uses a special dynamic event name constructed from the key and type of the file. + * You do not need to create this class directly, the Input system will create an instance of it automatically. * - * For example, if you have loaded an `image` with a key of `monster`, you can listen for it - * using the following: + * You can access it from within a Scene using `this.input.keyboard`. For example, you can do: * * ```javascript - * this.load.on('filecomplete-image-monster', function (key, type, data) { - * // Your handler code - * }); + * this.input.keyboard.on('keydown', callback, context); * ``` * - * Or, if you have loaded a texture `atlas` with a key of `Level1`: + * Or, to listen for a specific key: * * ```javascript - * this.load.on('filecomplete-atlas-Level1', function (key, type, data) { - * // Your handler code - * }); + * this.input.keyboard.on('keydown-A', callback, context); * ``` * - * Or, if you have loaded a sprite sheet with a key of `Explosion` and a prefix of `GAMEOVER`: + * You can also create Key objects, which you can then poll in your game loop: * * ```javascript - * this.load.on('filecomplete-spritesheet-GAMEOVERExplosion', function (key, type, data) { - * // Your handler code - * }); + * var spaceBar = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.SPACE); * ``` * - * You can also listen for the generic completion of files. See the [FILE_COMPLETE]{@linkcode Phaser.Loader.Events#event:FILE_COMPLETE} event. - */ - const FILE_KEY_COMPLETE: any; - - /** - * The File Load Error Event. + * If you have multiple parallel Scenes, each trying to get keyboard input, be sure to disable capture on them to stop them from + * stealing input from another Scene in the list. You can do this with `this.input.keyboard.enabled = false` within the + * Scene to stop all input, or `this.input.keyboard.preventDefault = false` to stop a Scene halting input on another Scene. * - * This event is dispatched by the Loader Plugin when a file fails to load. + * _Note_: Many keyboards are unable to process certain combinations of keys due to hardware limitations known as ghosting. + * See http://www.html5gamedevs.com/topic/4876-impossible-to-use-more-than-2-keyboard-input-buttons-at-the-same-time/ for more details. * - * Listen to it from a Scene using: `this.load.on('loaderror', listener)`. + * Also please be aware that certain browser extensions can disable or override Phaser keyboard handling. + * For example the Chrome extension vimium is known to disable Phaser from using the D key, while EverNote disables the backtick key. + * And there are others. So, please check your extensions before opening Phaser issues about keys that don't work. */ - const FILE_LOAD_ERROR: any; + class KeyboardPlugin extends Phaser.Events.EventEmitter { + /** + * + * @param sceneInputPlugin A reference to the Scene Input Plugin that the KeyboardPlugin belongs to. + */ + constructor(sceneInputPlugin: Phaser.Input.InputPlugin); - /** - * The File Load Event. - * - * This event is dispatched by the Loader Plugin when a file finishes loading, - * but _before_ it is processed and added to the internal Phaser caches. - * - * Listen to it from a Scene using: `this.load.on('load', listener)`. - */ - const FILE_LOAD: any; - - /** - * The File Load Progress Event. - * - * This event is dispatched by the Loader Plugin during the load of a file, if the browser receives a DOM ProgressEvent and - * the `lengthComputable` event property is true. Depending on the size of the file and browser in use, this may, or may not happen. - * - * Listen to it from a Scene using: `this.load.on('fileprogress', listener)`. - */ - const FILE_PROGRESS: any; - - /** - * The Loader Plugin Post Process Event. - * - * This event is dispatched by the Loader Plugin when the Loader has finished loading everything in the load queue. - * It is dispatched before the internal lists are cleared and each File is destroyed. - * - * Use this hook to perform any last minute processing of files that can only happen once the - * Loader has completed, but prior to it emitting the `complete` event. - * - * Listen to it from a Scene using: `this.load.on('postprocess', listener)`. - */ - const POST_PROCESS: any; - - /** - * The Loader Plugin Progress Event. - * - * This event is dispatched when the Loader updates its load progress, typically as a result of a file having completed loading. - * - * Listen to it from a Scene using: `this.load.on('progress', listener)`. - */ - const PROGRESS: any; - - /** - * The Loader Plugin Start Event. - * - * This event is dispatched when the Loader starts running. At this point load progress is zero. - * - * This event is dispatched even if there aren't any files in the load queue. - * - * Listen to it from a Scene using: `this.load.on('start', listener)`. - */ - const START: any; - - } - - /** - * The base File class used by all File Types that the Loader can support. - * You shouldn't create an instance of a File directly, but should extend it with your own class, setting a custom type and processing methods. - */ - class File { - /** - * - * @param loader The Loader that is going to load this File. - * @param fileConfig The file configuration object, as created by the file type. - */ - constructor(loader: Phaser.Loader.LoaderPlugin, fileConfig: Phaser.Types.Loader.FileConfig); - - /** - * A reference to the Loader that is going to load this file. - */ - loader: Phaser.Loader.LoaderPlugin; - - /** - * A reference to the Cache, or Texture Manager, that is going to store this file if it loads. - */ - cache: Phaser.Cache.BaseCache | Phaser.Textures.TextureManager; - - /** - * The file type string (image, json, etc) for sorting within the Loader. - */ - type: string; - - /** - * Unique cache key (unique within its file type) - */ - key: string; - - /** - * The URL of the file, not including baseURL. - * Automatically has Loader.path prepended to it. - */ - url: string; - - /** - * The final URL this file will load from, including baseURL and path. - * Set automatically when the Loader calls 'load' on this file. - */ - src: string; - - /** - * The merged XHRSettings for this file. - */ - xhrSettings: Phaser.Types.Loader.XHRSettingsObject; - - /** - * The XMLHttpRequest instance (as created by XHR Loader) that is loading this File. - */ - xhrLoader: XMLHttpRequest; - - /** - * The current state of the file. One of the FILE_CONST values. - */ - state: integer; - - /** - * The total size of this file. - * Set by onProgress and only if loading via XHR. - */ - bytesTotal: number; - - /** - * Updated as the file loads. - * Only set if loading via XHR. - */ - bytesLoaded: number; - - /** - * A percentage value between 0 and 1 indicating how much of this file has loaded. - * Only set if loading via XHR. - */ - percentComplete: number; - - /** - * For CORs based loading. - * If this is undefined then the File will check BaseLoader.crossOrigin and use that (if set) - */ - crossOrigin: string | undefined; - - /** - * The processed file data, stored here after the file has loaded. - */ - data: any; - - /** - * A config object that can be used by file types to store transitional data. - */ - config: any; - - /** - * If this is a multipart file, i.e. an atlas and its json together, then this is a reference - * to the parent MultiFile. Set and used internally by the Loader or specific file types. - */ - multiFile: Phaser.Loader.MultiFile; - - /** - * Does this file have an associated linked file? Such as an image and a normal map. - * Atlases and Bitmap Fonts use the multiFile, because those files need loading together but aren't - * actually bound by data, where-as a linkFile is. - */ - linkFile: Phaser.Loader.File; - - /** - * Links this File with another, so they depend upon each other for loading and processing. - * @param fileB The file to link to this one. - */ - setLink(fileB: Phaser.Loader.File): void; - - /** - * Resets the XHRLoader instance this file is using. - */ - resetXHR(): void; - - /** - * Called by the Loader, starts the actual file downloading. - * During the load the methods onLoad, onError and onProgress are called, based on the XHR events. - * You shouldn't normally call this method directly, it's meant to be invoked by the Loader. - */ - load(): void; - - /** - * Called when the file finishes loading, is sent a DOM ProgressEvent. - * @param xhr The XMLHttpRequest that caused this onload event. - * @param event The DOM ProgressEvent that resulted from this load. - */ - onLoad(xhr: XMLHttpRequest, event: ProgressEvent): void; - - /** - * Called if the file errors while loading, is sent a DOM ProgressEvent. - * @param xhr The XMLHttpRequest that caused this onload event. - * @param event The DOM ProgressEvent that resulted from this error. - */ - onError(xhr: XMLHttpRequest, event: ProgressEvent): void; - - /** - * Called during the file load progress. Is sent a DOM ProgressEvent. - * @param event The DOM ProgressEvent. - */ - onProgress(event: ProgressEvent): void; - - /** - * Usually overridden by the FileTypes and is called by Loader.nextFile. - * This method controls what extra work this File does with its loaded data, for example a JSON file will parse itself during this stage. - */ - onProcess(): void; - - /** - * Called when the File has completed processing. - * Checks on the state of its multifile, if set. - */ - onProcessComplete(): void; - - /** - * Called when the File has completed processing but it generated an error. - * Checks on the state of its multifile, if set. - */ - onProcessError(): void; - - /** - * Checks if a key matching the one used by this file exists in the target Cache or not. - * This is called automatically by the LoaderPlugin to decide if the file can be safely - * loaded or will conflict. - */ - hasCacheConflict(): boolean; - - /** - * Adds this file to its target cache upon successful loading and processing. - * This method is often overridden by specific file types. - */ - addToCache(): void; - - /** - * Called once the file has been added to its cache and is now ready for deletion from the Loader. - * It will emit a `filecomplete` event from the LoaderPlugin. - */ - pendingDestroy(): void; - - /** - * Destroy this File and any references it holds. - */ - destroy(): void; - - /** - * Static method for creating object URL using URL API and setting it as image 'src' attribute. - * If URL API is not supported (usually on old browsers) it falls back to creating Base64 encoded url using FileReader. - * @param image Image object which 'src' attribute should be set to object URL. - * @param blob A Blob object to create an object URL for. - * @param defaultType Default mime type used if blob type is not available. - */ - static createObjectURL(image: HTMLImageElement, blob: Blob, defaultType: string): void; - - /** - * Static method for releasing an existing object URL which was previously created - * by calling {@link File#createObjectURL} method. - * @param image Image object which 'src' attribute should be revoked. - */ - static revokeObjectURL(image: HTMLImageElement): void; - - } - - namespace FileTypes { - /** - * A single Animation JSON File suitable for loading by the Loader. - * - * These are created when you use the Phaser.Loader.LoaderPlugin#animation method and are not typically created directly. - * - * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#animation. - */ - class AnimationJSONFile extends Phaser.Loader.File { /** - * - * @param loader A reference to the Loader that is responsible for this file. - * @param key The key to use for this file, or a file configuration object. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". - * @param xhrSettings Extra XHR Settings specifically for this file. - * @param dataKey When the JSON file loads only this property will be stored in the Cache. + * A reference to the core game, so we can listen for visibility events. */ - constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.JSONFileConfig, url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject, dataKey?: string); + game: Phaser.Game; /** - * Called automatically by Loader.nextFile. - * This method controls what extra work this File does with its loaded data. + * A reference to the Scene that this Input Plugin is responsible for. */ - onProcess(): void; + scene: Phaser.Scene; /** - * Called at the end of the load process, after the Loader has finished all files in its queue. + * A reference to the Scene Systems Settings. */ - onLoadComplete(): void; - - } + settings: Phaser.Types.Scenes.SettingsObject; - /** - * A single JSON based Texture Atlas File suitable for loading by the Loader. - * - * These are created when you use the Phaser.Loader.LoaderPlugin#atlas method and are not typically created directly. - * - * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#atlas. - * - * https://www.codeandweb.com/texturepacker/tutorials/how-to-create-sprite-sheets-for-phaser3?source=photonstorm - */ - class AtlasJSONFile extends Phaser.Loader.MultiFile { /** - * - * @param loader A reference to the Loader that is responsible for this file. - * @param key The key to use for this file, or a file configuration object. - * @param textureURL The absolute or relative URL to load the texture image file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". - * @param atlasURL The absolute or relative URL to load the texture atlas json data file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". - * @param textureXhrSettings An XHR Settings configuration object for the atlas image file. Used in replacement of the Loaders default XHR Settings. - * @param atlasXhrSettings An XHR Settings configuration object for the atlas json file. Used in replacement of the Loaders default XHR Settings. + * A reference to the Scene Input Plugin that created this Keyboard Plugin. */ - constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.AtlasJSONFileConfig, textureURL?: string | string[], atlasURL?: string, textureXhrSettings?: Phaser.Types.Loader.XHRSettingsObject, atlasXhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + sceneInputPlugin: Phaser.Input.InputPlugin; /** - * Adds this file to its target cache upon successful loading and processing. + * A reference to the global Keyboard Manager. */ - addToCache(): void; - - } + manager: Phaser.Input.InputPlugin; - /** - * A single XML based Texture Atlas File suitable for loading by the Loader. - * - * These are created when you use the Phaser.Loader.LoaderPlugin#atlasXML method and are not typically created directly. - * - * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#atlasXML. - */ - class AtlasXMLFile extends Phaser.Loader.MultiFile { /** - * - * @param loader A reference to the Loader that is responsible for this file. - * @param key The key to use for this file, or a file configuration object. - * @param textureURL The absolute or relative URL to load the texture image file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". - * @param atlasURL The absolute or relative URL to load the texture atlas xml data file from. If undefined or `null` it will be set to `.xml`, i.e. if `key` was "alien" then the URL will be "alien.xml". - * @param textureXhrSettings An XHR Settings configuration object for the atlas image file. Used in replacement of the Loaders default XHR Settings. - * @param atlasXhrSettings An XHR Settings configuration object for the atlas xml file. Used in replacement of the Loaders default XHR Settings. + * A boolean that controls if this Keyboard Plugin is enabled or not. + * Can be toggled on the fly. */ - constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.AtlasXMLFileConfig, textureURL?: string | string[], atlasURL?: string, textureXhrSettings?: Phaser.Types.Loader.XHRSettingsObject, atlasXhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + enabled: boolean; /** - * Adds this file to its target cache upon successful loading and processing. + * An array of Key objects to process. */ - addToCache(): void; - - } + keys: Phaser.Input.Keyboard.Key[]; - /** - * A single Audio File suitable for loading by the Loader. - * - * These are created when you use the Phaser.Loader.LoaderPlugin#audio method and are not typically created directly. - * - * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#audio. - */ - class AudioFile extends Phaser.Loader.File { /** - * - * @param loader A reference to the Loader that is responsible for this file. - * @param key The key to use for this file, or a file configuration object. - * @param urlConfig The absolute or relative URL to load this file from in a config object. - * @param xhrSettings Extra XHR Settings specifically for this file. - * @param audioContext The AudioContext this file will use to process itself. + * An array of KeyCombo objects to process. */ - constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.AudioFileConfig, urlConfig?: any, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject, audioContext?: AudioContext); + combos: Phaser.Input.Keyboard.KeyCombo[]; /** - * Called automatically by Loader.nextFile. - * This method controls what extra work this File does with its loaded data. + * Checks to see if both this plugin and the Scene to which it belongs is active. */ - onProcess(): void; + isActive(): boolean; - } + /** + * By default when a key is pressed Phaser will not stop the event from propagating up to the browser. + * There are some keys this can be annoying for, like the arrow keys or space bar, which make the browser window scroll. + * + * This `addCapture` method enables consuming keyboard events for specific keys, so they don't bubble up the browser + * and cause the default behaviors. + * + * Please note that keyboard captures are global. This means that if you call this method from within a Scene, to say prevent + * the SPACE BAR from triggering a page scroll, then it will prevent it for any Scene in your game, not just the calling one. + * + * You can pass a single key code value: + * + * ```javascript + * this.input.keyboard.addCapture(62); + * ``` + * + * An array of key codes: + * + * ```javascript + * this.input.keyboard.addCapture([ 62, 63, 64 ]); + * ``` + * + * Or, a comma-delimited string: + * + * ```javascript + * this.input.keyboard.addCapture('W,S,A,D'); + * ``` + * + * To use non-alpha numeric keys, use a string, such as 'UP', 'SPACE' or 'LEFT'. + * + * You can also provide an array mixing both strings and key code integers. + * @param keycode The Key Codes to enable event capture for. + */ + addCapture(keycode: string | number | number[] | any[]): this; - /** - * An Audio Sprite File suitable for loading by the Loader. - * - * These are created when you use the Phaser.Loader.LoaderPlugin#audioSprite method and are not typically created directly. - * - * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#audioSprite. - */ - class AudioSpriteFile extends Phaser.Loader.MultiFile { /** + * Removes an existing key capture. * - * @param loader A reference to the Loader that is responsible for this file. - * @param key The key to use for this file, or a file configuration object. - * @param jsonURL The absolute or relative URL to load the json file from. Or a well formed JSON object to use instead. - * @param audioURL The absolute or relative URL to load the audio file from. If empty it will be obtained by parsing the JSON file. - * @param audioConfig The audio configuration options. - * @param audioXhrSettings An XHR Settings configuration object for the audio file. Used in replacement of the Loaders default XHR Settings. - * @param jsonXhrSettings An XHR Settings configuration object for the json file. Used in replacement of the Loaders default XHR Settings. + * Please note that keyboard captures are global. This means that if you call this method from within a Scene, to remove + * the capture of a key, then it will remove it for any Scene in your game, not just the calling one. + * + * You can pass a single key code value: + * + * ```javascript + * this.input.keyboard.removeCapture(62); + * ``` + * + * An array of key codes: + * + * ```javascript + * this.input.keyboard.removeCapture([ 62, 63, 64 ]); + * ``` + * + * Or, a comma-delimited string: + * + * ```javascript + * this.input.keyboard.removeCapture('W,S,A,D'); + * ``` + * + * To use non-alpha numeric keys, use a string, such as 'UP', 'SPACE' or 'LEFT'. + * + * You can also provide an array mixing both strings and key code integers. + * @param keycode The Key Codes to disable event capture for. */ - constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.AudioSpriteFileConfig, jsonURL: string, audioURL?: Object, audioConfig?: any, audioXhrSettings?: Phaser.Types.Loader.XHRSettingsObject, jsonXhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + removeCapture(keycode: string | number | number[] | any[]): this; /** - * Called by each File when it finishes loading. - * @param file The File that has completed processing. + * Returns an array that contains all of the keyboard captures currently enabled. */ - onFileComplete(file: Phaser.Loader.File): void; + getCaptures(): number[]; /** - * Adds this file to its target cache upon successful loading and processing. + * Allows Phaser to prevent any key captures you may have defined from bubbling up the browser. + * You can use this to re-enable event capturing if you had paused it via `disableGlobalCapture`. */ - addToCache(): void; + enableGlobalCapture(): this; - } + /** + * Disables Phaser from preventing any key captures you may have defined, without actually removing them. + * You can use this to temporarily disable event capturing if, for example, you swap to a DOM element. + */ + disableGlobalCapture(): this; - /** - * A single Binary File suitable for loading by the Loader. - * - * These are created when you use the Phaser.Loader.LoaderPlugin#binary method and are not typically created directly. - * - * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#binary. - */ - class BinaryFile extends Phaser.Loader.File { /** + * Removes all keyboard captures. * - * @param loader A reference to the Loader that is responsible for this file. - * @param key The key to use for this file, or a file configuration object. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.bin`, i.e. if `key` was "alien" then the URL will be "alien.bin". - * @param xhrSettings Extra XHR Settings specifically for this file. - * @param dataType Optional type to cast the binary file to once loaded. For example, `Uint8Array`. + * Note that this is a global change. It will clear all event captures across your game, not just for this specific Scene. */ - constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.BinaryFileConfig, url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject, dataType?: any); + clearCaptures(): this; /** - * Called automatically by Loader.nextFile. - * This method controls what extra work this File does with its loaded data. + * Creates and returns an object containing 4 hotkeys for Up, Down, Left and Right, and also Space Bar and shift. */ - onProcess(): void; - - } + createCursorKeys(): Phaser.Types.Input.Keyboard.CursorKeys; - /** - * A single Bitmap Font based File suitable for loading by the Loader. - * - * These are created when you use the Phaser.Loader.LoaderPlugin#bitmapFont method and are not typically created directly. - * - * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#bitmapFont. - */ - class BitmapFontFile extends Phaser.Loader.MultiFile { /** + * A practical way to create an object containing user selected hotkeys. * - * @param loader A reference to the Loader that is responsible for this file. - * @param key The key to use for this file, or a file configuration object. - * @param textureURL The absolute or relative URL to load the font image file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". - * @param fontDataURL The absolute or relative URL to load the font xml data file from. If undefined or `null` it will be set to `.xml`, i.e. if `key` was "alien" then the URL will be "alien.xml". - * @param textureXhrSettings An XHR Settings configuration object for the font image file. Used in replacement of the Loaders default XHR Settings. - * @param fontDataXhrSettings An XHR Settings configuration object for the font data xml file. Used in replacement of the Loaders default XHR Settings. + * For example: + * + * ```javascript + * this.input.keyboard.addKeys({ 'up': Phaser.Input.Keyboard.KeyCodes.W, 'down': Phaser.Input.Keyboard.KeyCodes.S }); + * ``` + * + * would return an object containing the properties (`up` and `down`) mapped to W and S {@link Phaser.Input.Keyboard.Key} objects. + * + * You can also pass in a comma-separated string: + * + * ```javascript + * this.input.keyboard.addKeys('W,S,A,D'); + * ``` + * + * Which will return an object with the properties W, S, A and D mapped to the relevant Key objects. + * + * To use non-alpha numeric keys, use a string, such as 'UP', 'SPACE' or 'LEFT'. + * @param keys An object containing Key Codes, or a comma-separated string. + * @param enableCapture Automatically call `preventDefault` on the native DOM browser event for the key codes being added. Default true. + * @param emitOnRepeat Controls if the Key will continuously emit a 'down' event while being held down (true), or emit the event just once (false, the default). Default false. */ - constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.BitmapFontFileConfig, textureURL?: string | string[], fontDataURL?: string, textureXhrSettings?: Phaser.Types.Loader.XHRSettingsObject, fontDataXhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + addKeys(keys: object | string, enableCapture?: boolean, emitOnRepeat?: boolean): object; /** - * Adds this file to its target cache upon successful loading and processing. + * Adds a Key object to this Keyboard Plugin. + * + * The given argument can be either an existing Key object, a string, such as `A` or `SPACE`, or a key code value. + * + * If a Key object is given, and one already exists matching the same key code, the existing one is replaced with the new one. + * @param key Either a Key object, a string, such as `A` or `SPACE`, or a key code value. + * @param enableCapture Automatically call `preventDefault` on the native DOM browser event for the key codes being added. Default true. + * @param emitOnRepeat Controls if the Key will continuously emit a 'down' event while being held down (true), or emit the event just once (false, the default). Default false. */ - addToCache(): void; + addKey(key: Phaser.Input.Keyboard.Key | string | number, enableCapture?: boolean, emitOnRepeat?: boolean): Phaser.Input.Keyboard.Key; - } + /** + * Removes a Key object from this Keyboard Plugin. + * + * The given argument can be either a Key object, a string, such as `A` or `SPACE`, or a key code value. + * @param key Either a Key object, a string, such as `A` or `SPACE`, or a key code value. + * @param destroy Call `Key.destroy` on the removed Key object? Default false. + */ + removeKey(key: Phaser.Input.Keyboard.Key | string | number, destroy?: boolean): this; - /** - * A single CSS File suitable for loading by the Loader. - * - * These are created when you use the Phaser.Loader.LoaderPlugin#css method and are not typically created directly. - * - * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#css. - */ - class CSSFile extends Phaser.Loader.File { /** + * Removes all Key objects created by _this_ Keyboard Plugin. + * @param destroy Call `Key.destroy` on each removed Key object? Default false. + */ + removeAllKeys(destroy?: boolean): this; + + /** + * Creates a new KeyCombo. * - * @param loader A reference to the Loader that is responsible for this file. - * @param key The key to use for this file, or a file configuration object. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.js`, i.e. if `key` was "alien" then the URL will be "alien.js". - * @param xhrSettings Extra XHR Settings specifically for this file. + * A KeyCombo will listen for a specific string of keys from the Keyboard, and when it receives them + * it will emit a `keycombomatch` event from this Keyboard Plugin. + * + * The keys to be listened for can be defined as: + * + * A string (i.e. 'ATARI') + * An array of either integers (key codes) or strings, or a mixture of both + * An array of objects (such as Key objects) with a public 'keyCode' property + * + * For example, to listen for the Konami code (up, up, down, down, left, right, left, right, b, a, enter) + * you could pass the following array of key codes: + * + * ```javascript + * this.input.keyboard.createCombo([ 38, 38, 40, 40, 37, 39, 37, 39, 66, 65, 13 ], { resetOnMatch: true }); + * + * this.input.keyboard.on('keycombomatch', function (event) { + * console.log('Konami Code entered!'); + * }); + * ``` + * + * Or, to listen for the user entering the word PHASER: + * + * ```javascript + * this.input.keyboard.createCombo('PHASER'); + * ``` + * @param keys The keys that comprise this combo. + * @param config A Key Combo configuration object. */ - constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.CSSFileConfig, url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + createCombo(keys: string | number[] | object[], config?: Phaser.Types.Input.Keyboard.KeyComboConfig): Phaser.Input.Keyboard.KeyCombo; /** - * Called automatically by Loader.nextFile. - * This method controls what extra work this File does with its loaded data. + * Checks if the given Key object is currently being held down. + * + * The difference between this method and checking the `Key.isDown` property directly is that you can provide + * a duration to this method. For example, if you wanted a key press to fire a bullet, but you only wanted + * it to be able to fire every 100ms, then you can call this method with a `duration` of 100 and it + * will only return `true` every 100ms. + * + * If the Keyboard Plugin has been disabled, this method will always return `false`. + * @param key A Key object. + * @param duration The duration which must have elapsed before this Key is considered as being down. Default 0. */ - onProcess(): void; + checkDown(key: Phaser.Input.Keyboard.Key, duration?: number): boolean; + + /** + * Resets all Key objects created by _this_ Keyboard Plugin back to their default un-pressed states. + * This can only reset keys created via the `addKey`, `addKeys` or `createCursorKeys` methods. + * If you have created a Key object directly you'll need to reset it yourself. + * + * This method is called automatically when the Keyboard Plugin shuts down, but can be + * invoked directly at any time you require. + */ + resetKeys(): this; } /** - * A single GLSL File suitable for loading by the Loader. + * Returns `true` if the Key was pressed down within the `duration` value given, based on the current + * game clock time. Or `false` if it either isn't down, or was pressed down longer ago than the given duration. + * @param key The Key object to test. + * @param duration The duration, in ms, within which the key must have been pressed down. Default 50. + */ + function DownDuration(key: Phaser.Input.Keyboard.Key, duration?: number): boolean; + + /** + * The justDown value allows you to test if this Key has just been pressed down or not. * - * These are created when you use the Phaser.Loader.LoaderPlugin#glsl method and are not typically created directly. + * When you check this value it will return `true` if the Key is down, otherwise `false`. * - * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#glsl. + * You can only call justDown once per key press. It will only return `true` once, until the Key is released and pressed down again. + * This allows you to use it in situations where you want to check if this key is down without using an event, such as in a core game loop. + * @param key The Key to check to see if it's just down or not. */ - class GLSLFile extends Phaser.Loader.File { + function JustDown(key: Phaser.Input.Keyboard.Key): boolean; + + /** + * The justUp value allows you to test if this Key has just been released or not. + * + * When you check this value it will return `true` if the Key is up, otherwise `false`. + * + * You can only call JustUp once per key release. It will only return `true` once, until the Key is pressed down and released again. + * This allows you to use it in situations where you want to check if this key is up without using an event, such as in a core game loop. + * @param key The Key to check to see if it's just up or not. + */ + function JustUp(key: Phaser.Input.Keyboard.Key): boolean; + + /** + * A generic Key object which can be passed to the Process functions (and so on) + * keycode must be an integer + */ + class Key extends Phaser.Events.EventEmitter { /** * - * @param loader A reference to the Loader that is responsible for this file. - * @param key The key to use for this file, or a file configuration object. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.txt`, i.e. if `key` was "alien" then the URL will be "alien.txt". - * @param shaderType The type of shader. Either `fragment` for a fragment shader, or `vertex` for a vertex shader. This is ignored if you load a shader bundle. Default 'fragment'. - * @param xhrSettings Extra XHR Settings specifically for this file. + * @param plugin The Keyboard Plugin instance that owns this Key object. + * @param keyCode The keycode of this key. */ - constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.GLSLFileConfig, url?: string, shaderType?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + constructor(plugin: Phaser.Input.Keyboard.KeyboardPlugin, keyCode: number); /** - * Called automatically by Loader.nextFile. - * This method controls what extra work this File does with its loaded data. + * The Keyboard Plugin instance that owns this Key object. */ - onProcess(): void; + plugin: Phaser.Input.Keyboard.KeyboardPlugin; /** - * Adds this file to its target cache upon successful loading and processing. + * The keycode of this key. */ - addToCache(): void; + keyCode: number; /** - * Returns the name of the shader from the header block. - * @param headerSource The header data. + * The original DOM event. */ - getShaderName(headerSource: string[]): string; + originalEvent: KeyboardEvent; /** - * Returns the type of the shader from the header block. - * @param headerSource The header data. + * Can this Key be processed? */ - getShaderType(headerSource: string[]): string; + enabled: boolean; /** - * Returns the shader uniforms from the header block. - * @param headerSource The header data. + * The "down" state of the key. This will remain `true` for as long as the keyboard thinks this key is held down. */ - getShaderUniforms(headerSource: string[]): any; - - } + isDown: boolean; - /** - * A single Audio File suitable for loading by the Loader. - * - * These are created when you use the Phaser.Loader.LoaderPlugin#audio method and are not typically created directly. - * - * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#audio. - */ - class HTML5AudioFile extends Phaser.Loader.File { /** - * - * @param loader A reference to the Loader that is responsible for this file. - * @param key The key to use for this file, or a file configuration object. - * @param urlConfig The absolute or relative URL to load this file from. - * @param xhrSettings Extra XHR Settings specifically for this file. + * The "up" state of the key. This will remain `true` for as long as the keyboard thinks this key is up. */ - constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.AudioFileConfig, urlConfig?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + isUp: boolean; /** - * Called when the file finishes loading. + * The down state of the ALT key, if pressed at the same time as this key. */ - onLoad(): void; + altKey: boolean; /** - * Called if the file errors while loading. + * The down state of the CTRL key, if pressed at the same time as this key. */ - onError(): void; + ctrlKey: boolean; /** - * Called during the file load progress. Is sent a DOM ProgressEvent. + * The down state of the SHIFT key, if pressed at the same time as this key. */ - onProgress(): void; + shiftKey: boolean; /** - * Called by the Loader, starts the actual file downloading. - * During the load the methods onLoad, onError and onProgress are called, based on the XHR events. - * You shouldn't normally call this method directly, it's meant to be invoked by the Loader. + * The down state of the Meta key, if pressed at the same time as this key. + * On a Mac the Meta Key is the Command key. On Windows keyboards, it's the Windows key. */ - load(): void; + metaKey: boolean; - } + /** + * The location of the modifier key. 0 for standard (or unknown), 1 for left, 2 for right, 3 for numpad. + */ + location: number; - /** - * A single HTML File suitable for loading by the Loader. - * - * These are created when you use the Phaser.Loader.LoaderPlugin#html method and are not typically created directly. - * - * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#html. - */ - class HTMLFile extends Phaser.Loader.File { /** - * - * @param loader A reference to the Loader that is responsible for this file. - * @param key The key to use for this file, or a file configuration object. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.txt`, i.e. if `key` was "alien" then the URL will be "alien.html". - * @param xhrSettings Extra XHR Settings specifically for this file. + * The timestamp when the key was last pressed down. */ - constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.HTMLFileConfig, url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + timeDown: number; /** - * Called automatically by Loader.nextFile. - * This method controls what extra work this File does with its loaded data. + * The number of milliseconds this key was held down for in the previous down - up sequence. + * This value isn't updated every game step, only when the Key changes state. + * To get the current duration use the `getDuration` method. */ - onProcess(): void; + duration: number; - } + /** + * The timestamp when the key was last released. + */ + timeUp: number; - /** - * A single HTML File suitable for loading by the Loader. - * - * These are created when you use the Phaser.Loader.LoaderPlugin#htmlTexture method and are not typically created directly. - * - * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#htmlTexture. - */ - class HTMLTextureFile extends Phaser.Loader.File { /** + * When a key is held down should it continuously fire the `down` event each time it repeats? * - * @param loader A reference to the Loader that is responsible for this file. - * @param key The key to use for this file, or a file configuration object. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". - * @param width The width of the texture the HTML will be rendered to. - * @param height The height of the texture the HTML will be rendered to. - * @param xhrSettings Extra XHR Settings specifically for this file. + * By default it will emit the `down` event just once, but if you wish to receive the event + * for each repeat as well, enable this property. */ - constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.HTMLTextureFileConfig, url?: string, width?: integer, height?: integer, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + emitOnRepeat: boolean; /** - * Called automatically by Loader.nextFile. - * This method controls what extra work this File does with its loaded data. + * If a key is held down this holds down the number of times the key has 'repeated'. */ - onProcess(): void; + repeats: number; /** - * Adds this file to its target cache upon successful loading and processing. + * Controls if this Key will continuously emit a `down` event while being held down (true), + * or emit the event just once, on first press, and then skip future events (false). + * @param value Emit `down` events on repeated key down actions, or just once? */ - addToCache(): void; - - } + setEmitOnRepeat(value: boolean): this; - /** - * A single Image File suitable for loading by the Loader. - * - * These are created when you use the Phaser.Loader.LoaderPlugin#image method and are not typically created directly. - * - * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#image. - */ - class ImageFile extends Phaser.Loader.File { /** - * - * @param loader A reference to the Loader that is responsible for this file. - * @param key The key to use for this file, or a file configuration object. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". - * @param xhrSettings Extra XHR Settings specifically for this file. - * @param frameConfig The frame configuration object. Only provided for, and used by, Sprite Sheets. + * Processes the Key Down action for this Key. + * Called automatically by the Keyboard Plugin. + * @param event The native DOM Keyboard event. */ - constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.ImageFileConfig, url?: string | string[], xhrSettings?: Phaser.Types.Loader.XHRSettingsObject, frameConfig?: Phaser.Types.Loader.FileTypes.ImageFrameConfig); + onDown(event: KeyboardEvent): void; /** - * Called automatically by Loader.nextFile. - * This method controls what extra work this File does with its loaded data. + * Processes the Key Up action for this Key. + * Called automatically by the Keyboard Plugin. + * @param event The native DOM Keyboard event. */ - onProcess(): void; + onUp(event: KeyboardEvent): void; /** - * Adds this file to its target cache upon successful loading and processing. + * Resets this Key object back to its default un-pressed state. */ - addToCache(): void; + reset(): this; - } - - /** - * A single JSON File suitable for loading by the Loader. - * - * These are created when you use the Phaser.Loader.LoaderPlugin#json method and are not typically created directly. - * - * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#json. - */ - class JSONFile extends Phaser.Loader.File { /** + * Returns the duration, in ms, that the Key has been held down for. * - * @param loader A reference to the Loader that is responsible for this file. - * @param key The key to use for this file, or a file configuration object. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". - * @param xhrSettings Extra XHR Settings specifically for this file. - * @param dataKey When the JSON file loads only this property will be stored in the Cache. + * If the key is not currently down it will return zero. + * + * The get the duration the Key was held down for in the previous up-down cycle, + * use the `Key.duration` property value instead. */ - constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.JSONFileConfig, url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject, dataKey?: string); + getDuration(): number; /** - * Called automatically by Loader.nextFile. - * This method controls what extra work this File does with its loaded data. + * Removes any bound event handlers and removes local references. */ - onProcess(): void; + destroy(): void; } /** - * A single Multi Texture Atlas File suitable for loading by the Loader. - * - * These are created when you use the Phaser.Loader.LoaderPlugin#multiatlas method and are not typically created directly. - * - * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#multiatlas. + * Keyboard Codes. */ - class MultiAtlasFile extends Phaser.Loader.MultiFile { + namespace KeyCodes { /** - * - * @param loader A reference to the Loader that is responsible for this file. - * @param key The key of the file. Must be unique within both the Loader and the Texture Manager. Or a config object. - * @param atlasURL The absolute or relative URL to load the multi atlas json file from. - * @param path Optional path to use when loading the textures defined in the atlas data. - * @param baseURL Optional Base URL to use when loading the textures defined in the atlas data. - * @param atlasXhrSettings Extra XHR Settings specifically for the atlas json file. - * @param textureXhrSettings Extra XHR Settings specifically for the texture files. + * The BACKSPACE key. */ - constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.MultiAtlasFileConfig, atlasURL?: string, path?: string, baseURL?: string, atlasXhrSettings?: Phaser.Types.Loader.XHRSettingsObject, textureXhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + var BACKSPACE: number; /** - * Called by each File when it finishes loading. - * @param file The File that has completed processing. + * The TAB key. */ - onFileComplete(file: Phaser.Loader.File): void; + var TAB: number; /** - * Adds this file to its target cache upon successful loading and processing. + * The ENTER key. */ - addToCache(): void; + var ENTER: number; - } - - /** - * A Multi Script File suitable for loading by the Loader. - * - * These are created when you use the Phaser.Loader.LoaderPlugin#scripts method and are not typically created directly. - * - * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#scripts. - */ - class MultiScriptFile extends Phaser.Loader.MultiFile { /** - * - * @param loader A reference to the Loader that is responsible for this file. - * @param key The key to use for this file, or a file configuration object. - * @param url An array of absolute or relative URLs to load the script files from. They are processed in the order given in the array. - * @param xhrSettings An XHR Settings configuration object for the script files. Used in replacement of the Loaders default XHR Settings. + * The SHIFT key. */ - constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.MultiScriptFileConfig, url?: string[], xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + var SHIFT: number; /** - * Adds this file to its target cache upon successful loading and processing. + * The CTRL key. */ - addToCache(): void; + var CTRL: number; - } - - /** - * A single JSON Pack File suitable for loading by the Loader. - * - * These are created when you use the Phaser.Loader.LoaderPlugin#pack method and are not typically created directly. - * - * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#pack. - */ - class PackFile extends Phaser.Loader.File { /** - * - * @param loader A reference to the Loader that is responsible for this file. - * @param key The key to use for this file, or a file configuration object. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". - * @param xhrSettings Extra XHR Settings specifically for this file. - * @param dataKey When the JSON file loads only this property will be stored in the Cache. + * The ALT key. */ - constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.PackFileConfig, url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject, dataKey?: string); + var ALT: number; /** - * Called automatically by Loader.nextFile. - * This method controls what extra work this File does with its loaded data. + * The PAUSE key. */ - onProcess(): void; + var PAUSE: number; - } + /** + * The CAPS_LOCK key. + */ + var CAPS_LOCK: number; - /** - * A single Plugin Script File suitable for loading by the Loader. - * - * These are created when you use the Phaser.Loader.LoaderPlugin#plugin method and are not typically created directly. - * - * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#plugin. - */ - class PluginFile extends Phaser.Loader.File { /** - * - * @param loader A reference to the Loader that is responsible for this file. - * @param key The key to use for this file, or a file configuration object. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.js`, i.e. if `key` was "alien" then the URL will be "alien.js". - * @param start Automatically start the plugin after loading? Default false. - * @param mapping If this plugin is to be injected into the Scene, this is the property key used. - * @param xhrSettings Extra XHR Settings specifically for this file. + * The ESC key. */ - constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.PluginFileConfig, url?: string, start?: boolean, mapping?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + var ESC: number; /** - * Called automatically by Loader.nextFile. - * This method controls what extra work this File does with its loaded data. + * The SPACE key. */ - onProcess(): void; + var SPACE: number; - } + /** + * The PAGE_UP key. + */ + var PAGE_UP: number; - /** - * An external Scene JavaScript File suitable for loading by the Loader. - * - * These are created when you use the Phaser.Loader.LoaderPlugin#sceneFile method and are not typically created directly. - * - * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#sceneFile. - */ - class SceneFile extends Phaser.Loader.File { /** - * - * @param loader A reference to the Loader that is responsible for this file. - * @param key The key to use for this file, or a file configuration object. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.js`, i.e. if `key` was "alien" then the URL will be "alien.js". - * @param xhrSettings Extra XHR Settings specifically for this file. + * The PAGE_DOWN key. */ - constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.SceneFileConfig, url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + var PAGE_DOWN: number; /** - * Called automatically by Loader.nextFile. - * This method controls what extra work this File does with its loaded data. + * The END key. */ - onProcess(): void; + var END: number; /** - * Adds this file to its target cache upon successful loading and processing. + * The HOME key. */ - addToCache(): void; + var HOME: number; - } + /** + * The LEFT key. + */ + var LEFT: number; - /** - * A single Scene Plugin Script File suitable for loading by the Loader. - * - * These are created when you use the Phaser.Loader.LoaderPlugin#scenePlugin method and are not typically created directly. - * - * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#scenePlugin. - */ - class ScenePluginFile extends Phaser.Loader.File { /** - * - * @param loader A reference to the Loader that is responsible for this file. - * @param key The key to use for this file, or a file configuration object. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.js`, i.e. if `key` was "alien" then the URL will be "alien.js". - * @param systemKey If this plugin is to be added to Scene.Systems, this is the property key for it. - * @param sceneKey If this plugin is to be added to the Scene, this is the property key for it. - * @param xhrSettings Extra XHR Settings specifically for this file. + * The UP key. */ - constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.ScenePluginFileConfig, url?: string, systemKey?: string, sceneKey?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + var UP: number; /** - * Called automatically by Loader.nextFile. - * This method controls what extra work this File does with its loaded data. + * The RIGHT key. */ - onProcess(): void; + var RIGHT: number; - } + /** + * The DOWN key. + */ + var DOWN: number; - /** - * A single Script File suitable for loading by the Loader. - * - * These are created when you use the Phaser.Loader.LoaderPlugin#script method and are not typically created directly. - * - * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#script. - */ - class ScriptFile extends Phaser.Loader.File { /** - * - * @param loader A reference to the Loader that is responsible for this file. - * @param key The key to use for this file, or a file configuration object. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.js`, i.e. if `key` was "alien" then the URL will be "alien.js". - * @param xhrSettings Extra XHR Settings specifically for this file. + * The PRINT_SCREEN key. */ - constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.ScriptFileConfig, url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + var PRINT_SCREEN: number; /** - * Called automatically by Loader.nextFile. - * This method controls what extra work this File does with its loaded data. + * The INSERT key. */ - onProcess(): void; + var INSERT: number; - } + /** + * The DELETE key. + */ + var DELETE: number; - /** - * A single Sprite Sheet Image File suitable for loading by the Loader. - * - * These are created when you use the Phaser.Loader.LoaderPlugin#spritesheet method and are not typically created directly. - * - * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#spritesheet. - */ - class SpriteSheetFile extends Phaser.Loader.File { /** - * - * @param loader A reference to the Loader that is responsible for this file. - * @param key The key to use for this file, or a file configuration object. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". - * @param frameConfig The frame configuration object. - * @param xhrSettings Extra XHR Settings specifically for this file. + * The ZERO key. */ - constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.SpriteSheetFileConfig, url?: string | string[], frameConfig?: Phaser.Types.Loader.FileTypes.ImageFrameConfig, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + var ZERO: number; /** - * Adds this file to its target cache upon successful loading and processing. + * The ONE key. */ - addToCache(): void; + var ONE: number; - } + /** + * The TWO key. + */ + var TWO: number; - /** - * A single SVG File suitable for loading by the Loader. - * - * These are created when you use the Phaser.Loader.LoaderPlugin#svg method and are not typically created directly. - * - * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#svg. - */ - class SVGFile extends Phaser.Loader.File { /** - * - * @param loader A reference to the Loader that is responsible for this file. - * @param key The key to use for this file, or a file configuration object. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.svg`, i.e. if `key` was "alien" then the URL will be "alien.svg". - * @param svgConfig The svg size configuration object. - * @param xhrSettings Extra XHR Settings specifically for this file. + * The THREE key. */ - constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.SVGFileConfig, url?: string, svgConfig?: Phaser.Types.Loader.FileTypes.SVGSizeConfig, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + var THREE: number; /** - * Called automatically by Loader.nextFile. - * This method controls what extra work this File does with its loaded data. + * The FOUR key. */ - onProcess(): void; + var FOUR: number; /** - * Adds this file to its target cache upon successful loading and processing. + * The FIVE key. */ - addToCache(): void; + var FIVE: number; - } + /** + * The SIX key. + */ + var SIX: number; - /** - * A single Text File suitable for loading by the Loader. - * - * These are created when you use the Phaser.Loader.LoaderPlugin#text method and are not typically created directly. - * - * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#text. - */ - class TextFile extends Phaser.Loader.File { /** - * - * @param loader A reference to the Loader that is responsible for this file. - * @param key The key to use for this file, or a file configuration object. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.txt`, i.e. if `key` was "alien" then the URL will be "alien.txt". - * @param xhrSettings Extra XHR Settings specifically for this file. + * The SEVEN key. */ - constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.TextFileConfig, url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + var SEVEN: number; /** - * Called automatically by Loader.nextFile. - * This method controls what extra work this File does with its loaded data. + * The EIGHT key. */ - onProcess(): void; + var EIGHT: number; - } + /** + * The NINE key. + */ + var NINE: number; - /** - * A single Tilemap CSV File suitable for loading by the Loader. - * - * These are created when you use the Phaser.Loader.LoaderPlugin#tilemapCSV method and are not typically created directly. - * - * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#tilemapCSV. - */ - class TilemapCSVFile extends Phaser.Loader.File { /** - * - * @param loader A reference to the Loader that is responsible for this file. - * @param key The key to use for this file, or a file configuration object. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.csv`, i.e. if `key` was "alien" then the URL will be "alien.csv". - * @param xhrSettings Extra XHR Settings specifically for this file. + * The NUMPAD_ZERO key. */ - constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.TilemapCSVFileConfig, url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + var NUMPAD_ZERO: number; /** - * Called automatically by Loader.nextFile. - * This method controls what extra work this File does with its loaded data. + * The NUMPAD_ONE key. */ - onProcess(): void; + var NUMPAD_ONE: number; /** - * Adds this file to its target cache upon successful loading and processing. + * The NUMPAD_TWO key. */ - addToCache(): void; + var NUMPAD_TWO: number; - } + /** + * The NUMPAD_THREE key. + */ + var NUMPAD_THREE: number; - /** - * A single Impact.js Tilemap JSON File suitable for loading by the Loader. - * - * These are created when you use the Phaser.Loader.LoaderPlugin#tilemapImpact method and are not typically created directly. - * - * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#tilemapImpact. - */ - class TilemapImpactFile extends Phaser.Loader.File { /** - * - * @param loader A reference to the Loader that is responsible for this file. - * @param key The key to use for this file, or a file configuration object. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". - * @param xhrSettings Extra XHR Settings specifically for this file. + * The NUMPAD_FOUR key. */ - constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.TilemapImpactFileConfig, url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + var NUMPAD_FOUR: number; /** - * Adds this file to its target cache upon successful loading and processing. + * The NUMPAD_FIVE key. */ - addToCache(): void; + var NUMPAD_FIVE: number; - } + /** + * The NUMPAD_SIX key. + */ + var NUMPAD_SIX: number; - /** - * A single Tiled Tilemap JSON File suitable for loading by the Loader. - * - * These are created when you use the Phaser.Loader.LoaderPlugin#tilemapTiledJSON method and are not typically created directly. - * - * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#tilemapTiledJSON. - */ - class TilemapJSONFile extends Phaser.Loader.File { /** - * - * @param loader A reference to the Loader that is responsible for this file. - * @param key The key to use for this file, or a file configuration object. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". - * @param xhrSettings Extra XHR Settings specifically for this file. + * The NUMPAD_SEVEN key. */ - constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.TilemapJSONFileConfig, url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + var NUMPAD_SEVEN: number; /** - * Adds this file to its target cache upon successful loading and processing. + * The NUMPAD_EIGHT key. */ - addToCache(): void; + var NUMPAD_EIGHT: number; - } + /** + * The NUMPAD_NINE key. + */ + var NUMPAD_NINE: number; - /** - * A single text file based Unity Texture Atlas File suitable for loading by the Loader. - * - * These are created when you use the Phaser.Loader.LoaderPlugin#unityAtlas method and are not typically created directly. - * - * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#unityAtlas. - */ - class UnityAtlasFile extends Phaser.Loader.MultiFile { /** - * - * @param loader A reference to the Loader that is responsible for this file. - * @param key The key to use for this file, or a file configuration object. - * @param textureURL The absolute or relative URL to load the texture image file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". - * @param atlasURL The absolute or relative URL to load the texture atlas data file from. If undefined or `null` it will be set to `.txt`, i.e. if `key` was "alien" then the URL will be "alien.txt". - * @param textureXhrSettings An XHR Settings configuration object for the atlas image file. Used in replacement of the Loaders default XHR Settings. - * @param atlasXhrSettings An XHR Settings configuration object for the atlas data file. Used in replacement of the Loaders default XHR Settings. + * The Numpad Addition (+) key. */ - constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.UnityAtlasFileConfig, textureURL?: string | string[], atlasURL?: string, textureXhrSettings?: Phaser.Types.Loader.XHRSettingsObject, atlasXhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + var NUMPAD_ADD: number; /** - * Adds this file to its target cache upon successful loading and processing. + * The Numpad Subtraction (-) key. */ - addToCache(): void; + var NUMPAD_SUBTRACT: number; - } + /** + * The A key. + */ + var A: number; - /** - * A single Video File suitable for loading by the Loader. - * - * These are created when you use the Phaser.Loader.LoaderPlugin#video method and are not typically created directly. - * - * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#video. - */ - class VideoFile extends Phaser.Loader.File { /** - * - * @param loader A reference to the Loader that is responsible for this file. - * @param key The key to use for this file, or a file configuration object. - * @param urlConfig The absolute or relative URL to load this file from in a config object. - * @param loadEvent The load event to listen for when _not_ loading as a blob. Either 'loadeddata', 'canplay' or 'canplaythrough'. - * @param asBlob Load the video as a data blob, or via the Video element? - * @param noAudio Does the video have an audio track? If not you can enable auto-playing on it. - * @param xhrSettings Extra XHR Settings specifically for this file. + * The B key. */ - constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.VideoFileConfig, urlConfig?: any, loadEvent?: string, asBlob?: boolean, noAudio?: boolean, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + var B: number; /** - * Called automatically by Loader.nextFile. - * This method controls what extra work this File does with its loaded data. + * The C key. */ - onProcess(): void; + var C: number; /** - * Called by the Loader, starts the actual file downloading. - * During the load the methods onLoad, onError and onProgress are called, based on the XHR events. - * You shouldn't normally call this method directly, it's meant to be invoked by the Loader. + * The D key. */ - load(): void; + var D: number; - } + /** + * The E key. + */ + var E: number; - /** - * A single XML File suitable for loading by the Loader. - * - * These are created when you use the Phaser.Loader.LoaderPlugin#xml method and are not typically created directly. - * - * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#xml. - */ - class XMLFile extends Phaser.Loader.File { /** - * - * @param loader A reference to the Loader that is responsible for this file. - * @param key The key to use for this file, or a file configuration object. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.xml`, i.e. if `key` was "alien" then the URL will be "alien.xml". - * @param xhrSettings Extra XHR Settings specifically for this file. + * The F key. */ - constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.XMLFileConfig, url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + var F: number; /** - * Called automatically by Loader.nextFile. - * This method controls what extra work this File does with its loaded data. + * The G key. */ - onProcess(): void; + var G: number; - } + /** + * The H key. + */ + var H: number; - } + /** + * The I key. + */ + var I: number; - namespace FileTypesManager { - /** - * Static method called when a LoaderPlugin is created. - * - * Loops through the local types object and injects all of them as - * properties into the LoaderPlugin instance. - * @param loader The LoaderPlugin to install the types into. - */ - function install(loader: Phaser.Loader.LoaderPlugin): void; + /** + * The J key. + */ + var J: number; - /** - * Static method called directly by the File Types. - * - * The key is a reference to the function used to load the files via the Loader, i.e. `image`. - * @param key The key that will be used as the method name in the LoaderPlugin. - * @param factoryFunction The function that will be called when LoaderPlugin.key is invoked. - */ - function register(key: string, factoryFunction: Function): void; + /** + * The K key. + */ + var K: number; - /** - * Removed all associated file types. - */ - function destroy(): void; + /** + * The L key. + */ + var L: number; - } + /** + * The M key. + */ + var M: number; - /** - * Given a File and a baseURL value this returns the URL the File will use to download from. - * @param file The File object. - * @param baseURL A default base URL. - */ - function GetURL(file: Phaser.Loader.File, baseURL: string): string; + /** + * The N key. + */ + var N: number; + + /** + * The O key. + */ + var O: number; + + /** + * The P key. + */ + var P: number; + + /** + * The Q key. + */ + var Q: number; + + /** + * The R key. + */ + var R: number; + + /** + * The S key. + */ + var S: number; + + /** + * The T key. + */ + var T: number; + + /** + * The U key. + */ + var U: number; + + /** + * The V key. + */ + var V: number; + + /** + * The W key. + */ + var W: number; + + /** + * The X key. + */ + var X: number; + + /** + * The Y key. + */ + var Y: number; + + /** + * The Z key. + */ + var Z: number; + + /** + * The F1 key. + */ + var F1: number; + + /** + * The F2 key. + */ + var F2: number; + + /** + * The F3 key. + */ + var F3: number; + + /** + * The F4 key. + */ + var F4: number; + + /** + * The F5 key. + */ + var F5: number; + + /** + * The F6 key. + */ + var F6: number; + + /** + * The F7 key. + */ + var F7: number; + + /** + * The F8 key. + */ + var F8: number; + + /** + * The F9 key. + */ + var F9: number; + + /** + * The F10 key. + */ + var F10: number; + + /** + * The F11 key. + */ + var F11: number; + + /** + * The F12 key. + */ + var F12: number; + + /** + * The SEMICOLON key. + */ + var SEMICOLON: number; + + /** + * The PLUS key. + */ + var PLUS: number; + + /** + * The COMMA key. + */ + var COMMA: number; + + /** + * The MINUS key. + */ + var MINUS: number; + + /** + * The PERIOD key. + */ + var PERIOD: number; + + /** + * The FORWARD_SLASH key. + */ + var FORWARD_SLASH: number; + + /** + * The BACK_SLASH key. + */ + var BACK_SLASH: number; + + /** + * The QUOTES key. + */ + var QUOTES: number; + + /** + * The BACKTICK key. + */ + var BACKTICK: number; + + /** + * The OPEN_BRACKET key. + */ + var OPEN_BRACKET: number; + + /** + * The CLOSED_BRACKET key. + */ + var CLOSED_BRACKET: number; + + /** + * The SEMICOLON_FIREFOX key. + */ + var SEMICOLON_FIREFOX: number; + + /** + * The COLON key. + */ + var COLON: number; + + /** + * The COMMA_FIREFOX_WINDOWS key. + */ + var COMMA_FIREFOX_WINDOWS: number; + + /** + * The COMMA_FIREFOX key. + */ + var COMMA_FIREFOX: number; + + /** + * The BRACKET_RIGHT_FIREFOX key. + */ + var BRACKET_RIGHT_FIREFOX: number; + + /** + * The BRACKET_LEFT_FIREFOX key. + */ + var BRACKET_LEFT_FIREFOX: number; + + } - /** - * The Loader handles loading all external content such as Images, Sounds, Texture Atlases and data files. - * You typically interact with it via `this.load` in your Scene. Scenes can have a `preload` method, which is always - * called before the Scenes `create` method, allowing you to preload assets that the Scene may need. - * - * If you call any `this.load` methods from outside of `Scene.preload` then you need to start the Loader going - * yourself by calling `Loader.start()`. It's only automatically started during the Scene preload. - * - * The Loader uses a combination of tag loading (eg. Audio elements) and XHR and provides progress and completion events. - * Files are loaded in parallel by default. The amount of concurrent connections can be controlled in your Game Configuration. - * - * Once the Loader has started loading you are still able to add files to it. These can be injected as a result of a loader - * event, the type of file being loaded (such as a pack file) or other external events. As long as the Loader hasn't finished - * simply adding a new file to it, while running, will ensure it's added into the current queue. - * - * Every Scene has its own instance of the Loader and they are bound to the Scene in which they are created. However, - * assets loaded by the Loader are placed into global game-level caches. For example, loading an XML file will place that - * file inside `Game.cache.xml`, which is accessible from every Scene in your game, no matter who was responsible - * for loading it. The same is true of Textures. A texture loaded in one Scene is instantly available to all other Scenes - * in your game. - * - * The Loader works by using custom File Types. These are stored in the FileTypesManager, which injects them into the Loader - * when it's instantiated. You can create your own custom file types by extending either the File or MultiFile classes. - * See those files for more details. - */ - class LoaderPlugin extends Phaser.Events.EventEmitter { /** - * - * @param scene The Scene which owns this Loader instance. + * Returns `true` if the Key was released within the `duration` value given, based on the current + * game clock time. Or returns `false` if it either isn't up, or was released longer ago than the given duration. + * @param key The Key object to test. + * @param duration The duration, in ms, within which the key must have been released. Default 50. */ - constructor(scene: Phaser.Scene); + function UpDuration(key: Phaser.Input.Keyboard.Key, duration?: number): boolean; + + } + namespace Mouse { /** - * Adds an Animation JSON Data file, or array of Animation JSON files, to the current load queue. - * - * You can call this method from within your Scene's `preload`, along with any other files you wish to load: - * - * ```javascript - * function preload () - * { - * this.load.animation('baddieAnims', 'files/BaddieAnims.json'); - * } - * ``` - * - * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, - * or if it's already running, when the next free load slot becomes available. This happens automatically if you - * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued - * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. - * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the - * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been - * loaded. - * - * If you call this from outside of `preload` then you are responsible for starting the Loader afterwards and monitoring - * its events to know when it's safe to use the asset. Please see the Phaser.Loader.LoaderPlugin class for more details. - * - * The key must be a unique String. It is used to add the file to the global JSON Cache upon a successful load. - * The key should be unique both in terms of files being loaded and files already present in the JSON Cache. - * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file - * then remove it from the JSON Cache first, before loading a new one. - * - * Instead of passing arguments you can pass a configuration object, such as: - * - * ```javascript - * this.load.animation({ - * key: 'baddieAnims', - * url: 'files/BaddieAnims.json' - * }); - * ``` - * - * See the documentation for `Phaser.Types.Loader.FileTypes.JSONFileConfig` for more details. - * - * Once the file has finished loading it will automatically be passed to the global Animation Managers `fromJSON` method. - * This will parse all of the JSON data and create animation data from it. This process happens at the very end - * of the Loader, once every other file in the load queue has finished. The reason for this is to allow you to load - * both animation data and the images it relies upon in the same load call. - * - * Once the animation data has been parsed you will be able to play animations using that data. - * Please see the Animation Manager `fromJSON` method for more details about the format and playback. - * - * You can also access the raw animation data from its Cache using its key: - * - * ```javascript - * this.load.animation('baddieAnims', 'files/BaddieAnims.json'); - * // and later in your game ... - * var data = this.cache.json.get('baddieAnims'); - * ``` - * - * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files - * key. For example, if the prefix was `LEVEL1.` and the key was `Waves` the final key will be `LEVEL1.Waves` and - * this is what you would use to retrieve the text from the JSON Cache. - * - * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. - * - * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "data" - * and no URL is given then the Loader will set the URL to be "data.json". It will always add `.json` as the extension, although - * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. - * - * You can also optionally provide a `dataKey` to use. This allows you to extract only a part of the JSON and store it in the Cache, - * rather than the whole file. For example, if your JSON data had a structure like this: - * - * ```json - * { - * "level1": { - * "baddies": { - * "aliens": {}, - * "boss": {} - * } - * }, - * "level2": {}, - * "level3": {} - * } - * ``` + * The Mouse Manager is a helper class that belongs to the Input Manager. * - * And if you only wanted to create animations from the `boss` data, then you could pass `level1.baddies.boss`as the `dataKey`. + * Its role is to listen for native DOM Mouse Events and then pass them onto the Input Manager for further processing. * - * Note: The ability to load this type of file will only be available if the JSON File type has been built into Phaser. - * It is available in the default build but can be excluded from custom builds. - * @param key The key to use for this file, or a file configuration object, or array of them. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". - * @param dataKey When the Animation JSON file loads only this property will be stored in the Cache and used to create animation data. - * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. + * You do not need to create this class directly, the Input Manager will create an instance of it automatically. */ - animation(key: string | Phaser.Types.Loader.FileTypes.JSONFileConfig | Phaser.Types.Loader.FileTypes.JSONFileConfig[], url?: string, dataKey?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): Phaser.Loader.LoaderPlugin; - + class MouseManager { + /** + * + * @param inputManager A reference to the Input Manager. + */ + constructor(inputManager: Phaser.Input.InputManager); + + /** + * A reference to the Input Manager. + */ + manager: Phaser.Input.InputManager; + + /** + * If `true` the DOM `mousedown` event will have `preventDefault` set. + */ + preventDefaultDown: boolean; + + /** + * If `true` the DOM `mouseup` event will have `preventDefault` set. + */ + preventDefaultUp: boolean; + + /** + * If `true` the DOM `mousemove` event will have `preventDefault` set. + */ + preventDefaultMove: boolean; + + /** + * If `true` the DOM `wheel` event will have `preventDefault` set. + */ + preventDefaultWheel: boolean; + + /** + * A boolean that controls if the Mouse Manager is enabled or not. + * Can be toggled on the fly. + */ + enabled: boolean; + + /** + * The Mouse target, as defined in the Game Config. + * Typically the canvas to which the game is rendering, but can be any interactive DOM element. + */ + target: any; + + /** + * If the mouse has been pointer locked successfully this will be set to true. + */ + locked: boolean; + + /** + * The Mouse Move Event handler. + * This function is sent the native DOM MouseEvent. + * Initially empty and bound in the `startListeners` method. + */ + onMouseMove: Function; + + /** + * The Mouse Down Event handler. + * This function is sent the native DOM MouseEvent. + * Initially empty and bound in the `startListeners` method. + */ + onMouseDown: Function; + + /** + * The Mouse Up Event handler. + * This function is sent the native DOM MouseEvent. + * Initially empty and bound in the `startListeners` method. + */ + onMouseUp: Function; + + /** + * The Mouse Down Event handler specifically for events on the Window. + * This function is sent the native DOM MouseEvent. + * Initially empty and bound in the `startListeners` method. + */ + onMouseDownWindow: Function; + + /** + * The Mouse Up Event handler specifically for events on the Window. + * This function is sent the native DOM MouseEvent. + * Initially empty and bound in the `startListeners` method. + */ + onMouseUpWindow: Function; + + /** + * The Mouse Over Event handler. + * This function is sent the native DOM MouseEvent. + * Initially empty and bound in the `startListeners` method. + */ + onMouseOver: Function; + + /** + * The Mouse Out Event handler. + * This function is sent the native DOM MouseEvent. + * Initially empty and bound in the `startListeners` method. + */ + onMouseOut: Function; + + /** + * The Mouse Wheel Event handler. + * This function is sent the native DOM MouseEvent. + * Initially empty and bound in the `startListeners` method. + */ + onMouseWheel: Function; + + /** + * Internal pointerLockChange handler. + * This function is sent the native DOM MouseEvent. + * Initially empty and bound in the `startListeners` method. + */ + pointerLockChange: Function; + + /** + * Are the event listeners hooked into `window.top` or `window`? + * + * This is set during the `boot` sequence. If the browser does not have access to `window.top`, + * such as in cross-origin iframe environments, this property gets set to `false` and the events + * are hooked into `window` instead. + */ + readonly isTop: boolean; + + /** + * Attempts to disable the context menu from appearing if you right-click on the browser. + * + * Works by listening for the `contextmenu` event and prevent defaulting it. + * + * Use this if you need to enable right-button mouse support in your game, and the browser + * menu keeps getting in the way. + */ + disableContextMenu(): this; + + /** + * If the browser supports it, you can request that the pointer be locked to the browser window. + * + * This is classically known as 'FPS controls', where the pointer can't leave the browser until + * the user presses an exit key. + * + * If the browser successfully enters a locked state, a `POINTER_LOCK_CHANGE_EVENT` will be dispatched, + * from the games Input Manager, with an `isPointerLocked` property. + * + * It is important to note that pointer lock can only be enabled after an 'engagement gesture', + * see: https://w3c.github.io/pointerlock/#dfn-engagement-gesture. + * + * Note for Firefox: There is a bug in certain Firefox releases that cause native DOM events like + * `mousemove` to fire continuously when in pointer lock mode. You can get around this by setting + * `this.preventDefaultMove` to `false` in this class. You may also need to do the same for + * `preventDefaultDown` and/or `preventDefaultUp`. Please test combinations of these if you encounter + * the error. + */ + requestPointerLock(): void; + + /** + * If the browser supports pointer lock, this will request that the pointer lock is released. If + * the browser successfully enters a locked state, a 'POINTER_LOCK_CHANGE_EVENT' will be + * dispatched - from the game's input manager - with an `isPointerLocked` property. + */ + releasePointerLock(): void; + + /** + * Starts the Mouse Event listeners running. + * This is called automatically and does not need to be manually invoked. + */ + startListeners(): void; + + /** + * Stops the Mouse Event listeners. + * This is called automatically and does not need to be manually invoked. + */ + stopListeners(): void; + + /** + * Destroys this Mouse Manager instance. + */ + destroy(): void; + + } + + } + + /** + * A Pointer object encapsulates both mouse and touch input within Phaser. + * + * By default, Phaser will create 2 pointers for your game to use. If you require more, i.e. for a multi-touch + * game, then use the `InputPlugin.addPointer` method to do so, rather than instantiating this class directly, + * otherwise it won't be managed by the input system. + * + * You can reference the current active pointer via `InputPlugin.activePointer`. You can also use the properties + * `InputPlugin.pointer1` through to `pointer10`, for each pointer you have enabled in your game. + * + * The properties of this object are set by the Input Plugin during processing. This object is then sent in all + * input related events that the Input Plugin emits, so you can reference properties from it directly in your + * callbacks. + */ + class Pointer { /** - * Adds a JSON based Texture Atlas, or array of atlases, to the current load queue. - * - * You can call this method from within your Scene's `preload`, along with any other files you wish to load: - * - * ```javascript - * function preload () - * { - * this.load.atlas('mainmenu', 'images/MainMenu.png', 'images/MainMenu.json'); - * } - * ``` - * - * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, - * or if it's already running, when the next free load slot becomes available. This happens automatically if you - * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued - * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. - * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the - * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been - * loaded. - * - * If you call this from outside of `preload` then you are responsible for starting the Loader afterwards and monitoring - * its events to know when it's safe to use the asset. Please see the Phaser.Loader.LoaderPlugin class for more details. - * - * Phaser expects the atlas data to be provided in a JSON file, using either the JSON Hash or JSON Array format. - * These files are created by software such as Texture Packer, Shoebox and Adobe Flash / Animate. - * If you are using Texture Packer and have enabled multi-atlas support, then please use the Phaser Multi Atlas loader - * instead of this one. - * - * Phaser can load all common image types: png, jpg, gif and any other format the browser can natively handle. - * - * The key must be a unique String. It is used to add the file to the global Texture Manager upon a successful load. - * The key should be unique both in terms of files being loaded and files already present in the Texture Manager. - * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file - * then remove it from the Texture Manager first, before loading a new one. - * - * Instead of passing arguments you can pass a configuration object, such as: - * - * ```javascript - * this.load.atlas({ - * key: 'mainmenu', - * textureURL: 'images/MainMenu.png', - * atlasURL: 'images/MainMenu.json' - * }); - * ``` - * - * See the documentation for `Phaser.Types.Loader.FileTypes.AtlasJSONFileConfig` for more details. - * - * Instead of passing a URL for the atlas JSON data you can also pass in a well formed JSON object instead. - * - * Once the atlas has finished loading you can use frames from it as textures for a Game Object by referencing its key: - * - * ```javascript - * this.load.atlas('mainmenu', 'images/MainMenu.png', 'images/MainMenu.json'); - * // and later in your game ... - * this.add.image(x, y, 'mainmenu', 'background'); - * ``` - * - * To get a list of all available frames within an atlas please consult your Texture Atlas software. - * - * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files - * key. For example, if the prefix was `MENU.` and the key was `Background` the final key will be `MENU.Background` and - * this is what you would use to retrieve the image from the Texture Manager. - * - * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. - * - * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "alien" - * and no URL is given then the Loader will set the URL to be "alien.png". It will always add `.png` as the extension, although - * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. - * - * Phaser also supports the automatic loading of associated normal maps. If you have a normal map to go with this image, - * then you can specify it by providing an array as the `url` where the second element is the normal map: - * - * ```javascript - * this.load.atlas('mainmenu', [ 'images/MainMenu.png', 'images/MainMenu-n.png' ], 'images/MainMenu.json'); - * ``` - * - * Or, if you are using a config object use the `normalMap` property: - * - * ```javascript - * this.load.atlas({ - * key: 'mainmenu', - * textureURL: 'images/MainMenu.png', - * normalMap: 'images/MainMenu-n.png', - * atlasURL: 'images/MainMenu.json' - * }); - * ``` * - * The normal map file is subject to the same conditions as the image file with regard to the path, baseURL, CORs and XHR Settings. - * Normal maps are a WebGL only feature. - * - * Note: The ability to load this type of file will only be available if the Atlas JSON File type has been built into Phaser. - * It is available in the default build but can be excluded from custom builds. - * @param key The key to use for this file, or a file configuration object, or array of them. - * @param textureURL The absolute or relative URL to load the texture image file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". - * @param atlasURL The absolute or relative URL to load the texture atlas json data file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". - * @param textureXhrSettings An XHR Settings configuration object for the atlas image file. Used in replacement of the Loaders default XHR Settings. - * @param atlasXhrSettings An XHR Settings configuration object for the atlas json file. Used in replacement of the Loaders default XHR Settings. + * @param manager A reference to the Input Manager. + * @param id The internal ID of this Pointer. */ - atlas(key: string | Phaser.Types.Loader.FileTypes.AtlasJSONFileConfig | Phaser.Types.Loader.FileTypes.AtlasJSONFileConfig[], textureURL?: string | string[], atlasURL?: string, textureXhrSettings?: Phaser.Types.Loader.XHRSettingsObject, atlasXhrSettings?: Phaser.Types.Loader.XHRSettingsObject): Phaser.Loader.LoaderPlugin; + constructor(manager: Phaser.Input.InputManager, id: number); /** - * Adds an XML based Texture Atlas, or array of atlases, to the current load queue. - * - * You can call this method from within your Scene's `preload`, along with any other files you wish to load: - * - * ```javascript - * function preload () - * { - * this.load.atlasXML('mainmenu', 'images/MainMenu.png', 'images/MainMenu.xml'); - * } - * ``` - * - * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, - * or if it's already running, when the next free load slot becomes available. This happens automatically if you - * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued - * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. - * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the - * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been - * loaded. - * - * If you call this from outside of `preload` then you are responsible for starting the Loader afterwards and monitoring - * its events to know when it's safe to use the asset. Please see the Phaser.Loader.LoaderPlugin class for more details. - * - * Phaser expects the atlas data to be provided in an XML file format. - * These files are created by software such as Shoebox and Adobe Flash / Animate. - * - * Phaser can load all common image types: png, jpg, gif and any other format the browser can natively handle. - * - * The key must be a unique String. It is used to add the file to the global Texture Manager upon a successful load. - * The key should be unique both in terms of files being loaded and files already present in the Texture Manager. - * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file - * then remove it from the Texture Manager first, before loading a new one. - * - * Instead of passing arguments you can pass a configuration object, such as: - * - * ```javascript - * this.load.atlasXML({ - * key: 'mainmenu', - * textureURL: 'images/MainMenu.png', - * atlasURL: 'images/MainMenu.xml' - * }); - * ``` - * - * See the documentation for `Phaser.Types.Loader.FileTypes.AtlasXMLFileConfig` for more details. - * - * Once the atlas has finished loading you can use frames from it as textures for a Game Object by referencing its key: - * - * ```javascript - * this.load.atlasXML('mainmenu', 'images/MainMenu.png', 'images/MainMenu.xml'); - * // and later in your game ... - * this.add.image(x, y, 'mainmenu', 'background'); - * ``` - * - * To get a list of all available frames within an atlas please consult your Texture Atlas software. - * - * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files - * key. For example, if the prefix was `MENU.` and the key was `Background` the final key will be `MENU.Background` and - * this is what you would use to retrieve the image from the Texture Manager. + * A reference to the Input Manager. + */ + manager: Phaser.Input.InputManager; + + /** + * The internal ID of this Pointer. + */ + readonly id: number; + + /** + * The most recent native DOM Event this Pointer has processed. + */ + event: TouchEvent | MouseEvent; + + /** + * The DOM element the Pointer was pressed down on, taken from the DOM event. + * In a default set-up this will be the Canvas that Phaser is rendering to, or the Window element. + */ + readonly downElement: any; + + /** + * The DOM element the Pointer was released on, taken from the DOM event. + * In a default set-up this will be the Canvas that Phaser is rendering to, or the Window element. + */ + readonly upElement: any; + + /** + * The camera the Pointer interacted with during its last update. * - * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. + * A Pointer can only ever interact with one camera at once, which will be the top-most camera + * in the list should multiple cameras be positioned on-top of each other. + */ + camera: Phaser.Cameras.Scene2D.Camera; + + /** + * A read-only property that indicates which button was pressed, or released, on the pointer + * during the most recent event. It is only set during `up` and `down` events. * - * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "alien" - * and no URL is given then the Loader will set the URL to be "alien.png". It will always add `.png` as the extension, although - * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. + * On Touch devices the value is always 0. * - * Phaser also supports the automatic loading of associated normal maps. If you have a normal map to go with this image, - * then you can specify it by providing an array as the `url` where the second element is the normal map: + * Users may change the configuration of buttons on their pointing device so that if an event's button property + * is zero, it may not have been caused by the button that is physically left–most on the pointing device; + * however, it should behave as if the left button was clicked in the standard button layout. + */ + readonly button: number; + + /** + * 0: No button or un-initialized + * 1: Left button + * 2: Right button + * 4: Wheel button or middle button + * 8: 4th button (typically the "Browser Back" button) + * 16: 5th button (typically the "Browser Forward" button) * - * ```javascript - * this.load.atlasXML('mainmenu', [ 'images/MainMenu.png', 'images/MainMenu-n.png' ], 'images/MainMenu.xml'); - * ``` + * For a mouse configured for left-handed use, the button actions are reversed. + * In this case, the values are read from right to left. + */ + buttons: number; + + /** + * The position of the Pointer in screen space. + */ + readonly position: Phaser.Math.Vector2; + + /** + * The previous position of the Pointer in screen space. * - * Or, if you are using a config object use the `normalMap` property: + * The old x and y values are stored in here during the InputManager.transformPointer call. * - * ```javascript - * this.load.atlasXML({ - * key: 'mainmenu', - * textureURL: 'images/MainMenu.png', - * normalMap: 'images/MainMenu-n.png', - * atlasURL: 'images/MainMenu.xml' - * }); - * ``` + * Use the properties `velocity`, `angle` and `distance` to create your own gesture recognition. + */ + readonly prevPosition: Phaser.Math.Vector2; + + /** + * The current velocity of the Pointer, based on its current and previous positions. * - * The normal map file is subject to the same conditions as the image file with regard to the path, baseURL, CORs and XHR Settings. - * Normal maps are a WebGL only feature. + * This value is smoothed out each frame, according to the `motionFactor` property. * - * Note: The ability to load this type of file will only be available if the Atlas XML File type has been built into Phaser. - * It is available in the default build but can be excluded from custom builds. - * @param key The key to use for this file, or a file configuration object, or array of them. - * @param textureURL The absolute or relative URL to load the texture image file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". - * @param atlasURL The absolute or relative URL to load the texture atlas xml data file from. If undefined or `null` it will be set to `.xml`, i.e. if `key` was "alien" then the URL will be "alien.xml". - * @param textureXhrSettings An XHR Settings configuration object for the atlas image file. Used in replacement of the Loaders default XHR Settings. - * @param atlasXhrSettings An XHR Settings configuration object for the atlas xml file. Used in replacement of the Loaders default XHR Settings. + * This property is updated whenever the Pointer moves, regardless of any button states. In other words, + * it changes based on movement alone - a button doesn't have to be pressed first. */ - atlasXML(key: string | Phaser.Types.Loader.FileTypes.AtlasXMLFileConfig | Phaser.Types.Loader.FileTypes.AtlasXMLFileConfig[], textureURL?: string | string[], atlasURL?: string, textureXhrSettings?: Phaser.Types.Loader.XHRSettingsObject, atlasXhrSettings?: Phaser.Types.Loader.XHRSettingsObject): Phaser.Loader.LoaderPlugin; + readonly velocity: Phaser.Math.Vector2; /** - * Adds an Audio or HTML5Audio file, or array of audio files, to the current load queue. - * - * You can call this method from within your Scene's `preload`, along with any other files you wish to load: + * The current angle the Pointer is moving, in radians, based on its previous and current position. * - * ```javascript - * function preload () - * { - * this.load.audio('title', [ 'music/Title.ogg', 'music/Title.mp3', 'music/Title.m4a' ]); - * } - * ``` + * The angle is based on the old position facing to the current position. * - * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, - * or if it's already running, when the next free load slot becomes available. This happens automatically if you - * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued - * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. - * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the - * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been - * loaded. + * This property is updated whenever the Pointer moves, regardless of any button states. In other words, + * it changes based on movement alone - a button doesn't have to be pressed first. + */ + readonly angle: number; + + /** + * The distance the Pointer has moved, based on its previous and current position. * - * The key must be a unique String. It is used to add the file to the global Audio Cache upon a successful load. - * The key should be unique both in terms of files being loaded and files already present in the Audio Cache. - * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file - * then remove it from the Audio Cache first, before loading a new one. + * This value is smoothed out each frame, according to the `motionFactor` property. * - * Instead of passing arguments you can pass a configuration object, such as: + * This property is updated whenever the Pointer moves, regardless of any button states. In other words, + * it changes based on movement alone - a button doesn't have to be pressed first. * - * ```javascript - * this.load.audio({ - * key: 'title', - * url: [ 'music/Title.ogg', 'music/Title.mp3', 'music/Title.m4a' ] - * }); - * ``` + * If you need the total distance travelled since the primary buttons was pressed down, + * then use the `Pointer.getDistance` method. + */ + readonly distance: number; + + /** + * The smoothing factor to apply to the Pointer position. * - * See the documentation for `Phaser.Types.Loader.FileTypes.AudioFileConfig` for more details. + * Due to their nature, pointer positions are inherently noisy. While this is fine for lots of games, if you need cleaner positions + * then you can set this value to apply an automatic smoothing to the positions as they are recorded. * - * The URLs can be relative or absolute. If the URLs are relative the `Loader.baseURL` and `Loader.path` values will be prepended to them. + * The default value of zero means 'no smoothing'. + * Set to a small value, such as 0.2, to apply an average level of smoothing between positions. You can do this by changing this + * value directly, or by setting the `input.smoothFactor` property in the Game Config. * - * Due to different browsers supporting different audio file types you should usually provide your audio files in a variety of formats. - * ogg, mp3 and m4a are the most common. If you provide an array of URLs then the Loader will determine which _one_ file to load based on - * browser support. + * Positions are only smoothed when the pointer moves. If the primary button on this Pointer enters an Up or Down state, then the position + * is always precise, and not smoothed. + */ + smoothFactor: number; + + /** + * The factor applied to the motion smoothing each frame. * - * If audio has been disabled in your game, either via the game config, or lack of support from the device, then no audio will be loaded. + * This value is passed to the Smooth Step Interpolation that is used to calculate the velocity, + * angle and distance of the Pointer. It's applied every frame, until the midPoint reaches the current + * position of the Pointer. 0.2 provides a good average but can be increased if you need a + * quicker update and are working in a high performance environment. Never set this value to + * zero. + */ + motionFactor: number; + + /** + * The x position of this Pointer, translated into the coordinate space of the most recent Camera it interacted with. * - * Note: The ability to load this type of file will only be available if the Audio File type has been built into Phaser. - * It is available in the default build but can be excluded from custom builds. - * @param key The key to use for this file, or a file configuration object, or array of them. - * @param urls The absolute or relative URL to load the audio files from. - * @param config An object containing an `instances` property for HTML5Audio. Defaults to 1. - * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. + * If you wish to use this value _outside_ of an input event handler then you should update it first by calling + * the `Pointer.updateWorldPoint` method. */ - audio(key: string | Phaser.Types.Loader.FileTypes.AudioFileConfig | Phaser.Types.Loader.FileTypes.AudioFileConfig[], urls?: string | string[], config?: any, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): Phaser.Loader.LoaderPlugin; + worldX: number; /** - * Adds a JSON based Audio Sprite, or array of audio sprites, to the current load queue. + * The y position of this Pointer, translated into the coordinate space of the most recent Camera it interacted with. * - * You can call this method from within your Scene's `preload`, along with any other files you wish to load: - * - * ```javascript - * function preload () - * { - * this.load.audioSprite('kyobi', 'kyobi.json', [ - * 'kyobi.ogg', - * 'kyobi.mp3', - * 'kyobi.m4a' - * ]); - * } - * ``` - * - * Audio Sprites are a combination of audio files and a JSON configuration. - * The JSON follows the format of that created by https://github.com/tonistiigi/audiosprite - * - * If the JSON file includes a 'resource' object then you can let Phaser parse it and load the audio - * files automatically based on its content. To do this exclude the audio URLs from the load: - * - * ```javascript - * function preload () - * { - * this.load.audioSprite('kyobi', 'kyobi.json'); - * } - * ``` - * - * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, - * or if it's already running, when the next free load slot becomes available. This happens automatically if you - * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued - * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. - * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the - * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been - * loaded. - * - * If you call this from outside of `preload` then you are responsible for starting the Loader afterwards and monitoring - * its events to know when it's safe to use the asset. Please see the Phaser.Loader.LoaderPlugin class for more details. - * - * The key must be a unique String. It is used to add the file to the global Audio Cache upon a successful load. - * The key should be unique both in terms of files being loaded and files already present in the Audio Cache. - * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file - * then remove it from the Audio Cache first, before loading a new one. - * - * Instead of passing arguments you can pass a configuration object, such as: - * - * ```javascript - * this.load.audioSprite({ - * key: 'kyobi', - * jsonURL: 'audio/Kyobi.json', - * audioURL: [ - * 'audio/Kyobi.ogg', - * 'audio/Kyobi.mp3', - * 'audio/Kyobi.m4a' - * ] - * }); - * ``` - * - * See the documentation for `Phaser.Types.Loader.FileTypes.AudioSpriteFileConfig` for more details. - * - * Instead of passing a URL for the audio JSON data you can also pass in a well formed JSON object instead. - * - * Once the audio has finished loading you can use it create an Audio Sprite by referencing its key: - * - * ```javascript - * this.load.audioSprite('kyobi', 'kyobi.json'); - * // and later in your game ... - * var music = this.sound.addAudioSprite('kyobi'); - * music.play('title'); - * ``` - * - * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files - * key. For example, if the prefix was `MENU.` and the key was `Background` the final key will be `MENU.Background` and - * this is what you would use to retrieve the image from the Texture Manager. - * - * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. - * - * Due to different browsers supporting different audio file types you should usually provide your audio files in a variety of formats. - * ogg, mp3 and m4a are the most common. If you provide an array of URLs then the Loader will determine which _one_ file to load based on - * browser support. - * - * If audio has been disabled in your game, either via the game config, or lack of support from the device, then no audio will be loaded. - * - * Note: The ability to load this type of file will only be available if the Audio Sprite File type has been built into Phaser. - * It is available in the default build but can be excluded from custom builds. - * @param key The key to use for this file, or a file configuration object, or an array of objects. - * @param jsonURL The absolute or relative URL to load the json file from. Or a well formed JSON object to use instead. - * @param audioURL The absolute or relative URL to load the audio file from. If empty it will be obtained by parsing the JSON file. - * @param audioConfig The audio configuration options. - * @param audioXhrSettings An XHR Settings configuration object for the audio file. Used in replacement of the Loaders default XHR Settings. - * @param jsonXhrSettings An XHR Settings configuration object for the json file. Used in replacement of the Loaders default XHR Settings. + * If you wish to use this value _outside_ of an input event handler then you should update it first by calling + * the `Pointer.updateWorldPoint` method. */ - audioSprite(key: string | Phaser.Types.Loader.FileTypes.AudioSpriteFileConfig | Phaser.Types.Loader.FileTypes.AudioSpriteFileConfig[], jsonURL: string, audioURL?: string | string[], audioConfig?: any, audioXhrSettings?: Phaser.Types.Loader.XHRSettingsObject, jsonXhrSettings?: Phaser.Types.Loader.XHRSettingsObject): Phaser.Loader.LoaderPlugin; + worldY: number; /** - * Adds a Binary file, or array of Binary files, to the current load queue. - * - * You can call this method from within your Scene's `preload`, along with any other files you wish to load: - * - * ```javascript - * function preload () - * { - * this.load.binary('doom', 'files/Doom.wad'); - * } - * ``` - * - * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, - * or if it's already running, when the next free load slot becomes available. This happens automatically if you - * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued - * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. - * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the - * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been - * loaded. - * - * The key must be a unique String. It is used to add the file to the global Binary Cache upon a successful load. - * The key should be unique both in terms of files being loaded and files already present in the Binary Cache. - * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file - * then remove it from the Binary Cache first, before loading a new one. - * - * Instead of passing arguments you can pass a configuration object, such as: - * - * ```javascript - * this.load.binary({ - * key: 'doom', - * url: 'files/Doom.wad', - * dataType: Uint8Array - * }); - * ``` - * - * See the documentation for `Phaser.Types.Loader.FileTypes.BinaryFileConfig` for more details. - * - * Once the file has finished loading you can access it from its Cache using its key: - * - * ```javascript - * this.load.binary('doom', 'files/Doom.wad'); - * // and later in your game ... - * var data = this.cache.binary.get('doom'); - * ``` - * - * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files - * key. For example, if the prefix was `LEVEL1.` and the key was `Data` the final key will be `LEVEL1.Data` and - * this is what you would use to retrieve the text from the Binary Cache. - * - * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. - * - * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "doom" - * and no URL is given then the Loader will set the URL to be "doom.bin". It will always add `.bin` as the extension, although - * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. - * - * Note: The ability to load this type of file will only be available if the Binary File type has been built into Phaser. - * It is available in the default build but can be excluded from custom builds. - * @param key The key to use for this file, or a file configuration object, or array of them. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.bin`, i.e. if `key` was "alien" then the URL will be "alien.bin". - * @param dataType Optional type to cast the binary file to once loaded. For example, `Uint8Array`. - * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. + * Time when this Pointer was most recently moved (regardless of the state of its buttons, if any) */ - binary(key: string | Phaser.Types.Loader.FileTypes.BinaryFileConfig | Phaser.Types.Loader.FileTypes.BinaryFileConfig[], url?: string, dataType?: any, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): Phaser.Loader.LoaderPlugin; + moveTime: number; /** - * Adds an XML based Bitmap Font, or array of fonts, to the current load queue. - * - * You can call this method from within your Scene's `preload`, along with any other files you wish to load: - * ```javascript - * function preload () - * { - * this.load.bitmapFont('goldenFont', 'images/GoldFont.png', 'images/GoldFont.xml'); - * } - * ``` - * - * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, - * or if it's already running, when the next free load slot becomes available. This happens automatically if you - * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued - * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. - * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the - * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been - * loaded. - * - * If you call this from outside of `preload` then you are responsible for starting the Loader afterwards and monitoring - * its events to know when it's safe to use the asset. Please see the Phaser.Loader.LoaderPlugin class for more details. - * - * Phaser expects the font data to be provided in an XML file format. - * These files are created by software such as the [Angelcode Bitmap Font Generator](http://www.angelcode.com/products/bmfont/), - * [Littera](http://kvazars.com/littera/) or [Glyph Designer](https://71squared.com/glyphdesigner) - * - * Phaser can load all common image types: png, jpg, gif and any other format the browser can natively handle. - * - * The key must be a unique String. It is used to add the file to the global Texture Manager upon a successful load. - * The key should be unique both in terms of files being loaded and files already present in the Texture Manager. - * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file - * then remove it from the Texture Manager first, before loading a new one. - * - * Instead of passing arguments you can pass a configuration object, such as: - * - * ```javascript - * this.load.bitmapFont({ - * key: 'goldenFont', - * textureURL: 'images/GoldFont.png', - * fontDataURL: 'images/GoldFont.xml' - * }); - * ``` - * - * See the documentation for `Phaser.Types.Loader.FileTypes.BitmapFontFileConfig` for more details. - * - * Once the atlas has finished loading you can use key of it when creating a Bitmap Text Game Object: - * - * ```javascript - * this.load.bitmapFont('goldenFont', 'images/GoldFont.png', 'images/GoldFont.xml'); - * // and later in your game ... - * this.add.bitmapText(x, y, 'goldenFont', 'Hello World'); - * ``` - * - * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files - * key. For example, if the prefix was `MENU.` and the key was `Background` the final key will be `MENU.Background` and - * this is what you would use when creating a Bitmap Text object. + * X coordinate of the Pointer when Button 1 (left button), or Touch, was pressed, used for dragging objects. + */ + downX: number; + + /** + * Y coordinate of the Pointer when Button 1 (left button), or Touch, was pressed, used for dragging objects. + */ + downY: number; + + /** + * The Event timestamp when the first button, or Touch input, was pressed. Used for dragging objects. + */ + downTime: number; + + /** + * X coordinate of the Pointer when Button 1 (left button), or Touch, was released, used for dragging objects. + */ + upX: number; + + /** + * Y coordinate of the Pointer when Button 1 (left button), or Touch, was released, used for dragging objects. + */ + upY: number; + + /** + * The Event timestamp when the final button, or Touch input, was released. Used for dragging objects. + */ + upTime: number; + + /** + * Is the primary button down? (usually button 0, the left mouse button) + */ + primaryDown: boolean; + + /** + * Is _any_ button on this pointer considered as being down? + */ + isDown: boolean; + + /** + * Did the previous input event come from a Touch input (true) or Mouse? (false) + */ + wasTouch: boolean; + + /** + * Did this Pointer get canceled by a touchcancel event? * - * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. + * Note: "canceled" is the American-English spelling of "cancelled". Please don't submit PRs correcting it! + */ + wasCanceled: boolean; + + /** + * If the mouse is locked, the horizontal relative movement of the Pointer in pixels since last frame. + */ + movementX: number; + + /** + * If the mouse is locked, the vertical relative movement of the Pointer in pixels since last frame. + */ + movementY: number; + + /** + * The identifier property of the Pointer as set by the DOM event when this Pointer is started. + */ + identifier: number; + + /** + * The pointerId property of the Pointer as set by the DOM event when this Pointer is started. + * The browser can and will recycle this value. + */ + pointerId: number; + + /** + * An active Pointer is one that is currently pressed down on the display. + * A Mouse is always considered as active. + */ + active: boolean; + + /** + * Is this pointer Pointer Locked? * - * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "alien" - * and no URL is given then the Loader will set the URL to be "alien.png". It will always add `.png` as the extension, although - * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. + * Only a mouse pointer can be locked and it only becomes locked when requested via + * the browsers Pointer Lock API. * - * Phaser also supports the automatic loading of associated normal maps. If you have a normal map to go with this image, - * then you can specify it by providing an array as the `url` where the second element is the normal map: + * You can request this by calling the `this.input.mouse.requestPointerLock()` method from + * a `pointerdown` or `pointerup` event handler. + */ + readonly locked: boolean; + + /** + * The horizontal scroll amount that occurred due to the user moving a mouse wheel or similar input device. + */ + deltaX: number; + + /** + * The vertical scroll amount that occurred due to the user moving a mouse wheel or similar input device. + * This value will typically be less than 0 if the user scrolls up and greater than zero if scrolling down. + */ + deltaY: number; + + /** + * The z-axis scroll amount that occurred due to the user moving a mouse wheel or similar input device. + */ + deltaZ: number; + + /** + * Takes a Camera and updates this Pointer's `worldX` and `worldY` values so they are + * the result of a translation through the given Camera. * - * ```javascript - * this.load.bitmapFont('goldenFont', [ 'images/GoldFont.png', 'images/GoldFont-n.png' ], 'images/GoldFont.xml'); - * ``` + * Note that the values will be automatically replaced the moment the Pointer is + * updated by an input event, such as a mouse move, so should be used immediately. + * @param camera The Camera which is being tested against. + */ + updateWorldPoint(camera: Phaser.Cameras.Scene2D.Camera): this; + + /** + * Takes a Camera and returns a Vector2 containing the translated position of this Pointer + * within that Camera. This can be used to convert this Pointers position into camera space. + * @param camera The Camera to use for the translation. + * @param output A Vector2-like object in which to store the translated position. + */ + positionToCamera(camera: Phaser.Cameras.Scene2D.Camera, output?: Phaser.Math.Vector2 | object): Phaser.Math.Vector2 | object; + + /** + * Checks to see if any buttons are being held down on this Pointer. + */ + noButtonDown(): boolean; + + /** + * Checks to see if the left button is being held down on this Pointer. + */ + leftButtonDown(): boolean; + + /** + * Checks to see if the right button is being held down on this Pointer. + */ + rightButtonDown(): boolean; + + /** + * Checks to see if the middle button is being held down on this Pointer. + */ + middleButtonDown(): boolean; + + /** + * Checks to see if the back button is being held down on this Pointer. + */ + backButtonDown(): boolean; + + /** + * Checks to see if the forward button is being held down on this Pointer. + */ + forwardButtonDown(): boolean; + + /** + * Checks to see if the left button was just released on this Pointer. + */ + leftButtonReleased(): boolean; + + /** + * Checks to see if the right button was just released on this Pointer. + */ + rightButtonReleased(): boolean; + + /** + * Checks to see if the middle button was just released on this Pointer. + */ + middleButtonReleased(): boolean; + + /** + * Checks to see if the back button was just released on this Pointer. + */ + backButtonReleased(): boolean; + + /** + * Checks to see if the forward button was just released on this Pointer. + */ + forwardButtonReleased(): boolean; + + /** + * If the Pointer has a button pressed down at the time this method is called, it will return the + * distance between the Pointer's `downX` and `downY` values and the current position. * - * Or, if you are using a config object use the `normalMap` property: + * If no button is held down, it will return the last recorded distance, based on where + * the Pointer was when the button was released. * - * ```javascript - * this.load.bitmapFont({ - * key: 'goldenFont', - * textureURL: 'images/GoldFont.png', - * normalMap: 'images/GoldFont-n.png', - * fontDataURL: 'images/GoldFont.xml' - * }); - * ``` + * If you wish to get the distance being travelled currently, based on the velocity of the Pointer, + * then see the `Pointer.distance` property. + */ + getDistance(): number; + + /** + * If the Pointer has a button pressed down at the time this method is called, it will return the + * horizontal distance between the Pointer's `downX` and `downY` values and the current position. * - * The normal map file is subject to the same conditions as the image file with regard to the path, baseURL, CORs and XHR Settings. - * Normal maps are a WebGL only feature. + * If no button is held down, it will return the last recorded horizontal distance, based on where + * the Pointer was when the button was released. + */ + getDistanceX(): number; + + /** + * If the Pointer has a button pressed down at the time this method is called, it will return the + * vertical distance between the Pointer's `downX` and `downY` values and the current position. * - * Note: The ability to load this type of file will only be available if the Bitmap Font File type has been built into Phaser. - * It is available in the default build but can be excluded from custom builds. - * @param key The key to use for this file, or a file configuration object, or array of them. - * @param textureURL The absolute or relative URL to load the font image file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". - * @param fontDataURL The absolute or relative URL to load the font xml data file from. If undefined or `null` it will be set to `.xml`, i.e. if `key` was "alien" then the URL will be "alien.xml". - * @param textureXhrSettings An XHR Settings configuration object for the font image file. Used in replacement of the Loaders default XHR Settings. - * @param fontDataXhrSettings An XHR Settings configuration object for the font data xml file. Used in replacement of the Loaders default XHR Settings. + * If no button is held down, it will return the last recorded vertical distance, based on where + * the Pointer was when the button was released. */ - bitmapFont(key: string | Phaser.Types.Loader.FileTypes.BitmapFontFileConfig | Phaser.Types.Loader.FileTypes.BitmapFontFileConfig[], textureURL?: string | string[], fontDataURL?: string, textureXhrSettings?: Phaser.Types.Loader.XHRSettingsObject, fontDataXhrSettings?: Phaser.Types.Loader.XHRSettingsObject): Phaser.Loader.LoaderPlugin; + getDistanceY(): number; /** - * Adds a CSS file, or array of CSS files, to the current load queue. + * If the Pointer has a button pressed down at the time this method is called, it will return the + * duration since the button was pressed down. * - * You can call this method from within your Scene's `preload`, along with any other files you wish to load: + * If no button is held down, it will return the last recorded duration, based on the time + * the last button on the Pointer was released. + */ + getDuration(): number; + + /** + * If the Pointer has a button pressed down at the time this method is called, it will return the + * angle between the Pointer's `downX` and `downY` values and the current position. * - * ```javascript - * function preload () - * { - * this.load.css('headers', 'styles/headers.css'); - * } - * ``` + * If no button is held down, it will return the last recorded angle, based on where + * the Pointer was when the button was released. * - * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, - * or if it's already running, when the next free load slot becomes available. This happens automatically if you - * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued - * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. - * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the - * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been - * loaded. + * The angle is based on the old position facing to the current position. * - * The key must be a unique String and not already in-use by another file in the Loader. + * If you wish to get the current angle, based on the velocity of the Pointer, then + * see the `Pointer.angle` property. + */ + getAngle(): number; + + /** + * Takes the previous and current Pointer positions and then generates an array of interpolated values between + * the two. The array will be populated up to the size of the `steps` argument. * - * Instead of passing arguments you can pass a configuration object, such as: + * ```javaScript + * var points = pointer.getInterpolatedPosition(4); * - * ```javascript - * this.load.css({ - * key: 'headers', - * url: 'styles/headers.css' - * }); + * // points[0] = { x: 0, y: 0 } + * // points[1] = { x: 2, y: 1 } + * // points[2] = { x: 3, y: 2 } + * // points[3] = { x: 6, y: 3 } * ``` * - * See the documentation for `Phaser.Types.Loader.FileTypes.CSSFileConfig` for more details. - * - * Once the file has finished loading it will automatically be converted into a style DOM element - * via `document.createElement('style')`. It will have its `defer` property set to false and then the - * resulting element will be appended to `document.head`. The CSS styles are then applied to the current document. - * - * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. + * Use this if you need to get smoothed values between the previous and current pointer positions. DOM pointer + * events can often fire faster than the main browser loop, and this will help you avoid janky movement + * especially if you have an object following a Pointer. * - * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "alien" - * and no URL is given then the Loader will set the URL to be "alien.css". It will always add `.css` as the extension, although - * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. + * Note that if you provide an output array it will only be populated up to the number of steps provided. + * It will not clear any previous data that may have existed beyond the range of the steps count. * - * Note: The ability to load this type of file will only be available if the CSS File type has been built into Phaser. - * It is available in the default build but can be excluded from custom builds. - * @param key The key to use for this file, or a file configuration object, or array of them. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.css`, i.e. if `key` was "alien" then the URL will be "alien.css". - * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. + * Internally it uses the Smooth Step interpolation calculation. + * @param steps The number of interpolation steps to use. Default 10. + * @param out An array to store the results in. If not provided a new one will be created. */ - css(key: string | Phaser.Types.Loader.FileTypes.CSSFileConfig | Phaser.Types.Loader.FileTypes.CSSFileConfig[], url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): Phaser.Loader.LoaderPlugin; + getInterpolatedPosition(steps?: number, out?: any[]): any[]; /** - * Adds a GLSL file, or array of GLSL files, to the current load queue. - * In Phaser 3 GLSL files are just plain Text files at the current moment in time. - * - * You can call this method from within your Scene's `preload`, along with any other files you wish to load: - * - * ```javascript - * function preload () - * { - * this.load.glsl('plasma', 'shaders/Plasma.glsl'); - * } - * ``` - * - * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, - * or if it's already running, when the next free load slot becomes available. This happens automatically if you - * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued - * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. - * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the - * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been - * loaded. + * Destroys this Pointer instance and resets its external references. + */ + destroy(): void; + + /** + * The x position of this Pointer. + * The value is in screen space. + * See `worldX` to get a camera converted position. + */ + x: number; + + /** + * The y position of this Pointer. + * The value is in screen space. + * See `worldY` to get a camera converted position. + */ + y: number; + + /** + * Time when this Pointer was most recently updated by a DOM Event. + * This comes directly from the `event.timeStamp` property. + * If no event has yet taken place, it will return zero. + */ + readonly time: number; + + } + + namespace Touch { + /** + * The Touch Manager is a helper class that belongs to the Input Manager. * - * The key must be a unique String. It is used to add the file to the global Shader Cache upon a successful load. - * The key should be unique both in terms of files being loaded and files already present in the Shader Cache. - * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file - * then remove it from the Shader Cache first, before loading a new one. + * Its role is to listen for native DOM Touch Events and then pass them onto the Input Manager for further processing. * - * Instead of passing arguments you can pass a configuration object, such as: + * You do not need to create this class directly, the Input Manager will create an instance of it automatically. + */ + class TouchManager { + /** + * + * @param inputManager A reference to the Input Manager. + */ + constructor(inputManager: Phaser.Input.InputManager); + + /** + * A reference to the Input Manager. + */ + manager: Phaser.Input.InputManager; + + /** + * If true the DOM events will have event.preventDefault applied to them, if false they will propagate fully. + */ + capture: boolean; + + /** + * A boolean that controls if the Touch Manager is enabled or not. + * Can be toggled on the fly. + */ + enabled: boolean; + + /** + * The Touch Event target, as defined in the Game Config. + * Typically the canvas to which the game is rendering, but can be any interactive DOM element. + */ + target: any; + + /** + * The Touch Start event handler function. + * Initially empty and bound in the `startListeners` method. + */ + onTouchStart: Function; + + /** + * The Touch Start event handler function specifically for events on the Window. + * Initially empty and bound in the `startListeners` method. + */ + onTouchStartWindow: Function; + + /** + * The Touch Move event handler function. + * Initially empty and bound in the `startListeners` method. + */ + onTouchMove: Function; + + /** + * The Touch End event handler function. + * Initially empty and bound in the `startListeners` method. + */ + onTouchEnd: Function; + + /** + * The Touch End event handler function specifically for events on the Window. + * Initially empty and bound in the `startListeners` method. + */ + onTouchEndWindow: Function; + + /** + * The Touch Cancel event handler function. + * Initially empty and bound in the `startListeners` method. + */ + onTouchCancel: Function; + + /** + * The Touch Cancel event handler function specifically for events on the Window. + * Initially empty and bound in the `startListeners` method. + */ + onTouchCancelWindow: Function; + + /** + * The Touch Over event handler function. + * Initially empty and bound in the `startListeners` method. + */ + onTouchOver: Function; + + /** + * The Touch Out event handler function. + * Initially empty and bound in the `startListeners` method. + */ + onTouchOut: Function; + + /** + * Attempts to disable the context menu from appearing if you touch-hold on the browser. + * + * Works by listening for the `contextmenu` event and prevent defaulting it. + * + * Use this if you need to disable the OS context menu on mobile. + */ + disableContextMenu(): this; + + /** + * Starts the Touch Event listeners running as long as an input target is set. + * + * This method is called automatically if Touch Input is enabled in the game config, + * which it is by default. However, you can call it manually should you need to + * delay input capturing until later in the game. + */ + startListeners(): void; + + /** + * Stops the Touch Event listeners. + * This is called automatically and does not need to be manually invoked. + */ + stopListeners(): void; + + /** + * Destroys this Touch Manager instance. + */ + destroy(): void; + + } + + } + + } + + namespace Loader { + /** + * The Loader is idle. + */ + var LOADER_IDLE: number; + + /** + * The Loader is actively loading. + */ + var LOADER_LOADING: number; + + /** + * The Loader is processing files is has loaded. + */ + var LOADER_PROCESSING: number; + + /** + * The Loader has completed loading and processing. + */ + var LOADER_COMPLETE: number; + + /** + * The Loader is shutting down. + */ + var LOADER_SHUTDOWN: number; + + /** + * The Loader has been destroyed. + */ + var LOADER_DESTROYED: number; + + /** + * File is in the load queue but not yet started + */ + var FILE_PENDING: number; + + /** + * File has been started to load by the loader (onLoad called) + */ + var FILE_LOADING: number; + + /** + * File has loaded successfully, awaiting processing + */ + var FILE_LOADED: number; + + /** + * File failed to load + */ + var FILE_FAILED: number; + + /** + * File is being processed (onProcess callback) + */ + var FILE_PROCESSING: number; + + /** + * The File has errored somehow during processing. + */ + var FILE_ERRORED: number; + + /** + * File has finished processing. + */ + var FILE_COMPLETE: number; + + /** + * File has been destroyed + */ + var FILE_DESTROYED: number; + + /** + * File was populated from local data and doesn't need an HTTP request + */ + var FILE_POPULATED: number; + + namespace Events { + /** + * The Loader Plugin Add File Event. * - * ```javascript - * this.load.glsl({ - * key: 'plasma', - * shaderType: 'fragment', - * url: 'shaders/Plasma.glsl' - * }); - * ``` + * This event is dispatched when a new file is successfully added to the Loader and placed into the load queue. * - * See the documentation for `Phaser.Types.Loader.FileTypes.GLSLFileConfig` for more details. + * Listen to it from a Scene using: `this.load.on('addfile', listener)`. * - * Once the file has finished loading you can access it from its Cache using its key: + * If you add lots of files to a Loader from a `preload` method, it will dispatch this event for each one of them. + */ + const ADD: any; + + /** + * The Loader Plugin Complete Event. * - * ```javascript - * this.load.glsl('plasma', 'shaders/Plasma.glsl'); - * // and later in your game ... - * var data = this.cache.shader.get('plasma'); - * ``` + * This event is dispatched when the Loader has fully processed everything in the load queue. + * By this point every loaded file will now be in its associated cache and ready for use. * - * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files - * key. For example, if the prefix was `FX.` and the key was `Plasma` the final key will be `FX.Plasma` and - * this is what you would use to retrieve the text from the Shader Cache. + * Listen to it from a Scene using: `this.load.on('complete', listener)`. + */ + const COMPLETE: any; + + /** + * The File Load Complete Event. * - * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. + * This event is dispatched by the Loader Plugin when any file in the queue finishes loading. * - * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "plasma" - * and no URL is given then the Loader will set the URL to be "plasma.glsl". It will always add `.glsl` as the extension, although - * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. + * Listen to it from a Scene using: `this.load.on('filecomplete', listener)`. * - * Note: The ability to load this type of file will only be available if the GLSL File type has been built into Phaser. - * It is available in the default build but can be excluded from custom builds. - * @param key The key to use for this file, or a file configuration object, or array of them. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.glsl`, i.e. if `key` was "alien" then the URL will be "alien.glsl". - * @param shaderType The type of shader. Either `fragment` for a fragment shader, or `vertex` for a vertex shader. This is ignored if you load a shader bundle. Default 'fragment'. - * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. + * You can also listen for the completion of a specific file. See the [FILE_KEY_COMPLETE]{@linkcode Phaser.Loader.Events#event:FILE_KEY_COMPLETE} event. */ - glsl(key: string | Phaser.Types.Loader.FileTypes.GLSLFileConfig | Phaser.Types.Loader.FileTypes.GLSLFileConfig[], url?: string, shaderType?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): Phaser.Loader.LoaderPlugin; + const FILE_COMPLETE: any; /** - * Adds an HTML file, or array of HTML files, to the current load queue. - * - * You can call this method from within your Scene's `preload`, along with any other files you wish to load: - * - * ```javascript - * function preload () - * { - * this.load.html('story', 'files/LoginForm.html'); - * } - * ``` + * The File Load Complete Event. * - * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, - * or if it's already running, when the next free load slot becomes available. This happens automatically if you - * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued - * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. - * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the - * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been - * loaded. + * This event is dispatched by the Loader Plugin when any file in the queue finishes loading. * - * The key must be a unique String. It is used to add the file to the global HTML Cache upon a successful load. - * The key should be unique both in terms of files being loaded and files already present in the HTML Cache. - * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file - * then remove it from the HTML Cache first, before loading a new one. + * It uses a special dynamic event name constructed from the key and type of the file. * - * Instead of passing arguments you can pass a configuration object, such as: + * For example, if you have loaded an `image` with a key of `monster`, you can listen for it + * using the following: * * ```javascript - * this.load.html({ - * key: 'login', - * url: 'files/LoginForm.html' + * this.load.on('filecomplete-image-monster', function (key, type, data) { + * // Your handler code * }); * ``` * - * See the documentation for `Phaser.Types.Loader.FileTypes.HTMLFileConfig` for more details. - * - * Once the file has finished loading you can access it from its Cache using its key: + * Or, if you have loaded a texture `atlas` with a key of `Level1`: * * ```javascript - * this.load.html('login', 'files/LoginForm.html'); - * // and later in your game ... - * var data = this.cache.html.get('login'); + * this.load.on('filecomplete-atlas-Level1', function (key, type, data) { + * // Your handler code + * }); * ``` * - * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files - * key. For example, if the prefix was `LEVEL1.` and the key was `Story` the final key will be `LEVEL1.Story` and - * this is what you would use to retrieve the html from the HTML Cache. - * - * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. + * Or, if you have loaded a sprite sheet with a key of `Explosion` and a prefix of `GAMEOVER`: * - * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "story" - * and no URL is given then the Loader will set the URL to be "story.html". It will always add `.html` as the extension, although - * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. + * ```javascript + * this.load.on('filecomplete-spritesheet-GAMEOVERExplosion', function (key, type, data) { + * // Your handler code + * }); + * ``` * - * Note: The ability to load this type of file will only be available if the HTML File type has been built into Phaser. - * It is available in the default build but can be excluded from custom builds. - * @param key The key to use for this file, or a file configuration object, or array of them. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.html`, i.e. if `key` was "alien" then the URL will be "alien.html". - * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. + * You can also listen for the generic completion of files. See the [FILE_COMPLETE]{@linkcode Phaser.Loader.Events#event:FILE_COMPLETE} event. */ - html(key: string | Phaser.Types.Loader.FileTypes.HTMLFileConfig | Phaser.Types.Loader.FileTypes.HTMLFileConfig[], url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): Phaser.Loader.LoaderPlugin; + const FILE_KEY_COMPLETE: any; /** - * Adds an HTML File, or array of HTML Files, to the current load queue. When the files are loaded they - * will be rendered to textures and stored in the Texture Manager. - * - * You can call this method from within your Scene's `preload`, along with any other files you wish to load: - * - * ```javascript - * function preload () - * { - * this.load.htmlTexture('instructions', 'content/intro.html', 256, 512); - * } - * ``` - * - * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, - * or if it's already running, when the next free load slot becomes available. This happens automatically if you - * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued - * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. - * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the - * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been - * loaded. - * - * The key must be a unique String. It is used to add the file to the global Texture Manager upon a successful load. - * The key should be unique both in terms of files being loaded and files already present in the Texture Manager. - * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file - * then remove it from the Texture Manager first, before loading a new one. - * - * Instead of passing arguments you can pass a configuration object, such as: + * The File Load Error Event. * - * ```javascript - * this.load.htmlTexture({ - * key: 'instructions', - * url: 'content/intro.html', - * width: 256, - * height: 512 - * }); - * ``` + * This event is dispatched by the Loader Plugin when a file fails to load. * - * See the documentation for `Phaser.Types.Loader.FileTypes.HTMLTextureFileConfig` for more details. + * Listen to it from a Scene using: `this.load.on('loaderror', listener)`. + */ + const FILE_LOAD_ERROR: any; + + /** + * The File Load Event. * - * Once the file has finished loading you can use it as a texture for a Game Object by referencing its key: + * This event is dispatched by the Loader Plugin when a file finishes loading, + * but _before_ it is processed and added to the internal Phaser caches. * - * ```javascript - * this.load.htmlTexture('instructions', 'content/intro.html', 256, 512); - * // and later in your game ... - * this.add.image(x, y, 'instructions'); - * ``` + * Listen to it from a Scene using: `this.load.on('load', listener)`. + */ + const FILE_LOAD: any; + + /** + * The File Load Progress Event. * - * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files - * key. For example, if the prefix was `MENU.` and the key was `Background` the final key will be `MENU.Background` and - * this is what you would use to retrieve the image from the Texture Manager. + * This event is dispatched by the Loader Plugin during the load of a file, if the browser receives a DOM ProgressEvent and + * the `lengthComputable` event property is true. Depending on the size of the file and browser in use, this may, or may not happen. * - * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. + * Listen to it from a Scene using: `this.load.on('fileprogress', listener)`. + */ + const FILE_PROGRESS: any; + + /** + * The Loader Plugin Post Process Event. * - * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "alien" - * and no URL is given then the Loader will set the URL to be "alien.html". It will always add `.html` as the extension, although - * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. + * This event is dispatched by the Loader Plugin when the Loader has finished loading everything in the load queue. + * It is dispatched before the internal lists are cleared and each File is destroyed. * - * The width and height are the size of the texture to which the HTML will be rendered. It's not possible to determine these - * automatically, so you will need to provide them, either as arguments or in the file config object. - * When the HTML file has loaded a new SVG element is created with a size and viewbox set to the width and height given. - * The SVG file has a body tag added to it, with the HTML file contents included. It then calls `window.Blob` on the SVG, - * and if successful is added to the Texture Manager, otherwise it fails processing. The overall quality of the rendered - * HTML depends on your browser, and some of them may not even support the svg / blob process used. Be aware that there are - * limitations on what HTML can be inside an SVG. You can find out more details in this - * [Mozilla MDN entry](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Drawing_DOM_objects_into_a_canvas). + * Use this hook to perform any last minute processing of files that can only happen once the + * Loader has completed, but prior to it emitting the `complete` event. * - * Note: The ability to load this type of file will only be available if the HTMLTextureFile File type has been built into Phaser. - * It is available in the default build but can be excluded from custom builds. - * @param key The key to use for this file, or a file configuration object, or array of them. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.html`, i.e. if `key` was "alien" then the URL will be "alien.html". - * @param width The width of the texture the HTML will be rendered to. Default 512. - * @param height The height of the texture the HTML will be rendered to. Default 512. - * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. + * Listen to it from a Scene using: `this.load.on('postprocess', listener)`. */ - htmlTexture(key: string | Phaser.Types.Loader.FileTypes.HTMLTextureFileConfig | Phaser.Types.Loader.FileTypes.HTMLTextureFileConfig[], url?: string, width?: integer, height?: integer, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): Phaser.Loader.LoaderPlugin; + const POST_PROCESS: any; /** - * Adds an Image, or array of Images, to the current load queue. - * - * You can call this method from within your Scene's `preload`, along with any other files you wish to load: + * The Loader Plugin Progress Event. * - * ```javascript - * function preload () - * { - * this.load.image('logo', 'images/phaserLogo.png'); - * } - * ``` + * This event is dispatched when the Loader updates its load progress, typically as a result of a file having completed loading. * - * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, - * or if it's already running, when the next free load slot becomes available. This happens automatically if you - * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued - * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. - * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the - * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been - * loaded. + * Listen to it from a Scene using: `this.load.on('progress', listener)`. + */ + const PROGRESS: any; + + /** + * The Loader Plugin Start Event. * - * Phaser can load all common image types: png, jpg, gif and any other format the browser can natively handle. - * If you try to load an animated gif only the first frame will be rendered. Browsers do not natively support playback - * of animated gifs to Canvas elements. + * This event is dispatched when the Loader starts running. At this point load progress is zero. * - * The key must be a unique String. It is used to add the file to the global Texture Manager upon a successful load. - * The key should be unique both in terms of files being loaded and files already present in the Texture Manager. - * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file - * then remove it from the Texture Manager first, before loading a new one. + * This event is dispatched even if there aren't any files in the load queue. * - * Instead of passing arguments you can pass a configuration object, such as: + * Listen to it from a Scene using: `this.load.on('start', listener)`. + */ + const START: any; + + } + + /** + * The base File class used by all File Types that the Loader can support. + * You shouldn't create an instance of a File directly, but should extend it with your own class, setting a custom type and processing methods. + */ + class File { + /** * - * ```javascript - * this.load.image({ - * key: 'logo', - * url: 'images/AtariLogo.png' - * }); - * ``` + * @param loader The Loader that is going to load this File. + * @param fileConfig The file configuration object, as created by the file type. + */ + constructor(loader: Phaser.Loader.LoaderPlugin, fileConfig: Phaser.Types.Loader.FileConfig); + + /** + * A reference to the Loader that is going to load this file. + */ + loader: Phaser.Loader.LoaderPlugin; + + /** + * A reference to the Cache, or Texture Manager, that is going to store this file if it loads. + */ + cache: Phaser.Cache.BaseCache | Phaser.Textures.TextureManager; + + /** + * The file type string (image, json, etc) for sorting within the Loader. + */ + type: string; + + /** + * Unique cache key (unique within its file type) + */ + key: string; + + /** + * The URL of the file, not including baseURL. * - * See the documentation for `Phaser.Types.Loader.FileTypes.ImageFileConfig` for more details. + * Automatically has Loader.path prepended to it if a string. * - * Once the file has finished loading you can use it as a texture for a Game Object by referencing its key: - * - * ```javascript - * this.load.image('logo', 'images/AtariLogo.png'); - * // and later in your game ... - * this.add.image(x, y, 'logo'); - * ``` - * - * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files - * key. For example, if the prefix was `MENU.` and the key was `Background` the final key will be `MENU.Background` and - * this is what you would use to retrieve the image from the Texture Manager. - * - * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. - * - * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "alien" - * and no URL is given then the Loader will set the URL to be "alien.png". It will always add `.png` as the extension, although - * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. - * - * Phaser also supports the automatic loading of associated normal maps. If you have a normal map to go with this image, - * then you can specify it by providing an array as the `url` where the second element is the normal map: - * - * ```javascript - * this.load.image('logo', [ 'images/AtariLogo.png', 'images/AtariLogo-n.png' ]); - * ``` - * - * Or, if you are using a config object use the `normalMap` property: - * - * ```javascript - * this.load.image({ - * key: 'logo', - * url: 'images/AtariLogo.png', - * normalMap: 'images/AtariLogo-n.png' - * }); - * ``` - * - * The normal map file is subject to the same conditions as the image file with regard to the path, baseURL, CORs and XHR Settings. - * Normal maps are a WebGL only feature. - * - * Note: The ability to load this type of file will only be available if the Image File type has been built into Phaser. - * It is available in the default build but can be excluded from custom builds. - * @param key The key to use for this file, or a file configuration object, or array of them. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". - * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. + * Can also be a JavaScript Object, such as the results of parsing JSON data. */ - image(key: string | Phaser.Types.Loader.FileTypes.ImageFileConfig | Phaser.Types.Loader.FileTypes.ImageFileConfig[], url?: string | string[], xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): Phaser.Loader.LoaderPlugin; + url: object | string; /** - * Adds a JSON file, or array of JSON files, to the current load queue. + * The final URL this file will load from, including baseURL and path. + * Set automatically when the Loader calls 'load' on this file. + */ + src: string; + + /** + * The merged XHRSettings for this file. + */ + xhrSettings: Phaser.Types.Loader.XHRSettingsObject; + + /** + * The XMLHttpRequest instance (as created by XHR Loader) that is loading this File. + */ + xhrLoader: XMLHttpRequest; + + /** + * The current state of the file. One of the FILE_CONST values. + */ + state: number; + + /** + * The total size of this file. + * Set by onProgress and only if loading via XHR. + */ + bytesTotal: number; + + /** + * Updated as the file loads. + * Only set if loading via XHR. + */ + bytesLoaded: number; + + /** + * A percentage value between 0 and 1 indicating how much of this file has loaded. + * Only set if loading via XHR. + */ + percentComplete: number; + + /** + * For CORs based loading. + * If this is undefined then the File will check BaseLoader.crossOrigin and use that (if set) + */ + crossOrigin: string | undefined; + + /** + * The processed file data, stored here after the file has loaded. + */ + data: any; + + /** + * A config object that can be used by file types to store transitional data. + */ + config: any; + + /** + * If this is a multipart file, i.e. an atlas and its json together, then this is a reference + * to the parent MultiFile. Set and used internally by the Loader or specific file types. + */ + multiFile: Phaser.Loader.MultiFile; + + /** + * Does this file have an associated linked file? Such as an image and a normal map. + * Atlases and Bitmap Fonts use the multiFile, because those files need loading together but aren't + * actually bound by data, where-as a linkFile is. + */ + linkFile: Phaser.Loader.File; + + /** + * Links this File with another, so they depend upon each other for loading and processing. + * @param fileB The file to link to this one. + */ + setLink(fileB: Phaser.Loader.File): void; + + /** + * Resets the XHRLoader instance this file is using. + */ + resetXHR(): void; + + /** + * Called by the Loader, starts the actual file downloading. + * During the load the methods onLoad, onError and onProgress are called, based on the XHR events. + * You shouldn't normally call this method directly, it's meant to be invoked by the Loader. + */ + load(): void; + + /** + * Called when the file finishes loading, is sent a DOM ProgressEvent. + * @param xhr The XMLHttpRequest that caused this onload event. + * @param event The DOM ProgressEvent that resulted from this load. + */ + onLoad(xhr: XMLHttpRequest, event: ProgressEvent): void; + + /** + * Called if the file errors while loading, is sent a DOM ProgressEvent. + * @param xhr The XMLHttpRequest that caused this onload event. + * @param event The DOM ProgressEvent that resulted from this error. + */ + onError(xhr: XMLHttpRequest, event: ProgressEvent): void; + + /** + * Called during the file load progress. Is sent a DOM ProgressEvent. + * @param event The DOM ProgressEvent. + */ + onProgress(event: ProgressEvent): void; + + /** + * Usually overridden by the FileTypes and is called by Loader.nextFile. + * This method controls what extra work this File does with its loaded data, for example a JSON file will parse itself during this stage. + */ + onProcess(): void; + + /** + * Called when the File has completed processing. + * Checks on the state of its multifile, if set. + */ + onProcessComplete(): void; + + /** + * Called when the File has completed processing but it generated an error. + * Checks on the state of its multifile, if set. + */ + onProcessError(): void; + + /** + * Checks if a key matching the one used by this file exists in the target Cache or not. + * This is called automatically by the LoaderPlugin to decide if the file can be safely + * loaded or will conflict. + */ + hasCacheConflict(): boolean; + + /** + * Adds this file to its target cache upon successful loading and processing. + * This method is often overridden by specific file types. + */ + addToCache(): void; + + /** + * Called once the file has been added to its cache and is now ready for deletion from the Loader. + * It will emit a `filecomplete` event from the LoaderPlugin. + */ + pendingDestroy(): void; + + /** + * Destroy this File and any references it holds. + */ + destroy(): void; + + /** + * Static method for creating object URL using URL API and setting it as image 'src' attribute. + * If URL API is not supported (usually on old browsers) it falls back to creating Base64 encoded url using FileReader. + * @param image Image object which 'src' attribute should be set to object URL. + * @param blob A Blob object to create an object URL for. + * @param defaultType Default mime type used if blob type is not available. + */ + static createObjectURL(image: HTMLImageElement, blob: Blob, defaultType: string): void; + + /** + * Static method for releasing an existing object URL which was previously created + * by calling {@link File#createObjectURL} method. + * @param image Image object which 'src' attribute should be revoked. + */ + static revokeObjectURL(image: HTMLImageElement): void; + + } + + namespace FileTypes { + /** + * A single Animation JSON File suitable for loading by the Loader. * - * You can call this method from within your Scene's `preload`, along with any other files you wish to load: + * These are created when you use the Phaser.Loader.LoaderPlugin#animation method and are not typically created directly. * - * ```javascript - * function preload () - * { - * this.load.json('wavedata', 'files/AlienWaveData.json'); - * } - * ``` + * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#animation. + */ + class AnimationJSONFile extends Phaser.Loader.File { + /** + * + * @param loader A reference to the Loader that is responsible for this file. + * @param key The key to use for this file, or a file configuration object. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". + * @param xhrSettings Extra XHR Settings specifically for this file. + * @param dataKey When the JSON file loads only this property will be stored in the Cache. + */ + constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.JSONFileConfig, url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject, dataKey?: string); + + /** + * Called automatically by Loader.nextFile. + * This method controls what extra work this File does with its loaded data. + */ + onProcess(): void; + + /** + * Called at the end of the load process, after the Loader has finished all files in its queue. + */ + onLoadComplete(): void; + + } + + /** + * A single JSON based Texture Atlas File suitable for loading by the Loader. * - * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, - * or if it's already running, when the next free load slot becomes available. This happens automatically if you - * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued - * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. - * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the - * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been - * loaded. + * These are created when you use the Phaser.Loader.LoaderPlugin#atlas method and are not typically created directly. * - * The key must be a unique String. It is used to add the file to the global JSON Cache upon a successful load. - * The key should be unique both in terms of files being loaded and files already present in the JSON Cache. - * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file - * then remove it from the JSON Cache first, before loading a new one. + * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#atlas. * - * Instead of passing arguments you can pass a configuration object, such as: + * https://www.codeandweb.com/texturepacker/tutorials/how-to-create-sprite-sheets-for-phaser3?source=photonstorm + */ + class AsepriteFile extends Phaser.Loader.MultiFile { + /** + * + * @param loader A reference to the Loader that is responsible for this file. + * @param key The key to use for this file, or a file configuration object. + * @param textureURL The absolute or relative URL to load the texture image file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". + * @param atlasURL The absolute or relative URL to load the texture atlas json data file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". Or, a well formed JSON object. + * @param textureXhrSettings An XHR Settings configuration object for the atlas image file. Used in replacement of the Loaders default XHR Settings. + * @param atlasXhrSettings An XHR Settings configuration object for the atlas json file. Used in replacement of the Loaders default XHR Settings. + */ + constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.AsepriteFileConfig, textureURL?: string | string[], atlasURL?: object | string, textureXhrSettings?: Phaser.Types.Loader.XHRSettingsObject, atlasXhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + + /** + * Adds this file to its target cache upon successful loading and processing. + */ + addToCache(): void; + + } + + /** + * A single JSON based Texture Atlas File suitable for loading by the Loader. * - * ```javascript - * this.load.json({ - * key: 'wavedata', - * url: 'files/AlienWaveData.json' - * }); - * ``` + * These are created when you use the Phaser.Loader.LoaderPlugin#atlas method and are not typically created directly. * - * See the documentation for `Phaser.Types.Loader.FileTypes.JSONFileConfig` for more details. + * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#atlas. * - * Once the file has finished loading you can access it from its Cache using its key: + * https://www.codeandweb.com/texturepacker/tutorials/how-to-create-sprite-sheets-for-phaser3?source=photonstorm + */ + class AtlasJSONFile extends Phaser.Loader.MultiFile { + /** + * + * @param loader A reference to the Loader that is responsible for this file. + * @param key The key to use for this file, or a file configuration object. + * @param textureURL The absolute or relative URL to load the texture image file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". + * @param atlasURL The absolute or relative URL to load the texture atlas json data file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". Or, a well formed JSON object. + * @param textureXhrSettings An XHR Settings configuration object for the atlas image file. Used in replacement of the Loaders default XHR Settings. + * @param atlasXhrSettings An XHR Settings configuration object for the atlas json file. Used in replacement of the Loaders default XHR Settings. + */ + constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.AtlasJSONFileConfig, textureURL?: string | string[], atlasURL?: object | string, textureXhrSettings?: Phaser.Types.Loader.XHRSettingsObject, atlasXhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + + /** + * Adds this file to its target cache upon successful loading and processing. + */ + addToCache(): void; + + } + + /** + * A single XML based Texture Atlas File suitable for loading by the Loader. * - * ```javascript - * this.load.json('wavedata', 'files/AlienWaveData.json'); - * // and later in your game ... - * var data = this.cache.json.get('wavedata'); - * ``` + * These are created when you use the Phaser.Loader.LoaderPlugin#atlasXML method and are not typically created directly. * - * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files - * key. For example, if the prefix was `LEVEL1.` and the key was `Waves` the final key will be `LEVEL1.Waves` and - * this is what you would use to retrieve the text from the JSON Cache. + * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#atlasXML. + */ + class AtlasXMLFile extends Phaser.Loader.MultiFile { + /** + * + * @param loader A reference to the Loader that is responsible for this file. + * @param key The key to use for this file, or a file configuration object. + * @param textureURL The absolute or relative URL to load the texture image file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". + * @param atlasURL The absolute or relative URL to load the texture atlas xml data file from. If undefined or `null` it will be set to `.xml`, i.e. if `key` was "alien" then the URL will be "alien.xml". + * @param textureXhrSettings An XHR Settings configuration object for the atlas image file. Used in replacement of the Loaders default XHR Settings. + * @param atlasXhrSettings An XHR Settings configuration object for the atlas xml file. Used in replacement of the Loaders default XHR Settings. + */ + constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.AtlasXMLFileConfig, textureURL?: string | string[], atlasURL?: string, textureXhrSettings?: Phaser.Types.Loader.XHRSettingsObject, atlasXhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + + /** + * Adds this file to its target cache upon successful loading and processing. + */ + addToCache(): void; + + } + + /** + * A single Audio File suitable for loading by the Loader. * - * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. + * These are created when you use the Phaser.Loader.LoaderPlugin#audio method and are not typically created directly. * - * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "data" - * and no URL is given then the Loader will set the URL to be "data.json". It will always add `.json` as the extension, although - * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. + * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#audio. + */ + class AudioFile extends Phaser.Loader.File { + /** + * + * @param loader A reference to the Loader that is responsible for this file. + * @param key The key to use for this file, or a file configuration object. + * @param urlConfig The absolute or relative URL to load this file from in a config object. + * @param xhrSettings Extra XHR Settings specifically for this file. + * @param audioContext The AudioContext this file will use to process itself. + */ + constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.AudioFileConfig, urlConfig?: any, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject, audioContext?: AudioContext); + + /** + * Called automatically by Loader.nextFile. + * This method controls what extra work this File does with its loaded data. + */ + onProcess(): void; + + } + + /** + * An Audio Sprite File suitable for loading by the Loader. * - * You can also optionally provide a `dataKey` to use. This allows you to extract only a part of the JSON and store it in the Cache, - * rather than the whole file. For example, if your JSON data had a structure like this: + * These are created when you use the Phaser.Loader.LoaderPlugin#audioSprite method and are not typically created directly. * - * ```json - * { - * "level1": { - * "baddies": { - * "aliens": {}, - * "boss": {} - * } - * }, - * "level2": {}, - * "level3": {} - * } - * ``` + * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#audioSprite. + */ + class AudioSpriteFile extends Phaser.Loader.MultiFile { + /** + * + * @param loader A reference to the Loader that is responsible for this file. + * @param key The key to use for this file, or a file configuration object. + * @param jsonURL The absolute or relative URL to load the json file from. Or a well formed JSON object to use instead. + * @param audioURL The absolute or relative URL to load the audio file from. If empty it will be obtained by parsing the JSON file. + * @param audioConfig The audio configuration options. + * @param audioXhrSettings An XHR Settings configuration object for the audio file. Used in replacement of the Loaders default XHR Settings. + * @param jsonXhrSettings An XHR Settings configuration object for the json file. Used in replacement of the Loaders default XHR Settings. + */ + constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.AudioSpriteFileConfig, jsonURL: string, audioURL?: Object, audioConfig?: any, audioXhrSettings?: Phaser.Types.Loader.XHRSettingsObject, jsonXhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + + /** + * Called by each File when it finishes loading. + * @param file The File that has completed processing. + */ + onFileComplete(file: Phaser.Loader.File): void; + + /** + * Adds this file to its target cache upon successful loading and processing. + */ + addToCache(): void; + + } + + /** + * A single Binary File suitable for loading by the Loader. * - * And you only wanted to store the `boss` data in the Cache, then you could pass `level1.baddies.boss`as the `dataKey`. + * These are created when you use the Phaser.Loader.LoaderPlugin#binary method and are not typically created directly. * - * Note: The ability to load this type of file will only be available if the JSON File type has been built into Phaser. - * It is available in the default build but can be excluded from custom builds. - * @param key The key to use for this file, or a file configuration object, or array of them. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". - * @param dataKey When the JSON file loads only this property will be stored in the Cache. - * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. + * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#binary. */ - json(key: string | Phaser.Types.Loader.FileTypes.JSONFileConfig | Phaser.Types.Loader.FileTypes.JSONFileConfig[], url?: string, dataKey?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): Phaser.Loader.LoaderPlugin; + class BinaryFile extends Phaser.Loader.File { + /** + * + * @param loader A reference to the Loader that is responsible for this file. + * @param key The key to use for this file, or a file configuration object. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.bin`, i.e. if `key` was "alien" then the URL will be "alien.bin". + * @param xhrSettings Extra XHR Settings specifically for this file. + * @param dataType Optional type to cast the binary file to once loaded. For example, `Uint8Array`. + */ + constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.BinaryFileConfig, url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject, dataType?: any); + + /** + * Called automatically by Loader.nextFile. + * This method controls what extra work this File does with its loaded data. + */ + onProcess(): void; + + } /** - * Adds a Multi Texture Atlas, or array of multi atlases, to the current load queue. + * A single Bitmap Font based File suitable for loading by the Loader. * - * You can call this method from within your Scene's `preload`, along with any other files you wish to load: + * These are created when you use the Phaser.Loader.LoaderPlugin#bitmapFont method and are not typically created directly. * - * ```javascript - * function preload () - * { - * this.load.multiatlas('level1', 'images/Level1.json'); - * } - * ``` + * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#bitmapFont. + */ + class BitmapFontFile extends Phaser.Loader.MultiFile { + /** + * + * @param loader A reference to the Loader that is responsible for this file. + * @param key The key to use for this file, or a file configuration object. + * @param textureURL The absolute or relative URL to load the font image file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". + * @param fontDataURL The absolute or relative URL to load the font xml data file from. If undefined or `null` it will be set to `.xml`, i.e. if `key` was "alien" then the URL will be "alien.xml". + * @param textureXhrSettings An XHR Settings configuration object for the font image file. Used in replacement of the Loaders default XHR Settings. + * @param fontDataXhrSettings An XHR Settings configuration object for the font data xml file. Used in replacement of the Loaders default XHR Settings. + */ + constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.BitmapFontFileConfig, textureURL?: string | string[], fontDataURL?: string, textureXhrSettings?: Phaser.Types.Loader.XHRSettingsObject, fontDataXhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + + /** + * Adds this file to its target cache upon successful loading and processing. + */ + addToCache(): void; + + } + + /** + * A single CSS File suitable for loading by the Loader. * - * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, - * or if it's already running, when the next free load slot becomes available. This happens automatically if you - * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued - * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. - * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the - * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been - * loaded. + * These are created when you use the Phaser.Loader.LoaderPlugin#css method and are not typically created directly. * - * If you call this from outside of `preload` then you are responsible for starting the Loader afterwards and monitoring - * its events to know when it's safe to use the asset. Please see the Phaser.Loader.LoaderPlugin class for more details. + * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#css. + */ + class CSSFile extends Phaser.Loader.File { + /** + * + * @param loader A reference to the Loader that is responsible for this file. + * @param key The key to use for this file, or a file configuration object. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.js`, i.e. if `key` was "alien" then the URL will be "alien.js". + * @param xhrSettings Extra XHR Settings specifically for this file. + */ + constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.CSSFileConfig, url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + + /** + * Called automatically by Loader.nextFile. + * This method controls what extra work this File does with its loaded data. + */ + onProcess(): void; + + } + + /** + * A single GLSL File suitable for loading by the Loader. * - * Phaser expects the atlas data to be provided in a JSON file as exported from the application Texture Packer, - * version 4.6.3 or above, where you have made sure to use the Phaser 3 Export option. + * These are created when you use the Phaser.Loader.LoaderPlugin#glsl method and are not typically created directly. * - * The way it works internally is that you provide a URL to the JSON file. Phaser then loads this JSON, parses it and - * extracts which texture files it also needs to load to complete the process. If the JSON also defines normal maps, - * Phaser will load those as well. - * - * The key must be a unique String. It is used to add the file to the global Texture Manager upon a successful load. - * The key should be unique both in terms of files being loaded and files already present in the Texture Manager. - * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file - * then remove it from the Texture Manager first, before loading a new one. - * - * Instead of passing arguments you can pass a configuration object, such as: + * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#glsl. + */ + class GLSLFile extends Phaser.Loader.File { + /** + * + * @param loader A reference to the Loader that is responsible for this file. + * @param key The key to use for this file, or a file configuration object. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.txt`, i.e. if `key` was "alien" then the URL will be "alien.txt". + * @param shaderType The type of shader. Either `fragment` for a fragment shader, or `vertex` for a vertex shader. This is ignored if you load a shader bundle. Default 'fragment'. + * @param xhrSettings Extra XHR Settings specifically for this file. + */ + constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.GLSLFileConfig, url?: string, shaderType?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + + /** + * Called automatically by Loader.nextFile. + * This method controls what extra work this File does with its loaded data. + */ + onProcess(): void; + + /** + * Adds this file to its target cache upon successful loading and processing. + */ + addToCache(): void; + + /** + * Returns the name of the shader from the header block. + * @param headerSource The header data. + */ + getShaderName(headerSource: string[]): string; + + /** + * Returns the type of the shader from the header block. + * @param headerSource The header data. + */ + getShaderType(headerSource: string[]): string; + + /** + * Returns the shader uniforms from the header block. + * @param headerSource The header data. + */ + getShaderUniforms(headerSource: string[]): any; + + } + + /** + * A single Audio File suitable for loading by the Loader. * - * ```javascript - * this.load.multiatlas({ - * key: 'level1', - * atlasURL: 'images/Level1.json' - * }); - * ``` + * These are created when you use the Phaser.Loader.LoaderPlugin#audio method and are not typically created directly. * - * See the documentation for `Phaser.Types.Loader.FileTypes.MultiAtlasFileConfig` for more details. + * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#audio. + */ + class HTML5AudioFile extends Phaser.Loader.File { + /** + * + * @param loader A reference to the Loader that is responsible for this file. + * @param key The key to use for this file, or a file configuration object. + * @param urlConfig The absolute or relative URL to load this file from. + * @param xhrSettings Extra XHR Settings specifically for this file. + */ + constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.AudioFileConfig, urlConfig?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + + /** + * Called when the file finishes loading. + */ + onLoad(): void; + + /** + * Called if the file errors while loading. + */ + onError(): void; + + /** + * Called during the file load progress. Is sent a DOM ProgressEvent. + */ + onProgress(): void; + + /** + * Called by the Loader, starts the actual file downloading. + * During the load the methods onLoad, onError and onProgress are called, based on the XHR events. + * You shouldn't normally call this method directly, it's meant to be invoked by the Loader. + */ + load(): void; + + } + + /** + * A single HTML File suitable for loading by the Loader. * - * Instead of passing a URL for the atlas JSON data you can also pass in a well formed JSON object instead. + * These are created when you use the Phaser.Loader.LoaderPlugin#html method and are not typically created directly. * - * Once the atlas has finished loading you can use frames from it as textures for a Game Object by referencing its key: + * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#html. + */ + class HTMLFile extends Phaser.Loader.File { + /** + * + * @param loader A reference to the Loader that is responsible for this file. + * @param key The key to use for this file, or a file configuration object. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.html`, i.e. if `key` was "alien" then the URL will be "alien.html". + * @param xhrSettings Extra XHR Settings specifically for this file. + */ + constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.HTMLFileConfig, url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + + /** + * Called automatically by Loader.nextFile. + * This method controls what extra work this File does with its loaded data. + */ + onProcess(): void; + + } + + /** + * A single HTML File suitable for loading by the Loader. * - * ```javascript - * this.load.multiatlas('level1', 'images/Level1.json'); - * // and later in your game ... - * this.add.image(x, y, 'level1', 'background'); - * ``` + * These are created when you use the Phaser.Loader.LoaderPlugin#htmlTexture method and are not typically created directly. * - * To get a list of all available frames within an atlas please consult your Texture Atlas software. + * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#htmlTexture. + */ + class HTMLTextureFile extends Phaser.Loader.File { + /** + * + * @param loader A reference to the Loader that is responsible for this file. + * @param key The key to use for this file, or a file configuration object. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". + * @param width The width of the texture the HTML will be rendered to. + * @param height The height of the texture the HTML will be rendered to. + * @param xhrSettings Extra XHR Settings specifically for this file. + */ + constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.HTMLTextureFileConfig, url?: string, width?: number, height?: number, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + + /** + * Called automatically by Loader.nextFile. + * This method controls what extra work this File does with its loaded data. + */ + onProcess(): void; + + /** + * Adds this file to its target cache upon successful loading and processing. + */ + addToCache(): void; + + } + + /** + * A single Image File suitable for loading by the Loader. * - * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files - * key. For example, if the prefix was `MENU.` and the key was `Background` the final key will be `MENU.Background` and - * this is what you would use to retrieve the image from the Texture Manager. + * These are created when you use the Phaser.Loader.LoaderPlugin#image method and are not typically created directly. * - * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. + * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#image. + */ + class ImageFile extends Phaser.Loader.File { + /** + * + * @param loader A reference to the Loader that is responsible for this file. + * @param key The key to use for this file, or a file configuration object. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". + * @param xhrSettings Extra XHR Settings specifically for this file. + * @param frameConfig The frame configuration object. Only provided for, and used by, Sprite Sheets. + */ + constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.ImageFileConfig, url?: string | string[], xhrSettings?: Phaser.Types.Loader.XHRSettingsObject, frameConfig?: Phaser.Types.Loader.FileTypes.ImageFrameConfig); + + /** + * Called automatically by Loader.nextFile. + * This method controls what extra work this File does with its loaded data. + */ + onProcess(): void; + + /** + * Adds this file to its target cache upon successful loading and processing. + */ + addToCache(): void; + + } + + /** + * A single JSON File suitable for loading by the Loader. * - * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "alien" - * and no URL is given then the Loader will set the URL to be "alien.png". It will always add `.png` as the extension, although - * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. + * These are created when you use the Phaser.Loader.LoaderPlugin#json method and are not typically created directly. * - * Note: The ability to load this type of file will only be available if the Multi Atlas File type has been built into Phaser. - * It is available in the default build but can be excluded from custom builds. - * @param key The key to use for this file, or a file configuration object, or array of them. - * @param atlasURL The absolute or relative URL to load the texture atlas json data file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". - * @param path Optional path to use when loading the textures defined in the atlas data. - * @param baseURL Optional Base URL to use when loading the textures defined in the atlas data. - * @param atlasXhrSettings An XHR Settings configuration object for the atlas json file. Used in replacement of the Loaders default XHR Settings. + * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#json. */ - multiatlas(key: string | Phaser.Types.Loader.FileTypes.MultiAtlasFileConfig | Phaser.Types.Loader.FileTypes.MultiAtlasFileConfig[], atlasURL?: string, path?: string, baseURL?: string, atlasXhrSettings?: Phaser.Types.Loader.XHRSettingsObject): Phaser.Loader.LoaderPlugin; + class JSONFile extends Phaser.Loader.File { + /** + * + * @param loader A reference to the Loader that is responsible for this file. + * @param key The key to use for this file, or a file configuration object. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". Or, can be a fully formed JSON Object. + * @param xhrSettings Extra XHR Settings specifically for this file. + * @param dataKey When the JSON file loads only this property will be stored in the Cache. + */ + constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.JSONFileConfig, url?: object | string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject, dataKey?: string); + + /** + * Called automatically by Loader.nextFile. + * This method controls what extra work this File does with its loaded data. + */ + onProcess(): void; + + } /** - * Adds an array of Script files to the current load queue. + * A single Multi Texture Atlas File suitable for loading by the Loader. * - * The difference between this and the `ScriptFile` file type is that you give an array of scripts to this method, - * and the scripts are then processed _exactly_ in that order. This allows you to load a bunch of scripts that - * may have dependencies on each other without worrying about the async nature of traditional script loading. + * These are created when you use the Phaser.Loader.LoaderPlugin#multiatlas method and are not typically created directly. * - * You can call this method from within your Scene's `preload`, along with any other files you wish to load: + * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#multiatlas. + */ + class MultiAtlasFile extends Phaser.Loader.MultiFile { + /** + * + * @param loader A reference to the Loader that is responsible for this file. + * @param key The key of the file. Must be unique within both the Loader and the Texture Manager. Or a config object. + * @param atlasURL The absolute or relative URL to load the multi atlas json file from. + * @param path Optional path to use when loading the textures defined in the atlas data. + * @param baseURL Optional Base URL to use when loading the textures defined in the atlas data. + * @param atlasXhrSettings Extra XHR Settings specifically for the atlas json file. + * @param textureXhrSettings Extra XHR Settings specifically for the texture files. + */ + constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.MultiAtlasFileConfig, atlasURL?: string, path?: string, baseURL?: string, atlasXhrSettings?: Phaser.Types.Loader.XHRSettingsObject, textureXhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + + /** + * Called by each File when it finishes loading. + * @param file The File that has completed processing. + */ + onFileComplete(file: Phaser.Loader.File): void; + + /** + * Adds this file to its target cache upon successful loading and processing. + */ + addToCache(): void; + + } + + /** + * A Multi Script File suitable for loading by the Loader. * - * ```javascript - * function preload () - * { - * this.load.scripts('PostProcess', [ - * 'libs/shaders/CopyShader.js', - * 'libs/postprocessing/EffectComposer.js', - * 'libs/postprocessing/RenderPass.js', - * 'libs/postprocessing/MaskPass.js', - * 'libs/postprocessing/ShaderPass.js', - * 'libs/postprocessing/AfterimagePass.js' - * ]); - * } - * ``` + * These are created when you use the Phaser.Loader.LoaderPlugin#scripts method and are not typically created directly. * - * In the code above the script files will all be loaded in parallel but only processed (i.e. invoked) in the exact - * order given in the array. + * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#scripts. + */ + class MultiScriptFile extends Phaser.Loader.MultiFile { + /** + * + * @param loader A reference to the Loader that is responsible for this file. + * @param key The key to use for this file, or a file configuration object. + * @param url An array of absolute or relative URLs to load the script files from. They are processed in the order given in the array. + * @param xhrSettings An XHR Settings configuration object for the script files. Used in replacement of the Loaders default XHR Settings. + */ + constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.MultiScriptFileConfig, url?: string[], xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + + /** + * Adds this file to its target cache upon successful loading and processing. + */ + addToCache(): void; + + } + + /** + * A single Wavefront OBJ File suitable for loading by the Loader. * - * The files are **not** loaded right away. They are added to a queue ready to be loaded either when the loader starts, - * or if it's already running, when the next free load slot becomes available. This happens automatically if you - * are calling this from within the Scene's `preload` method, or a related callback. Because the files are queued - * it means you cannot use the files immediately after calling this method, but must wait for the files to complete. - * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the - * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been - * loaded. + * These are created when you use the Phaser.Loader.LoaderPlugin#obj method and are not typically created directly. * - * The key must be a unique String and not already in-use by another file in the Loader. + * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#obj. + */ + class OBJFile extends Phaser.Loader.MultiFile { + /** + * + * @param loader A reference to the Loader that is responsible for this file. + * @param key The key to use for this file, or a file configuration object. + * @param objURL The absolute or relative URL to load the obj file from. If undefined or `null` it will be set to `.obj`, i.e. if `key` was "alien" then the URL will be "alien.obj". + * @param matURL The absolute or relative URL to load the material file from. If undefined or `null` it will be set to `.mat`, i.e. if `key` was "alien" then the URL will be "alien.mat". + * @param flipUV Flip the UV coordinates stored in the model data? + * @param xhrSettings Extra XHR Settings specifically for these files. + */ + constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.OBJFileConfig, objURL?: string, matURL?: string, flipUV?: boolean, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + + /** + * Adds this file to its target cache upon successful loading and processing. + */ + addToCache(): void; + + } + + /** + * A single JSON Pack File suitable for loading by the Loader. * - * Instead of passing arguments you can pass a configuration object, such as: + * These are created when you use the Phaser.Loader.LoaderPlugin#pack method and are not typically created directly. * - * ```javascript - * this.load.scripts({ - * key: 'PostProcess', - * url: [ - * 'libs/shaders/CopyShader.js', - * 'libs/postprocessing/EffectComposer.js', - * 'libs/postprocessing/RenderPass.js', - * 'libs/postprocessing/MaskPass.js', - * 'libs/postprocessing/ShaderPass.js', - * 'libs/postprocessing/AfterimagePass.js' - * ] - * }); - * ``` + * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#pack. + */ + class PackFile extends Phaser.Loader.File { + /** + * + * @param loader A reference to the Loader that is responsible for this file. + * @param key The key to use for this file, or a file configuration object. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". + * @param xhrSettings Extra XHR Settings specifically for this file. + * @param dataKey When the JSON file loads only this property will be stored in the Cache. + */ + constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.PackFileConfig, url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject, dataKey?: string); + + /** + * Called automatically by Loader.nextFile. + * This method controls what extra work this File does with its loaded data. + */ + onProcess(): void; + + } + + /** + * A single Plugin Script File suitable for loading by the Loader. * - * See the documentation for `Phaser.Types.Loader.FileTypes.MultiScriptFileConfig` for more details. + * These are created when you use the Phaser.Loader.LoaderPlugin#plugin method and are not typically created directly. * - * Once all the files have finished loading they will automatically be converted into a script element - * via `document.createElement('script')`. They will have their language set to JavaScript, `defer` set to - * false and then the resulting element will be appended to `document.head`. Any code then in the - * script will be executed. This is done in the exact order the files are specified in the url array. + * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#plugin. + */ + class PluginFile extends Phaser.Loader.File { + /** + * + * @param loader A reference to the Loader that is responsible for this file. + * @param key The key to use for this file, or a file configuration object. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.js`, i.e. if `key` was "alien" then the URL will be "alien.js". + * @param start Automatically start the plugin after loading? Default false. + * @param mapping If this plugin is to be injected into the Scene, this is the property key used. + * @param xhrSettings Extra XHR Settings specifically for this file. + */ + constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.PluginFileConfig, url?: string, start?: boolean, mapping?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + + /** + * Called automatically by Loader.nextFile. + * This method controls what extra work this File does with its loaded data. + */ + onProcess(): void; + + } + + /** + * An external Scene JavaScript File suitable for loading by the Loader. * - * The URLs can be relative or absolute. If the URLs are relative the `Loader.baseURL` and `Loader.path` values will be prepended to them. + * These are created when you use the Phaser.Loader.LoaderPlugin#sceneFile method and are not typically created directly. * - * Note: The ability to load this type of file will only be available if the MultiScript File type has been built into Phaser. - * It is available in the default build but can be excluded from custom builds. - * @param key The key to use for this file, or a file configuration object, or array of them. - * @param url An array of absolute or relative URLs to load the script files from. They are processed in the order given in the array. - * @param extension The default file extension to use if no url is provided. Default 'js'. - * @param xhrSettings Extra XHR Settings specifically for these files. + * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#sceneFile. */ - scripts(key: string | Phaser.Types.Loader.FileTypes.MultiScriptFileConfig | Phaser.Types.Loader.FileTypes.MultiScriptFileConfig[], url?: string[], extension?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): Phaser.Loader.LoaderPlugin; + class SceneFile extends Phaser.Loader.File { + /** + * + * @param loader A reference to the Loader that is responsible for this file. + * @param key The key to use for this file, or a file configuration object. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.js`, i.e. if `key` was "alien" then the URL will be "alien.js". + * @param xhrSettings Extra XHR Settings specifically for this file. + */ + constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.SceneFileConfig, url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + + /** + * Called automatically by Loader.nextFile. + * This method controls what extra work this File does with its loaded data. + */ + onProcess(): void; + + /** + * Adds this file to its target cache upon successful loading and processing. + */ + addToCache(): void; + + } /** - * Adds a JSON File Pack, or array of packs, to the current load queue. - * - * You can call this method from within your Scene's `preload`, along with any other files you wish to load: + * A single Scene Plugin Script File suitable for loading by the Loader. * - * ```javascript - * function preload () - * { - * this.load.pack('level1', 'data/Level1Files.json'); - * } - * ``` + * These are created when you use the Phaser.Loader.LoaderPlugin#scenePlugin method and are not typically created directly. * - * A File Pack is a JSON file (or object) that contains details about other files that should be added into the Loader. - * Here is a small example: + * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#scenePlugin. + */ + class ScenePluginFile extends Phaser.Loader.File { + /** + * + * @param loader A reference to the Loader that is responsible for this file. + * @param key The key to use for this file, or a file configuration object. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.js`, i.e. if `key` was "alien" then the URL will be "alien.js". + * @param systemKey If this plugin is to be added to Scene.Systems, this is the property key for it. + * @param sceneKey If this plugin is to be added to the Scene, this is the property key for it. + * @param xhrSettings Extra XHR Settings specifically for this file. + */ + constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.ScenePluginFileConfig, url?: string, systemKey?: string, sceneKey?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + + /** + * Called automatically by Loader.nextFile. + * This method controls what extra work this File does with its loaded data. + */ + onProcess(): void; + + } + + /** + * A single Script File suitable for loading by the Loader. * - * ```json - * { - * "test1": { - * "files": [ - * { - * "type": "image", - * "key": "taikodrummaster", - * "url": "assets/pics/taikodrummaster.jpg" - * }, - * { - * "type": "image", - * "key": "sukasuka-chtholly", - * "url": "assets/pics/sukasuka-chtholly.png" - * } - * ] - * }, - * "meta": { - * "generated": "1401380327373", - * "app": "Phaser 3 Asset Packer", - * "url": "https://phaser.io", - * "version": "1.0", - * "copyright": "Photon Storm Ltd. 2018" - * } - * } - * ``` + * These are created when you use the Phaser.Loader.LoaderPlugin#script method and are not typically created directly. * - * The pack can be split into sections. In the example above you'll see a section called `test1. You can tell - * the `load.pack` method to parse only a particular section of a pack. The pack is stored in the JSON Cache, - * so you can pass it to the Loader to process additional sections as needed in your game, or you can just load - * them all at once without specifying anything. + * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#script. + */ + class ScriptFile extends Phaser.Loader.File { + /** + * + * @param loader A reference to the Loader that is responsible for this file. + * @param key The key to use for this file, or a file configuration object. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.js`, i.e. if `key` was "alien" then the URL will be "alien.js". + * @param xhrSettings Extra XHR Settings specifically for this file. + */ + constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.ScriptFileConfig, url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + + /** + * Called automatically by Loader.nextFile. + * This method controls what extra work this File does with its loaded data. + */ + onProcess(): void; + + } + + /** + * A single Sprite Sheet Image File suitable for loading by the Loader. * - * The pack file can contain an entry for any type of file that Phaser can load. The object structures exactly - * match that of the file type configs, and all properties available within the file type configs can be used - * in the pack file too. + * These are created when you use the Phaser.Loader.LoaderPlugin#spritesheet method and are not typically created directly. * - * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, - * or if it's already running, when the next free load slot becomes available. This happens automatically if you - * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued + * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#spritesheet. + */ + class SpriteSheetFile extends Phaser.Loader.File { + /** + * + * @param loader A reference to the Loader that is responsible for this file. + * @param key The key to use for this file, or a file configuration object. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". + * @param frameConfig The frame configuration object. + * @param xhrSettings Extra XHR Settings specifically for this file. + */ + constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.SpriteSheetFileConfig, url?: string | string[], frameConfig?: Phaser.Types.Loader.FileTypes.ImageFrameConfig, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + + /** + * Adds this file to its target cache upon successful loading and processing. + */ + addToCache(): void; + + } + + /** + * A single SVG File suitable for loading by the Loader. + * + * These are created when you use the Phaser.Loader.LoaderPlugin#svg method and are not typically created directly. + * + * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#svg. + */ + class SVGFile extends Phaser.Loader.File { + /** + * + * @param loader A reference to the Loader that is responsible for this file. + * @param key The key to use for this file, or a file configuration object. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.svg`, i.e. if `key` was "alien" then the URL will be "alien.svg". + * @param svgConfig The svg size configuration object. + * @param xhrSettings Extra XHR Settings specifically for this file. + */ + constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.SVGFileConfig, url?: string, svgConfig?: Phaser.Types.Loader.FileTypes.SVGSizeConfig, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + + /** + * Called automatically by Loader.nextFile. + * This method controls what extra work this File does with its loaded data. + */ + onProcess(): void; + + /** + * Adds this file to its target cache upon successful loading and processing. + */ + addToCache(): void; + + } + + /** + * A single Text File suitable for loading by the Loader. + * + * These are created when you use the Phaser.Loader.LoaderPlugin#text method and are not typically created directly. + * + * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#text. + */ + class TextFile extends Phaser.Loader.File { + /** + * + * @param loader A reference to the Loader that is responsible for this file. + * @param key The key to use for this file, or a file configuration object. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.txt`, i.e. if `key` was "alien" then the URL will be "alien.txt". + * @param xhrSettings Extra XHR Settings specifically for this file. + */ + constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.TextFileConfig, url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + + /** + * Called automatically by Loader.nextFile. + * This method controls what extra work this File does with its loaded data. + */ + onProcess(): void; + + } + + /** + * A single Tilemap CSV File suitable for loading by the Loader. + * + * These are created when you use the Phaser.Loader.LoaderPlugin#tilemapCSV method and are not typically created directly. + * + * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#tilemapCSV. + */ + class TilemapCSVFile extends Phaser.Loader.File { + /** + * + * @param loader A reference to the Loader that is responsible for this file. + * @param key The key to use for this file, or a file configuration object. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.csv`, i.e. if `key` was "alien" then the URL will be "alien.csv". + * @param xhrSettings Extra XHR Settings specifically for this file. + */ + constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.TilemapCSVFileConfig, url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + + /** + * Called automatically by Loader.nextFile. + * This method controls what extra work this File does with its loaded data. + */ + onProcess(): void; + + /** + * Adds this file to its target cache upon successful loading and processing. + */ + addToCache(): void; + + } + + /** + * A single Impact.js Tilemap JSON File suitable for loading by the Loader. + * + * These are created when you use the Phaser.Loader.LoaderPlugin#tilemapImpact method and are not typically created directly. + * + * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#tilemapImpact. + */ + class TilemapImpactFile extends Phaser.Loader.File { + /** + * + * @param loader A reference to the Loader that is responsible for this file. + * @param key The key to use for this file, or a file configuration object. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". + * @param xhrSettings Extra XHR Settings specifically for this file. + */ + constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.TilemapImpactFileConfig, url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + + /** + * Adds this file to its target cache upon successful loading and processing. + */ + addToCache(): void; + + } + + /** + * A single Tiled Tilemap JSON File suitable for loading by the Loader. + * + * These are created when you use the Phaser.Loader.LoaderPlugin#tilemapTiledJSON method and are not typically created directly. + * + * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#tilemapTiledJSON. + */ + class TilemapJSONFile extends Phaser.Loader.File { + /** + * + * @param loader A reference to the Loader that is responsible for this file. + * @param key The key to use for this file, or a file configuration object. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". Or, a well formed JSON object. + * @param xhrSettings Extra XHR Settings specifically for this file. + */ + constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.TilemapJSONFileConfig, url?: object | string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + + /** + * Adds this file to its target cache upon successful loading and processing. + */ + addToCache(): void; + + } + + /** + * A single text file based Unity Texture Atlas File suitable for loading by the Loader. + * + * These are created when you use the Phaser.Loader.LoaderPlugin#unityAtlas method and are not typically created directly. + * + * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#unityAtlas. + */ + class UnityAtlasFile extends Phaser.Loader.MultiFile { + /** + * + * @param loader A reference to the Loader that is responsible for this file. + * @param key The key to use for this file, or a file configuration object. + * @param textureURL The absolute or relative URL to load the texture image file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". + * @param atlasURL The absolute or relative URL to load the texture atlas data file from. If undefined or `null` it will be set to `.txt`, i.e. if `key` was "alien" then the URL will be "alien.txt". + * @param textureXhrSettings An XHR Settings configuration object for the atlas image file. Used in replacement of the Loaders default XHR Settings. + * @param atlasXhrSettings An XHR Settings configuration object for the atlas data file. Used in replacement of the Loaders default XHR Settings. + */ + constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.UnityAtlasFileConfig, textureURL?: string | string[], atlasURL?: string, textureXhrSettings?: Phaser.Types.Loader.XHRSettingsObject, atlasXhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + + /** + * Adds this file to its target cache upon successful loading and processing. + */ + addToCache(): void; + + } + + /** + * A single Video File suitable for loading by the Loader. + * + * These are created when you use the Phaser.Loader.LoaderPlugin#video method and are not typically created directly. + * + * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#video. + */ + class VideoFile extends Phaser.Loader.File { + /** + * + * @param loader A reference to the Loader that is responsible for this file. + * @param key The key to use for this file, or a file configuration object. + * @param urlConfig The absolute or relative URL to load this file from in a config object. + * @param loadEvent The load event to listen for when _not_ loading as a blob. Either 'loadeddata', 'canplay' or 'canplaythrough'. + * @param asBlob Load the video as a data blob, or via the Video element? + * @param noAudio Does the video have an audio track? If not you can enable auto-playing on it. + * @param xhrSettings Extra XHR Settings specifically for this file. + */ + constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.VideoFileConfig, urlConfig?: any, loadEvent?: string, asBlob?: boolean, noAudio?: boolean, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + + /** + * Called automatically by Loader.nextFile. + * This method controls what extra work this File does with its loaded data. + */ + onProcess(): void; + + /** + * Called by the Loader, starts the actual file downloading. + * During the load the methods onLoad, onError and onProgress are called, based on the XHR events. + * You shouldn't normally call this method directly, it's meant to be invoked by the Loader. + */ + load(): void; + + } + + /** + * A single XML File suitable for loading by the Loader. + * + * These are created when you use the Phaser.Loader.LoaderPlugin#xml method and are not typically created directly. + * + * For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#xml. + */ + class XMLFile extends Phaser.Loader.File { + /** + * + * @param loader A reference to the Loader that is responsible for this file. + * @param key The key to use for this file, or a file configuration object. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.xml`, i.e. if `key` was "alien" then the URL will be "alien.xml". + * @param xhrSettings Extra XHR Settings specifically for this file. + */ + constructor(loader: Phaser.Loader.LoaderPlugin, key: string | Phaser.Types.Loader.FileTypes.XMLFileConfig, url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject); + + /** + * Called automatically by Loader.nextFile. + * This method controls what extra work this File does with its loaded data. + */ + onProcess(): void; + + } + + } + + namespace FileTypesManager { + /** + * Static method called when a LoaderPlugin is created. + * + * Loops through the local types object and injects all of them as + * properties into the LoaderPlugin instance. + * @param loader The LoaderPlugin to install the types into. + */ + function install(loader: Phaser.Loader.LoaderPlugin): void; + + /** + * Static method called directly by the File Types. + * + * The key is a reference to the function used to load the files via the Loader, i.e. `image`. + * @param key The key that will be used as the method name in the LoaderPlugin. + * @param factoryFunction The function that will be called when LoaderPlugin.key is invoked. + */ + function register(key: string, factoryFunction: Function): void; + + /** + * Removed all associated file types. + */ + function destroy(): void; + + } + + /** + * Given a File and a baseURL value this returns the URL the File will use to download from. + * @param file The File object. + * @param baseURL A default base URL. + */ + function GetURL(file: Phaser.Loader.File, baseURL: string): string; + + /** + * The Loader handles loading all external content such as Images, Sounds, Texture Atlases and data files. + * You typically interact with it via `this.load` in your Scene. Scenes can have a `preload` method, which is always + * called before the Scenes `create` method, allowing you to preload assets that the Scene may need. + * + * If you call any `this.load` methods from outside of `Scene.preload` then you need to start the Loader going + * yourself by calling `Loader.start()`. It's only automatically started during the Scene preload. + * + * The Loader uses a combination of tag loading (eg. Audio elements) and XHR and provides progress and completion events. + * Files are loaded in parallel by default. The amount of concurrent connections can be controlled in your Game Configuration. + * + * Once the Loader has started loading you are still able to add files to it. These can be injected as a result of a loader + * event, the type of file being loaded (such as a pack file) or other external events. As long as the Loader hasn't finished + * simply adding a new file to it, while running, will ensure it's added into the current queue. + * + * Every Scene has its own instance of the Loader and they are bound to the Scene in which they are created. However, + * assets loaded by the Loader are placed into global game-level caches. For example, loading an XML file will place that + * file inside `Game.cache.xml`, which is accessible from every Scene in your game, no matter who was responsible + * for loading it. The same is true of Textures. A texture loaded in one Scene is instantly available to all other Scenes + * in your game. + * + * The Loader works by using custom File Types. These are stored in the FileTypesManager, which injects them into the Loader + * when it's instantiated. You can create your own custom file types by extending either the File or MultiFile classes. + * See those files for more details. + */ + class LoaderPlugin extends Phaser.Events.EventEmitter { + /** + * + * @param scene The Scene which owns this Loader instance. + */ + constructor(scene: Phaser.Scene); + + /** + * Adds an Animation JSON Data file, or array of Animation JSON files, to the current load queue. + * + * You can call this method from within your Scene's `preload`, along with any other files you wish to load: + * + * ```javascript + * function preload () + * { + * this.load.animation('baddieAnims', 'files/BaddieAnims.json'); + * } + * ``` + * + * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, + * or if it's already running, when the next free load slot becomes available. This happens automatically if you + * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been @@ -47256,13 +53639,29 @@ declare namespace Phaser { * Instead of passing arguments you can pass a configuration object, such as: * * ```javascript - * this.load.pack({ - * key: 'level1', - * url: 'data/Level1Files.json' + * this.load.animation({ + * key: 'baddieAnims', + * url: 'files/BaddieAnims.json' * }); * ``` * - * See the documentation for `Phaser.Types.Loader.FileTypes.PackFileConfig` for more details. + * See the documentation for `Phaser.Types.Loader.FileTypes.JSONFileConfig` for more details. + * + * Once the file has finished loading it will automatically be passed to the global Animation Managers `fromJSON` method. + * This will parse all of the JSON data and create animation data from it. This process happens at the very end + * of the Loader, once every other file in the load queue has finished. The reason for this is to allow you to load + * both animation data and the images it relies upon in the same load call. + * + * Once the animation data has been parsed you will be able to play animations using that data. + * Please see the Animation Manager `fromJSON` method for more details about the format and playback. + * + * You can also access the raw animation data from its Cache using its key: + * + * ```javascript + * this.load.animation('baddieAnims', 'files/BaddieAnims.json'); + * // and later in your game ... + * var data = this.cache.json.get('baddieAnims'); + * ``` * * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files * key. For example, if the prefix was `LEVEL1.` and the key was `Waves` the final key will be `LEVEL1.Waves` and @@ -47290,26 +53689,30 @@ declare namespace Phaser { * } * ``` * - * And you only wanted to store the `boss` data in the Cache, then you could pass `level1.baddies.boss`as the `dataKey`. + * And if you only wanted to create animations from the `boss` data, then you could pass `level1.baddies.boss`as the `dataKey`. * - * Note: The ability to load this type of file will only be available if the Pack File type has been built into Phaser. + * Note: The ability to load this type of file will only be available if the JSON File type has been built into Phaser. * It is available in the default build but can be excluded from custom builds. * @param key The key to use for this file, or a file configuration object, or array of them. * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". - * @param dataKey When the JSON file loads only this property will be stored in the Cache. + * @param dataKey When the Animation JSON file loads only this property will be stored in the Cache and used to create animation data. * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. */ - pack(key: string | Phaser.Types.Loader.FileTypes.PackFileConfig | Phaser.Types.Loader.FileTypes.PackFileConfig[], url?: string, dataKey?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): Phaser.Loader.LoaderPlugin; + animation(key: string | Phaser.Types.Loader.FileTypes.JSONFileConfig | Phaser.Types.Loader.FileTypes.JSONFileConfig[], url?: string, dataKey?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): this; /** - * Adds a Plugin Script file, or array of plugin files, to the current load queue. + * Aseprite is a powerful animated sprite editor and pixel art tool. + * + * You can find more details at https://www.aseprite.org/ + * + * Adds a JSON based Aseprite Animation, or array of animations, to the current load queue. * * You can call this method from within your Scene's `preload`, along with any other files you wish to load: * * ```javascript * function preload () * { - * this.load.plugin('modplayer', 'plugins/ModPlayer.js'); + * this.load.aseprite('gladiator', 'images/Gladiator.png', 'images/Gladiator.json'); * } * ``` * @@ -47321,49 +53724,112 @@ declare namespace Phaser { * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been * loaded. * - * The key must be a unique String and not already in-use by another file in the Loader. + * If you call this from outside of `preload` then you are responsible for starting the Loader afterwards and monitoring + * its events to know when it's safe to use the asset. Please see the Phaser.Loader.LoaderPlugin class for more details. + * + * To export a compatible JSON file in Aseprite, please do the following: + * + * 1. Go to "File - Export Sprite Sheet" + * + * 2. On the **Layout** tab: + * 2a. Set the "Sheet type" to "Packed" + * 2b. Set the "Constraints" to "None" + * 2c. Check the "Merge Duplicates" checkbox + * + * 3. On the **Sprite** tab: + * 3a. Set "Layers" to "Visible layers" + * 3b. Set "Frames" to "All frames", unless you only wish to export a sub-set of tags + * + * 4. On the **Borders** tab: + * 4a. Check the "Trim Sprite" and "Trim Cells" options + * 4b. Ensure "Border Padding", "Spacing" and "Inner Padding" are all > 0 (1 is usually enough) + * + * 5. On the **Output** tab: + * 5a. Check "Output File", give your image a name and make sure you choose "png files" as the file type + * 5b. Check "JSON Data" and give your json file a name + * 5c. The JSON Data type can be either a Hash or Array, Phaser doesn't mind. + * 5d. Make sure "Tags" is checked in the Meta options + * 5e. In the "Item Filename" input box, make sure it says just "{frame}" and nothing more. + * + * 6. Click export + * + * This was tested with Aseprite 1.2.25. + * + * This will export a png and json file which you can load using the Aseprite Loader, i.e.: + * + * Phaser can load all common image types: png, jpg, gif and any other format the browser can natively handle. + * + * The key must be a unique String. It is used to add the file to the global Texture Manager upon a successful load. + * The key should be unique both in terms of files being loaded and files already present in the Texture Manager. + * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file + * then remove it from the Texture Manager first, before loading a new one. * * Instead of passing arguments you can pass a configuration object, such as: * * ```javascript - * this.load.plugin({ - * key: 'modplayer', - * url: 'plugins/ModPlayer.js' + * this.load.aseprite({ + * key: 'gladiator', + * textureURL: 'images/Gladiator.png', + * atlasURL: 'images/Gladiator.json' * }); * ``` * - * See the documentation for `Phaser.Types.Loader.FileTypes.PluginFileConfig` for more details. + * See the documentation for `Phaser.Types.Loader.FileTypes.AsepriteFileConfig` for more details. * - * Once the file has finished loading it will automatically be converted into a script element - * via `document.createElement('script')`. It will have its language set to JavaScript, `defer` set to - * false and then the resulting element will be appended to `document.head`. Any code then in the - * script will be executed. It will then be passed to the Phaser PluginCache.register method. + * Instead of passing a URL for the JSON data you can also pass in a well formed JSON object instead. + * + * Once loaded, you can call this method from within a Scene with the 'atlas' key: + * + * ```javascript + * this.anims.createFromAseprite('paladin'); + * ``` + * + * Any animations defined in the JSON will now be available to use in Phaser and you play them + * via their Tag name. For example, if you have an animation called 'War Cry' on your Aseprite timeline, + * you can play it in Phaser using that Tag name: + * + * ```javascript + * this.add.sprite(400, 300).play('War Cry'); + * ``` + * + * When calling this method you can optionally provide an array of tag names, and only those animations + * will be created. For example: + * + * ```javascript + * this.anims.createFromAseprite('paladin', [ 'step', 'War Cry', 'Magnum Break' ]); + * ``` + * + * This will only create the 3 animations defined. Note that the tag names are case-sensitive. + * + * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files + * key. For example, if the prefix was `MENU.` and the key was `Background` the final key will be `MENU.Background` and + * this is what you would use to retrieve the image from the Texture Manager. * * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. * * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "alien" - * and no URL is given then the Loader will set the URL to be "alien.js". It will always add `.js` as the extension, although + * and no URL is given then the Loader will set the URL to be "alien.png". It will always add `.png` as the extension, although * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. * - * Note: The ability to load this type of file will only be available if the Plugin File type has been built into Phaser. + * Note: The ability to load this type of file will only be available if the Aseprite File type has been built into Phaser. * It is available in the default build but can be excluded from custom builds. * @param key The key to use for this file, or a file configuration object, or array of them. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.js`, i.e. if `key` was "alien" then the URL will be "alien.js". Or, a plugin function. - * @param start Automatically start the plugin after loading? - * @param mapping If this plugin is to be injected into the Scene, this is the property key used. - * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. + * @param textureURL The absolute or relative URL to load the texture image file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". + * @param atlasURL The absolute or relative URL to load the texture atlas json data file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". Or, a well formed JSON object. + * @param textureXhrSettings An XHR Settings configuration object for the atlas image file. Used in replacement of the Loaders default XHR Settings. + * @param atlasXhrSettings An XHR Settings configuration object for the atlas json file. Used in replacement of the Loaders default XHR Settings. */ - plugin(key: string | Phaser.Types.Loader.FileTypes.PluginFileConfig | Phaser.Types.Loader.FileTypes.PluginFileConfig[], url?: string | Function, start?: boolean, mapping?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): Phaser.Loader.LoaderPlugin; + aseprite(key: string | Phaser.Types.Loader.FileTypes.AsepriteFileConfig | Phaser.Types.Loader.FileTypes.AsepriteFileConfig[], textureURL?: string | string[], atlasURL?: object | string, textureXhrSettings?: Phaser.Types.Loader.XHRSettingsObject, atlasXhrSettings?: Phaser.Types.Loader.XHRSettingsObject): this; /** - * Adds an external Scene file, or array of Scene files, to the current load queue. + * Adds a JSON based Texture Atlas, or array of atlases, to the current load queue. * * You can call this method from within your Scene's `preload`, along with any other files you wish to load: * * ```javascript * function preload () * { - * this.load.sceneFile('Level1', 'src/Level1.js'); + * this.load.atlas('mainmenu', 'images/MainMenu.png', 'images/MainMenu.json'); * } * ``` * @@ -47375,85 +53841,95 @@ declare namespace Phaser { * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been * loaded. * - * The key must be a unique String. It is used to add the file to the global Scene Manager upon a successful load. - * - * For a Scene File it's vitally important that the key matches the class name in the JavaScript file. - * - * For example here is the source file: - * - * ```javascript - * class ExternalScene extends Phaser.Scene { - * - * constructor () - * { - * super('myScene'); - * } - * - * } - * ``` - * - * Because the class is called `ExternalScene` that is the exact same key you must use when loading it: + * If you call this from outside of `preload` then you are responsible for starting the Loader afterwards and monitoring + * its events to know when it's safe to use the asset. Please see the Phaser.Loader.LoaderPlugin class for more details. * - * ```javascript - * function preload () - * { - * this.load.sceneFile('ExternalScene', 'src/yourScene.js'); - * } - * ``` + * Phaser expects the atlas data to be provided in a JSON file, using either the JSON Hash or JSON Array format. + * These files are created by software such as Texture Packer, Shoebox and Adobe Flash / Animate. + * If you are using Texture Packer and have enabled multi-atlas support, then please use the Phaser Multi Atlas loader + * instead of this one. * - * The key that is used within the Scene Manager can either be set to the same, or you can override it in the Scene - * constructor, as we've done in the example above, where the Scene key was changed to `myScene`. + * Phaser can load all common image types: png, jpg, gif and any other format the browser can natively handle. * - * The key should be unique both in terms of files being loaded and Scenes already present in the Scene Manager. + * The key must be a unique String. It is used to add the file to the global Texture Manager upon a successful load. + * The key should be unique both in terms of files being loaded and files already present in the Texture Manager. * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file - * then remove it from the Scene Manager first, before loading a new one. + * then remove it from the Texture Manager first, before loading a new one. * * Instead of passing arguments you can pass a configuration object, such as: * * ```javascript - * this.load.sceneFile({ - * key: 'Level1', - * url: 'src/Level1.js' + * this.load.atlas({ + * key: 'mainmenu', + * textureURL: 'images/MainMenu.png', + * atlasURL: 'images/MainMenu.json' * }); * ``` * - * See the documentation for `Phaser.Types.Loader.FileTypes.SceneFileConfig` for more details. + * See the documentation for `Phaser.Types.Loader.FileTypes.AtlasJSONFileConfig` for more details. * - * Once the file has finished loading it will be added to the Scene Manager. + * Instead of passing a URL for the atlas JSON data you can also pass in a well formed JSON object instead. + * + * Once the atlas has finished loading you can use frames from it as textures for a Game Object by referencing its key: * * ```javascript - * this.load.sceneFile('Level1', 'src/Level1.js'); + * this.load.atlas('mainmenu', 'images/MainMenu.png', 'images/MainMenu.json'); * // and later in your game ... - * this.scene.start('Level1'); + * this.add.image(x, y, 'mainmenu', 'background'); * ``` * + * To get a list of all available frames within an atlas please consult your Texture Atlas software. + * * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files - * key. For example, if the prefix was `WORLD1.` and the key was `Story` the final key will be `WORLD1.Story` and - * this is what you would use to retrieve the text from the Scene Manager. + * key. For example, if the prefix was `MENU.` and the key was `Background` the final key will be `MENU.Background` and + * this is what you would use to retrieve the image from the Texture Manager. * * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. * - * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "story" - * and no URL is given then the Loader will set the URL to be "story.js". It will always add `.js` as the extension, although + * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "alien" + * and no URL is given then the Loader will set the URL to be "alien.png". It will always add `.png` as the extension, although * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. * - * Note: The ability to load this type of file will only be available if the Scene File type has been built into Phaser. + * Phaser also supports the automatic loading of associated normal maps. If you have a normal map to go with this image, + * then you can specify it by providing an array as the `url` where the second element is the normal map: + * + * ```javascript + * this.load.atlas('mainmenu', [ 'images/MainMenu.png', 'images/MainMenu-n.png' ], 'images/MainMenu.json'); + * ``` + * + * Or, if you are using a config object use the `normalMap` property: + * + * ```javascript + * this.load.atlas({ + * key: 'mainmenu', + * textureURL: 'images/MainMenu.png', + * normalMap: 'images/MainMenu-n.png', + * atlasURL: 'images/MainMenu.json' + * }); + * ``` + * + * The normal map file is subject to the same conditions as the image file with regard to the path, baseURL, CORs and XHR Settings. + * Normal maps are a WebGL only feature. + * + * Note: The ability to load this type of file will only be available if the Atlas JSON File type has been built into Phaser. * It is available in the default build but can be excluded from custom builds. * @param key The key to use for this file, or a file configuration object, or array of them. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.js`, i.e. if `key` was "alien" then the URL will be "alien.js". - * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. + * @param textureURL The absolute or relative URL to load the texture image file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". + * @param atlasURL The absolute or relative URL to load the texture atlas json data file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". Or, a well formed JSON object. + * @param textureXhrSettings An XHR Settings configuration object for the atlas image file. Used in replacement of the Loaders default XHR Settings. + * @param atlasXhrSettings An XHR Settings configuration object for the atlas json file. Used in replacement of the Loaders default XHR Settings. */ - sceneFile(key: string | Phaser.Types.Loader.FileTypes.SceneFileConfig | Phaser.Types.Loader.FileTypes.SceneFileConfig[], url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): Phaser.Loader.LoaderPlugin; + atlas(key: string | Phaser.Types.Loader.FileTypes.AtlasJSONFileConfig | Phaser.Types.Loader.FileTypes.AtlasJSONFileConfig[], textureURL?: string | string[], atlasURL?: object | string, textureXhrSettings?: Phaser.Types.Loader.XHRSettingsObject, atlasXhrSettings?: Phaser.Types.Loader.XHRSettingsObject): this; /** - * Adds a Scene Plugin Script file, or array of plugin files, to the current load queue. + * Adds an XML based Texture Atlas, or array of atlases, to the current load queue. * * You can call this method from within your Scene's `preload`, along with any other files you wish to load: * * ```javascript * function preload () * { - * this.load.scenePlugin('ModPlayer', 'plugins/ModPlayer.js', 'modPlayer', 'mods'); + * this.load.atlasXML('mainmenu', 'images/MainMenu.png', 'images/MainMenu.xml'); * } * ``` * @@ -47465,49 +53941,91 @@ declare namespace Phaser { * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been * loaded. * - * The key must be a unique String and not already in-use by another file in the Loader. + * If you call this from outside of `preload` then you are responsible for starting the Loader afterwards and monitoring + * its events to know when it's safe to use the asset. Please see the Phaser.Loader.LoaderPlugin class for more details. + * + * Phaser expects the atlas data to be provided in an XML file format. + * These files are created by software such as Shoebox and Adobe Flash / Animate. + * + * Phaser can load all common image types: png, jpg, gif and any other format the browser can natively handle. + * + * The key must be a unique String. It is used to add the file to the global Texture Manager upon a successful load. + * The key should be unique both in terms of files being loaded and files already present in the Texture Manager. + * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file + * then remove it from the Texture Manager first, before loading a new one. * * Instead of passing arguments you can pass a configuration object, such as: * * ```javascript - * this.load.scenePlugin({ - * key: 'modplayer', - * url: 'plugins/ModPlayer.js' + * this.load.atlasXML({ + * key: 'mainmenu', + * textureURL: 'images/MainMenu.png', + * atlasURL: 'images/MainMenu.xml' * }); * ``` * - * See the documentation for `Phaser.Types.Loader.FileTypes.ScenePluginFileConfig` for more details. + * See the documentation for `Phaser.Types.Loader.FileTypes.AtlasXMLFileConfig` for more details. * - * Once the file has finished loading it will automatically be converted into a script element - * via `document.createElement('script')`. It will have its language set to JavaScript, `defer` set to - * false and then the resulting element will be appended to `document.head`. Any code then in the - * script will be executed. It will then be passed to the Phaser PluginCache.register method. + * Once the atlas has finished loading you can use frames from it as textures for a Game Object by referencing its key: + * + * ```javascript + * this.load.atlasXML('mainmenu', 'images/MainMenu.png', 'images/MainMenu.xml'); + * // and later in your game ... + * this.add.image(x, y, 'mainmenu', 'background'); + * ``` + * + * To get a list of all available frames within an atlas please consult your Texture Atlas software. + * + * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files + * key. For example, if the prefix was `MENU.` and the key was `Background` the final key will be `MENU.Background` and + * this is what you would use to retrieve the image from the Texture Manager. * * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. * * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "alien" - * and no URL is given then the Loader will set the URL to be "alien.js". It will always add `.js` as the extension, although + * and no URL is given then the Loader will set the URL to be "alien.png". It will always add `.png` as the extension, although * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. * - * Note: The ability to load this type of file will only be available if the Script File type has been built into Phaser. + * Phaser also supports the automatic loading of associated normal maps. If you have a normal map to go with this image, + * then you can specify it by providing an array as the `url` where the second element is the normal map: + * + * ```javascript + * this.load.atlasXML('mainmenu', [ 'images/MainMenu.png', 'images/MainMenu-n.png' ], 'images/MainMenu.xml'); + * ``` + * + * Or, if you are using a config object use the `normalMap` property: + * + * ```javascript + * this.load.atlasXML({ + * key: 'mainmenu', + * textureURL: 'images/MainMenu.png', + * normalMap: 'images/MainMenu-n.png', + * atlasURL: 'images/MainMenu.xml' + * }); + * ``` + * + * The normal map file is subject to the same conditions as the image file with regard to the path, baseURL, CORs and XHR Settings. + * Normal maps are a WebGL only feature. + * + * Note: The ability to load this type of file will only be available if the Atlas XML File type has been built into Phaser. * It is available in the default build but can be excluded from custom builds. * @param key The key to use for this file, or a file configuration object, or array of them. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.js`, i.e. if `key` was "alien" then the URL will be "alien.js". Or, set to a plugin function. - * @param systemKey If this plugin is to be added to Scene.Systems, this is the property key for it. - * @param sceneKey If this plugin is to be added to the Scene, this is the property key for it. - * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. + * @param textureURL The absolute or relative URL to load the texture image file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". + * @param atlasURL The absolute or relative URL to load the texture atlas xml data file from. If undefined or `null` it will be set to `.xml`, i.e. if `key` was "alien" then the URL will be "alien.xml". + * @param textureXhrSettings An XHR Settings configuration object for the atlas image file. Used in replacement of the Loaders default XHR Settings. + * @param atlasXhrSettings An XHR Settings configuration object for the atlas xml file. Used in replacement of the Loaders default XHR Settings. */ - scenePlugin(key: string | Phaser.Types.Loader.FileTypes.ScenePluginFileConfig | Phaser.Types.Loader.FileTypes.ScenePluginFileConfig[], url?: string | Function, systemKey?: string, sceneKey?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): Phaser.Loader.LoaderPlugin; + atlasXML(key: string | Phaser.Types.Loader.FileTypes.AtlasXMLFileConfig | Phaser.Types.Loader.FileTypes.AtlasXMLFileConfig[], textureURL?: string | string[], atlasURL?: string, textureXhrSettings?: Phaser.Types.Loader.XHRSettingsObject, atlasXhrSettings?: Phaser.Types.Loader.XHRSettingsObject): this; /** - * Adds a Script file, or array of Script files, to the current load queue. + * Adds an Audio or HTML5Audio file, or array of audio files, to the current load queue. * * You can call this method from within your Scene's `preload`, along with any other files you wish to load: * * ```javascript * function preload () * { - * this.load.script('aliens', 'lib/aliens.js'); + * this.load.audio('title', [ 'music/Title.ogg', 'music/Title.mp3', 'music/Title.m4a' ]); * } * ``` * @@ -47519,53 +54037,65 @@ declare namespace Phaser { * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been * loaded. * - * The key must be a unique String and not already in-use by another file in the Loader. + * The key must be a unique String. It is used to add the file to the global Audio Cache upon a successful load. + * The key should be unique both in terms of files being loaded and files already present in the Audio Cache. + * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file + * then remove it from the Audio Cache first, before loading a new one. * * Instead of passing arguments you can pass a configuration object, such as: * * ```javascript - * this.load.script({ - * key: 'aliens', - * url: 'lib/aliens.js' + * this.load.audio({ + * key: 'title', + * url: [ 'music/Title.ogg', 'music/Title.mp3', 'music/Title.m4a' ] * }); * ``` * - * See the documentation for `Phaser.Types.Loader.FileTypes.ScriptFileConfig` for more details. + * See the documentation for `Phaser.Types.Loader.FileTypes.AudioFileConfig` for more details. * - * Once the file has finished loading it will automatically be converted into a script element - * via `document.createElement('script')`. It will have its language set to JavaScript, `defer` set to - * false and then the resulting element will be appended to `document.head`. Any code then in the - * script will be executed. + * The URLs can be relative or absolute. If the URLs are relative the `Loader.baseURL` and `Loader.path` values will be prepended to them. * - * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. + * Due to different browsers supporting different audio file types you should usually provide your audio files in a variety of formats. + * ogg, mp3 and m4a are the most common. If you provide an array of URLs then the Loader will determine which _one_ file to load based on + * browser support. * - * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "alien" - * and no URL is given then the Loader will set the URL to be "alien.js". It will always add `.js` as the extension, although - * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. + * If audio has been disabled in your game, either via the game config, or lack of support from the device, then no audio will be loaded. * - * Note: The ability to load this type of file will only be available if the Script File type has been built into Phaser. + * Note: The ability to load this type of file will only be available if the Audio File type has been built into Phaser. * It is available in the default build but can be excluded from custom builds. * @param key The key to use for this file, or a file configuration object, or array of them. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.js`, i.e. if `key` was "alien" then the URL will be "alien.js". + * @param urls The absolute or relative URL to load the audio files from. + * @param config An object containing an `instances` property for HTML5Audio. Defaults to 1. * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. */ - script(key: string | Phaser.Types.Loader.FileTypes.ScriptFileConfig | Phaser.Types.Loader.FileTypes.ScriptFileConfig[], url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): Phaser.Loader.LoaderPlugin; + audio(key: string | Phaser.Types.Loader.FileTypes.AudioFileConfig | Phaser.Types.Loader.FileTypes.AudioFileConfig[], urls?: string | string[], config?: any, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): this; /** - * Adds a Sprite Sheet Image, or array of Sprite Sheet Images, to the current load queue. - * - * The term 'Sprite Sheet' in Phaser means a fixed-size sheet. Where every frame in the sheet is the exact same size, - * and you reference those frames using numbers, not frame names. This is not the same thing as a Texture Atlas, where - * the frames are packed in a way where they take up the least amount of space, and are referenced by their names, - * not numbers. Some articles and software use the term 'Sprite Sheet' to mean Texture Atlas, so please be aware of - * what sort of file you're actually trying to load. + * Adds a JSON based Audio Sprite, or array of audio sprites, to the current load queue. * * You can call this method from within your Scene's `preload`, along with any other files you wish to load: * * ```javascript * function preload () * { - * this.load.spritesheet('bot', 'images/robot.png', { frameWidth: 32, frameHeight: 38 }); + * this.load.audioSprite('kyobi', 'kyobi.json', [ + * 'kyobi.ogg', + * 'kyobi.mp3', + * 'kyobi.m4a' + * ]); + * } + * ``` + * + * Audio Sprites are a combination of audio files and a JSON configuration. + * The JSON follows the format of that created by https://github.com/tonistiigi/audiosprite + * + * If the JSON file includes a 'resource' object then you can let Phaser parse it and load the audio + * files automatically based on its content. To do this exclude the audio URLs from the load: + * + * ```javascript + * function preload () + * { + * this.load.audioSprite('kyobi', 'kyobi.json'); * } * ``` * @@ -47577,93 +54107,73 @@ declare namespace Phaser { * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been * loaded. * - * Phaser can load all common image types: png, jpg, gif and any other format the browser can natively handle. - * If you try to load an animated gif only the first frame will be rendered. Browsers do not natively support playback - * of animated gifs to Canvas elements. + * If you call this from outside of `preload` then you are responsible for starting the Loader afterwards and monitoring + * its events to know when it's safe to use the asset. Please see the Phaser.Loader.LoaderPlugin class for more details. * - * The key must be a unique String. It is used to add the file to the global Texture Manager upon a successful load. - * The key should be unique both in terms of files being loaded and files already present in the Texture Manager. + * The key must be a unique String. It is used to add the file to the global Audio Cache upon a successful load. + * The key should be unique both in terms of files being loaded and files already present in the Audio Cache. * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file - * then remove it from the Texture Manager first, before loading a new one. + * then remove it from the Audio Cache first, before loading a new one. * * Instead of passing arguments you can pass a configuration object, such as: * * ```javascript - * this.load.spritesheet({ - * key: 'bot', - * url: 'images/robot.png', - * frameConfig: { - * frameWidth: 32, - * frameHeight: 38, - * startFrame: 0, - * endFrame: 8 - * } + * this.load.audioSprite({ + * key: 'kyobi', + * jsonURL: 'audio/Kyobi.json', + * audioURL: [ + * 'audio/Kyobi.ogg', + * 'audio/Kyobi.mp3', + * 'audio/Kyobi.m4a' + * ] * }); * ``` * - * See the documentation for `Phaser.Types.Loader.FileTypes.SpriteSheetFileConfig` for more details. + * See the documentation for `Phaser.Types.Loader.FileTypes.AudioSpriteFileConfig` for more details. * - * Once the file has finished loading you can use it as a texture for a Game Object by referencing its key: + * Instead of passing a URL for the audio JSON data you can also pass in a well formed JSON object instead. + * + * Once the audio has finished loading you can use it create an Audio Sprite by referencing its key: * * ```javascript - * this.load.spritesheet('bot', 'images/robot.png', { frameWidth: 32, frameHeight: 38 }); + * this.load.audioSprite('kyobi', 'kyobi.json'); * // and later in your game ... - * this.add.image(x, y, 'bot', 0); + * var music = this.sound.addAudioSprite('kyobi'); + * music.play('title'); * ``` * * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files - * key. For example, if the prefix was `PLAYER.` and the key was `Running` the final key will be `PLAYER.Running` and + * key. For example, if the prefix was `MENU.` and the key was `Background` the final key will be `MENU.Background` and * this is what you would use to retrieve the image from the Texture Manager. * * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. * - * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "alien" - * and no URL is given then the Loader will set the URL to be "alien.png". It will always add `.png` as the extension, although - * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. - * - * Phaser also supports the automatic loading of associated normal maps. If you have a normal map to go with this image, - * then you can specify it by providing an array as the `url` where the second element is the normal map: - * - * ```javascript - * this.load.spritesheet('logo', [ 'images/AtariLogo.png', 'images/AtariLogo-n.png' ], { frameWidth: 256, frameHeight: 80 }); - * ``` - * - * Or, if you are using a config object use the `normalMap` property: - * - * ```javascript - * this.load.spritesheet({ - * key: 'logo', - * url: 'images/AtariLogo.png', - * normalMap: 'images/AtariLogo-n.png', - * frameConfig: { - * frameWidth: 256, - * frameHeight: 80 - * } - * }); - * ``` + * Due to different browsers supporting different audio file types you should usually provide your audio files in a variety of formats. + * ogg, mp3 and m4a are the most common. If you provide an array of URLs then the Loader will determine which _one_ file to load based on + * browser support. * - * The normal map file is subject to the same conditions as the image file with regard to the path, baseURL, CORs and XHR Settings. - * Normal maps are a WebGL only feature. + * If audio has been disabled in your game, either via the game config, or lack of support from the device, then no audio will be loaded. * - * Note: The ability to load this type of file will only be available if the Sprite Sheet File type has been built into Phaser. + * Note: The ability to load this type of file will only be available if the Audio Sprite File type has been built into Phaser. * It is available in the default build but can be excluded from custom builds. - * @param key The key to use for this file, or a file configuration object, or array of them. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". - * @param frameConfig The frame configuration object. At a minimum it should have a `frameWidth` property. - * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. + * @param key The key to use for this file, or a file configuration object, or an array of objects. + * @param jsonURL The absolute or relative URL to load the json file from. Or a well formed JSON object to use instead. + * @param audioURL The absolute or relative URL to load the audio file from. If empty it will be obtained by parsing the JSON file. + * @param audioConfig The audio configuration options. + * @param audioXhrSettings An XHR Settings configuration object for the audio file. Used in replacement of the Loaders default XHR Settings. + * @param jsonXhrSettings An XHR Settings configuration object for the json file. Used in replacement of the Loaders default XHR Settings. */ - spritesheet(key: string | Phaser.Types.Loader.FileTypes.SpriteSheetFileConfig | Phaser.Types.Loader.FileTypes.SpriteSheetFileConfig[], url?: string, frameConfig?: Phaser.Types.Loader.FileTypes.ImageFrameConfig, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): Phaser.Loader.LoaderPlugin; + audioSprite(key: string | Phaser.Types.Loader.FileTypes.AudioSpriteFileConfig | Phaser.Types.Loader.FileTypes.AudioSpriteFileConfig[], jsonURL: string, audioURL?: string | string[], audioConfig?: any, audioXhrSettings?: Phaser.Types.Loader.XHRSettingsObject, jsonXhrSettings?: Phaser.Types.Loader.XHRSettingsObject): this; /** - * Adds an SVG File, or array of SVG Files, to the current load queue. When the files are loaded they - * will be rendered to bitmap textures and stored in the Texture Manager. + * Adds a Binary file, or array of Binary files, to the current load queue. * * You can call this method from within your Scene's `preload`, along with any other files you wish to load: * * ```javascript * function preload () * { - * this.load.svg('morty', 'images/Morty.svg'); + * this.load.binary('doom', 'files/Doom.wad'); * } * ``` * @@ -47675,106 +54185,58 @@ declare namespace Phaser { * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been * loaded. * - * The key must be a unique String. It is used to add the file to the global Texture Manager upon a successful load. - * The key should be unique both in terms of files being loaded and files already present in the Texture Manager. + * The key must be a unique String. It is used to add the file to the global Binary Cache upon a successful load. + * The key should be unique both in terms of files being loaded and files already present in the Binary Cache. * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file - * then remove it from the Texture Manager first, before loading a new one. + * then remove it from the Binary Cache first, before loading a new one. * * Instead of passing arguments you can pass a configuration object, such as: * * ```javascript - * this.load.svg({ - * key: 'morty', - * url: 'images/Morty.svg' + * this.load.binary({ + * key: 'doom', + * url: 'files/Doom.wad', + * dataType: Uint8Array * }); * ``` * - * See the documentation for `Phaser.Types.Loader.FileTypes.SVGFileConfig` for more details. + * See the documentation for `Phaser.Types.Loader.FileTypes.BinaryFileConfig` for more details. * - * Once the file has finished loading you can use it as a texture for a Game Object by referencing its key: + * Once the file has finished loading you can access it from its Cache using its key: * * ```javascript - * this.load.svg('morty', 'images/Morty.svg'); + * this.load.binary('doom', 'files/Doom.wad'); * // and later in your game ... - * this.add.image(x, y, 'morty'); + * var data = this.cache.binary.get('doom'); * ``` * * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files - * key. For example, if the prefix was `MENU.` and the key was `Background` the final key will be `MENU.Background` and - * this is what you would use to retrieve the image from the Texture Manager. + * key. For example, if the prefix was `LEVEL1.` and the key was `Data` the final key will be `LEVEL1.Data` and + * this is what you would use to retrieve the text from the Binary Cache. * * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. * - * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "alien" - * and no URL is given then the Loader will set the URL to be "alien.html". It will always add `.html` as the extension, although + * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "doom" + * and no URL is given then the Loader will set the URL to be "doom.bin". It will always add `.bin` as the extension, although * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. * - * You can optionally pass an SVG Resize Configuration object when you load an SVG file. By default the SVG will be rendered to a texture - * at the same size defined in the SVG file attributes. However, this isn't always desirable. You may wish to resize the SVG (either down - * or up) to improve texture clarity, or reduce texture memory consumption. You can either specify an exact width and height to resize - * the SVG to: - * - * ```javascript - * function preload () - * { - * this.load.svg('morty', 'images/Morty.svg', { width: 300, height: 600 }); - * } - * ``` - * - * Or when using a configuration object: - * - * ```javascript - * this.load.svg({ - * key: 'morty', - * url: 'images/Morty.svg', - * svgConfig: { - * width: 300, - * height: 600 - * } - * }); - * ``` - * - * Alternatively, you can just provide a scale factor instead: - * - * ```javascript - * function preload () - * { - * this.load.svg('morty', 'images/Morty.svg', { scale: 2.5 }); - * } - * ``` - * - * Or when using a configuration object: - * - * ```javascript - * this.load.svg({ - * key: 'morty', - * url: 'images/Morty.svg', - * svgConfig: { - * scale: 2.5 - * } - * }); - * ``` - * - * If scale, width and height values are all given, the scale has priority and the width and height values are ignored. - * - * Note: The ability to load this type of file will only be available if the SVG File type has been built into Phaser. + * Note: The ability to load this type of file will only be available if the Binary File type has been built into Phaser. * It is available in the default build but can be excluded from custom builds. * @param key The key to use for this file, or a file configuration object, or array of them. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.svg`, i.e. if `key` was "alien" then the URL will be "alien.svg". - * @param svgConfig The svg size configuration object. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.bin`, i.e. if `key` was "alien" then the URL will be "alien.bin". + * @param dataType Optional type to cast the binary file to once loaded. For example, `Uint8Array`. * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. */ - svg(key: string | Phaser.Types.Loader.FileTypes.SVGFileConfig | Phaser.Types.Loader.FileTypes.SVGFileConfig[], url?: string, svgConfig?: Phaser.Types.Loader.FileTypes.SVGSizeConfig, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): Phaser.Loader.LoaderPlugin; + binary(key: string | Phaser.Types.Loader.FileTypes.BinaryFileConfig | Phaser.Types.Loader.FileTypes.BinaryFileConfig[], url?: string, dataType?: any, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): this; /** - * Adds a Text file, or array of Text files, to the current load queue. + * Adds an XML based Bitmap Font, or array of fonts, to the current load queue. * * You can call this method from within your Scene's `preload`, along with any other files you wish to load: - * * ```javascript * function preload () * { - * this.load.text('story', 'files/IntroStory.txt'); + * this.load.bitmapFont('goldenFont', 'images/GoldFont.png', 'images/GoldFont.xml'); * } * ``` * @@ -47786,62 +54248,93 @@ declare namespace Phaser { * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been * loaded. * - * The key must be a unique String. It is used to add the file to the global Text Cache upon a successful load. - * The key should be unique both in terms of files being loaded and files already present in the Text Cache. + * If you call this from outside of `preload` then you are responsible for starting the Loader afterwards and monitoring + * its events to know when it's safe to use the asset. Please see the Phaser.Loader.LoaderPlugin class for more details. + * + * Phaser expects the font data to be provided in an XML file format. + * These files are created by software such as the [Angelcode Bitmap Font Generator](http://www.angelcode.com/products/bmfont/), + * [Littera](http://kvazars.com/littera/) or [Glyph Designer](https://71squared.com/glyphdesigner) + * + * Phaser can load all common image types: png, jpg, gif and any other format the browser can natively handle. + * + * The key must be a unique String. It is used to add the file to the global Texture Manager upon a successful load. + * The key should be unique both in terms of files being loaded and files already present in the Texture Manager. * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file - * then remove it from the Text Cache first, before loading a new one. + * then remove it from the Texture Manager first, before loading a new one. * * Instead of passing arguments you can pass a configuration object, such as: * * ```javascript - * this.load.text({ - * key: 'story', - * url: 'files/IntroStory.txt' + * this.load.bitmapFont({ + * key: 'goldenFont', + * textureURL: 'images/GoldFont.png', + * fontDataURL: 'images/GoldFont.xml' * }); * ``` * - * See the documentation for `Phaser.Types.Loader.FileTypes.TextFileConfig` for more details. + * See the documentation for `Phaser.Types.Loader.FileTypes.BitmapFontFileConfig` for more details. * - * Once the file has finished loading you can access it from its Cache using its key: + * Once the atlas has finished loading you can use key of it when creating a Bitmap Text Game Object: * * ```javascript - * this.load.text('story', 'files/IntroStory.txt'); + * this.load.bitmapFont('goldenFont', 'images/GoldFont.png', 'images/GoldFont.xml'); * // and later in your game ... - * var data = this.cache.text.get('story'); + * this.add.bitmapText(x, y, 'goldenFont', 'Hello World'); * ``` * * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files - * key. For example, if the prefix was `LEVEL1.` and the key was `Story` the final key will be `LEVEL1.Story` and - * this is what you would use to retrieve the text from the Text Cache. + * key. For example, if the prefix was `MENU.` and the key was `Background` the final key will be `MENU.Background` and + * this is what you would use when creating a Bitmap Text object. * * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. * - * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "story" - * and no URL is given then the Loader will set the URL to be "story.txt". It will always add `.txt` as the extension, although + * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "alien" + * and no URL is given then the Loader will set the URL to be "alien.png". It will always add `.png` as the extension, although * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. * - * Note: The ability to load this type of file will only be available if the Text File type has been built into Phaser. + * Phaser also supports the automatic loading of associated normal maps. If you have a normal map to go with this image, + * then you can specify it by providing an array as the `url` where the second element is the normal map: + * + * ```javascript + * this.load.bitmapFont('goldenFont', [ 'images/GoldFont.png', 'images/GoldFont-n.png' ], 'images/GoldFont.xml'); + * ``` + * + * Or, if you are using a config object use the `normalMap` property: + * + * ```javascript + * this.load.bitmapFont({ + * key: 'goldenFont', + * textureURL: 'images/GoldFont.png', + * normalMap: 'images/GoldFont-n.png', + * fontDataURL: 'images/GoldFont.xml' + * }); + * ``` + * + * The normal map file is subject to the same conditions as the image file with regard to the path, baseURL, CORs and XHR Settings. + * Normal maps are a WebGL only feature. + * + * Note: The ability to load this type of file will only be available if the Bitmap Font File type has been built into Phaser. * It is available in the default build but can be excluded from custom builds. * @param key The key to use for this file, or a file configuration object, or array of them. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.txt`, i.e. if `key` was "alien" then the URL will be "alien.txt". - * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. + * @param textureURL The absolute or relative URL to load the font image file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". + * @param fontDataURL The absolute or relative URL to load the font xml data file from. If undefined or `null` it will be set to `.xml`, i.e. if `key` was "alien" then the URL will be "alien.xml". + * @param textureXhrSettings An XHR Settings configuration object for the font image file. Used in replacement of the Loaders default XHR Settings. + * @param fontDataXhrSettings An XHR Settings configuration object for the font data xml file. Used in replacement of the Loaders default XHR Settings. */ - text(key: string | Phaser.Types.Loader.FileTypes.TextFileConfig | Phaser.Types.Loader.FileTypes.TextFileConfig[], url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): Phaser.Loader.LoaderPlugin; + bitmapFont(key: string | Phaser.Types.Loader.FileTypes.BitmapFontFileConfig | Phaser.Types.Loader.FileTypes.BitmapFontFileConfig[], textureURL?: string | string[], fontDataURL?: string, textureXhrSettings?: Phaser.Types.Loader.XHRSettingsObject, fontDataXhrSettings?: Phaser.Types.Loader.XHRSettingsObject): this; /** - * Adds a CSV Tilemap file, or array of CSV files, to the current load queue. + * Adds a CSS file, or array of CSS files, to the current load queue. * * You can call this method from within your Scene's `preload`, along with any other files you wish to load: * * ```javascript * function preload () * { - * this.load.tilemapCSV('level1', 'maps/Level1.csv'); + * this.load.css('headers', 'styles/headers.css'); * } * ``` * - * Tilemap CSV data can be created in a text editor, or a 3rd party app that exports as CSV. - * * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, * or if it's already running, when the next free load slot becomes available. This happens automatically if you * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued @@ -47850,62 +54343,50 @@ declare namespace Phaser { * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been * loaded. * - * The key must be a unique String. It is used to add the file to the global Tilemap Cache upon a successful load. - * The key should be unique both in terms of files being loaded and files already present in the Tilemap Cache. - * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file - * then remove it from the Text Cache first, before loading a new one. + * The key must be a unique String and not already in-use by another file in the Loader. * * Instead of passing arguments you can pass a configuration object, such as: * * ```javascript - * this.load.tilemapCSV({ - * key: 'level1', - * url: 'maps/Level1.csv' + * this.load.css({ + * key: 'headers', + * url: 'styles/headers.css' * }); * ``` * - * See the documentation for `Phaser.Types.Loader.FileTypes.TilemapCSVFileConfig` for more details. - * - * Once the file has finished loading you can access it from its Cache using its key: - * - * ```javascript - * this.load.tilemapCSV('level1', 'maps/Level1.csv'); - * // and later in your game ... - * var map = this.make.tilemap({ key: 'level1' }); - * ``` + * See the documentation for `Phaser.Types.Loader.FileTypes.CSSFileConfig` for more details. * - * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files - * key. For example, if the prefix was `LEVEL1.` and the key was `Story` the final key will be `LEVEL1.Story` and - * this is what you would use to retrieve the text from the Tilemap Cache. + * Once the file has finished loading it will automatically be converted into a style DOM element + * via `document.createElement('style')`. It will have its `defer` property set to false and then the + * resulting element will be appended to `document.head`. The CSS styles are then applied to the current document. * * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. * - * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "level" - * and no URL is given then the Loader will set the URL to be "level.csv". It will always add `.csv` as the extension, although + * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "alien" + * and no URL is given then the Loader will set the URL to be "alien.css". It will always add `.css` as the extension, although * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. * - * Note: The ability to load this type of file will only be available if the Tilemap CSV File type has been built into Phaser. + * Note: The ability to load this type of file will only be available if the CSS File type has been built into Phaser. * It is available in the default build but can be excluded from custom builds. * @param key The key to use for this file, or a file configuration object, or array of them. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.csv`, i.e. if `key` was "alien" then the URL will be "alien.csv". + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.css`, i.e. if `key` was "alien" then the URL will be "alien.css". * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. */ - tilemapCSV(key: string | Phaser.Types.Loader.FileTypes.TilemapCSVFileConfig | Phaser.Types.Loader.FileTypes.TilemapCSVFileConfig[], url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): Phaser.Loader.LoaderPlugin; + css(key: string | Phaser.Types.Loader.FileTypes.CSSFileConfig | Phaser.Types.Loader.FileTypes.CSSFileConfig[], url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): this; /** - * Adds an Impact.js Tilemap file, or array of map files, to the current load queue. + * Adds a GLSL file, or array of GLSL files, to the current load queue. + * In Phaser 3 GLSL files are just plain Text files at the current moment in time. * * You can call this method from within your Scene's `preload`, along with any other files you wish to load: * * ```javascript * function preload () * { - * this.load.tilemapImpact('level1', 'maps/Level1.json'); + * this.load.glsl('plasma', 'shaders/Plasma.glsl'); * } * ``` * - * Impact Tilemap data is created the Impact.js Map Editor called Weltmeister. - * * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, * or if it's already running, when the next free load slot becomes available. This happens automatically if you * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued @@ -47914,62 +54395,62 @@ declare namespace Phaser { * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been * loaded. * - * The key must be a unique String. It is used to add the file to the global Tilemap Cache upon a successful load. - * The key should be unique both in terms of files being loaded and files already present in the Tilemap Cache. + * The key must be a unique String. It is used to add the file to the global Shader Cache upon a successful load. + * The key should be unique both in terms of files being loaded and files already present in the Shader Cache. * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file - * then remove it from the Text Cache first, before loading a new one. + * then remove it from the Shader Cache first, before loading a new one. * * Instead of passing arguments you can pass a configuration object, such as: * * ```javascript - * this.load.tilemapImpact({ - * key: 'level1', - * url: 'maps/Level1.json' + * this.load.glsl({ + * key: 'plasma', + * shaderType: 'fragment', + * url: 'shaders/Plasma.glsl' * }); * ``` * - * See the documentation for `Phaser.Types.Loader.FileTypes.TilemapImpactFileConfig` for more details. + * See the documentation for `Phaser.Types.Loader.FileTypes.GLSLFileConfig` for more details. * * Once the file has finished loading you can access it from its Cache using its key: * * ```javascript - * this.load.tilemapImpact('level1', 'maps/Level1.json'); + * this.load.glsl('plasma', 'shaders/Plasma.glsl'); * // and later in your game ... - * var map = this.make.tilemap({ key: 'level1' }); + * var data = this.cache.shader.get('plasma'); * ``` * * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files - * key. For example, if the prefix was `LEVEL1.` and the key was `Story` the final key will be `LEVEL1.Story` and - * this is what you would use to retrieve the text from the Tilemap Cache. + * key. For example, if the prefix was `FX.` and the key was `Plasma` the final key will be `FX.Plasma` and + * this is what you would use to retrieve the text from the Shader Cache. * * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. * - * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "level" - * and no URL is given then the Loader will set the URL to be "level.json". It will always add `.json` as the extension, although + * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "plasma" + * and no URL is given then the Loader will set the URL to be "plasma.glsl". It will always add `.glsl` as the extension, although * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. * - * Note: The ability to load this type of file will only be available if the Tilemap Impact File type has been built into Phaser. + * Note: The ability to load this type of file will only be available if the GLSL File type has been built into Phaser. * It is available in the default build but can be excluded from custom builds. * @param key The key to use for this file, or a file configuration object, or array of them. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.glsl`, i.e. if `key` was "alien" then the URL will be "alien.glsl". + * @param shaderType The type of shader. Either `fragment` for a fragment shader, or `vertex` for a vertex shader. This is ignored if you load a shader bundle. Default 'fragment'. * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. */ - tilemapImpact(key: string | Phaser.Types.Loader.FileTypes.TilemapImpactFileConfig | Phaser.Types.Loader.FileTypes.TilemapImpactFileConfig[], url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): Phaser.Loader.LoaderPlugin; + glsl(key: string | Phaser.Types.Loader.FileTypes.GLSLFileConfig | Phaser.Types.Loader.FileTypes.GLSLFileConfig[], url?: string, shaderType?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): this; /** - * Adds a Tiled JSON Tilemap file, or array of map files, to the current load queue. + * Adds an HTML file, or array of HTML files, to the current load queue. * * You can call this method from within your Scene's `preload`, along with any other files you wish to load: * * ```javascript * function preload () * { - * this.load.tilemapTiledJSON('level1', 'maps/Level1.json'); + * this.load.html('story', 'files/LoginForm.html'); * } * ``` * - * The Tilemap data is created using the Tiled Map Editor and selecting JSON as the export format. - * * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, * or if it's already running, when the next free load slot becomes available. This happens automatically if you * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued @@ -47978,57 +54459,58 @@ declare namespace Phaser { * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been * loaded. * - * The key must be a unique String. It is used to add the file to the global Tilemap Cache upon a successful load. - * The key should be unique both in terms of files being loaded and files already present in the Tilemap Cache. + * The key must be a unique String. It is used to add the file to the global HTML Cache upon a successful load. + * The key should be unique both in terms of files being loaded and files already present in the HTML Cache. * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file - * then remove it from the Text Cache first, before loading a new one. + * then remove it from the HTML Cache first, before loading a new one. * * Instead of passing arguments you can pass a configuration object, such as: * * ```javascript - * this.load.tilemapTiledJSON({ - * key: 'level1', - * url: 'maps/Level1.json' + * this.load.html({ + * key: 'login', + * url: 'files/LoginForm.html' * }); * ``` * - * See the documentation for `Phaser.Types.Loader.FileTypes.TilemapJSONFileConfig` for more details. + * See the documentation for `Phaser.Types.Loader.FileTypes.HTMLFileConfig` for more details. * * Once the file has finished loading you can access it from its Cache using its key: * * ```javascript - * this.load.tilemapTiledJSON('level1', 'maps/Level1.json'); + * this.load.html('login', 'files/LoginForm.html'); * // and later in your game ... - * var map = this.make.tilemap({ key: 'level1' }); + * var data = this.cache.html.get('login'); * ``` * * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files * key. For example, if the prefix was `LEVEL1.` and the key was `Story` the final key will be `LEVEL1.Story` and - * this is what you would use to retrieve the text from the Tilemap Cache. + * this is what you would use to retrieve the html from the HTML Cache. * * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. * - * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "level" - * and no URL is given then the Loader will set the URL to be "level.json". It will always add `.json` as the extension, although + * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "story" + * and no URL is given then the Loader will set the URL to be "story.html". It will always add `.html` as the extension, although * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. * - * Note: The ability to load this type of file will only be available if the Tilemap JSON File type has been built into Phaser. + * Note: The ability to load this type of file will only be available if the HTML File type has been built into Phaser. * It is available in the default build but can be excluded from custom builds. * @param key The key to use for this file, or a file configuration object, or array of them. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.html`, i.e. if `key` was "alien" then the URL will be "alien.html". * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. */ - tilemapTiledJSON(key: string | Phaser.Types.Loader.FileTypes.TilemapJSONFileConfig | Phaser.Types.Loader.FileTypes.TilemapJSONFileConfig[], url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): Phaser.Loader.LoaderPlugin; + html(key: string | Phaser.Types.Loader.FileTypes.HTMLFileConfig | Phaser.Types.Loader.FileTypes.HTMLFileConfig[], url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): this; /** - * Adds a Unity YAML based Texture Atlas, or array of atlases, to the current load queue. + * Adds an HTML File, or array of HTML Files, to the current load queue. When the files are loaded they + * will be rendered to textures and stored in the Texture Manager. * * You can call this method from within your Scene's `preload`, along with any other files you wish to load: * * ```javascript * function preload () * { - * this.load.unityAtlas('mainmenu', 'images/MainMenu.png', 'images/MainMenu.txt'); + * this.load.htmlTexture('instructions', 'content/intro.html', 256, 512); * } * ``` * @@ -48040,13 +54522,6 @@ declare namespace Phaser { * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been * loaded. * - * If you call this from outside of `preload` then you are responsible for starting the Loader afterwards and monitoring - * its events to know when it's safe to use the asset. Please see the Phaser.Loader.LoaderPlugin class for more details. - * - * Phaser expects the atlas data to be provided in a YAML formatted text file as exported from Unity. - * - * Phaser can load all common image types: png, jpg, gif and any other format the browser can natively handle. - * * The key must be a unique String. It is used to add the file to the global Texture Manager upon a successful load. * The key should be unique both in terms of files being loaded and files already present in the Texture Manager. * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file @@ -48055,24 +54530,100 @@ declare namespace Phaser { * Instead of passing arguments you can pass a configuration object, such as: * * ```javascript - * this.load.unityAtlas({ - * key: 'mainmenu', - * textureURL: 'images/MainMenu.png', - * atlasURL: 'images/MainMenu.txt' + * this.load.htmlTexture({ + * key: 'instructions', + * url: 'content/intro.html', + * width: 256, + * height: 512 * }); * ``` * - * See the documentation for `Phaser.Types.Loader.FileTypes.UnityAtlasFileConfig` for more details. + * See the documentation for `Phaser.Types.Loader.FileTypes.HTMLTextureFileConfig` for more details. * - * Once the atlas has finished loading you can use frames from it as textures for a Game Object by referencing its key: + * Once the file has finished loading you can use it as a texture for a Game Object by referencing its key: * * ```javascript - * this.load.unityAtlas('mainmenu', 'images/MainMenu.png', 'images/MainMenu.json'); + * this.load.htmlTexture('instructions', 'content/intro.html', 256, 512); * // and later in your game ... - * this.add.image(x, y, 'mainmenu', 'background'); + * this.add.image(x, y, 'instructions'); * ``` * - * To get a list of all available frames within an atlas please consult your Texture Atlas software. + * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files + * key. For example, if the prefix was `MENU.` and the key was `Background` the final key will be `MENU.Background` and + * this is what you would use to retrieve the image from the Texture Manager. + * + * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. + * + * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "alien" + * and no URL is given then the Loader will set the URL to be "alien.html". It will always add `.html` as the extension, although + * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. + * + * The width and height are the size of the texture to which the HTML will be rendered. It's not possible to determine these + * automatically, so you will need to provide them, either as arguments or in the file config object. + * When the HTML file has loaded a new SVG element is created with a size and viewbox set to the width and height given. + * The SVG file has a body tag added to it, with the HTML file contents included. It then calls `window.Blob` on the SVG, + * and if successful is added to the Texture Manager, otherwise it fails processing. The overall quality of the rendered + * HTML depends on your browser, and some of them may not even support the svg / blob process used. Be aware that there are + * limitations on what HTML can be inside an SVG. You can find out more details in this + * [Mozilla MDN entry](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Drawing_DOM_objects_into_a_canvas). + * + * Note: The ability to load this type of file will only be available if the HTMLTextureFile File type has been built into Phaser. + * It is available in the default build but can be excluded from custom builds. + * @param key The key to use for this file, or a file configuration object, or array of them. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.html`, i.e. if `key` was "alien" then the URL will be "alien.html". + * @param width The width of the texture the HTML will be rendered to. Default 512. + * @param height The height of the texture the HTML will be rendered to. Default 512. + * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. + */ + htmlTexture(key: string | Phaser.Types.Loader.FileTypes.HTMLTextureFileConfig | Phaser.Types.Loader.FileTypes.HTMLTextureFileConfig[], url?: string, width?: number, height?: number, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): this; + + /** + * Adds an Image, or array of Images, to the current load queue. + * + * You can call this method from within your Scene's `preload`, along with any other files you wish to load: + * + * ```javascript + * function preload () + * { + * this.load.image('logo', 'images/phaserLogo.png'); + * } + * ``` + * + * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, + * or if it's already running, when the next free load slot becomes available. This happens automatically if you + * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued + * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. + * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the + * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been + * loaded. + * + * Phaser can load all common image types: png, jpg, gif and any other format the browser can natively handle. + * If you try to load an animated gif only the first frame will be rendered. Browsers do not natively support playback + * of animated gifs to Canvas elements. + * + * The key must be a unique String. It is used to add the file to the global Texture Manager upon a successful load. + * The key should be unique both in terms of files being loaded and files already present in the Texture Manager. + * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file + * then remove it from the Texture Manager first, before loading a new one. + * + * Instead of passing arguments you can pass a configuration object, such as: + * + * ```javascript + * this.load.image({ + * key: 'logo', + * url: 'images/AtariLogo.png' + * }); + * ``` + * + * See the documentation for `Phaser.Types.Loader.FileTypes.ImageFileConfig` for more details. + * + * Once the file has finished loading you can use it as a texture for a Game Object by referencing its key: + * + * ```javascript + * this.load.image('logo', 'images/AtariLogo.png'); + * // and later in your game ... + * this.add.image(x, y, 'logo'); + * ``` * * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files * key. For example, if the prefix was `MENU.` and the key was `Background` the final key will be `MENU.Background` and @@ -48088,42 +54639,39 @@ declare namespace Phaser { * then you can specify it by providing an array as the `url` where the second element is the normal map: * * ```javascript - * this.load.unityAtlas('mainmenu', [ 'images/MainMenu.png', 'images/MainMenu-n.png' ], 'images/MainMenu.txt'); + * this.load.image('logo', [ 'images/AtariLogo.png', 'images/AtariLogo-n.png' ]); * ``` * * Or, if you are using a config object use the `normalMap` property: * * ```javascript - * this.load.unityAtlas({ - * key: 'mainmenu', - * textureURL: 'images/MainMenu.png', - * normalMap: 'images/MainMenu-n.png', - * atlasURL: 'images/MainMenu.txt' + * this.load.image({ + * key: 'logo', + * url: 'images/AtariLogo.png', + * normalMap: 'images/AtariLogo-n.png' * }); * ``` * * The normal map file is subject to the same conditions as the image file with regard to the path, baseURL, CORs and XHR Settings. * Normal maps are a WebGL only feature. * - * Note: The ability to load this type of file will only be available if the Unity Atlas File type has been built into Phaser. + * Note: The ability to load this type of file will only be available if the Image File type has been built into Phaser. * It is available in the default build but can be excluded from custom builds. * @param key The key to use for this file, or a file configuration object, or array of them. - * @param textureURL The absolute or relative URL to load the texture image file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". - * @param atlasURL The absolute or relative URL to load the texture atlas data file from. If undefined or `null` it will be set to `.txt`, i.e. if `key` was "alien" then the URL will be "alien.txt". - * @param textureXhrSettings An XHR Settings configuration object for the atlas image file. Used in replacement of the Loaders default XHR Settings. - * @param atlasXhrSettings An XHR Settings configuration object for the atlas data file. Used in replacement of the Loaders default XHR Settings. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". + * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. */ - unityAtlas(key: string | Phaser.Types.Loader.FileTypes.UnityAtlasFileConfig | Phaser.Types.Loader.FileTypes.UnityAtlasFileConfig[], textureURL?: string | string[], atlasURL?: string, textureXhrSettings?: Phaser.Types.Loader.XHRSettingsObject, atlasXhrSettings?: Phaser.Types.Loader.XHRSettingsObject): Phaser.Loader.LoaderPlugin; + image(key: string | Phaser.Types.Loader.FileTypes.ImageFileConfig | Phaser.Types.Loader.FileTypes.ImageFileConfig[], url?: string | string[], xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): this; /** - * Adds a Video file, or array of video files, to the current load queue. + * Adds a JSON file, or array of JSON files, to the current load queue. * * You can call this method from within your Scene's `preload`, along with any other files you wish to load: * * ```javascript * function preload () * { - * this.load.video('intro', [ 'video/level1.mp4', 'video/level1.webm', 'video/level1.mov' ]); + * this.load.json('wavedata', 'files/AlienWaveData.json'); * } * ``` * @@ -48135,53 +54683,76 @@ declare namespace Phaser { * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been * loaded. * - * The key must be a unique String. It is used to add the file to the global Video Cache upon a successful load. - * The key should be unique both in terms of files being loaded and files already present in the Video Cache. + * The key must be a unique String. It is used to add the file to the global JSON Cache upon a successful load. + * The key should be unique both in terms of files being loaded and files already present in the JSON Cache. * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file - * then remove it from the Video Cache first, before loading a new one. + * then remove it from the JSON Cache first, before loading a new one. * * Instead of passing arguments you can pass a configuration object, such as: * * ```javascript - * this.load.video({ - * key: 'intro', - * url: [ 'video/level1.mp4', 'video/level1.webm', 'video/level1.mov' ], - * asBlob: false, - * noAudio: true + * this.load.json({ + * key: 'wavedata', + * url: 'files/AlienWaveData.json' * }); * ``` * - * See the documentation for `Phaser.Types.Loader.FileTypes.VideoFileConfig` for more details. + * See the documentation for `Phaser.Types.Loader.FileTypes.JSONFileConfig` for more details. * - * The URLs can be relative or absolute. If the URLs are relative the `Loader.baseURL` and `Loader.path` values will be prepended to them. + * Once the file has finished loading you can access it from its Cache using its key: * - * Due to different browsers supporting different video file types you should usually provide your video files in a variety of formats. - * mp4, mov and webm are the most common. If you provide an array of URLs then the Loader will determine which _one_ file to load based on - * browser support, starting with the first in the array and progressing to the end. + * ```javascript + * this.load.json('wavedata', 'files/AlienWaveData.json'); + * // and later in your game ... + * var data = this.cache.json.get('wavedata'); + * ``` * - * Unlike most asset-types, videos do not _need_ to be preloaded. You can create a Video Game Object and then call its `loadURL` method, - * to load a video at run-time, rather than in advance. + * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files + * key. For example, if the prefix was `LEVEL1.` and the key was `Waves` the final key will be `LEVEL1.Waves` and + * this is what you would use to retrieve the text from the JSON Cache. * - * Note: The ability to load this type of file will only be available if the Video File type has been built into Phaser. + * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. + * + * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "data" + * and no URL is given then the Loader will set the URL to be "data.json". It will always add `.json` as the extension, although + * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. + * + * You can also optionally provide a `dataKey` to use. This allows you to extract only a part of the JSON and store it in the Cache, + * rather than the whole file. For example, if your JSON data had a structure like this: + * + * ```json + * { + * "level1": { + * "baddies": { + * "aliens": {}, + * "boss": {} + * } + * }, + * "level2": {}, + * "level3": {} + * } + * ``` + * + * And you only wanted to store the `boss` data in the Cache, then you could pass `level1.baddies.boss`as the `dataKey`. + * + * Note: The ability to load this type of file will only be available if the JSON File type has been built into Phaser. * It is available in the default build but can be excluded from custom builds. * @param key The key to use for this file, or a file configuration object, or array of them. - * @param urls The absolute or relative URL to load the video files from. - * @param loadEvent The load event to listen for when _not_ loading as a blob. Either `loadeddata`, `canplay` or `canplaythrough`. Default 'loadeddata'. - * @param asBlob Load the video as a data blob, or stream it via the Video element? Default false. - * @param noAudio Does the video have an audio track? If not you can enable auto-playing on it. Default false. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". Or, can be a fully formed JSON Object. + * @param dataKey When the JSON file loads only this property will be stored in the Cache. * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. */ - video(key: string | Phaser.Types.Loader.FileTypes.VideoFileConfig | Phaser.Types.Loader.FileTypes.VideoFileConfig[], urls?: string | string[], loadEvent?: string, asBlob?: boolean, noAudio?: boolean, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): Phaser.Loader.LoaderPlugin; + json(key: string | Phaser.Types.Loader.FileTypes.JSONFileConfig | Phaser.Types.Loader.FileTypes.JSONFileConfig[], url?: object | string, dataKey?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): this; /** - * Adds an XML file, or array of XML files, to the current load queue. + * Adds a Multi Texture Atlas, or array of multi atlases, to the current load queue. * * You can call this method from within your Scene's `preload`, along with any other files you wish to load: * * ```javascript * function preload () * { - * this.load.xml('wavedata', 'files/AlienWaveData.xml'); + * this.load.multiatlas('level1', 'images/Level1.json'); * } * ``` * @@ -48193,15008 +54764,13474 @@ declare namespace Phaser { * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been * loaded. * - * The key must be a unique String. It is used to add the file to the global XML Cache upon a successful load. - * The key should be unique both in terms of files being loaded and files already present in the XML Cache. + * If you call this from outside of `preload` then you are responsible for starting the Loader afterwards and monitoring + * its events to know when it's safe to use the asset. Please see the Phaser.Loader.LoaderPlugin class for more details. + * + * Phaser expects the atlas data to be provided in a JSON file as exported from the application Texture Packer, + * version 4.6.3 or above, where you have made sure to use the Phaser 3 Export option. + * + * The way it works internally is that you provide a URL to the JSON file. Phaser then loads this JSON, parses it and + * extracts which texture files it also needs to load to complete the process. If the JSON also defines normal maps, + * Phaser will load those as well. + * + * The key must be a unique String. It is used to add the file to the global Texture Manager upon a successful load. + * The key should be unique both in terms of files being loaded and files already present in the Texture Manager. * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file - * then remove it from the XML Cache first, before loading a new one. + * then remove it from the Texture Manager first, before loading a new one. * * Instead of passing arguments you can pass a configuration object, such as: * * ```javascript - * this.load.xml({ - * key: 'wavedata', - * url: 'files/AlienWaveData.xml' + * this.load.multiatlas({ + * key: 'level1', + * atlasURL: 'images/Level1.json' * }); * ``` * - * See the documentation for `Phaser.Types.Loader.FileTypes.XMLFileConfig` for more details. + * See the documentation for `Phaser.Types.Loader.FileTypes.MultiAtlasFileConfig` for more details. * - * Once the file has finished loading you can access it from its Cache using its key: + * Instead of passing a URL for the atlas JSON data you can also pass in a well formed JSON object instead. + * + * Once the atlas has finished loading you can use frames from it as textures for a Game Object by referencing its key: * * ```javascript - * this.load.xml('wavedata', 'files/AlienWaveData.xml'); + * this.load.multiatlas('level1', 'images/Level1.json'); * // and later in your game ... - * var data = this.cache.xml.get('wavedata'); + * this.add.image(x, y, 'level1', 'background'); * ``` * + * To get a list of all available frames within an atlas please consult your Texture Atlas software. + * * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files - * key. For example, if the prefix was `LEVEL1.` and the key was `Waves` the final key will be `LEVEL1.Waves` and - * this is what you would use to retrieve the text from the XML Cache. + * key. For example, if the prefix was `MENU.` and the key was `Background` the final key will be `MENU.Background` and + * this is what you would use to retrieve the image from the Texture Manager. * * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. * - * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "data" - * and no URL is given then the Loader will set the URL to be "data.xml". It will always add `.xml` as the extension, although + * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "alien" + * and no URL is given then the Loader will set the URL to be "alien.png". It will always add `.png` as the extension, although * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. * - * Note: The ability to load this type of file will only be available if the XML File type has been built into Phaser. + * Note: The ability to load this type of file will only be available if the Multi Atlas File type has been built into Phaser. * It is available in the default build but can be excluded from custom builds. * @param key The key to use for this file, or a file configuration object, or array of them. - * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.xml`, i.e. if `key` was "alien" then the URL will be "alien.xml". - * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. - */ - xml(key: string | Phaser.Types.Loader.FileTypes.XMLFileConfig | Phaser.Types.Loader.FileTypes.XMLFileConfig[], url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): Phaser.Loader.LoaderPlugin; - - /** - * The Scene which owns this Loader instance. - */ - scene: Phaser.Scene; - - /** - * A reference to the Scene Systems. - */ - systems: Phaser.Scenes.Systems; - - /** - * A reference to the global Cache Manager. - */ - cacheManager: Phaser.Cache.CacheManager; - - /** - * A reference to the global Texture Manager. - */ - textureManager: Phaser.Textures.TextureManager; - - /** - * A reference to the global Scene Manager. - */ - protected sceneManager: Phaser.Scenes.SceneManager; - - /** - * An optional prefix that is automatically prepended to the start of every file key. - * If prefix was `MENU.` and you load an image with the key 'Background' the resulting key would be `MENU.Background`. - * You can set this directly, or call `Loader.setPrefix()`. It will then affect every file added to the Loader - * from that point on. It does _not_ change any file already in the load queue. + * @param atlasURL The absolute or relative URL to load the texture atlas json data file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". + * @param path Optional path to use when loading the textures defined in the atlas data. + * @param baseURL Optional Base URL to use when loading the textures defined in the atlas data. + * @param atlasXhrSettings An XHR Settings configuration object for the atlas json file. Used in replacement of the Loaders default XHR Settings. */ - prefix: string; + multiatlas(key: string | Phaser.Types.Loader.FileTypes.MultiAtlasFileConfig | Phaser.Types.Loader.FileTypes.MultiAtlasFileConfig[], atlasURL?: string, path?: string, baseURL?: string, atlasXhrSettings?: Phaser.Types.Loader.XHRSettingsObject): this; /** - * The value of `path`, if set, is placed before any _relative_ file path given. For example: + * Adds an array of Script files to the current load queue. * - * ```javascript - * this.load.path = "images/sprites/"; - * this.load.image("ball", "ball.png"); - * this.load.image("tree", "level1/oaktree.png"); - * this.load.image("boom", "http://server.com/explode.png"); - * ``` + * The difference between this and the `ScriptFile` file type is that you give an array of scripts to this method, + * and the scripts are then processed _exactly_ in that order. This allows you to load a bunch of scripts that + * may have dependencies on each other without worrying about the async nature of traditional script loading. * - * Would load the `ball` file from `images/sprites/ball.png` and the tree from - * `images/sprites/level1/oaktree.png` but the file `boom` would load from the URL - * given as it's an absolute URL. + * You can call this method from within your Scene's `preload`, along with any other files you wish to load: * - * Please note that the path is added before the filename but *after* the baseURL (if set.) + * ```javascript + * function preload () + * { + * this.load.scripts('PostProcess', [ + * 'libs/shaders/CopyShader.js', + * 'libs/postprocessing/EffectComposer.js', + * 'libs/postprocessing/RenderPass.js', + * 'libs/postprocessing/MaskPass.js', + * 'libs/postprocessing/ShaderPass.js', + * 'libs/postprocessing/AfterimagePass.js' + * ]); + * } + * ``` * - * If you set this property directly then it _must_ end with a "/". Alternatively, call `setPath()` and it'll do it for you. - */ - path: string; - - /** - * If you want to append a URL before the path of any asset you can set this here. + * In the code above the script files will all be loaded in parallel but only processed (i.e. invoked) in the exact + * order given in the array. * - * Useful if allowing the asset base url to be configured outside of the game code. + * The files are **not** loaded right away. They are added to a queue ready to be loaded either when the loader starts, + * or if it's already running, when the next free load slot becomes available. This happens automatically if you + * are calling this from within the Scene's `preload` method, or a related callback. Because the files are queued + * it means you cannot use the files immediately after calling this method, but must wait for the files to complete. + * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the + * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been + * loaded. * - * If you set this property directly then it _must_ end with a "/". Alternatively, call `setBaseURL()` and it'll do it for you. - */ - baseURL: string; - - /** - * The number of concurrent / parallel resources to try and fetch at once. + * The key must be a unique String and not already in-use by another file in the Loader. * - * Old browsers limit 6 requests per domain; modern ones, especially those with HTTP/2 don't limit it at all. + * Instead of passing arguments you can pass a configuration object, such as: * - * The default is 32 but you can change this in your Game Config, or by changing this property before the Loader starts. - */ - maxParallelDownloads: integer; - - /** - * xhr specific global settings (can be overridden on a per-file basis) - */ - xhr: Phaser.Types.Loader.XHRSettingsObject; - - /** - * The crossOrigin value applied to loaded images. Very often this needs to be set to 'anonymous'. - */ - crossOrigin: string; - - /** - * The total number of files to load. It may not always be accurate because you may add to the Loader during the process - * of loading, especially if you load a Pack File. Therefore this value can change, but in most cases remains static. - */ - totalToLoad: integer; - - /** - * The progress of the current load queue, as a float value between 0 and 1. - * This is updated automatically as files complete loading. - * Note that it is possible for this value to go down again if you add content to the current load queue during a load. - */ - progress: number; - - /** - * Files are placed in this Set when they're added to the Loader via `addFile`. + * ```javascript + * this.load.scripts({ + * key: 'PostProcess', + * url: [ + * 'libs/shaders/CopyShader.js', + * 'libs/postprocessing/EffectComposer.js', + * 'libs/postprocessing/RenderPass.js', + * 'libs/postprocessing/MaskPass.js', + * 'libs/postprocessing/ShaderPass.js', + * 'libs/postprocessing/AfterimagePass.js' + * ] + * }); + * ``` * - * They are moved to the `inflight` Set when they start loading, and assuming a successful - * load, to the `queue` Set for further processing. + * See the documentation for `Phaser.Types.Loader.FileTypes.MultiScriptFileConfig` for more details. * - * By the end of the load process this Set will be empty. - */ - list: Phaser.Structs.Set; - - /** - * Files are stored in this Set while they're in the process of being loaded. + * Once all the files have finished loading they will automatically be converted into a script element + * via `document.createElement('script')`. They will have their language set to JavaScript, `defer` set to + * false and then the resulting element will be appended to `document.head`. Any code then in the + * script will be executed. This is done in the exact order the files are specified in the url array. * - * Upon a successful load they are moved to the `queue` Set. + * The URLs can be relative or absolute. If the URLs are relative the `Loader.baseURL` and `Loader.path` values will be prepended to them. * - * By the end of the load process this Set will be empty. + * Note: The ability to load this type of file will only be available if the MultiScript File type has been built into Phaser. + * It is available in the default build but can be excluded from custom builds. + * @param key The key to use for this file, or a file configuration object, or array of them. + * @param url An array of absolute or relative URLs to load the script files from. They are processed in the order given in the array. + * @param extension The default file extension to use if no url is provided. Default 'js'. + * @param xhrSettings Extra XHR Settings specifically for these files. */ - inflight: Phaser.Structs.Set; + scripts(key: string | Phaser.Types.Loader.FileTypes.MultiScriptFileConfig | Phaser.Types.Loader.FileTypes.MultiScriptFileConfig[], url?: string[], extension?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): this; /** - * Files are stored in this Set while they're being processed. + * Adds a Wavefront OBJ file, or array of OBJ files, to the current load queue. * - * If the process is successful they are moved to their final destination, which could be - * a Cache or the Texture Manager. + * Note: You should ensure your 3D package has triangulated the OBJ file prior to export. * - * At the end of the load process this Set will be empty. - */ - queue: Phaser.Structs.Set; - - /** - * The total number of files that failed to load during the most recent load. - * This value is reset when you call `Loader.start`. - */ - totalFailed: integer; - - /** - * The total number of files that successfully loaded during the most recent load. - * This value is reset when you call `Loader.start`. - */ - totalComplete: integer; - - /** - * The current state of the Loader. - */ - readonly state: integer; - - /** - * If you want to append a URL before the path of any asset you can set this here. + * You can call this method from within your Scene's `preload`, along with any other files you wish to load: * - * Useful if allowing the asset base url to be configured outside of the game code. + * ```javascript + * function preload () + * { + * this.load.obj('ufo', 'files/spaceship.obj'); + * } + * ``` * - * Once a base URL is set it will affect every file loaded by the Loader from that point on. It does _not_ change any - * file _already_ being loaded. To reset it, call this method with no arguments. - * @param url The URL to use. Leave empty to reset. - */ - setBaseURL(url?: string): Phaser.Loader.LoaderPlugin; - - /** - * The value of `path`, if set, is placed before any _relative_ file path given. For example: + * You can optionally also load a Wavefront Material file as well, by providing the 3rd parameter: * * ```javascript - * this.load.setPath("images/sprites/"); - * this.load.image("ball", "ball.png"); - * this.load.image("tree", "level1/oaktree.png"); - * this.load.image("boom", "http://server.com/explode.png"); + * function preload () + * { + * this.load.obj('ufo', 'files/spaceship.obj', 'files/spaceship.mtl'); + * } * ``` * - * Would load the `ball` file from `images/sprites/ball.png` and the tree from - * `images/sprites/level1/oaktree.png` but the file `boom` would load from the URL - * given as it's an absolute URL. + * If given, the material will be parsed and stored along with the obj data in the cache. * - * Please note that the path is added before the filename but *after* the baseURL (if set.) + * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, + * or if it's already running, when the next free load slot becomes available. This happens automatically if you + * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued + * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. + * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the + * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been + * loaded. * - * Once a path is set it will then affect every file added to the Loader from that point on. It does _not_ change any - * file _already_ in the load queue. To reset it, call this method with no arguments. - * @param path The path to use. Leave empty to reset. - */ - setPath(path?: string): Phaser.Loader.LoaderPlugin; - - /** - * An optional prefix that is automatically prepended to the start of every file key. + * The key must be a unique String. It is used to add the file to the global OBJ Cache upon a successful load. + * The key should be unique both in terms of files being loaded and files already present in the OBJ Cache. + * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file + * then remove it from the OBJ Cache first, before loading a new one. * - * If prefix was `MENU.` and you load an image with the key 'Background' the resulting key would be `MENU.Background`. + * Instead of passing arguments you can pass a configuration object, such as: * - * Once a prefix is set it will then affect every file added to the Loader from that point on. It does _not_ change any - * file _already_ in the load queue. To reset it, call this method with no arguments. - * @param prefix The prefix to use. Leave empty to reset. - */ - setPrefix(prefix?: string): Phaser.Loader.LoaderPlugin; - - /** - * Sets the Cross Origin Resource Sharing value used when loading files. + * ```javascript + * this.load.obj({ + * key: 'ufo', + * url: 'files/spaceship.obj', + * matURL: 'files/spaceship.mtl', + * flipUV: true + * }); + * ``` * - * Files can override this value on a per-file basis by specifying an alternative `crossOrigin` value in their file config. + * See the documentation for `Phaser.Types.Loader.FileTypes.OBJFileConfig` for more details. * - * Once CORs is set it will then affect every file loaded by the Loader from that point on, as long as they don't have - * their own CORs setting. To reset it, call this method with no arguments. + * Once the file has finished loading you can access it from its Cache using its key: * - * For more details about CORs see https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS - * @param crossOrigin The value to use for the `crossOrigin` property in the load request. - */ - setCORS(crossOrigin?: string): Phaser.Loader.LoaderPlugin; - - /** - * Adds a file, or array of files, into the load queue. + * ```javascript + * this.load.obj('ufo', 'files/spaceship.obj'); + * // and later in your game ... + * var data = this.cache.obj.get('ufo'); + * ``` * - * The file must be an instance of `Phaser.Loader.File`, or a class that extends it. The Loader will check that the key - * used by the file won't conflict with any other key either in the loader, the inflight queue or the target cache. - * If allowed it will then add the file into the pending list, read for the load to start. Or, if the load has already - * started, ready for the next batch of files to be pulled from the list to the inflight queue. + * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files + * key. For example, if the prefix was `LEVEL1.` and the key was `Story` the final key will be `LEVEL1.Story` and + * this is what you would use to retrieve the obj from the OBJ Cache. * - * You should not normally call this method directly, but rather use one of the Loader methods like `image` or `atlas`, - * however you can call this as long as the file given to it is well formed. - * @param file The file, or array of files, to be added to the load queue. - */ - addFile(file: Phaser.Loader.File | Phaser.Loader.File[]): void; - - /** - * Checks the key and type of the given file to see if it will conflict with anything already - * in a Cache, the Texture Manager, or the list or inflight queues. - * @param file The file to check the key of. - */ - keyExists(file: Phaser.Loader.File): boolean; - - /** - * Takes a well formed, fully parsed pack file object and adds its entries into the load queue. Usually you do not call - * this method directly, but instead use `Loader.pack` and supply a path to a JSON file that holds the - * pack data. However, if you've got the data prepared you can pass it to this method. + * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. * - * You can also provide an optional key. If you do then it will only add the entries from that part of the pack into - * to the load queue. If not specified it will add all entries it finds. For more details about the pack file format - * see the `LoaderPlugin.pack` method. - * @param data The Pack File data to be parsed and each entry of it to added to the load queue. - * @param packKey An optional key to use from the pack file data. - */ - addPack(data: any, packKey?: string): boolean; - - /** - * Is the Loader actively loading, or processing loaded files? - */ - isLoading(): boolean; - - /** - * Is the Loader ready to start a new load? + * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "story" + * and no URL is given then the Loader will set the URL to be "story.obj". It will always add `.obj` as the extension, although + * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. + * + * Note: The ability to load this type of file will only be available if the OBJ File type has been built into Phaser. + * It is available in the default build but can be excluded from custom builds. + * @param key The key to use for this file, or a file configuration object, or array of them. + * @param objURL The absolute or relative URL to load the obj file from. If undefined or `null` it will be set to `.obj`, i.e. if `key` was "alien" then the URL will be "alien.obj". + * @param matURL Optional absolute or relative URL to load the obj material file from. + * @param flipUV Flip the UV coordinates stored in the model data? + * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. */ - isReady(): boolean; + obj(key: string | Phaser.Types.Loader.FileTypes.OBJFileConfig | Phaser.Types.Loader.FileTypes.OBJFileConfig[], objURL?: string, matURL?: string, flipUV?: boolean, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): this; /** - * Starts the Loader running. This will reset the progress and totals and then emit a `start` event. - * If there is nothing in the queue the Loader will immediately complete, otherwise it will start - * loading the first batch of files. - * - * The Loader is started automatically if the queue is populated within your Scenes `preload` method. + * Adds a JSON File Pack, or array of packs, to the current load queue. * - * However, outside of this, you need to call this method to start it. + * You can call this method from within your Scene's `preload`, along with any other files you wish to load: * - * If the Loader is already running this method will simply return. - */ - start(): void; - - /** - * Called automatically during the load process. - * It updates the `progress` value and then emits a progress event, which you can use to - * display a loading bar in your game. - */ - updateProgress(): void; - - /** - * Called automatically during the load process. - */ - update(): void; - - /** - * An internal method called automatically by the XHRLoader belong to a File. + * ```javascript + * function preload () + * { + * this.load.pack('level1', 'data/Level1Files.json'); + * } + * ``` * - * This method will remove the given file from the inflight Set and update the load progress. - * If the file was successful its `onProcess` method is called, otherwise it is added to the delete queue. - * @param file The File that just finished loading, or errored during load. - * @param success `true` if the file loaded successfully, otherwise `false`. - */ - nextFile(file: Phaser.Loader.File, success: boolean): void; - - /** - * An internal method that is called automatically by the File when it has finished processing. + * A File Pack is a JSON file (or object) that contains details about other files that should be added into the Loader. + * Here is a small example: * - * If the process was successful, and the File isn't part of a MultiFile, its `addToCache` method is called. + * ```json + * { + * "test1": { + * "files": [ + * { + * "type": "image", + * "key": "taikodrummaster", + * "url": "assets/pics/taikodrummaster.jpg" + * }, + * { + * "type": "image", + * "key": "sukasuka-chtholly", + * "url": "assets/pics/sukasuka-chtholly.png" + * } + * ] + * }, + * "meta": { + * "generated": "1401380327373", + * "app": "Phaser 3 Asset Packer", + * "url": "https://phaser.io", + * "version": "1.0", + * "copyright": "Photon Storm Ltd. 2018" + * } + * } + * ``` * - * It this then removed from the queue. If there are no more files to load `loadComplete` is called. - * @param file The file that has finished processing. - */ - fileProcessComplete(file: Phaser.Loader.File): void; - - /** - * Called at the end when the load queue is exhausted and all files have either loaded or errored. - * By this point every loaded file will now be in its associated cache and ready for use. + * The pack can be split into sections. In the example above you'll see a section called `test1. You can tell + * the `load.pack` method to parse only a particular section of a pack. The pack is stored in the JSON Cache, + * so you can pass it to the Loader to process additional sections as needed in your game, or you can just load + * them all at once without specifying anything. * - * Also clears down the Sets, puts progress to 1 and clears the deletion queue. - */ - loadComplete(): void; - - /** - * Adds a File into the pending-deletion queue. - * @param file The File to be queued for deletion when the Loader completes. - */ - flagForRemoval(file: Phaser.Loader.File): void; - - /** - * Converts the given JSON data into a file that the browser then prompts you to download so you can save it locally. + * The pack file can contain an entry for any type of file that Phaser can load. The object structures exactly + * match that of the file type configs, and all properties available within the file type configs can be used + * in the pack file too. * - * The data must be well formed JSON and ready-parsed, not a JavaScript object. - * @param data The JSON data, ready parsed. - * @param filename The name to save the JSON file as. Default file.json. - */ - saveJSON(data: any, filename?: string): Phaser.Loader.LoaderPlugin; - - /** - * Causes the browser to save the given data as a file to its default Downloads folder. + * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, + * or if it's already running, when the next free load slot becomes available. This happens automatically if you + * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued + * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. + * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the + * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been + * loaded. * - * Creates a DOM level anchor link, assigns it as being a `download` anchor, sets the href - * to be an ObjectURL based on the given data, and then invokes a click event. - * @param data The data to be saved. Will be passed through URL.createObjectURL. - * @param filename The filename to save the file as. Default file.json. - * @param filetype The file type to use when saving the file. Defaults to JSON. Default application/json. - */ - save(data: any, filename?: string, filetype?: string): Phaser.Loader.LoaderPlugin; - - /** - * Resets the Loader. + * If you call this from outside of `preload` then you are responsible for starting the Loader afterwards and monitoring + * its events to know when it's safe to use the asset. Please see the Phaser.Loader.LoaderPlugin class for more details. * - * This will clear all lists and reset the base URL, path and prefix. + * The key must be a unique String. It is used to add the file to the global JSON Cache upon a successful load. + * The key should be unique both in terms of files being loaded and files already present in the JSON Cache. + * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file + * then remove it from the JSON Cache first, before loading a new one. * - * Warning: If the Loader is currently downloading files, or has files in its queue, they will be aborted. - */ - reset(): void; - - } - - /** - * Takes two XHRSettings Objects and creates a new XHRSettings object from them. - * - * The new object is seeded by the values given in the global settings, but any setting in - * the local object overrides the global ones. - * @param global The global XHRSettings object. - * @param local The local XHRSettings object. - */ - function MergeXHRSettings(global: Phaser.Types.Loader.XHRSettingsObject, local: Phaser.Types.Loader.XHRSettingsObject): Phaser.Types.Loader.XHRSettingsObject; - - /** - * A MultiFile is a special kind of parent that contains two, or more, Files as children and looks after - * the loading and processing of them all. It is commonly extended and used as a base class for file types such as AtlasJSON or BitmapFont. - * - * You shouldn't create an instance of a MultiFile directly, but should extend it with your own class, setting a custom type and processing methods. - */ - class MultiFile { - /** + * Instead of passing arguments you can pass a configuration object, such as: * - * @param loader The Loader that is going to load this File. - * @param type The file type string for sorting within the Loader. - * @param key The key of the file within the loader. - * @param files An array of Files that make-up this MultiFile. - */ - constructor(loader: Phaser.Loader.LoaderPlugin, type: string, key: string, files: Phaser.Loader.File[]); - - /** - * A reference to the Loader that is going to load this file. - */ - loader: Phaser.Loader.LoaderPlugin; - - /** - * The file type string for sorting within the Loader. - */ - type: string; - - /** - * Unique cache key (unique within its file type) - */ - key: string; - - /** - * Array of files that make up this MultiFile. - */ - files: Phaser.Loader.File[]; - - /** - * The completion status of this MultiFile. - */ - complete: boolean; - - /** - * The number of files to load. - */ - pending: integer; - - /** - * The number of files that failed to load. - */ - failed: integer; - - /** - * A storage container for transient data that the loading files need. - */ - config: any; - - /** - * A reference to the Loaders baseURL at the time this MultiFile was created. - * Used to populate child-files. - */ - baseURL: string; - - /** - * A reference to the Loaders path at the time this MultiFile was created. - * Used to populate child-files. - */ - path: string; - - /** - * A reference to the Loaders prefix at the time this MultiFile was created. - * Used to populate child-files. - */ - prefix: string; - - /** - * Checks if this MultiFile is ready to process its children or not. - */ - isReadyToProcess(): boolean; - - /** - * Adds another child to this MultiFile, increases the pending count and resets the completion status. - * @param files The File to add to this MultiFile. - */ - addToMultiFile(files: Phaser.Loader.File): Phaser.Loader.MultiFile; - - /** - * Called by each File when it finishes loading. - * @param file The File that has completed processing. - */ - onFileComplete(file: Phaser.Loader.File): void; - - /** - * Called by each File that fails to load. - * @param file The File that has failed to load. - */ - onFileFailed(file: Phaser.Loader.File): void; - - } - - /** - * Creates a new XMLHttpRequest (xhr) object based on the given File and XHRSettings - * and starts the download of it. It uses the Files own XHRSettings and merges them - * with the global XHRSettings object to set the xhr values before download. - * @param file The File to download. - * @param globalXHRSettings The global XHRSettings object. - */ - function XHRLoader(file: Phaser.Loader.File, globalXHRSettings: Phaser.Types.Loader.XHRSettingsObject): XMLHttpRequest; - - /** - * Creates an XHRSettings Object with default values. - * @param responseType The responseType, such as 'text'. Default ''. - * @param async Should the XHR request use async or not? Default true. - * @param user Optional username for the XHR request. Default ''. - * @param password Optional password for the XHR request. Default ''. - * @param timeout Optional XHR timeout value. Default 0. - */ - function XHRSettings(responseType?: XMLHttpRequestResponseType, async?: boolean, user?: string, password?: string, timeout?: integer): Phaser.Types.Loader.XHRSettingsObject; - - } - - namespace Math { - namespace Angle { - /** - * Find the angle of a segment from (x1, y1) -> (x2, y2). - * @param x1 The x coordinate of the first point. - * @param y1 The y coordinate of the first point. - * @param x2 The x coordinate of the second point. - * @param y2 The y coordinate of the second point. - */ - function Between(x1: number, y1: number, x2: number, y2: number): number; - - /** - * Find the angle of a segment from (point1.x, point1.y) -> (point2.x, point2.y). + * ```javascript + * this.load.pack({ + * key: 'level1', + * url: 'data/Level1Files.json' + * }); + * ``` * - * Calculates the angle of the vector from the first point to the second point. - * @param point1 The first point. - * @param point2 The second point. - */ - function BetweenPoints(point1: Phaser.Geom.Point | object, point2: Phaser.Geom.Point | object): number; - - /** - * Find the angle of a segment from (point1.x, point1.y) -> (point2.x, point2.y). + * See the documentation for `Phaser.Types.Loader.FileTypes.PackFileConfig` for more details. * - * The difference between this method and {@link Phaser.Math.Angle.BetweenPoints} is that this assumes the y coordinate - * travels down the screen. - * @param point1 The first point. - * @param point2 The second point. - */ - function BetweenPointsY(point1: Phaser.Geom.Point | object, point2: Phaser.Geom.Point | object): number; - - /** - * Find the angle of a segment from (x1, y1) -> (x2, y2). + * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files + * key. For example, if the prefix was `LEVEL1.` and the key was `Waves` the final key will be `LEVEL1.Waves` and + * this is what you would use to retrieve the text from the JSON Cache. * - * The difference between this method and {@link Phaser.Math.Angle.Between} is that this assumes the y coordinate - * travels down the screen. - * @param x1 The x coordinate of the first point. - * @param y1 The y coordinate of the first point. - * @param x2 The x coordinate of the second point. - * @param y2 The y coordinate of the second point. + * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. + * + * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "data" + * and no URL is given then the Loader will set the URL to be "data.json". It will always add `.json` as the extension, although + * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. + * + * You can also optionally provide a `dataKey` to use. This allows you to extract only a part of the JSON and store it in the Cache, + * rather than the whole file. For example, if your JSON data had a structure like this: + * + * ```json + * { + * "level1": { + * "baddies": { + * "aliens": {}, + * "boss": {} + * } + * }, + * "level2": {}, + * "level3": {} + * } + * ``` + * + * And you only wanted to store the `boss` data in the Cache, then you could pass `level1.baddies.boss`as the `dataKey`. + * + * Note: The ability to load this type of file will only be available if the Pack File type has been built into Phaser. + * It is available in the default build but can be excluded from custom builds. + * @param key The key to use for this file, or a file configuration object, or array of them. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". + * @param dataKey When the JSON file loads only this property will be stored in the Cache. + * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. */ - function BetweenY(x1: number, y1: number, x2: number, y2: number): number; + pack(key: string | Phaser.Types.Loader.FileTypes.PackFileConfig | Phaser.Types.Loader.FileTypes.PackFileConfig[], url?: string, dataKey?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): this; /** - * Takes an angle in Phasers default clockwise format and converts it so that - * 0 is North, 90 is West, 180 is South and 270 is East, - * therefore running counter-clockwise instead of clockwise. + * Adds a Plugin Script file, or array of plugin files, to the current load queue. * - * You can pass in the angle from a Game Object using: + * You can call this method from within your Scene's `preload`, along with any other files you wish to load: * * ```javascript - * var converted = CounterClockwise(gameobject.rotation); + * function preload () + * { + * this.load.plugin('modplayer', 'plugins/ModPlayer.js'); + * } * ``` * - * All values for this function are in radians. - * @param angle The angle to convert, in radians. - */ - function CounterClockwise(angle: number): number; - - /** - * Normalize an angle to the [0, 2pi] range. - * @param angle The angle to normalize, in radians. - */ - function Normalize(angle: number): number; - - /** - * Reverse the given angle. - * @param angle The angle to reverse, in radians. - */ - function Reverse(angle: number): number; - - /** - * Rotates `currentAngle` towards `targetAngle`, taking the shortest rotation distance. The `lerp` argument is the amount to rotate by in this call. - * @param currentAngle The current angle, in radians. - * @param targetAngle The target angle to rotate to, in radians. - * @param lerp The lerp value to add to the current angle. Default 0.05. - */ - function RotateTo(currentAngle: number, targetAngle: number, lerp?: number): number; - - /** - * Gets the shortest angle between `angle1` and `angle2`. + * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, + * or if it's already running, when the next free load slot becomes available. This happens automatically if you + * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued + * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. + * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the + * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been + * loaded. * - * Both angles must be in the range -180 to 180, which is the same clamped - * range that `sprite.angle` uses, so you can pass in two sprite angles to - * this method and get the shortest angle back between the two of them. + * The key must be a unique String and not already in-use by another file in the Loader. * - * The angle returned will be in the same range. If the returned angle is - * greater than 0 then it's a counter-clockwise rotation, if < 0 then it's - * a clockwise rotation. + * Instead of passing arguments you can pass a configuration object, such as: * - * TODO: Wrap the angles in this function? - * @param angle1 The first angle in the range -180 to 180. - * @param angle2 The second angle in the range -180 to 180. + * ```javascript + * this.load.plugin({ + * key: 'modplayer', + * url: 'plugins/ModPlayer.js' + * }); + * ``` + * + * See the documentation for `Phaser.Types.Loader.FileTypes.PluginFileConfig` for more details. + * + * Once the file has finished loading it will automatically be converted into a script element + * via `document.createElement('script')`. It will have its language set to JavaScript, `defer` set to + * false and then the resulting element will be appended to `document.head`. Any code then in the + * script will be executed. It will then be passed to the Phaser PluginCache.register method. + * + * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. + * + * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "alien" + * and no URL is given then the Loader will set the URL to be "alien.js". It will always add `.js` as the extension, although + * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. + * + * Note: The ability to load this type of file will only be available if the Plugin File type has been built into Phaser. + * It is available in the default build but can be excluded from custom builds. + * @param key The key to use for this file, or a file configuration object, or array of them. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.js`, i.e. if `key` was "alien" then the URL will be "alien.js". Or, a plugin function. + * @param start Automatically start the plugin after loading? + * @param mapping If this plugin is to be injected into the Scene, this is the property key used. + * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. */ - function ShortestBetween(angle1: number, angle2: number): number; + plugin(key: string | Phaser.Types.Loader.FileTypes.PluginFileConfig | Phaser.Types.Loader.FileTypes.PluginFileConfig[], url?: string | Function, start?: boolean, mapping?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): this; /** - * Wrap an angle. + * Adds an external Scene file, or array of Scene files, to the current load queue. * - * Wraps the angle to a value in the range of -PI to PI. - * @param angle The angle to wrap, in radians. + * You can call this method from within your Scene's `preload`, along with any other files you wish to load: + * + * ```javascript + * function preload () + * { + * this.load.sceneFile('Level1', 'src/Level1.js'); + * } + * ``` + * + * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, + * or if it's already running, when the next free load slot becomes available. This happens automatically if you + * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued + * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. + * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the + * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been + * loaded. + * + * The key must be a unique String. It is used to add the file to the global Scene Manager upon a successful load. + * + * For a Scene File it's vitally important that the key matches the class name in the JavaScript file. + * + * For example here is the source file: + * + * ```javascript + * class ExternalScene extends Phaser.Scene { + * + * constructor () + * { + * super('myScene'); + * } + * + * } + * ``` + * + * Because the class is called `ExternalScene` that is the exact same key you must use when loading it: + * + * ```javascript + * function preload () + * { + * this.load.sceneFile('ExternalScene', 'src/yourScene.js'); + * } + * ``` + * + * The key that is used within the Scene Manager can either be set to the same, or you can override it in the Scene + * constructor, as we've done in the example above, where the Scene key was changed to `myScene`. + * + * The key should be unique both in terms of files being loaded and Scenes already present in the Scene Manager. + * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file + * then remove it from the Scene Manager first, before loading a new one. + * + * Instead of passing arguments you can pass a configuration object, such as: + * + * ```javascript + * this.load.sceneFile({ + * key: 'Level1', + * url: 'src/Level1.js' + * }); + * ``` + * + * See the documentation for `Phaser.Types.Loader.FileTypes.SceneFileConfig` for more details. + * + * Once the file has finished loading it will be added to the Scene Manager. + * + * ```javascript + * this.load.sceneFile('Level1', 'src/Level1.js'); + * // and later in your game ... + * this.scene.start('Level1'); + * ``` + * + * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files + * key. For example, if the prefix was `WORLD1.` and the key was `Story` the final key will be `WORLD1.Story` and + * this is what you would use to retrieve the text from the Scene Manager. + * + * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. + * + * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "story" + * and no URL is given then the Loader will set the URL to be "story.js". It will always add `.js` as the extension, although + * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. + * + * Note: The ability to load this type of file will only be available if the Scene File type has been built into Phaser. + * It is available in the default build but can be excluded from custom builds. + * @param key The key to use for this file, or a file configuration object, or array of them. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.js`, i.e. if `key` was "alien" then the URL will be "alien.js". + * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. */ - function Wrap(angle: number): number; + sceneFile(key: string | Phaser.Types.Loader.FileTypes.SceneFileConfig | Phaser.Types.Loader.FileTypes.SceneFileConfig[], url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): this; /** - * Wrap an angle in degrees. + * Adds a Scene Plugin Script file, or array of plugin files, to the current load queue. * - * Wraps the angle to a value in the range of -180 to 180. - * @param angle The angle to wrap, in degrees. - */ - function WrapDegrees(angle: number): number; - - } - - /** - * Calculate the mean average of the given values. - * @param values The values to average. - */ - function Average(values: number[]): number; - - /** - * [description] - * @param n [description] - * @param i [description] - */ - function Bernstein(n: number, i: number): number; - - /** - * Compute a random integer between the `min` and `max` values, inclusive. - * @param min The minimum value. - * @param max The maximum value. - */ - function Between(min: integer, max: integer): integer; - - /** - * Calculates a Catmull-Rom value. - * @param t [description] - * @param p0 [description] - * @param p1 [description] - * @param p2 [description] - * @param p3 [description] - */ - function CatmullRom(t: number, p0: number, p1: number, p2: number, p3: number): number; - - /** - * Ceils to some place comparative to a `base`, default is 10 for decimal place. - * - * The `place` is represented by the power applied to `base` to get that place. - * @param value The value to round. - * @param place The place to round to. Default 0. - * @param base The base to round in. Default is 10 for decimal. Default 10. - */ - function CeilTo(value: number, place?: number, base?: integer): number; - - /** - * Force a value within the boundaries by clamping it to the range `min`, `max`. - * @param value The value to be clamped. - * @param min The minimum bounds. - * @param max The maximum bounds. - */ - function Clamp(value: number, min: number, max: number): number; - - /** - * The value of PI * 2. - */ - var PI2: number; - - /** - * The value of PI * 0.5. - */ - var TAU: number; - - /** - * An epsilon value (1.0e-6) - */ - var EPSILON: number; - - /** - * For converting degrees to radians (PI / 180) - */ - var DEG_TO_RAD: number; - - /** - * For converting radians to degrees (180 / PI) - */ - var RAD_TO_DEG: number; - - /** - * An instance of the Random Number Generator. - * This is not set until the Game boots. - */ - var RND: Phaser.Math.RandomDataGenerator; - - /** - * The minimum safe integer this browser supports. - * We use a const for backward compatibility with Internet Explorer. - */ - var MIN_SAFE_INTEGER: number; - - /** - * The maximum safe integer this browser supports. - * We use a const for backward compatibility with Internet Explorer. - */ - var MAX_SAFE_INTEGER: number; - - /** - * Convert the given angle from degrees, to the equivalent angle in radians. - * @param degrees The angle (in degrees) to convert to radians. - */ - function DegToRad(degrees: integer): number; - - /** - * Calculates the positive difference of two given numbers. - * @param a The first number in the calculation. - * @param b The second number in the calculation. - */ - function Difference(a: number, b: number): number; - - namespace Distance { - /** - * Calculate the distance between two sets of coordinates (points). - * @param x1 The x coordinate of the first point. - * @param y1 The y coordinate of the first point. - * @param x2 The x coordinate of the second point. - * @param y2 The y coordinate of the second point. - */ - function Between(x1: number, y1: number, x2: number, y2: number): number; - - /** - * Calculate the distance between two points. - * @param a The first point. - * @param b The second point. + * You can call this method from within your Scene's `preload`, along with any other files you wish to load: + * + * ```javascript + * function preload () + * { + * this.load.scenePlugin('ModPlayer', 'plugins/ModPlayer.js', 'modPlayer', 'mods'); + * } + * ``` + * + * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, + * or if it's already running, when the next free load slot becomes available. This happens automatically if you + * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued + * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. + * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the + * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been + * loaded. + * + * The key must be a unique String and not already in-use by another file in the Loader. + * + * Instead of passing arguments you can pass a configuration object, such as: + * + * ```javascript + * this.load.scenePlugin({ + * key: 'modplayer', + * url: 'plugins/ModPlayer.js' + * }); + * ``` + * + * See the documentation for `Phaser.Types.Loader.FileTypes.ScenePluginFileConfig` for more details. + * + * Once the file has finished loading it will automatically be converted into a script element + * via `document.createElement('script')`. It will have its language set to JavaScript, `defer` set to + * false and then the resulting element will be appended to `document.head`. Any code then in the + * script will be executed. It will then be passed to the Phaser PluginCache.register method. + * + * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. + * + * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "alien" + * and no URL is given then the Loader will set the URL to be "alien.js". It will always add `.js` as the extension, although + * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. + * + * Note: The ability to load this type of file will only be available if the Script File type has been built into Phaser. + * It is available in the default build but can be excluded from custom builds. + * @param key The key to use for this file, or a file configuration object, or array of them. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.js`, i.e. if `key` was "alien" then the URL will be "alien.js". Or, set to a plugin function. + * @param systemKey If this plugin is to be added to Scene.Systems, this is the property key for it. + * @param sceneKey If this plugin is to be added to the Scene, this is the property key for it. + * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. */ - function BetweenPoints(a: Phaser.Types.Math.Vector2Like, b: Phaser.Types.Math.Vector2Like): number; + scenePlugin(key: string | Phaser.Types.Loader.FileTypes.ScenePluginFileConfig | Phaser.Types.Loader.FileTypes.ScenePluginFileConfig[], url?: string | Function, systemKey?: string, sceneKey?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): this; /** - * Calculate the squared distance between two points. - * @param a The first point. - * @param b The second point. + * Adds a Script file, or array of Script files, to the current load queue. + * + * You can call this method from within your Scene's `preload`, along with any other files you wish to load: + * + * ```javascript + * function preload () + * { + * this.load.script('aliens', 'lib/aliens.js'); + * } + * ``` + * + * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, + * or if it's already running, when the next free load slot becomes available. This happens automatically if you + * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued + * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. + * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the + * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been + * loaded. + * + * The key must be a unique String and not already in-use by another file in the Loader. + * + * Instead of passing arguments you can pass a configuration object, such as: + * + * ```javascript + * this.load.script({ + * key: 'aliens', + * url: 'lib/aliens.js' + * }); + * ``` + * + * See the documentation for `Phaser.Types.Loader.FileTypes.ScriptFileConfig` for more details. + * + * Once the file has finished loading it will automatically be converted into a script element + * via `document.createElement('script')`. It will have its language set to JavaScript, `defer` set to + * false and then the resulting element will be appended to `document.head`. Any code then in the + * script will be executed. + * + * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. + * + * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "alien" + * and no URL is given then the Loader will set the URL to be "alien.js". It will always add `.js` as the extension, although + * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. + * + * Note: The ability to load this type of file will only be available if the Script File type has been built into Phaser. + * It is available in the default build but can be excluded from custom builds. + * @param key The key to use for this file, or a file configuration object, or array of them. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.js`, i.e. if `key` was "alien" then the URL will be "alien.js". + * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. */ - function BetweenPointsSquared(a: Phaser.Types.Math.Vector2Like, b: Phaser.Types.Math.Vector2Like): number; + script(key: string | Phaser.Types.Loader.FileTypes.ScriptFileConfig | Phaser.Types.Loader.FileTypes.ScriptFileConfig[], url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): this; /** - * Calculate the Chebyshev distance between two sets of coordinates (points). + * Adds a Sprite Sheet Image, or array of Sprite Sheet Images, to the current load queue. * - * Chebyshev distance (or chessboard distance) is the maximum of the horizontal and vertical distances. - * It's the effective distance when movement can be horizontal, vertical, or diagonal. - * @param x1 The x coordinate of the first point. - * @param y1 The y coordinate of the first point. - * @param x2 The x coordinate of the second point. - * @param y2 The y coordinate of the second point. + * The term 'Sprite Sheet' in Phaser means a fixed-size sheet. Where every frame in the sheet is the exact same size, + * and you reference those frames using numbers, not frame names. This is not the same thing as a Texture Atlas, where + * the frames are packed in a way where they take up the least amount of space, and are referenced by their names, + * not numbers. Some articles and software use the term 'Sprite Sheet' to mean Texture Atlas, so please be aware of + * what sort of file you're actually trying to load. + * + * You can call this method from within your Scene's `preload`, along with any other files you wish to load: + * + * ```javascript + * function preload () + * { + * this.load.spritesheet('bot', 'images/robot.png', { frameWidth: 32, frameHeight: 38 }); + * } + * ``` + * + * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, + * or if it's already running, when the next free load slot becomes available. This happens automatically if you + * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued + * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. + * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the + * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been + * loaded. + * + * Phaser can load all common image types: png, jpg, gif and any other format the browser can natively handle. + * If you try to load an animated gif only the first frame will be rendered. Browsers do not natively support playback + * of animated gifs to Canvas elements. + * + * The key must be a unique String. It is used to add the file to the global Texture Manager upon a successful load. + * The key should be unique both in terms of files being loaded and files already present in the Texture Manager. + * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file + * then remove it from the Texture Manager first, before loading a new one. + * + * Instead of passing arguments you can pass a configuration object, such as: + * + * ```javascript + * this.load.spritesheet({ + * key: 'bot', + * url: 'images/robot.png', + * frameConfig: { + * frameWidth: 32, + * frameHeight: 38, + * startFrame: 0, + * endFrame: 8 + * } + * }); + * ``` + * + * See the documentation for `Phaser.Types.Loader.FileTypes.SpriteSheetFileConfig` for more details. + * + * Once the file has finished loading you can use it as a texture for a Game Object by referencing its key: + * + * ```javascript + * this.load.spritesheet('bot', 'images/robot.png', { frameWidth: 32, frameHeight: 38 }); + * // and later in your game ... + * this.add.image(x, y, 'bot', 0); + * ``` + * + * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files + * key. For example, if the prefix was `PLAYER.` and the key was `Running` the final key will be `PLAYER.Running` and + * this is what you would use to retrieve the image from the Texture Manager. + * + * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. + * + * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "alien" + * and no URL is given then the Loader will set the URL to be "alien.png". It will always add `.png` as the extension, although + * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. + * + * Phaser also supports the automatic loading of associated normal maps. If you have a normal map to go with this image, + * then you can specify it by providing an array as the `url` where the second element is the normal map: + * + * ```javascript + * this.load.spritesheet('logo', [ 'images/AtariLogo.png', 'images/AtariLogo-n.png' ], { frameWidth: 256, frameHeight: 80 }); + * ``` + * + * Or, if you are using a config object use the `normalMap` property: + * + * ```javascript + * this.load.spritesheet({ + * key: 'logo', + * url: 'images/AtariLogo.png', + * normalMap: 'images/AtariLogo-n.png', + * frameConfig: { + * frameWidth: 256, + * frameHeight: 80 + * } + * }); + * ``` + * + * The normal map file is subject to the same conditions as the image file with regard to the path, baseURL, CORs and XHR Settings. + * Normal maps are a WebGL only feature. + * + * Note: The ability to load this type of file will only be available if the Sprite Sheet File type has been built into Phaser. + * It is available in the default build but can be excluded from custom builds. + * @param key The key to use for this file, or a file configuration object, or array of them. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". + * @param frameConfig The frame configuration object. At a minimum it should have a `frameWidth` property. + * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. */ - function Chebyshev(x1: number, y1: number, x2: number, y2: number): number; + spritesheet(key: string | Phaser.Types.Loader.FileTypes.SpriteSheetFileConfig | Phaser.Types.Loader.FileTypes.SpriteSheetFileConfig[], url?: string, frameConfig?: Phaser.Types.Loader.FileTypes.ImageFrameConfig, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): this; /** - * Calculate the distance between two sets of coordinates (points) to the power of `pow`. - * @param x1 The x coordinate of the first point. - * @param y1 The y coordinate of the first point. - * @param x2 The x coordinate of the second point. - * @param y2 The y coordinate of the second point. - * @param pow The exponent. + * Adds an SVG File, or array of SVG Files, to the current load queue. When the files are loaded they + * will be rendered to bitmap textures and stored in the Texture Manager. + * + * You can call this method from within your Scene's `preload`, along with any other files you wish to load: + * + * ```javascript + * function preload () + * { + * this.load.svg('morty', 'images/Morty.svg'); + * } + * ``` + * + * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, + * or if it's already running, when the next free load slot becomes available. This happens automatically if you + * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued + * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. + * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the + * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been + * loaded. + * + * The key must be a unique String. It is used to add the file to the global Texture Manager upon a successful load. + * The key should be unique both in terms of files being loaded and files already present in the Texture Manager. + * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file + * then remove it from the Texture Manager first, before loading a new one. + * + * Instead of passing arguments you can pass a configuration object, such as: + * + * ```javascript + * this.load.svg({ + * key: 'morty', + * url: 'images/Morty.svg' + * }); + * ``` + * + * See the documentation for `Phaser.Types.Loader.FileTypes.SVGFileConfig` for more details. + * + * Once the file has finished loading you can use it as a texture for a Game Object by referencing its key: + * + * ```javascript + * this.load.svg('morty', 'images/Morty.svg'); + * // and later in your game ... + * this.add.image(x, y, 'morty'); + * ``` + * + * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files + * key. For example, if the prefix was `MENU.` and the key was `Background` the final key will be `MENU.Background` and + * this is what you would use to retrieve the image from the Texture Manager. + * + * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. + * + * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "alien" + * and no URL is given then the Loader will set the URL to be "alien.html". It will always add `.html` as the extension, although + * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. + * + * You can optionally pass an SVG Resize Configuration object when you load an SVG file. By default the SVG will be rendered to a texture + * at the same size defined in the SVG file attributes. However, this isn't always desirable. You may wish to resize the SVG (either down + * or up) to improve texture clarity, or reduce texture memory consumption. You can either specify an exact width and height to resize + * the SVG to: + * + * ```javascript + * function preload () + * { + * this.load.svg('morty', 'images/Morty.svg', { width: 300, height: 600 }); + * } + * ``` + * + * Or when using a configuration object: + * + * ```javascript + * this.load.svg({ + * key: 'morty', + * url: 'images/Morty.svg', + * svgConfig: { + * width: 300, + * height: 600 + * } + * }); + * ``` + * + * Alternatively, you can just provide a scale factor instead: + * + * ```javascript + * function preload () + * { + * this.load.svg('morty', 'images/Morty.svg', { scale: 2.5 }); + * } + * ``` + * + * Or when using a configuration object: + * + * ```javascript + * this.load.svg({ + * key: 'morty', + * url: 'images/Morty.svg', + * svgConfig: { + * scale: 2.5 + * } + * }); + * ``` + * + * If scale, width and height values are all given, the scale has priority and the width and height values are ignored. + * + * Note: The ability to load this type of file will only be available if the SVG File type has been built into Phaser. + * It is available in the default build but can be excluded from custom builds. + * @param key The key to use for this file, or a file configuration object, or array of them. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.svg`, i.e. if `key` was "alien" then the URL will be "alien.svg". + * @param svgConfig The svg size configuration object. + * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. */ - function Power(x1: number, y1: number, x2: number, y2: number, pow: number): number; + svg(key: string | Phaser.Types.Loader.FileTypes.SVGFileConfig | Phaser.Types.Loader.FileTypes.SVGFileConfig[], url?: string, svgConfig?: Phaser.Types.Loader.FileTypes.SVGSizeConfig, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): this; /** - * Calculate the snake distance between two sets of coordinates (points). + * Adds a Text file, or array of Text files, to the current load queue. * - * Snake distance (rectilinear distance, Manhattan distance) is the sum of the horizontal and vertical distances. - * It's the effective distance when movement is allowed only horizontally or vertically (but not both). - * @param x1 The x coordinate of the first point. - * @param y1 The y coordinate of the first point. - * @param x2 The x coordinate of the second point. - * @param y2 The y coordinate of the second point. + * You can call this method from within your Scene's `preload`, along with any other files you wish to load: + * + * ```javascript + * function preload () + * { + * this.load.text('story', 'files/IntroStory.txt'); + * } + * ``` + * + * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, + * or if it's already running, when the next free load slot becomes available. This happens automatically if you + * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued + * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. + * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the + * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been + * loaded. + * + * The key must be a unique String. It is used to add the file to the global Text Cache upon a successful load. + * The key should be unique both in terms of files being loaded and files already present in the Text Cache. + * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file + * then remove it from the Text Cache first, before loading a new one. + * + * Instead of passing arguments you can pass a configuration object, such as: + * + * ```javascript + * this.load.text({ + * key: 'story', + * url: 'files/IntroStory.txt' + * }); + * ``` + * + * See the documentation for `Phaser.Types.Loader.FileTypes.TextFileConfig` for more details. + * + * Once the file has finished loading you can access it from its Cache using its key: + * + * ```javascript + * this.load.text('story', 'files/IntroStory.txt'); + * // and later in your game ... + * var data = this.cache.text.get('story'); + * ``` + * + * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files + * key. For example, if the prefix was `LEVEL1.` and the key was `Story` the final key will be `LEVEL1.Story` and + * this is what you would use to retrieve the text from the Text Cache. + * + * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. + * + * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "story" + * and no URL is given then the Loader will set the URL to be "story.txt". It will always add `.txt` as the extension, although + * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. + * + * Note: The ability to load this type of file will only be available if the Text File type has been built into Phaser. + * It is available in the default build but can be excluded from custom builds. + * @param key The key to use for this file, or a file configuration object, or array of them. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.txt`, i.e. if `key` was "alien" then the URL will be "alien.txt". + * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. */ - function Snake(x1: number, y1: number, x2: number, y2: number): number; + text(key: string | Phaser.Types.Loader.FileTypes.TextFileConfig | Phaser.Types.Loader.FileTypes.TextFileConfig[], url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): this; /** - * Calculate the distance between two sets of coordinates (points), squared. - * @param x1 The x coordinate of the first point. - * @param y1 The y coordinate of the first point. - * @param x2 The x coordinate of the second point. - * @param y2 The y coordinate of the second point. - */ - function Squared(x1: number, y1: number, x2: number, y2: number): number; - - } - - namespace Easing { - namespace Back { - /** - * Back ease-in. - * @param v The value to be tweened. - * @param overshoot The overshoot amount. Default 1.70158. - */ - function In(v: number, overshoot?: number): number; - - /** - * Back ease-in/out. - * @param v The value to be tweened. - * @param overshoot The overshoot amount. Default 1.70158. - */ - function InOut(v: number, overshoot?: number): number; - - /** - * Back ease-out. - * @param v The value to be tweened. - * @param overshoot The overshoot amount. Default 1.70158. - */ - function Out(v: number, overshoot?: number): number; + * Adds a CSV Tilemap file, or array of CSV files, to the current load queue. + * + * You can call this method from within your Scene's `preload`, along with any other files you wish to load: + * + * ```javascript + * function preload () + * { + * this.load.tilemapCSV('level1', 'maps/Level1.csv'); + * } + * ``` + * + * Tilemap CSV data can be created in a text editor, or a 3rd party app that exports as CSV. + * + * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, + * or if it's already running, when the next free load slot becomes available. This happens automatically if you + * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued + * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. + * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the + * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been + * loaded. + * + * The key must be a unique String. It is used to add the file to the global Tilemap Cache upon a successful load. + * The key should be unique both in terms of files being loaded and files already present in the Tilemap Cache. + * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file + * then remove it from the Text Cache first, before loading a new one. + * + * Instead of passing arguments you can pass a configuration object, such as: + * + * ```javascript + * this.load.tilemapCSV({ + * key: 'level1', + * url: 'maps/Level1.csv' + * }); + * ``` + * + * See the documentation for `Phaser.Types.Loader.FileTypes.TilemapCSVFileConfig` for more details. + * + * Once the file has finished loading you can access it from its Cache using its key: + * + * ```javascript + * this.load.tilemapCSV('level1', 'maps/Level1.csv'); + * // and later in your game ... + * var map = this.make.tilemap({ key: 'level1' }); + * ``` + * + * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files + * key. For example, if the prefix was `LEVEL1.` and the key was `Story` the final key will be `LEVEL1.Story` and + * this is what you would use to retrieve the text from the Tilemap Cache. + * + * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. + * + * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "level" + * and no URL is given then the Loader will set the URL to be "level.csv". It will always add `.csv` as the extension, although + * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. + * + * Note: The ability to load this type of file will only be available if the Tilemap CSV File type has been built into Phaser. + * It is available in the default build but can be excluded from custom builds. + * @param key The key to use for this file, or a file configuration object, or array of them. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.csv`, i.e. if `key` was "alien" then the URL will be "alien.csv". + * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. + */ + tilemapCSV(key: string | Phaser.Types.Loader.FileTypes.TilemapCSVFileConfig | Phaser.Types.Loader.FileTypes.TilemapCSVFileConfig[], url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): this; - } + /** + * Adds an Impact.js Tilemap file, or array of map files, to the current load queue. + * + * You can call this method from within your Scene's `preload`, along with any other files you wish to load: + * + * ```javascript + * function preload () + * { + * this.load.tilemapImpact('level1', 'maps/Level1.json'); + * } + * ``` + * + * Impact Tilemap data is created the Impact.js Map Editor called Weltmeister. + * + * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, + * or if it's already running, when the next free load slot becomes available. This happens automatically if you + * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued + * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. + * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the + * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been + * loaded. + * + * The key must be a unique String. It is used to add the file to the global Tilemap Cache upon a successful load. + * The key should be unique both in terms of files being loaded and files already present in the Tilemap Cache. + * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file + * then remove it from the Text Cache first, before loading a new one. + * + * Instead of passing arguments you can pass a configuration object, such as: + * + * ```javascript + * this.load.tilemapImpact({ + * key: 'level1', + * url: 'maps/Level1.json' + * }); + * ``` + * + * See the documentation for `Phaser.Types.Loader.FileTypes.TilemapImpactFileConfig` for more details. + * + * Once the file has finished loading you can access it from its Cache using its key: + * + * ```javascript + * this.load.tilemapImpact('level1', 'maps/Level1.json'); + * // and later in your game ... + * var map = this.make.tilemap({ key: 'level1' }); + * ``` + * + * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files + * key. For example, if the prefix was `LEVEL1.` and the key was `Story` the final key will be `LEVEL1.Story` and + * this is what you would use to retrieve the text from the Tilemap Cache. + * + * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. + * + * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "level" + * and no URL is given then the Loader will set the URL to be "level.json". It will always add `.json` as the extension, although + * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. + * + * Note: The ability to load this type of file will only be available if the Tilemap Impact File type has been built into Phaser. + * It is available in the default build but can be excluded from custom builds. + * @param key The key to use for this file, or a file configuration object, or array of them. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". + * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. + */ + tilemapImpact(key: string | Phaser.Types.Loader.FileTypes.TilemapImpactFileConfig | Phaser.Types.Loader.FileTypes.TilemapImpactFileConfig[], url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): this; - namespace Bounce { - /** - * Bounce ease-in. - * @param v The value to be tweened. - */ - function In(v: number): number; + /** + * Adds a Tiled JSON Tilemap file, or array of map files, to the current load queue. + * + * You can call this method from within your Scene's `preload`, along with any other files you wish to load: + * + * ```javascript + * function preload () + * { + * this.load.tilemapTiledJSON('level1', 'maps/Level1.json'); + * } + * ``` + * + * The Tilemap data is created using the Tiled Map Editor and selecting JSON as the export format. + * + * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, + * or if it's already running, when the next free load slot becomes available. This happens automatically if you + * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued + * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. + * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the + * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been + * loaded. + * + * The key must be a unique String. It is used to add the file to the global Tilemap Cache upon a successful load. + * The key should be unique both in terms of files being loaded and files already present in the Tilemap Cache. + * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file + * then remove it from the Text Cache first, before loading a new one. + * + * Instead of passing arguments you can pass a configuration object, such as: + * + * ```javascript + * this.load.tilemapTiledJSON({ + * key: 'level1', + * url: 'maps/Level1.json' + * }); + * ``` + * + * See the documentation for `Phaser.Types.Loader.FileTypes.TilemapJSONFileConfig` for more details. + * + * Once the file has finished loading you can access it from its Cache using its key: + * + * ```javascript + * this.load.tilemapTiledJSON('level1', 'maps/Level1.json'); + * // and later in your game ... + * var map = this.make.tilemap({ key: 'level1' }); + * ``` + * + * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files + * key. For example, if the prefix was `LEVEL1.` and the key was `Story` the final key will be `LEVEL1.Story` and + * this is what you would use to retrieve the text from the Tilemap Cache. + * + * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. + * + * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "level" + * and no URL is given then the Loader will set the URL to be "level.json". It will always add `.json` as the extension, although + * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. + * + * Note: The ability to load this type of file will only be available if the Tilemap JSON File type has been built into Phaser. + * It is available in the default build but can be excluded from custom builds. + * @param key The key to use for this file, or a file configuration object, or array of them. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". Or, a well formed JSON object. + * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. + */ + tilemapTiledJSON(key: string | Phaser.Types.Loader.FileTypes.TilemapJSONFileConfig | Phaser.Types.Loader.FileTypes.TilemapJSONFileConfig[], url?: object | string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): this; - /** - * Bounce ease-in/out. - * @param v The value to be tweened. - */ - function InOut(v: number): number; + /** + * Adds a Unity YAML based Texture Atlas, or array of atlases, to the current load queue. + * + * You can call this method from within your Scene's `preload`, along with any other files you wish to load: + * + * ```javascript + * function preload () + * { + * this.load.unityAtlas('mainmenu', 'images/MainMenu.png', 'images/MainMenu.txt'); + * } + * ``` + * + * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, + * or if it's already running, when the next free load slot becomes available. This happens automatically if you + * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued + * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. + * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the + * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been + * loaded. + * + * If you call this from outside of `preload` then you are responsible for starting the Loader afterwards and monitoring + * its events to know when it's safe to use the asset. Please see the Phaser.Loader.LoaderPlugin class for more details. + * + * Phaser expects the atlas data to be provided in a YAML formatted text file as exported from Unity. + * + * Phaser can load all common image types: png, jpg, gif and any other format the browser can natively handle. + * + * The key must be a unique String. It is used to add the file to the global Texture Manager upon a successful load. + * The key should be unique both in terms of files being loaded and files already present in the Texture Manager. + * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file + * then remove it from the Texture Manager first, before loading a new one. + * + * Instead of passing arguments you can pass a configuration object, such as: + * + * ```javascript + * this.load.unityAtlas({ + * key: 'mainmenu', + * textureURL: 'images/MainMenu.png', + * atlasURL: 'images/MainMenu.txt' + * }); + * ``` + * + * See the documentation for `Phaser.Types.Loader.FileTypes.UnityAtlasFileConfig` for more details. + * + * Once the atlas has finished loading you can use frames from it as textures for a Game Object by referencing its key: + * + * ```javascript + * this.load.unityAtlas('mainmenu', 'images/MainMenu.png', 'images/MainMenu.json'); + * // and later in your game ... + * this.add.image(x, y, 'mainmenu', 'background'); + * ``` + * + * To get a list of all available frames within an atlas please consult your Texture Atlas software. + * + * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files + * key. For example, if the prefix was `MENU.` and the key was `Background` the final key will be `MENU.Background` and + * this is what you would use to retrieve the image from the Texture Manager. + * + * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. + * + * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "alien" + * and no URL is given then the Loader will set the URL to be "alien.png". It will always add `.png` as the extension, although + * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. + * + * Phaser also supports the automatic loading of associated normal maps. If you have a normal map to go with this image, + * then you can specify it by providing an array as the `url` where the second element is the normal map: + * + * ```javascript + * this.load.unityAtlas('mainmenu', [ 'images/MainMenu.png', 'images/MainMenu-n.png' ], 'images/MainMenu.txt'); + * ``` + * + * Or, if you are using a config object use the `normalMap` property: + * + * ```javascript + * this.load.unityAtlas({ + * key: 'mainmenu', + * textureURL: 'images/MainMenu.png', + * normalMap: 'images/MainMenu-n.png', + * atlasURL: 'images/MainMenu.txt' + * }); + * ``` + * + * The normal map file is subject to the same conditions as the image file with regard to the path, baseURL, CORs and XHR Settings. + * Normal maps are a WebGL only feature. + * + * Note: The ability to load this type of file will only be available if the Unity Atlas File type has been built into Phaser. + * It is available in the default build but can be excluded from custom builds. + * @param key The key to use for this file, or a file configuration object, or array of them. + * @param textureURL The absolute or relative URL to load the texture image file from. If undefined or `null` it will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". + * @param atlasURL The absolute or relative URL to load the texture atlas data file from. If undefined or `null` it will be set to `.txt`, i.e. if `key` was "alien" then the URL will be "alien.txt". + * @param textureXhrSettings An XHR Settings configuration object for the atlas image file. Used in replacement of the Loaders default XHR Settings. + * @param atlasXhrSettings An XHR Settings configuration object for the atlas data file. Used in replacement of the Loaders default XHR Settings. + */ + unityAtlas(key: string | Phaser.Types.Loader.FileTypes.UnityAtlasFileConfig | Phaser.Types.Loader.FileTypes.UnityAtlasFileConfig[], textureURL?: string | string[], atlasURL?: string, textureXhrSettings?: Phaser.Types.Loader.XHRSettingsObject, atlasXhrSettings?: Phaser.Types.Loader.XHRSettingsObject): this; - /** - * Bounce ease-out. - * @param v The value to be tweened. - */ - function Out(v: number): number; + /** + * Adds a Video file, or array of video files, to the current load queue. + * + * You can call this method from within your Scene's `preload`, along with any other files you wish to load: + * + * ```javascript + * function preload () + * { + * this.load.video('intro', [ 'video/level1.mp4', 'video/level1.webm', 'video/level1.mov' ]); + * } + * ``` + * + * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, + * or if it's already running, when the next free load slot becomes available. This happens automatically if you + * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued + * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. + * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the + * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been + * loaded. + * + * The key must be a unique String. It is used to add the file to the global Video Cache upon a successful load. + * The key should be unique both in terms of files being loaded and files already present in the Video Cache. + * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file + * then remove it from the Video Cache first, before loading a new one. + * + * Instead of passing arguments you can pass a configuration object, such as: + * + * ```javascript + * this.load.video({ + * key: 'intro', + * url: [ 'video/level1.mp4', 'video/level1.webm', 'video/level1.mov' ], + * asBlob: false, + * noAudio: true + * }); + * ``` + * + * See the documentation for `Phaser.Types.Loader.FileTypes.VideoFileConfig` for more details. + * + * The URLs can be relative or absolute. If the URLs are relative the `Loader.baseURL` and `Loader.path` values will be prepended to them. + * + * Due to different browsers supporting different video file types you should usually provide your video files in a variety of formats. + * mp4, mov and webm are the most common. If you provide an array of URLs then the Loader will determine which _one_ file to load based on + * browser support, starting with the first in the array and progressing to the end. + * + * Unlike most asset-types, videos do not _need_ to be preloaded. You can create a Video Game Object and then call its `loadURL` method, + * to load a video at run-time, rather than in advance. + * + * Note: The ability to load this type of file will only be available if the Video File type has been built into Phaser. + * It is available in the default build but can be excluded from custom builds. + * @param key The key to use for this file, or a file configuration object, or array of them. + * @param urls The absolute or relative URL to load the video files from. + * @param loadEvent The load event to listen for when _not_ loading as a blob. Either `loadeddata`, `canplay` or `canplaythrough`. Default 'loadeddata'. + * @param asBlob Load the video as a data blob, or stream it via the Video element? Default false. + * @param noAudio Does the video have an audio track? If not you can enable auto-playing on it. Default false. + * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. + */ + video(key: string | Phaser.Types.Loader.FileTypes.VideoFileConfig | Phaser.Types.Loader.FileTypes.VideoFileConfig[], urls?: string | string[], loadEvent?: string, asBlob?: boolean, noAudio?: boolean, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): this; - } + /** + * Adds an XML file, or array of XML files, to the current load queue. + * + * You can call this method from within your Scene's `preload`, along with any other files you wish to load: + * + * ```javascript + * function preload () + * { + * this.load.xml('wavedata', 'files/AlienWaveData.xml'); + * } + * ``` + * + * The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts, + * or if it's already running, when the next free load slot becomes available. This happens automatically if you + * are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued + * it means you cannot use the file immediately after calling this method, but must wait for the file to complete. + * The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the + * Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been + * loaded. + * + * The key must be a unique String. It is used to add the file to the global XML Cache upon a successful load. + * The key should be unique both in terms of files being loaded and files already present in the XML Cache. + * Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file + * then remove it from the XML Cache first, before loading a new one. + * + * Instead of passing arguments you can pass a configuration object, such as: + * + * ```javascript + * this.load.xml({ + * key: 'wavedata', + * url: 'files/AlienWaveData.xml' + * }); + * ``` + * + * See the documentation for `Phaser.Types.Loader.FileTypes.XMLFileConfig` for more details. + * + * Once the file has finished loading you can access it from its Cache using its key: + * + * ```javascript + * this.load.xml('wavedata', 'files/AlienWaveData.xml'); + * // and later in your game ... + * var data = this.cache.xml.get('wavedata'); + * ``` + * + * If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files + * key. For example, if the prefix was `LEVEL1.` and the key was `Waves` the final key will be `LEVEL1.Waves` and + * this is what you would use to retrieve the text from the XML Cache. + * + * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. + * + * If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "data" + * and no URL is given then the Loader will set the URL to be "data.xml". It will always add `.xml` as the extension, although + * this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL. + * + * Note: The ability to load this type of file will only be available if the XML File type has been built into Phaser. + * It is available in the default build but can be excluded from custom builds. + * @param key The key to use for this file, or a file configuration object, or array of them. + * @param url The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.xml`, i.e. if `key` was "alien" then the URL will be "alien.xml". + * @param xhrSettings An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings. + */ + xml(key: string | Phaser.Types.Loader.FileTypes.XMLFileConfig | Phaser.Types.Loader.FileTypes.XMLFileConfig[], url?: string, xhrSettings?: Phaser.Types.Loader.XHRSettingsObject): this; - namespace Circular { - /** - * Circular ease-in. - * @param v The value to be tweened. - */ - function In(v: number): number; + /** + * The Scene which owns this Loader instance. + */ + scene: Phaser.Scene; - /** - * Circular ease-in/out. - * @param v The value to be tweened. - */ - function InOut(v: number): number; + /** + * A reference to the Scene Systems. + */ + systems: Phaser.Scenes.Systems; - /** - * Circular ease-out. - * @param v The value to be tweened. - */ - function Out(v: number): number; + /** + * A reference to the global Cache Manager. + */ + cacheManager: Phaser.Cache.CacheManager; - } + /** + * A reference to the global Texture Manager. + */ + textureManager: Phaser.Textures.TextureManager; - namespace Cubic { - /** - * Cubic ease-in. - * @param v The value to be tweened. - */ - function In(v: number): number; + /** + * A reference to the global Scene Manager. + */ + protected sceneManager: Phaser.Scenes.SceneManager; - /** - * Cubic ease-in/out. - * @param v The value to be tweened. - */ - function InOut(v: number): number; + /** + * An optional prefix that is automatically prepended to the start of every file key. + * If prefix was `MENU.` and you load an image with the key 'Background' the resulting key would be `MENU.Background`. + * You can set this directly, or call `Loader.setPrefix()`. It will then affect every file added to the Loader + * from that point on. It does _not_ change any file already in the load queue. + */ + prefix: string; - /** - * Cubic ease-out. - * @param v The value to be tweened. - */ - function Out(v: number): number; + /** + * The value of `path`, if set, is placed before any _relative_ file path given. For example: + * + * ```javascript + * this.load.path = "images/sprites/"; + * this.load.image("ball", "ball.png"); + * this.load.image("tree", "level1/oaktree.png"); + * this.load.image("boom", "http://server.com/explode.png"); + * ``` + * + * Would load the `ball` file from `images/sprites/ball.png` and the tree from + * `images/sprites/level1/oaktree.png` but the file `boom` would load from the URL + * given as it's an absolute URL. + * + * Please note that the path is added before the filename but *after* the baseURL (if set.) + * + * If you set this property directly then it _must_ end with a "/". Alternatively, call `setPath()` and it'll do it for you. + */ + path: string; - } + /** + * If you want to append a URL before the path of any asset you can set this here. + * + * Useful if allowing the asset base url to be configured outside of the game code. + * + * If you set this property directly then it _must_ end with a "/". Alternatively, call `setBaseURL()` and it'll do it for you. + */ + baseURL: string; - namespace Elastic { - /** - * Elastic ease-in. - * @param v The value to be tweened. - * @param amplitude The amplitude of the elastic ease. Default 0.1. - * @param period Sets how tight the sine-wave is, where smaller values are tighter waves, which result in more cycles. Default 0.1. - */ - function In(v: number, amplitude?: number, period?: number): number; - - /** - * Elastic ease-in/out. - * @param v The value to be tweened. - * @param amplitude The amplitude of the elastic ease. Default 0.1. - * @param period Sets how tight the sine-wave is, where smaller values are tighter waves, which result in more cycles. Default 0.1. - */ - function InOut(v: number, amplitude?: number, period?: number): number; - - /** - * Elastic ease-out. - * @param v The value to be tweened. - * @param amplitude The amplitude of the elastic ease. Default 0.1. - * @param period Sets how tight the sine-wave is, where smaller values are tighter waves, which result in more cycles. Default 0.1. - */ - function Out(v: number, amplitude?: number, period?: number): number; - - } - - namespace Expo { - /** - * Exponential ease-in. - * @param v The value to be tweened. - */ - function In(v: number): number; - - /** - * Exponential ease-in/out. - * @param v The value to be tweened. - */ - function InOut(v: number): number; - - /** - * Exponential ease-out. - * @param v The value to be tweened. - */ - function Out(v: number): number; - - } - - namespace Linear { - /** - * Linear easing (no variation). - * @param v The value to be tweened. - */ - function Linear(v: number): number; - - } - - namespace Quadratic { - /** - * Quadratic ease-in. - * @param v The value to be tweened. - */ - function In(v: number): number; - - /** - * Quadratic ease-in/out. - * @param v The value to be tweened. - */ - function InOut(v: number): number; - - /** - * Quadratic ease-out. - * @param v The value to be tweened. - */ - function Out(v: number): number; - - } - - namespace Quartic { - /** - * Quartic ease-in. - * @param v The value to be tweened. - */ - function In(v: number): number; - - /** - * Quartic ease-in/out. - * @param v The value to be tweened. - */ - function InOut(v: number): number; - - /** - * Quartic ease-out. - * @param v The value to be tweened. - */ - function Out(v: number): number; - - } - - namespace Quintic { - /** - * Quintic ease-in. - * @param v The value to be tweened. - */ - function In(v: number): number; - - /** - * Quintic ease-in/out. - * @param v The value to be tweened. - */ - function InOut(v: number): number; - - /** - * Quintic ease-out. - * @param v The value to be tweened. - */ - function Out(v: number): number; - - } - - namespace Sine { - /** - * Sinusoidal ease-in. - * @param v The value to be tweened. - */ - function In(v: number): number; - - /** - * Sinusoidal ease-in/out. - * @param v The value to be tweened. - */ - function InOut(v: number): number; - - /** - * Sinusoidal ease-out. - * @param v The value to be tweened. - */ - function Out(v: number): number; - - } - - namespace Stepped { - /** - * Stepped easing. - * @param v The value to be tweened. - * @param steps The number of steps in the ease. Default 1. - */ - function Stepped(v: number, steps?: number): number; - - } - - } - - /** - * Calculates the factorial of a given number for integer values greater than 0. - * @param value A positive integer to calculate the factorial of. - */ - function Factorial(value: number): number; - - /** - * Generate a random floating point number between the two given bounds, minimum inclusive, maximum exclusive. - * @param min The lower bound for the float, inclusive. - * @param max The upper bound for the float exclusive. - */ - function FloatBetween(min: number, max: number): number; - - /** - * Floors to some place comparative to a `base`, default is 10 for decimal place. - * - * The `place` is represented by the power applied to `base` to get that place. - * @param value The value to round. - * @param place The place to round to. Default 0. - * @param base The base to round in. Default is 10 for decimal. Default 10. - */ - function FloorTo(value: number, place?: integer, base?: integer): number; - - /** - * Return a value based on the range between `min` and `max` and the percentage given. - * @param percent A value between 0 and 1 representing the percentage. - * @param min The minimum value. - * @param max The maximum value. - */ - function FromPercent(percent: number, min: number, max?: number): number; - - namespace Fuzzy { /** - * Calculate the fuzzy ceiling of the given value. - * @param value The value. - * @param epsilon The epsilon. Default 0.0001. + * The number of concurrent / parallel resources to try and fetch at once. + * + * Old browsers limit 6 requests per domain; modern ones, especially those with HTTP/2 don't limit it at all. + * + * The default is 32 but you can change this in your Game Config, or by changing this property before the Loader starts. */ - function Ceil(value: number, epsilon?: number): number; + maxParallelDownloads: number; /** - * Check whether the given values are fuzzily equal. - * - * Two numbers are fuzzily equal if their difference is less than `epsilon`. - * @param a The first value. - * @param b The second value. - * @param epsilon The epsilon. Default 0.0001. + * xhr specific global settings (can be overridden on a per-file basis) */ - function Equal(a: number, b: number, epsilon?: number): boolean; + xhr: Phaser.Types.Loader.XHRSettingsObject; /** - * Calculate the fuzzy floor of the given value. - * @param value The value. - * @param epsilon The epsilon. Default 0.0001. + * The crossOrigin value applied to loaded images. Very often this needs to be set to 'anonymous'. */ - function Floor(value: number, epsilon?: number): number; + crossOrigin: string; /** - * Check whether `a` is fuzzily greater than `b`. - * - * `a` is fuzzily greater than `b` if it is more than `b - epsilon`. - * @param a The first value. - * @param b The second value. - * @param epsilon The epsilon. Default 0.0001. + * The total number of files to load. It may not always be accurate because you may add to the Loader during the process + * of loading, especially if you load a Pack File. Therefore this value can change, but in most cases remains static. */ - function GreaterThan(a: number, b: number, epsilon?: number): boolean; + totalToLoad: number; /** - * Check whether `a` is fuzzily less than `b`. - * - * `a` is fuzzily less than `b` if it is less than `b + epsilon`. - * @param a The first value. - * @param b The second value. - * @param epsilon The epsilon. Default 0.0001. + * The progress of the current load queue, as a float value between 0 and 1. + * This is updated automatically as files complete loading. + * Note that it is possible for this value to go down again if you add content to the current load queue during a load. */ - function LessThan(a: number, b: number, epsilon?: number): boolean; - - } - - /** - * Calculate a per-ms speed from a distance and time (given in seconds). - * @param distance The distance. - * @param time The time, in seconds. - */ - function GetSpeed(distance: number, time: integer): number; + progress: number; - namespace Interpolation { /** - * A bezier interpolation method. - * @param v The input array of values to interpolate between. - * @param k The percentage of interpolation, between 0 and 1. + * Files are placed in this Set when they're added to the Loader via `addFile`. + * + * They are moved to the `inflight` Set when they start loading, and assuming a successful + * load, to the `queue` Set for further processing. + * + * By the end of the load process this Set will be empty. */ - function Bezier(v: number[], k: number): number; + list: Phaser.Structs.Set; /** - * A Catmull-Rom interpolation method. - * @param v The input array of values to interpolate between. - * @param k The percentage of interpolation, between 0 and 1. + * Files are stored in this Set while they're in the process of being loaded. + * + * Upon a successful load they are moved to the `queue` Set. + * + * By the end of the load process this Set will be empty. */ - function CatmullRom(v: number[], k: number): number; + inflight: Phaser.Structs.Set; /** - * A cubic bezier interpolation method. + * Files are stored in this Set while they're being processed. * - * https://medium.com/@adrian_cooney/bezier-interpolation-13b68563313a - * @param t The percentage of interpolation, between 0 and 1. - * @param p0 The start point. - * @param p1 The first control point. - * @param p2 The second control point. - * @param p3 The end point. + * If the process is successful they are moved to their final destination, which could be + * a Cache or the Texture Manager. + * + * At the end of the load process this Set will be empty. */ - function CubicBezier(t: number, p0: number, p1: number, p2: number, p3: number): number; + queue: Phaser.Structs.Set; /** - * A linear interpolation method. - * @param v The input array of values to interpolate between. - * @param k The percentage of interpolation, between 0 and 1. + * The total number of files that failed to load during the most recent load. + * This value is reset when you call `Loader.start`. */ - function Linear(v: number[], k: number): number; + totalFailed: number; /** - * A quadratic bezier interpolation method. - * @param t The percentage of interpolation, between 0 and 1. - * @param p0 The start point. - * @param p1 The control point. - * @param p2 The end point. + * The total number of files that successfully loaded during the most recent load. + * This value is reset when you call `Loader.start`. */ - function QuadraticBezier(t: number, p0: number, p1: number, p2: number): number; + totalComplete: number; /** - * A Smoother Step interpolation method. - * @param t The percentage of interpolation, between 0 and 1. - * @param min The minimum value, also known as the 'left edge', assumed smaller than the 'right edge'. - * @param max The maximum value, also known as the 'right edge', assumed greater than the 'left edge'. + * The current state of the Loader. */ - function SmootherStep(t: number, min: number, max: number): number; + readonly state: number; /** - * A Smooth Step interpolation method. - * @param t The percentage of interpolation, between 0 and 1. - * @param min The minimum value, also known as the 'left edge', assumed smaller than the 'right edge'. - * @param max The maximum value, also known as the 'right edge', assumed greater than the 'left edge'. + * If you want to append a URL before the path of any asset you can set this here. + * + * Useful if allowing the asset base url to be configured outside of the game code. + * + * Once a base URL is set it will affect every file loaded by the Loader from that point on. It does _not_ change any + * file _already_ being loaded. To reset it, call this method with no arguments. + * @param url The URL to use. Leave empty to reset. */ - function SmoothStep(t: number, min: number, max: number): number; - - } - - /** - * Check if a given value is an even number. - * @param value The number to perform the check with. - */ - function IsEven(value: number): boolean; - - /** - * Check if a given value is an even number using a strict type check. - * @param value The number to perform the check with. - */ - function IsEvenStrict(value: number): boolean; - - /** - * Calculates a linear (interpolation) value over t. - * @param p0 The first point. - * @param p1 The second point. - * @param t The percentage between p0 and p1 to return, represented as a number between 0 and 1. - */ - function Linear(p0: number, p1: number, t: number): number; + setBaseURL(url?: string): this; - /** - * A three-dimensional matrix. - * - * Defaults to the identity matrix when instantiated. - */ - class Matrix3 { /** + * The value of `path`, if set, is placed before any _relative_ file path given. For example: * - * @param m Optional Matrix3 to copy values from. + * ```javascript + * this.load.setPath("images/sprites/"); + * this.load.image("ball", "ball.png"); + * this.load.image("tree", "level1/oaktree.png"); + * this.load.image("boom", "http://server.com/explode.png"); + * ``` + * + * Would load the `ball` file from `images/sprites/ball.png` and the tree from + * `images/sprites/level1/oaktree.png` but the file `boom` would load from the URL + * given as it's an absolute URL. + * + * Please note that the path is added before the filename but *after* the baseURL (if set.) + * + * Once a path is set it will then affect every file added to the Loader from that point on. It does _not_ change any + * file _already_ in the load queue. To reset it, call this method with no arguments. + * @param path The path to use. Leave empty to reset. */ - constructor(m?: Phaser.Math.Matrix3); + setPath(path?: string): this; /** - * The matrix values. + * An optional prefix that is automatically prepended to the start of every file key. + * + * If prefix was `MENU.` and you load an image with the key 'Background' the resulting key would be `MENU.Background`. + * + * Once a prefix is set it will then affect every file added to the Loader from that point on. It does _not_ change any + * file _already_ in the load queue. To reset it, call this method with no arguments. + * @param prefix The prefix to use. Leave empty to reset. */ - val: Float32Array; + setPrefix(prefix?: string): this; /** - * Make a clone of this Matrix3. + * Sets the Cross Origin Resource Sharing value used when loading files. + * + * Files can override this value on a per-file basis by specifying an alternative `crossOrigin` value in their file config. + * + * Once CORs is set it will then affect every file loaded by the Loader from that point on, as long as they don't have + * their own CORs setting. To reset it, call this method with no arguments. + * + * For more details about CORs see https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS + * @param crossOrigin The value to use for the `crossOrigin` property in the load request. */ - clone(): Phaser.Math.Matrix3; + setCORS(crossOrigin?: string): this; /** - * This method is an alias for `Matrix3.copy`. - * @param src The Matrix to set the values of this Matrix's from. + * Adds a file, or array of files, into the load queue. + * + * The file must be an instance of `Phaser.Loader.File`, or a class that extends it. The Loader will check that the key + * used by the file won't conflict with any other key either in the loader, the inflight queue or the target cache. + * If allowed it will then add the file into the pending list, read for the load to start. Or, if the load has already + * started, ready for the next batch of files to be pulled from the list to the inflight queue. + * + * You should not normally call this method directly, but rather use one of the Loader methods like `image` or `atlas`, + * however you can call this as long as the file given to it is well formed. + * @param file The file, or array of files, to be added to the load queue. */ - set(src: Phaser.Math.Matrix3): Phaser.Math.Matrix3; + addFile(file: Phaser.Loader.File | Phaser.Loader.File[]): void; /** - * Copy the values of a given Matrix into this Matrix. - * @param src The Matrix to copy the values from. + * Checks the key and type of the given file to see if it will conflict with anything already + * in a Cache, the Texture Manager, or the list or inflight queues. + * @param file The file to check the key of. */ - copy(src: Phaser.Math.Matrix3): Phaser.Math.Matrix3; + keyExists(file: Phaser.Loader.File): boolean; /** - * Copy the values of a given Matrix4 into this Matrix3. - * @param m The Matrix4 to copy the values from. + * Takes a well formed, fully parsed pack file object and adds its entries into the load queue. Usually you do not call + * this method directly, but instead use `Loader.pack` and supply a path to a JSON file that holds the + * pack data. However, if you've got the data prepared you can pass it to this method. + * + * You can also provide an optional key. If you do then it will only add the entries from that part of the pack into + * to the load queue. If not specified it will add all entries it finds. For more details about the pack file format + * see the `LoaderPlugin.pack` method. + * @param pack The Pack File data to be parsed and each entry of it to added to the load queue. + * @param packKey An optional key to use from the pack file data. */ - fromMat4(m: Phaser.Math.Matrix4): Phaser.Math.Matrix3; + addPack(pack: any, packKey?: string): boolean; /** - * Set the values of this Matrix from the given array. - * @param a The array to copy the values from. + * Is the Loader actively loading, or processing loaded files? */ - fromArray(a: any[]): Phaser.Math.Matrix3; + isLoading(): boolean; /** - * Reset this Matrix to an identity (default) matrix. + * Is the Loader ready to start a new load? */ - identity(): Phaser.Math.Matrix3; + isReady(): boolean; /** - * Transpose this Matrix. + * Starts the Loader running. This will reset the progress and totals and then emit a `start` event. + * If there is nothing in the queue the Loader will immediately complete, otherwise it will start + * loading the first batch of files. + * + * The Loader is started automatically if the queue is populated within your Scenes `preload` method. + * + * However, outside of this, you need to call this method to start it. + * + * If the Loader is already running this method will simply return. */ - transpose(): Phaser.Math.Matrix3; + start(): void; /** - * Invert this Matrix. + * Called automatically during the load process. + * It updates the `progress` value and then emits a progress event, which you can use to + * display a loading bar in your game. */ - invert(): Phaser.Math.Matrix3; + updateProgress(): void; /** - * Calculate the adjoint, or adjugate, of this Matrix. + * Called automatically during the load process. */ - adjoint(): Phaser.Math.Matrix3; + update(): void; /** - * Calculate the determinant of this Matrix. + * An internal method called automatically by the XHRLoader belong to a File. + * + * This method will remove the given file from the inflight Set and update the load progress. + * If the file was successful its `onProcess` method is called, otherwise it is added to the delete queue. + * @param file The File that just finished loading, or errored during load. + * @param success `true` if the file loaded successfully, otherwise `false`. */ - determinant(): number; + nextFile(file: Phaser.Loader.File, success: boolean): void; /** - * Multiply this Matrix by the given Matrix. - * @param src The Matrix to multiply this Matrix by. + * An internal method that is called automatically by the File when it has finished processing. + * + * If the process was successful, and the File isn't part of a MultiFile, its `addToCache` method is called. + * + * It this then removed from the queue. If there are no more files to load `loadComplete` is called. + * @param file The file that has finished processing. */ - multiply(src: Phaser.Math.Matrix3): Phaser.Math.Matrix3; + fileProcessComplete(file: Phaser.Loader.File): void; /** - * Translate this Matrix using the given Vector. - * @param v The Vector to translate this Matrix with. + * Called at the end when the load queue is exhausted and all files have either loaded or errored. + * By this point every loaded file will now be in its associated cache and ready for use. + * + * Also clears down the Sets, puts progress to 1 and clears the deletion queue. */ - translate(v: Phaser.Math.Vector2 | Phaser.Math.Vector3 | Phaser.Math.Vector4): Phaser.Math.Matrix3; + loadComplete(): void; /** - * Apply a rotation transformation to this Matrix. - * @param rad The angle in radians to rotate by. + * Adds a File into the pending-deletion queue. + * @param file The File to be queued for deletion when the Loader completes. */ - rotate(rad: number): Phaser.Math.Matrix3; + flagForRemoval(file: Phaser.Loader.File): void; /** - * Apply a scale transformation to this Matrix. + * Converts the given JSON data into a file that the browser then prompts you to download so you can save it locally. * - * Uses the `x` and `y` components of the given Vector to scale the Matrix. - * @param v The Vector to scale this Matrix with. + * The data must be well formed JSON and ready-parsed, not a JavaScript object. + * @param data The JSON data, ready parsed. + * @param filename The name to save the JSON file as. Default file.json. */ - scale(v: Phaser.Math.Vector2 | Phaser.Math.Vector3 | Phaser.Math.Vector4): Phaser.Math.Matrix3; + saveJSON(data: any, filename?: string): this; /** - * Set the values of this Matrix from the given Quaternion. - * @param q The Quaternion to set the values of this Matrix from. + * Causes the browser to save the given data as a file to its default Downloads folder. + * + * Creates a DOM level anchor link, assigns it as being a `download` anchor, sets the href + * to be an ObjectURL based on the given data, and then invokes a click event. + * @param data The data to be saved. Will be passed through URL.createObjectURL. + * @param filename The filename to save the file as. Default file.json. + * @param filetype The file type to use when saving the file. Defaults to JSON. Default application/json. */ - fromQuat(q: Phaser.Math.Quaternion): Phaser.Math.Matrix3; + save(data: any, filename?: string, filetype?: string): this; /** - * [description] - * @param m [description] + * Resets the Loader. + * + * This will clear all lists and reset the base URL, path and prefix. + * + * Warning: If the Loader is currently downloading files, or has files in its queue, they will be aborted. */ - normalFromMat4(m: Phaser.Math.Matrix4): Phaser.Math.Matrix3; + reset(): void; } /** - * A four-dimensional matrix. + * Takes two XHRSettings Objects and creates a new XHRSettings object from them. + * + * The new object is seeded by the values given in the global settings, but any setting in + * the local object overrides the global ones. + * @param global The global XHRSettings object. + * @param local The local XHRSettings object. */ - class Matrix4 { + function MergeXHRSettings(global: Phaser.Types.Loader.XHRSettingsObject, local: Phaser.Types.Loader.XHRSettingsObject): Phaser.Types.Loader.XHRSettingsObject; + + /** + * A MultiFile is a special kind of parent that contains two, or more, Files as children and looks after + * the loading and processing of them all. It is commonly extended and used as a base class for file types such as AtlasJSON or BitmapFont. + * + * You shouldn't create an instance of a MultiFile directly, but should extend it with your own class, setting a custom type and processing methods. + */ + class MultiFile { /** * - * @param m Optional Matrix4 to copy values from. + * @param loader The Loader that is going to load this File. + * @param type The file type string for sorting within the Loader. + * @param key The key of the file within the loader. + * @param files An array of Files that make-up this MultiFile. */ - constructor(m?: Phaser.Math.Matrix4); + constructor(loader: Phaser.Loader.LoaderPlugin, type: string, key: string, files: Phaser.Loader.File[]); /** - * The matrix values. + * A reference to the Loader that is going to load this file. */ - val: Float32Array; + loader: Phaser.Loader.LoaderPlugin; /** - * Make a clone of this Matrix4. + * The file type string for sorting within the Loader. */ - clone(): Phaser.Math.Matrix4; + type: string; /** - * This method is an alias for `Matrix4.copy`. - * @param src The Matrix to set the values of this Matrix's from. - */ - set(src: Phaser.Math.Matrix4): Phaser.Math.Matrix4; - - /** - * Copy the values of a given Matrix into this Matrix. - * @param src The Matrix to copy the values from. + * Unique cache key (unique within its file type) */ - copy(src: Phaser.Math.Matrix4): Phaser.Math.Matrix4; + key: string; /** - * Set the values of this Matrix from the given array. - * @param a The array to copy the values from. + * Array of files that make up this MultiFile. */ - fromArray(a: any[]): Phaser.Math.Matrix4; + files: Phaser.Loader.File[]; /** - * Reset this Matrix. - * - * Sets all values to `0`. + * The completion status of this MultiFile. */ - zero(): Phaser.Math.Matrix4; + complete: boolean; /** - * Set the `x`, `y` and `z` values of this Matrix. - * @param x The x value. - * @param y The y value. - * @param z The z value. + * The number of files to load. */ - xyz(x: number, y: number, z: number): Phaser.Math.Matrix4; + pending: number; /** - * Set the scaling values of this Matrix. - * @param x The x scaling value. - * @param y The y scaling value. - * @param z The z scaling value. + * The number of files that failed to load. */ - scaling(x: number, y: number, z: number): Phaser.Math.Matrix4; + failed: number; /** - * Reset this Matrix to an identity (default) matrix. + * A storage container for transient data that the loading files need. */ - identity(): Phaser.Math.Matrix4; + config: any; /** - * Transpose this Matrix. + * A reference to the Loaders baseURL at the time this MultiFile was created. + * Used to populate child-files. */ - transpose(): Phaser.Math.Matrix4; + baseURL: string; /** - * Invert this Matrix. + * A reference to the Loaders path at the time this MultiFile was created. + * Used to populate child-files. */ - invert(): Phaser.Math.Matrix4; + path: string; /** - * Calculate the adjoint, or adjugate, of this Matrix. + * A reference to the Loaders prefix at the time this MultiFile was created. + * Used to populate child-files. */ - adjoint(): Phaser.Math.Matrix4; + prefix: string; /** - * Calculate the determinant of this Matrix. + * Checks if this MultiFile is ready to process its children or not. */ - determinant(): number; + isReadyToProcess(): boolean; /** - * Multiply this Matrix by the given Matrix. - * @param src The Matrix to multiply this Matrix by. + * Adds another child to this MultiFile, increases the pending count and resets the completion status. + * @param files The File to add to this MultiFile. */ - multiply(src: Phaser.Math.Matrix4): Phaser.Math.Matrix4; + addToMultiFile(files: Phaser.Loader.File): Phaser.Loader.MultiFile; /** - * [description] - * @param src [description] + * Called by each File when it finishes loading. + * @param file The File that has completed processing. */ - multiplyLocal(src: Phaser.Math.Matrix4): Phaser.Math.Matrix4; + onFileComplete(file: Phaser.Loader.File): void; /** - * Translate this Matrix using the given Vector. - * @param v The Vector to translate this Matrix with. + * Called by each File that fails to load. + * @param file The File that has failed to load. */ - translate(v: Phaser.Math.Vector3 | Phaser.Math.Vector4): Phaser.Math.Matrix4; + onFileFailed(file: Phaser.Loader.File): void; - /** - * Translate this Matrix using the given values. - * @param x The x component. - * @param y The y component. - * @param z The z component. - */ - translateXYZ(x: number, y: number, z: number): Phaser.Math.Matrix4; + } - /** - * Apply a scale transformation to this Matrix. - * - * Uses the `x`, `y` and `z` components of the given Vector to scale the Matrix. - * @param v The Vector to scale this Matrix with. - */ - scale(v: Phaser.Math.Vector3 | Phaser.Math.Vector4): Phaser.Math.Matrix4; + /** + * Creates a new XMLHttpRequest (xhr) object based on the given File and XHRSettings + * and starts the download of it. It uses the Files own XHRSettings and merges them + * with the global XHRSettings object to set the xhr values before download. + * @param file The File to download. + * @param globalXHRSettings The global XHRSettings object. + */ + function XHRLoader(file: Phaser.Loader.File, globalXHRSettings: Phaser.Types.Loader.XHRSettingsObject): XMLHttpRequest; - /** - * Apply a scale transformation to this Matrix. - * @param x The x component. - * @param y The y component. - * @param z The z component. - */ - scaleXYZ(x: number, y: number, z: number): Phaser.Math.Matrix4; + /** + * Creates an XHRSettings Object with default values. + * @param responseType The responseType, such as 'text'. Default ''. + * @param async Should the XHR request use async or not? Default true. + * @param user Optional username for the XHR request. Default ''. + * @param password Optional password for the XHR request. Default ''. + * @param timeout Optional XHR timeout value. Default 0. + * @param withCredentials Optional XHR withCredentials value. Default false. + */ + function XHRSettings(responseType?: XMLHttpRequestResponseType, async?: boolean, user?: string, password?: string, timeout?: number, withCredentials?: boolean): Phaser.Types.Loader.XHRSettingsObject; - /** - * Derive a rotation matrix around the given axis. - * @param axis The rotation axis. - * @param angle The rotation angle in radians. - */ - makeRotationAxis(axis: Phaser.Math.Vector3 | Phaser.Math.Vector4, angle: number): Phaser.Math.Matrix4; + } + namespace Math { + namespace Angle { /** - * Apply a rotation transformation to this Matrix. - * @param rad The angle in radians to rotate by. - * @param axis The axis to rotate upon. + * Find the angle of a segment from (x1, y1) -> (x2, y2). + * @param x1 The x coordinate of the first point. + * @param y1 The y coordinate of the first point. + * @param x2 The x coordinate of the second point. + * @param y2 The y coordinate of the second point. */ - rotate(rad: number, axis: Phaser.Math.Vector3): Phaser.Math.Matrix4; + function Between(x1: number, y1: number, x2: number, y2: number): number; /** - * Rotate this matrix on its X axis. - * @param rad The angle in radians to rotate by. + * Find the angle of a segment from (point1.x, point1.y) -> (point2.x, point2.y). + * + * Calculates the angle of the vector from the first point to the second point. + * @param point1 The first point. + * @param point2 The second point. */ - rotateX(rad: number): Phaser.Math.Matrix4; + function BetweenPoints(point1: Phaser.Types.Math.Vector2Like, point2: Phaser.Types.Math.Vector2Like): number; /** - * Rotate this matrix on its Y axis. - * @param rad The angle to rotate by, in radians. + * Find the angle of a segment from (point1.x, point1.y) -> (point2.x, point2.y). + * + * The difference between this method and {@link Phaser.Math.Angle.BetweenPoints} is that this assumes the y coordinate + * travels down the screen. + * @param point1 The first point. + * @param point2 The second point. */ - rotateY(rad: number): Phaser.Math.Matrix4; + function BetweenPointsY(point1: Phaser.Types.Math.Vector2Like, point2: Phaser.Types.Math.Vector2Like): number; /** - * Rotate this matrix on its Z axis. - * @param rad The angle to rotate by, in radians. + * Find the angle of a segment from (x1, y1) -> (x2, y2). + * + * The difference between this method and {@link Phaser.Math.Angle.Between} is that this assumes the y coordinate + * travels down the screen. + * @param x1 The x coordinate of the first point. + * @param y1 The y coordinate of the first point. + * @param x2 The x coordinate of the second point. + * @param y2 The y coordinate of the second point. */ - rotateZ(rad: number): Phaser.Math.Matrix4; + function BetweenY(x1: number, y1: number, x2: number, y2: number): number; /** - * Set the values of this Matrix from the given rotation Quaternion and translation Vector. - * @param q The Quaternion to set rotation from. - * @param v The Vector to set translation from. + * Takes an angle in Phasers default clockwise format and converts it so that + * 0 is North, 90 is West, 180 is South and 270 is East, + * therefore running counter-clockwise instead of clockwise. + * + * You can pass in the angle from a Game Object using: + * + * ```javascript + * var converted = CounterClockwise(gameobject.rotation); + * ``` + * + * All values for this function are in radians. + * @param angle The angle to convert, in radians. */ - fromRotationTranslation(q: Phaser.Math.Quaternion, v: Phaser.Math.Vector3): Phaser.Math.Matrix4; + function CounterClockwise(angle: number): number; /** - * Set the values of this Matrix from the given Quaternion. - * @param q The Quaternion to set the values of this Matrix from. + * Normalize an angle to the [0, 2pi] range. + * @param angle The angle to normalize, in radians. */ - fromQuat(q: Phaser.Math.Quaternion): Phaser.Math.Matrix4; + function Normalize(angle: number): number; /** - * Generate a frustum matrix with the given bounds. - * @param left The left bound of the frustum. - * @param right The right bound of the frustum. - * @param bottom The bottom bound of the frustum. - * @param top The top bound of the frustum. - * @param near The near bound of the frustum. - * @param far The far bound of the frustum. + * Returns a random angle in the range [-pi, pi]. */ - frustum(left: number, right: number, bottom: number, top: number, near: number, far: number): Phaser.Math.Matrix4; + function Random(): number; /** - * Generate a perspective projection matrix with the given bounds. - * @param fovy Vertical field of view in radians - * @param aspect Aspect ratio. Typically viewport width /height. - * @param near Near bound of the frustum. - * @param far Far bound of the frustum. + * Returns a random angle in the range [-180, 180]. */ - perspective(fovy: number, aspect: number, near: number, far: number): Phaser.Math.Matrix4; + function RandomDegrees(): number; /** - * Generate a perspective projection matrix with the given bounds. - * @param width The width of the frustum. - * @param height The height of the frustum. - * @param near Near bound of the frustum. - * @param far Far bound of the frustum. + * Reverse the given angle. + * @param angle The angle to reverse, in radians. */ - perspectiveLH(width: number, height: number, near: number, far: number): Phaser.Math.Matrix4; + function Reverse(angle: number): number; /** - * Generate an orthogonal projection matrix with the given bounds. - * @param left The left bound of the frustum. - * @param right The right bound of the frustum. - * @param bottom The bottom bound of the frustum. - * @param top The top bound of the frustum. - * @param near The near bound of the frustum. - * @param far The far bound of the frustum. + * Rotates `currentAngle` towards `targetAngle`, taking the shortest rotation distance. The `lerp` argument is the amount to rotate by in this call. + * @param currentAngle The current angle, in radians. + * @param targetAngle The target angle to rotate to, in radians. + * @param lerp The lerp value to add to the current angle. Default 0.05. */ - ortho(left: number, right: number, bottom: number, top: number, near: number, far: number): Phaser.Math.Matrix4; + function RotateTo(currentAngle: number, targetAngle: number, lerp?: number): number; /** - * Generate a look-at matrix with the given eye position, focal point, and up axis. - * @param eye Position of the viewer - * @param center Point the viewer is looking at - * @param up vec3 pointing up. + * Gets the shortest angle between `angle1` and `angle2`. + * + * Both angles must be in the range -180 to 180, which is the same clamped + * range that `sprite.angle` uses, so you can pass in two sprite angles to + * this method and get the shortest angle back between the two of them. + * + * The angle returned will be in the same range. If the returned angle is + * greater than 0 then it's a counter-clockwise rotation, if < 0 then it's + * a clockwise rotation. + * @param angle1 The first angle in the range -180 to 180. + * @param angle2 The second angle in the range -180 to 180. */ - lookAt(eye: Phaser.Math.Vector3, center: Phaser.Math.Vector3, up: Phaser.Math.Vector3): Phaser.Math.Matrix4; + function ShortestBetween(angle1: number, angle2: number): number; /** - * Set the values of this matrix from the given `yaw`, `pitch` and `roll` values. - * @param yaw [description] - * @param pitch [description] - * @param roll [description] + * Wrap an angle. + * + * Wraps the angle to a value in the range of -PI to PI. + * @param angle The angle to wrap, in radians. */ - yawPitchRoll(yaw: number, pitch: number, roll: number): Phaser.Math.Matrix4; + function Wrap(angle: number): number; /** - * Generate a world matrix from the given rotation, position, scale, view matrix and projection matrix. - * @param rotation The rotation of the world matrix. - * @param position The position of the world matrix. - * @param scale The scale of the world matrix. - * @param viewMatrix The view matrix. - * @param projectionMatrix The projection matrix. + * Wrap an angle in degrees. + * + * Wraps the angle to a value in the range of -180 to 180. + * @param angle The angle to wrap, in degrees. */ - setWorldMatrix(rotation: Phaser.Math.Vector3, position: Phaser.Math.Vector3, scale: Phaser.Math.Vector3, viewMatrix?: Phaser.Math.Matrix4, projectionMatrix?: Phaser.Math.Matrix4): Phaser.Math.Matrix4; + function WrapDegrees(angle: number): number; } /** - * Add an `amount` to a `value`, limiting the maximum result to `max`. - * @param value The value to add to. - * @param amount The amount to add. - * @param max The maximum value to return. + * Calculate the mean average of the given values. + * @param values The values to average. */ - function MaxAdd(value: number, amount: number, max: number): number; + function Average(values: number[]): number; /** - * Subtract an `amount` from `value`, limiting the minimum result to `min`. - * @param value The value to subtract from. - * @param amount The amount to subtract. - * @param min The minimum value to return. + * Calculates the Bernstein basis from the three factorial coefficients. + * @param n The first value. + * @param i The second value. */ - function MinSub(value: number, amount: number, min: number): number; + function Bernstein(n: number, i: number): number; /** - * Work out what percentage `value` is of the range between `min` and `max`. - * If `max` isn't given then it will return the percentage of `value` to `min`. - * - * You can optionally specify an `upperMax` value, which is a mid-way point in the range that represents 100%, after which the % starts to go down to zero again. - * @param value The value to determine the percentage of. + * Compute a random integer between the `min` and `max` values, inclusive. * @param min The minimum value. * @param max The maximum value. - * @param upperMax The mid-way point in the range that represents 100%. */ - function Percent(value: number, min: number, max?: number, upperMax?: number): number; - - namespace Pow2 { - /** - * Returns the nearest power of 2 to the given `value`. - * @param value The value. - */ - function GetNext(value: number): integer; + function Between(min: number, max: number): number; - /** - * Checks if the given `width` and `height` are a power of two. - * Useful for checking texture dimensions. - * @param width The width. - * @param height The height. - */ - function IsSize(width: number, height: number): boolean; + /** + * Calculates a Catmull-Rom value from the given points, based on an alpha of 0.5. + * @param t The amount to interpolate by. + * @param p0 The first control point. + * @param p1 The second control point. + * @param p2 The third control point. + * @param p3 The fourth control point. + */ + function CatmullRom(t: number, p0: number, p1: number, p2: number, p3: number): number; - /** - * Tests the value and returns `true` if it is a power of two. - * @param value The value to check if it's a power of two. - */ - function IsValue(value: number): boolean; + /** + * Ceils to some place comparative to a `base`, default is 10 for decimal place. + * + * The `place` is represented by the power applied to `base` to get that place. + * @param value The value to round. + * @param place The place to round to. Default 0. + * @param base The base to round in. Default is 10 for decimal. Default 10. + */ + function CeilTo(value: number, place?: number, base?: number): number; - } + /** + * Force a value within the boundaries by clamping it to the range `min`, `max`. + * @param value The value to be clamped. + * @param min The minimum bounds. + * @param max The maximum bounds. + */ + function Clamp(value: number, min: number, max: number): number; /** - * A quaternion. + * The value of PI * 2. */ - class Quaternion { - /** - * - * @param x The x component. - * @param y The y component. - * @param z The z component. - * @param w The w component. - */ - constructor(x?: number, y?: number, z?: number, w?: number); + var PI2: number; - /** - * The x component of this Quaternion. - */ - x: number; + /** + * The value of PI * 0.5. + */ + var TAU: number; - /** - * The y component of this Quaternion. - */ - y: number; + /** + * An epsilon value (1.0e-6) + */ + var EPSILON: number; - /** - * The z component of this Quaternion. - */ - z: number; + /** + * For converting degrees to radians (PI / 180) + */ + var DEG_TO_RAD: number; - /** - * The w component of this Quaternion. - */ - w: number; + /** + * For converting radians to degrees (180 / PI) + */ + var RAD_TO_DEG: number; - /** - * Copy the components of a given Quaternion or Vector into this Quaternion. - * @param src The Quaternion or Vector to copy the components from. - */ - copy(src: Phaser.Math.Quaternion | Phaser.Math.Vector4): Phaser.Math.Quaternion; + /** + * An instance of the Random Number Generator. + * This is not set until the Game boots. + */ + var RND: Phaser.Math.RandomDataGenerator; - /** - * Set the components of this Quaternion. - * @param x The x component, or an object containing x, y, z, and w components. Default 0. - * @param y The y component. Default 0. - * @param z The z component. Default 0. - * @param w The w component. Default 0. - */ - set(x?: number | object, y?: number, z?: number, w?: number): Phaser.Math.Quaternion; + /** + * The minimum safe integer this browser supports. + * We use a const for backward compatibility with Internet Explorer. + */ + var MIN_SAFE_INTEGER: number; - /** - * Add a given Quaternion or Vector to this Quaternion. Addition is component-wise. - * @param v The Quaternion or Vector to add to this Quaternion. - */ - add(v: Phaser.Math.Quaternion | Phaser.Math.Vector4): Phaser.Math.Quaternion; + /** + * The maximum safe integer this browser supports. + * We use a const for backward compatibility with Internet Explorer. + */ + var MAX_SAFE_INTEGER: number; - /** - * Subtract a given Quaternion or Vector from this Quaternion. Subtraction is component-wise. - * @param v The Quaternion or Vector to subtract from this Quaternion. - */ - subtract(v: Phaser.Math.Quaternion | Phaser.Math.Vector4): Phaser.Math.Quaternion; + /** + * Convert the given angle from degrees, to the equivalent angle in radians. + * @param degrees The angle (in degrees) to convert to radians. + */ + function DegToRad(degrees: number): number; - /** - * Scale this Quaternion by the given value. - * @param scale The value to scale this Quaternion by. - */ - scale(scale: number): Phaser.Math.Quaternion; + /** + * Calculates the positive difference of two given numbers. + * @param a The first number in the calculation. + * @param b The second number in the calculation. + */ + function Difference(a: number, b: number): number; + namespace Distance { /** - * Calculate the length of this Quaternion. + * Calculate the distance between two sets of coordinates (points). + * @param x1 The x coordinate of the first point. + * @param y1 The y coordinate of the first point. + * @param x2 The x coordinate of the second point. + * @param y2 The y coordinate of the second point. */ - length(): number; + function Between(x1: number, y1: number, x2: number, y2: number): number; /** - * Calculate the length of this Quaternion squared. + * Calculate the distance between two points. + * @param a The first point. + * @param b The second point. */ - lengthSq(): number; + function BetweenPoints(a: Phaser.Types.Math.Vector2Like, b: Phaser.Types.Math.Vector2Like): number; /** - * Normalize this Quaternion. + * Calculate the squared distance between two points. + * @param a The first point. + * @param b The second point. */ - normalize(): Phaser.Math.Quaternion; + function BetweenPointsSquared(a: Phaser.Types.Math.Vector2Like, b: Phaser.Types.Math.Vector2Like): number; /** - * Calculate the dot product of this Quaternion and the given Quaternion or Vector. - * @param v The Quaternion or Vector to dot product with this Quaternion. + * Calculate the Chebyshev distance between two sets of coordinates (points). + * + * Chebyshev distance (or chessboard distance) is the maximum of the horizontal and vertical distances. + * It's the effective distance when movement can be horizontal, vertical, or diagonal. + * @param x1 The x coordinate of the first point. + * @param y1 The y coordinate of the first point. + * @param x2 The x coordinate of the second point. + * @param y2 The y coordinate of the second point. */ - dot(v: Phaser.Math.Quaternion | Phaser.Math.Vector4): number; + function Chebyshev(x1: number, y1: number, x2: number, y2: number): number; /** - * Linearly interpolate this Quaternion towards the given Quaternion or Vector. - * @param v The Quaternion or Vector to interpolate towards. - * @param t The percentage of interpolation. Default 0. + * Calculate the distance between two sets of coordinates (points) to the power of `pow`. + * @param x1 The x coordinate of the first point. + * @param y1 The y coordinate of the first point. + * @param x2 The x coordinate of the second point. + * @param y2 The y coordinate of the second point. + * @param pow The exponent. */ - lerp(v: Phaser.Math.Quaternion | Phaser.Math.Vector4, t?: number): Phaser.Math.Quaternion; + function Power(x1: number, y1: number, x2: number, y2: number, pow: number): number; /** - * [description] - * @param a [description] - * @param b [description] + * Calculate the snake distance between two sets of coordinates (points). + * + * Snake distance (rectilinear distance, Manhattan distance) is the sum of the horizontal and vertical distances. + * It's the effective distance when movement is allowed only horizontally or vertically (but not both). + * @param x1 The x coordinate of the first point. + * @param y1 The y coordinate of the first point. + * @param x2 The x coordinate of the second point. + * @param y2 The y coordinate of the second point. */ - rotationTo(a: Phaser.Math.Vector3, b: Phaser.Math.Vector3): Phaser.Math.Quaternion; + function Snake(x1: number, y1: number, x2: number, y2: number): number; /** - * Set the axes of this Quaternion. - * @param view The view axis. - * @param right The right axis. - * @param up The upwards axis. + * Calculate the distance between two sets of coordinates (points), squared. + * @param x1 The x coordinate of the first point. + * @param y1 The y coordinate of the first point. + * @param x2 The x coordinate of the second point. + * @param y2 The y coordinate of the second point. */ - setAxes(view: Phaser.Math.Vector3, right: Phaser.Math.Vector3, up: Phaser.Math.Vector3): Phaser.Math.Quaternion; + function Squared(x1: number, y1: number, x2: number, y2: number): number; - /** - * Reset this Matrix to an identity (default) Quaternion. - */ - identity(): Phaser.Math.Quaternion; + } - /** - * Set the axis angle of this Quaternion. - * @param axis The axis. - * @param rad The angle in radians. - */ - setAxisAngle(axis: Phaser.Math.Vector3, rad: number): Phaser.Math.Quaternion; + namespace Easing { + namespace Back { + /** + * Back ease-in. + * @param v The value to be tweened. + * @param overshoot The overshoot amount. Default 1.70158. + */ + function In(v: number, overshoot?: number): number; - /** - * Multiply this Quaternion by the given Quaternion or Vector. - * @param b The Quaternion or Vector to multiply this Quaternion by. - */ - multiply(b: Phaser.Math.Quaternion | Phaser.Math.Vector4): Phaser.Math.Quaternion; + /** + * Back ease-in/out. + * @param v The value to be tweened. + * @param overshoot The overshoot amount. Default 1.70158. + */ + function InOut(v: number, overshoot?: number): number; - /** - * Smoothly linearly interpolate this Quaternion towards the given Quaternion or Vector. - * @param b The Quaternion or Vector to interpolate towards. - * @param t The percentage of interpolation. - */ - slerp(b: Phaser.Math.Quaternion | Phaser.Math.Vector4, t: number): Phaser.Math.Quaternion; + /** + * Back ease-out. + * @param v The value to be tweened. + * @param overshoot The overshoot amount. Default 1.70158. + */ + function Out(v: number, overshoot?: number): number; - /** - * Invert this Quaternion. - */ - invert(): Phaser.Math.Quaternion; + } - /** - * Convert this Quaternion into its conjugate. - * - * Sets the x, y and z components. - */ - conjugate(): Phaser.Math.Quaternion; + namespace Bounce { + /** + * Bounce ease-in. + * @param v The value to be tweened. + */ + function In(v: number): number; - /** - * Rotate this Quaternion on the X axis. - * @param rad The rotation angle in radians. - */ - rotateX(rad: number): Phaser.Math.Quaternion; + /** + * Bounce ease-in/out. + * @param v The value to be tweened. + */ + function InOut(v: number): number; - /** - * Rotate this Quaternion on the Y axis. - * @param rad The rotation angle in radians. - */ - rotateY(rad: number): Phaser.Math.Quaternion; + /** + * Bounce ease-out. + * @param v The value to be tweened. + */ + function Out(v: number): number; + + } + + namespace Circular { + /** + * Circular ease-in. + * @param v The value to be tweened. + */ + function In(v: number): number; + + /** + * Circular ease-in/out. + * @param v The value to be tweened. + */ + function InOut(v: number): number; + + /** + * Circular ease-out. + * @param v The value to be tweened. + */ + function Out(v: number): number; + + } + + namespace Cubic { + /** + * Cubic ease-in. + * @param v The value to be tweened. + */ + function In(v: number): number; + + /** + * Cubic ease-in/out. + * @param v The value to be tweened. + */ + function InOut(v: number): number; + + /** + * Cubic ease-out. + * @param v The value to be tweened. + */ + function Out(v: number): number; + + } + + namespace Elastic { + /** + * Elastic ease-in. + * @param v The value to be tweened. + * @param amplitude The amplitude of the elastic ease. Default 0.1. + * @param period Sets how tight the sine-wave is, where smaller values are tighter waves, which result in more cycles. Default 0.1. + */ + function In(v: number, amplitude?: number, period?: number): number; + + /** + * Elastic ease-in/out. + * @param v The value to be tweened. + * @param amplitude The amplitude of the elastic ease. Default 0.1. + * @param period Sets how tight the sine-wave is, where smaller values are tighter waves, which result in more cycles. Default 0.1. + */ + function InOut(v: number, amplitude?: number, period?: number): number; + + /** + * Elastic ease-out. + * @param v The value to be tweened. + * @param amplitude The amplitude of the elastic ease. Default 0.1. + * @param period Sets how tight the sine-wave is, where smaller values are tighter waves, which result in more cycles. Default 0.1. + */ + function Out(v: number, amplitude?: number, period?: number): number; + + } + + namespace Expo { + /** + * Exponential ease-in. + * @param v The value to be tweened. + */ + function In(v: number): number; + + /** + * Exponential ease-in/out. + * @param v The value to be tweened. + */ + function InOut(v: number): number; + + /** + * Exponential ease-out. + * @param v The value to be tweened. + */ + function Out(v: number): number; + + } /** - * Rotate this Quaternion on the Z axis. - * @param rad The rotation angle in radians. + * Linear easing (no variation). + * @param v The value to be tweened. */ - rotateZ(rad: number): Phaser.Math.Quaternion; + function Linear(v: number): number; + + namespace Quadratic { + /** + * Quadratic ease-in. + * @param v The value to be tweened. + */ + function In(v: number): number; + + /** + * Quadratic ease-in/out. + * @param v The value to be tweened. + */ + function InOut(v: number): number; + + /** + * Quadratic ease-out. + * @param v The value to be tweened. + */ + function Out(v: number): number; + + } + + namespace Quartic { + /** + * Quartic ease-in. + * @param v The value to be tweened. + */ + function In(v: number): number; + + /** + * Quartic ease-in/out. + * @param v The value to be tweened. + */ + function InOut(v: number): number; + + /** + * Quartic ease-out. + * @param v The value to be tweened. + */ + function Out(v: number): number; + + } + + namespace Quintic { + /** + * Quintic ease-in. + * @param v The value to be tweened. + */ + function In(v: number): number; + + /** + * Quintic ease-in/out. + * @param v The value to be tweened. + */ + function InOut(v: number): number; + + /** + * Quintic ease-out. + * @param v The value to be tweened. + */ + function Out(v: number): number; + + } + + namespace Sine { + /** + * Sinusoidal ease-in. + * @param v The value to be tweened. + */ + function In(v: number): number; + + /** + * Sinusoidal ease-in/out. + * @param v The value to be tweened. + */ + function InOut(v: number): number; + + /** + * Sinusoidal ease-out. + * @param v The value to be tweened. + */ + function Out(v: number): number; + + } + + namespace Stepped { + } /** - * Create a unit (or rotation) Quaternion from its x, y, and z components. - * - * Sets the w component. + * Stepped easing. + * @param v The value to be tweened. + * @param steps The number of steps in the ease. Default 1. */ - calculateW(): Phaser.Math.Quaternion; + function Stepped(v: number, steps?: number): number; + } + + class Euler { /** - * Convert the given Matrix into this Quaternion. - * @param mat The Matrix to convert from. + * + * @param x The x component. + * @param y The y component. + * @param z The z component. */ - fromMat3(mat: Phaser.Math.Matrix3): Phaser.Math.Quaternion; + constructor(x?: number, y?: number, z?: number); } /** - * Convert the given angle in radians, to the equivalent angle in degrees. - * @param radians The angle in radians to convert ot degrees. + * Calculates the factorial of a given number for integer values greater than 0. + * @param value A positive integer to calculate the factorial of. */ - function RadToDeg(radians: number): integer; + function Factorial(value: number): number; /** - * A seeded Random Data Generator. - * - * Access via `Phaser.Math.RND` which is an instance of this class pre-defined - * by Phaser. Or, create your own instance to use as you require. - * - * The `Math.RND` generator is seeded by the Game Config property value `seed`. - * If no such config property exists, a random number is used. + * Generate a random floating point number between the two given bounds, minimum inclusive, maximum exclusive. + * @param min The lower bound for the float, inclusive. + * @param max The upper bound for the float exclusive. + */ + function FloatBetween(min: number, max: number): number; + + /** + * Floors to some place comparative to a `base`, default is 10 for decimal place. * - * If you create your own instance of this class you should provide a seed for it. - * If no seed is given it will use a 'random' one based on Date.now. + * The `place` is represented by the power applied to `base` to get that place. + * @param value The value to round. + * @param place The place to round to. Default 0. + * @param base The base to round in. Default is 10 for decimal. Default 10. */ - class RandomDataGenerator { + function FloorTo(value: number, place?: number, base?: number): number; + + /** + * Return a value based on the range between `min` and `max` and the percentage given. + * @param percent A value between 0 and 1 representing the percentage. + * @param min The minimum value. + * @param max The maximum value. + */ + function FromPercent(percent: number, min: number, max?: number): number; + + namespace Fuzzy { + /** + * Calculate the fuzzy ceiling of the given value. + * @param value The value. + * @param epsilon The epsilon. Default 0.0001. + */ + function Ceil(value: number, epsilon?: number): number; + /** + * Check whether the given values are fuzzily equal. * - * @param seeds The seeds to use for the random number generator. + * Two numbers are fuzzily equal if their difference is less than `epsilon`. + * @param a The first value. + * @param b The second value. + * @param epsilon The epsilon. Default 0.0001. */ - constructor(seeds?: string | string[]); + function Equal(a: number, b: number, epsilon?: number): boolean; /** - * Signs to choose from. + * Calculate the fuzzy floor of the given value. + * @param value The value. + * @param epsilon The epsilon. Default 0.0001. */ - signs: number[]; + function Floor(value: number, epsilon?: number): number; /** - * Initialize the state of the random data generator. - * @param seeds The seeds to initialize the random data generator with. + * Check whether `a` is fuzzily greater than `b`. + * + * `a` is fuzzily greater than `b` if it is more than `b - epsilon`. + * @param a The first value. + * @param b The second value. + * @param epsilon The epsilon. Default 0.0001. */ - init(seeds: string | string[]): void; + function GreaterThan(a: number, b: number, epsilon?: number): boolean; /** - * Reset the seed of the random data generator. + * Check whether `a` is fuzzily less than `b`. * - * _Note_: the seed array is only processed up to the first `undefined` (or `null`) value, should such be present. - * @param seeds The array of seeds: the `toString()` of each value is used. + * `a` is fuzzily less than `b` if it is less than `b + epsilon`. + * @param a The first value. + * @param b The second value. + * @param epsilon The epsilon. Default 0.0001. */ - sow(seeds: string[]): void; + function LessThan(a: number, b: number, epsilon?: number): boolean; + + } + + /** + * Calculate a per-ms speed from a distance and time (given in seconds). + * @param distance The distance. + * @param time The time, in seconds. + */ + function GetSpeed(distance: number, time: number): number; + namespace Interpolation { /** - * Returns a random integer between 0 and 2^32. + * A bezier interpolation method. + * @param v The input array of values to interpolate between. + * @param k The percentage of interpolation, between 0 and 1. */ - integer(): number; + function Bezier(v: number[], k: number): number; /** - * Returns a random real number between 0 and 1. + * A Catmull-Rom interpolation method. + * @param v The input array of values to interpolate between. + * @param k The percentage of interpolation, between 0 and 1. */ - frac(): number; + function CatmullRom(v: number[], k: number): number; /** - * Returns a random real number between 0 and 2^32. + * A cubic bezier interpolation method. + * + * https://medium.com/@adrian_cooney/bezier-interpolation-13b68563313a + * @param t The percentage of interpolation, between 0 and 1. + * @param p0 The start point. + * @param p1 The first control point. + * @param p2 The second control point. + * @param p3 The end point. */ - real(): number; + function CubicBezier(t: number, p0: number, p1: number, p2: number, p3: number): number; /** - * Returns a random integer between and including min and max. - * @param min The minimum value in the range. - * @param max The maximum value in the range. + * A linear interpolation method. + * @param v The input array of values to interpolate between. + * @param k The percentage of interpolation, between 0 and 1. */ - integerInRange(min: number, max: number): number; + function Linear(v: number[], k: number): number; /** - * Returns a random integer between and including min and max. - * This method is an alias for RandomDataGenerator.integerInRange. - * @param min The minimum value in the range. - * @param max The maximum value in the range. + * A quadratic bezier interpolation method. + * @param t The percentage of interpolation, between 0 and 1. + * @param p0 The start point. + * @param p1 The control point. + * @param p2 The end point. */ - between(min: number, max: number): number; + function QuadraticBezier(t: number, p0: number, p1: number, p2: number): number; /** - * Returns a random real number between min and max. - * @param min The minimum value in the range. - * @param max The maximum value in the range. + * A Smoother Step interpolation method. + * @param t The percentage of interpolation, between 0 and 1. + * @param min The minimum value, also known as the 'left edge', assumed smaller than the 'right edge'. + * @param max The maximum value, also known as the 'right edge', assumed greater than the 'left edge'. */ - realInRange(min: number, max: number): number; + function SmootherStep(t: number, min: number, max: number): number; /** - * Returns a random real number between -1 and 1. + * A Smooth Step interpolation method. + * @param t The percentage of interpolation, between 0 and 1. + * @param min The minimum value, also known as the 'left edge', assumed smaller than the 'right edge'. + * @param max The maximum value, also known as the 'right edge', assumed greater than the 'left edge'. */ - normal(): number; + function SmoothStep(t: number, min: number, max: number): number; + + } + + /** + * Check if a given value is an even number. + * @param value The number to perform the check with. + */ + function IsEven(value: number): boolean; + + /** + * Check if a given value is an even number using a strict type check. + * @param value The number to perform the check with. + */ + function IsEvenStrict(value: number): boolean; + + /** + * Calculates a linear (interpolation) value over t. + * @param p0 The first point. + * @param p1 The second point. + * @param t The percentage between p0 and p1 to return, represented as a number between 0 and 1. + */ + function Linear(p0: number, p1: number, t: number): number; + /** + * A three-dimensional matrix. + * + * Defaults to the identity matrix when instantiated. + */ + class Matrix3 { /** - * Returns a valid RFC4122 version4 ID hex string from https://gist.github.com/1308368 + * + * @param m Optional Matrix3 to copy values from. */ - uuid(): string; + constructor(m?: Phaser.Math.Matrix3); /** - * Returns a random element from within the given array. - * @param array The array to pick a random element from. + * The matrix values. */ - pick(array: T[]): T; + val: Float32Array; /** - * Returns a sign to be used with multiplication operator. + * Make a clone of this Matrix3. */ - sign(): number; + clone(): Phaser.Math.Matrix3; /** - * Returns a random element from within the given array, favoring the earlier entries. - * @param array The array to pick a random element from. + * This method is an alias for `Matrix3.copy`. + * @param src The Matrix to set the values of this Matrix's from. */ - weightedPick(array: T[]): T; + set(src: Phaser.Math.Matrix3): Phaser.Math.Matrix3; /** - * Returns a random timestamp between min and max, or between the beginning of 2000 and the end of 2020 if min and max aren't specified. - * @param min The minimum value in the range. - * @param max The maximum value in the range. + * Copy the values of a given Matrix into this Matrix. + * @param src The Matrix to copy the values from. */ - timestamp(min: number, max: number): number; + copy(src: Phaser.Math.Matrix3): Phaser.Math.Matrix3; /** - * Returns a random angle between -180 and 180. + * Copy the values of a given Matrix4 into this Matrix3. + * @param m The Matrix4 to copy the values from. */ - angle(): number; + fromMat4(m: Phaser.Math.Matrix4): Phaser.Math.Matrix3; /** - * Returns a random rotation in radians, between -3.141 and 3.141 + * Set the values of this Matrix from the given array. + * @param a The array to copy the values from. */ - rotation(): number; + fromArray(a: any[]): Phaser.Math.Matrix3; /** - * Gets or Sets the state of the generator. This allows you to retain the values - * that the generator is using between games, i.e. in a game save file. - * - * To seed this generator with a previously saved state you can pass it as the - * `seed` value in your game config, or call this method directly after Phaser has booted. - * - * Call this method with no parameters to return the current state. + * Reset this Matrix to an identity (default) matrix. + */ + identity(): Phaser.Math.Matrix3; + + /** + * Transpose this Matrix. + */ + transpose(): Phaser.Math.Matrix3; + + /** + * Invert this Matrix. + */ + invert(): Phaser.Math.Matrix3; + + /** + * Calculate the adjoint, or adjugate, of this Matrix. + */ + adjoint(): Phaser.Math.Matrix3; + + /** + * Calculate the determinant of this Matrix. + */ + determinant(): number; + + /** + * Multiply this Matrix by the given Matrix. + * @param src The Matrix to multiply this Matrix by. + */ + multiply(src: Phaser.Math.Matrix3): Phaser.Math.Matrix3; + + /** + * Translate this Matrix using the given Vector. + * @param v The Vector to translate this Matrix with. + */ + translate(v: Phaser.Math.Vector2 | Phaser.Math.Vector3 | Phaser.Math.Vector4): Phaser.Math.Matrix3; + + /** + * Apply a rotation transformation to this Matrix. + * @param rad The angle in radians to rotate by. + */ + rotate(rad: number): Phaser.Math.Matrix3; + + /** + * Apply a scale transformation to this Matrix. * - * If providing a state it should match the same format that this method - * returns, which is a string with a header `!rnd` followed by the `c`, - * `s0`, `s1` and `s2` values respectively, each comma-delimited. - * @param state Generator state to be set. + * Uses the `x` and `y` components of the given Vector to scale the Matrix. + * @param v The Vector to scale this Matrix with. */ - state(state?: string): string; + scale(v: Phaser.Math.Vector2 | Phaser.Math.Vector3 | Phaser.Math.Vector4): Phaser.Math.Matrix3; /** - * Shuffles the given array, using the current seed. - * @param array The array to be shuffled. + * Set the values of this Matrix from the given Quaternion. + * @param q The Quaternion to set the values of this Matrix from. */ - shuffle(array?: T[]): T[]; + fromQuat(q: Phaser.Math.Quaternion): Phaser.Math.Matrix3; + + /** + * Set the values of this Matrix3 to be normalized from the given Matrix4. + * @param m The Matrix4 to normalize the values from. + */ + normalFromMat4(m: Phaser.Math.Matrix4): Phaser.Math.Matrix3; } /** - * Compute a random unit vector. - * - * Computes random values for the given vector between -1 and 1 that can be used to represent a direction. + * A four-dimensional matrix. * - * Optionally accepts a scale value to scale the resulting vector by. - * @param vector The Vector to compute random values for. - * @param scale The scale of the random values. Default 1. + * Adapted from [gl-matrix](https://github.com/toji/gl-matrix) by toji + * and [vecmath](https://github.com/mattdesl/vecmath) by mattdesl */ - function RandomXY(vector: Phaser.Math.Vector2, scale?: number): Phaser.Math.Vector2; + class Matrix4 { + /** + * + * @param m Optional Matrix4 to copy values from. + */ + constructor(m?: Phaser.Math.Matrix4); - /** - * Compute a random position vector in a spherical area, optionally defined by the given radius. - * @param vec3 The Vector to compute random values for. - * @param radius The radius. Default 1. - */ - function RandomXYZ(vec3: Phaser.Math.Vector3, radius?: number): Phaser.Math.Vector3; + /** + * The matrix values. + */ + val: Float32Array; - /** - * Compute a random four-dimensional vector. - * @param vec4 The Vector to compute random values for. - * @param scale The scale of the random values. Default 1. - */ - function RandomXYZW(vec4: Phaser.Math.Vector4, scale?: number): Phaser.Math.Vector4; - - /** - * Rotate a given point by a given angle around the origin (0, 0), in an anti-clockwise direction. - * @param point The point to be rotated. - * @param angle The angle to be rotated by in an anticlockwise direction. - */ - function Rotate(point: Phaser.Geom.Point | object, angle: number): Phaser.Geom.Point; - - /** - * Rotate a `point` around `x` and `y` by the given `angle`. - * @param point The point to be rotated. - * @param x The horizontal coordinate to rotate around. - * @param y The vertical coordinate to rotate around. - * @param angle The angle of rotation in radians. - */ - function RotateAround(point: Phaser.Geom.Point | object, x: number, y: number, angle: number): Phaser.Geom.Point; - - /** - * Rotate a `point` around `x` and `y` by the given `angle` and `distance`. - * @param point The point to be rotated. - * @param x The horizontal coordinate to rotate around. - * @param y The vertical coordinate to rotate around. - * @param angle The angle of rotation in radians. - * @param distance The distance from (x, y) to place the point at. - */ - function RotateAroundDistance(point: Phaser.Geom.Point | object, x: number, y: number, angle: number, distance: number): Phaser.Geom.Point; - - /** - * Rotates a vector in place by axis angle. - * - * This is the same as transforming a point by an - * axis-angle quaternion, but it has higher precision. - * @param vec The vector to be rotated. - * @param axis The axis to rotate around. - * @param radians The angle of rotation in radians. - */ - function RotateVec3(vec: Phaser.Math.Vector3, axis: Phaser.Math.Vector3, radians: number): Phaser.Math.Vector3; - - /** - * Round a given number so it is further away from zero. That is, positive numbers are rounded up, and negative numbers are rounded down. - * @param value The number to round. - */ - function RoundAwayFromZero(value: number): number; - - /** - * Round a value to the given precision. - * - * For example: - * - * ```javascript - * RoundTo(123.456, 0) = 123 - * RoundTo(123.456, 1) = 120 - * RoundTo(123.456, 2) = 100 - * ``` - * - * To round the decimal, i.e. to round to precision, pass in a negative `place`: - * - * ```javascript - * RoundTo(123.456789, 0) = 123 - * RoundTo(123.456789, -1) = 123.5 - * RoundTo(123.456789, -2) = 123.46 - * RoundTo(123.456789, -3) = 123.457 - * ``` - * @param value The value to round. - * @param place The place to round to. Positive to round the units, negative to round the decimal. Default 0. - * @param base The base to round in. Default is 10 for decimal. Default 10. - */ - function RoundTo(value: number, place?: integer, base?: integer): number; - - /** - * Generate a series of sine and cosine values. - * @param length The number of values to generate. - * @param sinAmp The sine value amplitude. Default 1. - * @param cosAmp The cosine value amplitude. Default 1. - * @param frequency The frequency of the values. Default 1. - */ - function SinCosTableGenerator(length: number, sinAmp?: number, cosAmp?: number, frequency?: number): Phaser.Types.Math.SinCosTable; + /** + * Make a clone of this Matrix4. + */ + clone(): Phaser.Math.Matrix4; - /** - * Calculate a smoother interpolation percentage of `x` between `min` and `max`. - * - * The function receives the number `x` as an argument and returns 0 if `x` is less than or equal to the left edge, - * 1 if `x` is greater than or equal to the right edge, and smoothly interpolates, using a Hermite polynomial, - * between 0 and 1 otherwise. - * - * Produces an even smoother interpolation than {@link Phaser.Math.SmoothStep}. - * @param x The input value. - * @param min The minimum value, also known as the 'left edge', assumed smaller than the 'right edge'. - * @param max The maximum value, also known as the 'right edge', assumed greater than the 'left edge'. - */ - function SmootherStep(x: number, min: number, max: number): number; + /** + * This method is an alias for `Matrix4.copy`. + * @param src The Matrix to set the values of this Matrix's from. + */ + set(src: Phaser.Math.Matrix4): this; - /** - * Calculate a smooth interpolation percentage of `x` between `min` and `max`. - * - * The function receives the number `x` as an argument and returns 0 if `x` is less than or equal to the left edge, - * 1 if `x` is greater than or equal to the right edge, and smoothly interpolates, using a Hermite polynomial, - * between 0 and 1 otherwise. - * @param x The input value. - * @param min The minimum value, also known as the 'left edge', assumed smaller than the 'right edge'. - * @param max The maximum value, also known as the 'right edge', assumed greater than the 'left edge'. - */ - function SmoothStep(x: number, min: number, max: number): number; + /** + * Sets all values of this Matrix4. + * @param m00 The m00 value. + * @param m01 The m01 value. + * @param m02 The m02 value. + * @param m03 The m03 value. + * @param m10 The m10 value. + * @param m11 The m11 value. + * @param m12 The m12 value. + * @param m13 The m13 value. + * @param m20 The m20 value. + * @param m21 The m21 value. + * @param m22 The m22 value. + * @param m23 The m23 value. + * @param m30 The m30 value. + * @param m31 The m31 value. + * @param m32 The m32 value. + * @param m33 The m33 value. + */ + setValues(m00: number, m01: number, m02: number, m03: number, m10: number, m11: number, m12: number, m13: number, m20: number, m21: number, m22: number, m23: number, m30: number, m31: number, m32: number, m33: number): this; - namespace Snap { /** - * Snap a value to nearest grid slice, using ceil. - * - * Example: if you have an interval gap of `5` and a position of `12`... you will snap to `15`. - * As will `14` snap to `15`... but `16` will snap to `20`. - * @param value The value to snap. - * @param gap The interval gap of the grid. - * @param start Optional starting offset for gap. Default 0. - * @param divide If `true` it will divide the snapped value by the gap before returning. Default false. + * Copy the values of a given Matrix into this Matrix. + * @param src The Matrix to copy the values from. */ - function Ceil(value: number, gap: number, start?: number, divide?: boolean): number; + copy(src: Phaser.Math.Matrix4): this; /** - * Snap a value to nearest grid slice, using floor. - * - * Example: if you have an interval gap of `5` and a position of `12`... you will snap to `10`. - * As will `14` snap to `10`... but `16` will snap to `15`. - * @param value The value to snap. - * @param gap The interval gap of the grid. - * @param start Optional starting offset for gap. Default 0. - * @param divide If `true` it will divide the snapped value by the gap before returning. Default false. + * Set the values of this Matrix from the given array. + * @param a The array to copy the values from. Must have at least 16 elements. */ - function Floor(value: number, gap: number, start?: number, divide?: boolean): number; + fromArray(a: number[]): this; /** - * Snap a value to nearest grid slice, using rounding. + * Reset this Matrix. * - * Example: if you have an interval gap of `5` and a position of `12`... you will snap to `10` whereas `14` will snap to `15`. - * @param value The value to snap. - * @param gap The interval gap of the grid. - * @param start Optional starting offset for gap. Default 0. - * @param divide If `true` it will divide the snapped value by the gap before returning. Default false. + * Sets all values to `0`. */ - function To(value: number, gap: number, start?: number, divide?: boolean): number; - - } - - /** - * Returns a Vector2 containing the x and y position of the given index in a `width` x `height` sized grid. - * - * For example, in a 6 x 4 grid, index 16 would equal x: 4 y: 2. - * - * If the given index is out of range an empty Vector2 is returned. - * @param index The position within the grid to get the x/y value for. - * @param width The width of the grid. - * @param height The height of the grid. - * @param out An optional Vector2 to store the result in. If not given, a new Vector2 instance will be created. - */ - function ToXY(index: integer, width: integer, height: integer, out?: Phaser.Math.Vector2): Phaser.Math.Vector2; - - /** - * Takes the `x` and `y` coordinates and transforms them into the same space as - * defined by the position, rotation and scale values. - * @param x The x coordinate to be transformed. - * @param y The y coordinate to be transformed. - * @param positionX Horizontal position of the transform point. - * @param positionY Vertical position of the transform point. - * @param rotation Rotation of the transform point, in radians. - * @param scaleX Horizontal scale of the transform point. - * @param scaleY Vertical scale of the transform point. - * @param output The output vector, point or object for the translated coordinates. - */ - function TransformXY(x: number, y: number, positionX: number, positionY: number, rotation: number, scaleX: number, scaleY: number, output?: Phaser.Math.Vector2 | Phaser.Geom.Point | object): Phaser.Math.Vector2 | Phaser.Geom.Point | object; + zero(): Phaser.Math.Matrix4; - /** - * A representation of a vector in 2D space. - * - * A two-component vector. - */ - class Vector2 { /** - * - * @param x The x component, or an object with `x` and `y` properties. - * @param y The y component. + * Generates a transform matrix based on the given position, scale and rotation. + * @param position The position vector. + * @param scale The scale vector. + * @param rotation The rotation quaternion. */ - constructor(x?: number | Phaser.Types.Math.Vector2Like, y?: number); + transform(position: Phaser.Math.Vector3, scale: Phaser.Math.Vector3, rotation: Phaser.Math.Quaternion): this; /** - * The x component of this Vector. + * Set the `x`, `y` and `z` values of this Matrix. + * @param x The x value. + * @param y The y value. + * @param z The z value. */ - x: number; + xyz(x: number, y: number, z: number): this; /** - * The y component of this Vector. + * Set the scaling values of this Matrix. + * @param x The x scaling value. + * @param y The y scaling value. + * @param z The z scaling value. */ - y: number; + scaling(x: number, y: number, z: number): this; /** - * Make a clone of this Vector2. + * Reset this Matrix to an identity (default) matrix. */ - clone(): Phaser.Math.Vector2; + identity(): this; /** - * Copy the components of a given Vector into this Vector. - * @param src The Vector to copy the components from. + * Transpose this Matrix. */ - copy(src: Phaser.Math.Vector2): Phaser.Math.Vector2; + transpose(): this; /** - * Set the component values of this Vector from a given Vector2Like object. - * @param obj The object containing the component values to set for this Vector. + * Copies the given Matrix4 into this Matrix and then inverses it. + * @param m The Matrix4 to invert into this Matrix4. */ - setFromObject(obj: Phaser.Types.Math.Vector2Like): Phaser.Math.Vector2; + getInverse(m: Phaser.Math.Matrix4): this; /** - * Set the `x` and `y` components of the this Vector to the given `x` and `y` values. - * @param x The x value to set for this Vector. - * @param y The y value to set for this Vector. Default x. + * Invert this Matrix. */ - set(x: number, y?: number): Phaser.Math.Vector2; + invert(): this; /** - * This method is an alias for `Vector2.set`. - * @param x The x value to set for this Vector. - * @param y The y value to set for this Vector. Default x. + * Calculate the adjoint, or adjugate, of this Matrix. */ - setTo(x: number, y?: number): Phaser.Math.Vector2; + adjoint(): this; /** - * Sets the `x` and `y` values of this object from a given polar coordinate. - * @param azimuth The angular coordinate, in radians. - * @param radius The radial coordinate (length). Default 1. + * Calculate the determinant of this Matrix. */ - setToPolar(azimuth: number, radius?: number): Phaser.Math.Vector2; + determinant(): number; /** - * Check whether this Vector is equal to a given Vector. - * - * Performs a strict equality check against each Vector's components. - * @param v The vector to compare with this Vector. + * Multiply this Matrix by the given Matrix. + * @param src The Matrix to multiply this Matrix by. */ - equals(v: Phaser.Math.Vector2): boolean; + multiply(src: Phaser.Math.Matrix4): this; /** - * Calculate the angle between this Vector and the positive x-axis, in radians. + * Multiply the values of this Matrix4 by those given in the `src` argument. + * @param src The source Matrix4 that this Matrix4 is multiplied by. */ - angle(): number; + multiplyLocal(src: Phaser.Math.Matrix4): this; /** - * Add a given Vector to this Vector. Addition is component-wise. - * @param src The Vector to add to this Vector. + * Multiplies the given Matrix4 object with this Matrix. + * + * This is the same as calling `multiplyMatrices(m, this)`. + * @param m The Matrix4 to multiply with this one. */ - add(src: Phaser.Math.Vector2): Phaser.Math.Vector2; + premultiply(m: Phaser.Math.Matrix4): this; /** - * Subtract the given Vector from this Vector. Subtraction is component-wise. - * @param src The Vector to subtract from this Vector. + * Multiplies the two given Matrix4 objects and stores the results in this Matrix. + * @param a The first Matrix4 to multiply. + * @param b The second Matrix4 to multiply. */ - subtract(src: Phaser.Math.Vector2): Phaser.Math.Vector2; + multiplyMatrices(a: Phaser.Math.Matrix4, b: Phaser.Math.Matrix4): this; /** - * Perform a component-wise multiplication between this Vector and the given Vector. - * - * Multiplies this Vector by the given Vector. - * @param src The Vector to multiply this Vector by. + * Translate this Matrix using the given Vector. + * @param v The Vector to translate this Matrix with. */ - multiply(src: Phaser.Math.Vector2): Phaser.Math.Vector2; + translate(v: Phaser.Math.Vector3 | Phaser.Math.Vector4): this; /** - * Scale this Vector by the given value. - * @param value The value to scale this Vector by. + * Translate this Matrix using the given values. + * @param x The x component. + * @param y The y component. + * @param z The z component. */ - scale(value: number): Phaser.Math.Vector2; + translateXYZ(x: number, y: number, z: number): this; /** - * Perform a component-wise division between this Vector and the given Vector. + * Apply a scale transformation to this Matrix. * - * Divides this Vector by the given Vector. - * @param src The Vector to divide this Vector by. + * Uses the `x`, `y` and `z` components of the given Vector to scale the Matrix. + * @param v The Vector to scale this Matrix with. */ - divide(src: Phaser.Math.Vector2): Phaser.Math.Vector2; + scale(v: Phaser.Math.Vector3 | Phaser.Math.Vector4): this; /** - * Negate the `x` and `y` components of this Vector. + * Apply a scale transformation to this Matrix. + * @param x The x component. + * @param y The y component. + * @param z The z component. */ - negate(): Phaser.Math.Vector2; + scaleXYZ(x: number, y: number, z: number): this; /** - * Calculate the distance between this Vector and the given Vector. - * @param src The Vector to calculate the distance to. + * Derive a rotation matrix around the given axis. + * @param axis The rotation axis. + * @param angle The rotation angle in radians. */ - distance(src: Phaser.Math.Vector2): number; + makeRotationAxis(axis: Phaser.Math.Vector3 | Phaser.Math.Vector4, angle: number): this; /** - * Calculate the distance between this Vector and the given Vector, squared. - * @param src The Vector to calculate the distance to. + * Apply a rotation transformation to this Matrix. + * @param rad The angle in radians to rotate by. + * @param axis The axis to rotate upon. */ - distanceSq(src: Phaser.Math.Vector2): number; + rotate(rad: number, axis: Phaser.Math.Vector3): this; /** - * Calculate the length (or magnitude) of this Vector. + * Rotate this matrix on its X axis. + * @param rad The angle in radians to rotate by. */ - length(): number; + rotateX(rad: number): this; /** - * Calculate the length of this Vector squared. + * Rotate this matrix on its Y axis. + * @param rad The angle to rotate by, in radians. */ - lengthSq(): number; + rotateY(rad: number): this; /** - * Normalize this Vector. - * - * Makes the vector a unit length vector (magnitude of 1) in the same direction. + * Rotate this matrix on its Z axis. + * @param rad The angle to rotate by, in radians. */ - normalize(): Phaser.Math.Vector2; + rotateZ(rad: number): this; /** - * Right-hand normalize (make unit length) this Vector. + * Set the values of this Matrix from the given rotation Quaternion and translation Vector. + * @param q The Quaternion to set rotation from. + * @param v The Vector to set translation from. */ - normalizeRightHand(): Phaser.Math.Vector2; + fromRotationTranslation(q: Phaser.Math.Quaternion, v: Phaser.Math.Vector3): this; /** - * Calculate the dot product of this Vector and the given Vector. - * @param src The Vector2 to dot product with this Vector2. + * Set the values of this Matrix from the given Quaternion. + * @param q The Quaternion to set the values of this Matrix from. */ - dot(src: Phaser.Math.Vector2): number; + fromQuat(q: Phaser.Math.Quaternion): this; /** - * Calculate the cross product of this Vector and the given Vector. - * @param src The Vector2 to cross with this Vector2. + * Generate a frustum matrix with the given bounds. + * @param left The left bound of the frustum. + * @param right The right bound of the frustum. + * @param bottom The bottom bound of the frustum. + * @param top The top bound of the frustum. + * @param near The near bound of the frustum. + * @param far The far bound of the frustum. */ - cross(src: Phaser.Math.Vector2): number; + frustum(left: number, right: number, bottom: number, top: number, near: number, far: number): this; /** - * Linearly interpolate between this Vector and the given Vector. - * - * Interpolates this Vector towards the given Vector. - * @param src The Vector2 to interpolate towards. - * @param t The interpolation percentage, between 0 and 1. Default 0. + * Generate a perspective projection matrix with the given bounds. + * @param fovy Vertical field of view in radians + * @param aspect Aspect ratio. Typically viewport width /height. + * @param near Near bound of the frustum. + * @param far Far bound of the frustum. */ - lerp(src: Phaser.Math.Vector2, t?: number): Phaser.Math.Vector2; + perspective(fovy: number, aspect: number, near: number, far: number): this; /** - * Transform this Vector with the given Matrix. - * @param mat The Matrix3 to transform this Vector2 with. + * Generate a perspective projection matrix with the given bounds. + * @param width The width of the frustum. + * @param height The height of the frustum. + * @param near Near bound of the frustum. + * @param far Far bound of the frustum. */ - transformMat3(mat: Phaser.Math.Matrix3): Phaser.Math.Vector2; + perspectiveLH(width: number, height: number, near: number, far: number): this; /** - * Transform this Vector with the given Matrix. - * @param mat The Matrix4 to transform this Vector2 with. + * Generate an orthogonal projection matrix with the given bounds. + * @param left The left bound of the frustum. + * @param right The right bound of the frustum. + * @param bottom The bottom bound of the frustum. + * @param top The top bound of the frustum. + * @param near The near bound of the frustum. + * @param far The far bound of the frustum. */ - transformMat4(mat: Phaser.Math.Matrix4): Phaser.Math.Vector2; + ortho(left: number, right: number, bottom: number, top: number, near: number, far: number): this; /** - * Make this Vector the zero vector (0, 0). + * Generate a right-handed look-at matrix with the given eye position, target and up axis. + * @param eye Position of the viewer. + * @param target Point the viewer is looking at. + * @param up vec3 pointing up. */ - reset(): Phaser.Math.Vector2; + lookAtRH(eye: Phaser.Math.Vector3, target: Phaser.Math.Vector3, up: Phaser.Math.Vector3): this; /** - * A static zero Vector2 for use by reference. - * - * This constant is meant for comparison operations and should not be modified directly. + * Generate a look-at matrix with the given eye position, focal point, and up axis. + * @param eye Position of the viewer + * @param center Point the viewer is looking at + * @param up vec3 pointing up. */ - static readonly ZERO: Phaser.Math.Vector2; + lookAt(eye: Phaser.Math.Vector3, center: Phaser.Math.Vector3, up: Phaser.Math.Vector3): this; /** - * A static right Vector2 for use by reference. - * - * This constant is meant for comparison operations and should not be modified directly. + * Set the values of this matrix from the given `yaw`, `pitch` and `roll` values. + * @param yaw The yaw value. + * @param pitch The pitch value. + * @param roll The roll value. */ - static readonly RIGHT: Phaser.Math.Vector2; + yawPitchRoll(yaw: number, pitch: number, roll: number): this; /** - * A static left Vector2 for use by reference. - * - * This constant is meant for comparison operations and should not be modified directly. + * Generate a world matrix from the given rotation, position, scale, view matrix and projection matrix. + * @param rotation The rotation of the world matrix. + * @param position The position of the world matrix. + * @param scale The scale of the world matrix. + * @param viewMatrix The view matrix. + * @param projectionMatrix The projection matrix. */ - static readonly LEFT: Phaser.Math.Vector2; + setWorldMatrix(rotation: Phaser.Math.Vector3, position: Phaser.Math.Vector3, scale: Phaser.Math.Vector3, viewMatrix?: Phaser.Math.Matrix4, projectionMatrix?: Phaser.Math.Matrix4): this; /** - * A static up Vector2 for use by reference. - * - * This constant is meant for comparison operations and should not be modified directly. + * Multiplies this Matrix4 by the given `src` Matrix4 and stores the results in the `out` Matrix4. + * @param src The Matrix4 to multiply with this one. + * @param out The receiving Matrix. */ - static readonly UP: Phaser.Math.Vector2; + multiplyToMat4(src: Phaser.Math.Matrix4, out: Phaser.Math.Matrix4): Phaser.Math.Matrix4; /** - * A static down Vector2 for use by reference. - * - * This constant is meant for comparison operations and should not be modified directly. + * Takes the rotation and position vectors and builds this Matrix4 from them. + * @param rotation The rotation vector. + * @param position The position vector. + * @param translateFirst Should the operation translate then rotate (`true`), or rotate then translate? (`false`) */ - static readonly DOWN: Phaser.Math.Vector2; + fromRotationXYTranslation(rotation: Phaser.Math.Vector3, position: Phaser.Math.Vector3, translateFirst: boolean): this; /** - * A static one Vector2 for use by reference. - * - * This constant is meant for comparison operations and should not be modified directly. + * Returns the maximum axis scale from this Matrix4. */ - static readonly ONE: Phaser.Math.Vector2; + getMaxScaleOnAxis(): number; } /** - * A representation of a vector in 3D space. + * Add an `amount` to a `value`, limiting the maximum result to `max`. + * @param value The value to add to. + * @param amount The amount to add. + * @param max The maximum value to return. + */ + function MaxAdd(value: number, amount: number, max: number): number; + + /** + * Subtract an `amount` from `value`, limiting the minimum result to `min`. + * @param value The value to subtract from. + * @param amount The amount to subtract. + * @param min The minimum value to return. + */ + function MinSub(value: number, amount: number, min: number): number; + + /** + * Work out what percentage `value` is of the range between `min` and `max`. + * If `max` isn't given then it will return the percentage of `value` to `min`. * - * A three-component vector. + * You can optionally specify an `upperMax` value, which is a mid-way point in the range that represents 100%, after which the % starts to go down to zero again. + * @param value The value to determine the percentage of. + * @param min The minimum value. + * @param max The maximum value. + * @param upperMax The mid-way point in the range that represents 100%. */ - class Vector3 { - /** - * - * @param x The x component. - * @param y The y component. - * @param z The z component. - */ - constructor(x?: number, y?: number, z?: number); + function Percent(value: number, min: number, max?: number, upperMax?: number): number; + namespace Pow2 { /** - * The x component of this Vector. + * Returns the nearest power of 2 to the given `value`. + * @param value The value. */ - x: number; + function GetNext(value: number): number; /** - * The y component of this Vector. + * Checks if the given `width` and `height` are a power of two. + * Useful for checking texture dimensions. + * @param width The width. + * @param height The height. */ - y: number; + function IsSize(width: number, height: number): boolean; /** - * The z component of this Vector. + * Tests the value and returns `true` if it is a power of two. + * @param value The value to check if it's a power of two. */ - z: number; + function IsValue(value: number): boolean; + } + + /** + * A quaternion. + */ + class Quaternion { /** - * Set this Vector to point up. * - * Sets the y component of the vector to 1, and the others to 0. + * @param x The x component. Default 0. + * @param y The y component. Default 0. + * @param z The z component. Default 0. + * @param w The w component. Default 1. */ - up(): Phaser.Math.Vector3; + constructor(x?: number, y?: number, z?: number, w?: number); /** - * Make a clone of this Vector3. + * This callback is invoked, if set, each time a value in this quaternion is changed. + * The callback is passed one argument, a reference to this quaternion. */ - clone(): Phaser.Math.Vector3; + onChangeCallback: Function; /** - * Calculate the cross (vector) product of two given Vectors. - * @param a The first Vector to multiply. - * @param b The second Vector to multiply. + * The x component of this Quaternion. */ - crossVectors(a: Phaser.Math.Vector3, b: Phaser.Math.Vector3): Phaser.Math.Vector3; + x: number; /** - * Check whether this Vector is equal to a given Vector. - * - * Performs a strict equality check against each Vector's components. - * @param v The Vector3 to compare against. + * The y component of this Quaternion. */ - equals(v: Phaser.Math.Vector3): boolean; + y: number; /** - * Copy the components of a given Vector into this Vector. - * @param src The Vector to copy the components from. + * The z component of this Quaternion. */ - copy(src: Phaser.Math.Vector2 | Phaser.Math.Vector3): Phaser.Math.Vector3; + z: number; /** - * Set the `x`, `y`, and `z` components of this Vector to the given `x`, `y`, and `z` values. - * @param x The x value to set for this Vector, or an object containing x, y and z components. - * @param y The y value to set for this Vector. - * @param z The z value to set for this Vector. + * The w component of this Quaternion. */ - set(x: number | object, y?: number, z?: number): Phaser.Math.Vector3; + w: number; /** - * Add a given Vector to this Vector. Addition is component-wise. - * @param v The Vector to add to this Vector. + * Copy the components of a given Quaternion or Vector into this Quaternion. + * @param src The Quaternion or Vector to copy the components from. */ - add(v: Phaser.Math.Vector2 | Phaser.Math.Vector3): Phaser.Math.Vector3; + copy(src: Phaser.Math.Quaternion | Phaser.Math.Vector4): Phaser.Math.Quaternion; /** - * Subtract the given Vector from this Vector. Subtraction is component-wise. - * @param v The Vector to subtract from this Vector. + * Set the components of this Quaternion and optionally call the `onChangeCallback`. + * @param x The x component, or an object containing x, y, z, and w components. Default 0. + * @param y The y component. Default 0. + * @param z The z component. Default 0. + * @param w The w component. Default 0. + * @param update Call the `onChangeCallback`? Default true. */ - subtract(v: Phaser.Math.Vector2 | Phaser.Math.Vector3): Phaser.Math.Vector3; + set(x?: number | object, y?: number, z?: number, w?: number, update?: boolean): Phaser.Math.Quaternion; /** - * Perform a component-wise multiplication between this Vector and the given Vector. - * - * Multiplies this Vector by the given Vector. - * @param v The Vector to multiply this Vector by. + * Add a given Quaternion or Vector to this Quaternion. Addition is component-wise. + * @param v The Quaternion or Vector to add to this Quaternion. */ - multiply(v: Phaser.Math.Vector2 | Phaser.Math.Vector3): Phaser.Math.Vector3; + add(v: Phaser.Math.Quaternion | Phaser.Math.Vector4): Phaser.Math.Quaternion; /** - * Scale this Vector by the given value. - * @param scale The value to scale this Vector by. + * Subtract a given Quaternion or Vector from this Quaternion. Subtraction is component-wise. + * @param v The Quaternion or Vector to subtract from this Quaternion. */ - scale(scale: number): Phaser.Math.Vector3; + subtract(v: Phaser.Math.Quaternion | Phaser.Math.Vector4): Phaser.Math.Quaternion; /** - * Perform a component-wise division between this Vector and the given Vector. - * - * Divides this Vector by the given Vector. - * @param v The Vector to divide this Vector by. + * Scale this Quaternion by the given value. + * @param scale The value to scale this Quaternion by. */ - divide(v: Phaser.Math.Vector2 | Phaser.Math.Vector3): Phaser.Math.Vector3; + scale(scale: number): Phaser.Math.Quaternion; /** - * Negate the `x`, `y` and `z` components of this Vector. + * Calculate the length of this Quaternion. */ - negate(): Phaser.Math.Vector3; + length(): number; /** - * Calculate the distance between this Vector and the given Vector. - * @param v The Vector to calculate the distance to. + * Calculate the length of this Quaternion squared. */ - distance(v: Phaser.Math.Vector2 | Phaser.Math.Vector3): number; + lengthSq(): number; /** - * Calculate the distance between this Vector and the given Vector, squared. - * @param v The Vector to calculate the distance to. + * Normalize this Quaternion. */ - distanceSq(v: Phaser.Math.Vector2 | Phaser.Math.Vector3): number; + normalize(): Phaser.Math.Quaternion; /** - * Calculate the length (or magnitude) of this Vector. + * Calculate the dot product of this Quaternion and the given Quaternion or Vector. + * @param v The Quaternion or Vector to dot product with this Quaternion. */ - length(): number; + dot(v: Phaser.Math.Quaternion | Phaser.Math.Vector4): number; /** - * Calculate the length of this Vector squared. + * Linearly interpolate this Quaternion towards the given Quaternion or Vector. + * @param v The Quaternion or Vector to interpolate towards. + * @param t The percentage of interpolation. Default 0. */ - lengthSq(): number; + lerp(v: Phaser.Math.Quaternion | Phaser.Math.Vector4, t?: number): Phaser.Math.Quaternion; /** - * Normalize this Vector. - * - * Makes the vector a unit length vector (magnitude of 1) in the same direction. + * Rotates this Quaternion based on the two given vectors. + * @param a The transform rotation vector. + * @param b The target rotation vector. */ - normalize(): Phaser.Math.Vector3; + rotationTo(a: Phaser.Math.Vector3, b: Phaser.Math.Vector3): Phaser.Math.Quaternion; /** - * Calculate the dot product of this Vector and the given Vector. - * @param v The Vector3 to dot product with this Vector3. + * Set the axes of this Quaternion. + * @param view The view axis. + * @param right The right axis. + * @param up The upwards axis. */ - dot(v: Phaser.Math.Vector3): number; + setAxes(view: Phaser.Math.Vector3, right: Phaser.Math.Vector3, up: Phaser.Math.Vector3): Phaser.Math.Quaternion; /** - * Calculate the cross (vector) product of this Vector (which will be modified) and the given Vector. - * @param v The Vector to cross product with. + * Reset this Matrix to an identity (default) Quaternion. */ - cross(v: Phaser.Math.Vector3): Phaser.Math.Vector3; + identity(): Phaser.Math.Quaternion; /** - * Linearly interpolate between this Vector and the given Vector. - * - * Interpolates this Vector towards the given Vector. - * @param v The Vector3 to interpolate towards. - * @param t The interpolation percentage, between 0 and 1. Default 0. + * Set the axis angle of this Quaternion. + * @param axis The axis. + * @param rad The angle in radians. */ - lerp(v: Phaser.Math.Vector3, t?: number): Phaser.Math.Vector3; + setAxisAngle(axis: Phaser.Math.Vector3, rad: number): Phaser.Math.Quaternion; /** - * Transform this Vector with the given Matrix. - * @param mat The Matrix3 to transform this Vector3 with. + * Multiply this Quaternion by the given Quaternion or Vector. + * @param b The Quaternion or Vector to multiply this Quaternion by. */ - transformMat3(mat: Phaser.Math.Matrix3): Phaser.Math.Vector3; + multiply(b: Phaser.Math.Quaternion | Phaser.Math.Vector4): Phaser.Math.Quaternion; /** - * Transform this Vector with the given Matrix. - * @param mat The Matrix4 to transform this Vector3 with. + * Smoothly linearly interpolate this Quaternion towards the given Quaternion or Vector. + * @param b The Quaternion or Vector to interpolate towards. + * @param t The percentage of interpolation. */ - transformMat4(mat: Phaser.Math.Matrix4): Phaser.Math.Vector3; + slerp(b: Phaser.Math.Quaternion | Phaser.Math.Vector4, t: number): Phaser.Math.Quaternion; /** - * Transforms the coordinates of this Vector3 with the given Matrix4. - * @param mat The Matrix4 to transform this Vector3 with. + * Invert this Quaternion. */ - transformCoordinates(mat: Phaser.Math.Matrix4): Phaser.Math.Vector3; + invert(): Phaser.Math.Quaternion; /** - * Transform this Vector with the given Quaternion. - * @param q The Quaternion to transform this Vector with. + * Convert this Quaternion into its conjugate. + * + * Sets the x, y and z components. */ - transformQuat(q: Phaser.Math.Quaternion): Phaser.Math.Vector3; + conjugate(): Phaser.Math.Quaternion; /** - * Multiplies this Vector3 by the specified matrix, applying a W divide. This is useful for projection, - * e.g. unprojecting a 2D point into 3D space. - * @param mat The Matrix4 to multiply this Vector3 with. + * Rotate this Quaternion on the X axis. + * @param rad The rotation angle in radians. */ - project(mat: Phaser.Math.Matrix4): Phaser.Math.Vector3; + rotateX(rad: number): Phaser.Math.Quaternion; /** - * Unproject this point from 2D space to 3D space. - * The point should have its x and y properties set to - * 2D screen space, and the z either at 0 (near plane) - * or 1 (far plane). The provided matrix is assumed to already - * be combined, i.e. projection * view * model. - * - * After this operation, this vector's (x, y, z) components will - * represent the unprojected 3D coordinate. - * @param viewport Screen x, y, width and height in pixels. - * @param invProjectionView Combined projection and view matrix. + * Rotate this Quaternion on the Y axis. + * @param rad The rotation angle in radians. */ - unproject(viewport: Phaser.Math.Vector4, invProjectionView: Phaser.Math.Matrix4): Phaser.Math.Vector3; + rotateY(rad: number): Phaser.Math.Quaternion; /** - * Make this Vector the zero vector (0, 0, 0). + * Rotate this Quaternion on the Z axis. + * @param rad The rotation angle in radians. */ - reset(): Phaser.Math.Vector3; + rotateZ(rad: number): Phaser.Math.Quaternion; /** - * A static zero Vector3 for use by reference. + * Create a unit (or rotation) Quaternion from its x, y, and z components. * - * This constant is meant for comparison operations and should not be modified directly. + * Sets the w component. */ - static readonly ZERO: Phaser.Math.Vector3; + calculateW(): Phaser.Math.Quaternion; /** - * A static right Vector3 for use by reference. - * - * This constant is meant for comparison operations and should not be modified directly. + * Set this Quaternion from the given Euler, based on Euler order. + * @param euler The Euler to convert from. + * @param update Run the `onChangeCallback`? Default true. */ - static readonly RIGHT: Phaser.Math.Vector3; + setFromEuler(euler: Phaser.Math.Euler, update?: boolean): Phaser.Math.Quaternion; /** - * A static left Vector3 for use by reference. - * - * This constant is meant for comparison operations and should not be modified directly. + * Sets the rotation of this Quaternion from the given Matrix4. + * @param mat4 The Matrix4 to set the rotation from. */ - static readonly LEFT: Phaser.Math.Vector3; + setFromRotationMatrix(mat4: Phaser.Math.Matrix4): Phaser.Math.Quaternion; /** - * A static up Vector3 for use by reference. - * - * This constant is meant for comparison operations and should not be modified directly. + * Convert the given Matrix into this Quaternion. + * @param mat The Matrix to convert from. */ - static readonly UP: Phaser.Math.Vector3; + fromMat3(mat: Phaser.Math.Matrix3): Phaser.Math.Quaternion; + + } + + /** + * Convert the given angle in radians, to the equivalent angle in degrees. + * @param radians The angle in radians to convert ot degrees. + */ + function RadToDeg(radians: number): number; + /** + * A seeded Random Data Generator. + * + * Access via `Phaser.Math.RND` which is an instance of this class pre-defined + * by Phaser. Or, create your own instance to use as you require. + * + * The `Math.RND` generator is seeded by the Game Config property value `seed`. + * If no such config property exists, a random number is used. + * + * If you create your own instance of this class you should provide a seed for it. + * If no seed is given it will use a 'random' one based on Date.now. + */ + class RandomDataGenerator { /** - * A static down Vector3 for use by reference. * - * This constant is meant for comparison operations and should not be modified directly. + * @param seeds The seeds to use for the random number generator. */ - static readonly DOWN: Phaser.Math.Vector3; + constructor(seeds?: string | string[]); /** - * A static forward Vector3 for use by reference. - * - * This constant is meant for comparison operations and should not be modified directly. + * Signs to choose from. */ - static readonly FORWARD: Phaser.Math.Vector3; + signs: number[]; /** - * A static back Vector3 for use by reference. - * - * This constant is meant for comparison operations and should not be modified directly. + * Initialize the state of the random data generator. + * @param seeds The seeds to initialize the random data generator with. */ - static readonly BACK: Phaser.Math.Vector3; + init(seeds: string | string[]): void; /** - * A static one Vector3 for use by reference. + * Reset the seed of the random data generator. * - * This constant is meant for comparison operations and should not be modified directly. + * _Note_: the seed array is only processed up to the first `undefined` (or `null`) value, should such be present. + * @param seeds The array of seeds: the `toString()` of each value is used. */ - static readonly ONE: Phaser.Math.Vector3; - - } + sow(seeds: string[]): void; - /** - * A representation of a vector in 4D space. - * - * A four-component vector. - */ - class Vector4 { /** - * - * @param x The x component. - * @param y The y component. - * @param z The z component. - * @param w The w component. + * Returns a random integer between 0 and 2^32. */ - constructor(x?: number, y?: number, z?: number, w?: number); + integer(): number; /** - * The x component of this Vector. + * Returns a random real number between 0 and 1. */ - x: number; + frac(): number; /** - * The y component of this Vector. + * Returns a random real number between 0 and 2^32. */ - y: number; + real(): number; /** - * The z component of this Vector. + * Returns a random integer between and including min and max. + * @param min The minimum value in the range. + * @param max The maximum value in the range. */ - z: number; + integerInRange(min: number, max: number): number; /** - * The w component of this Vector. + * Returns a random integer between and including min and max. + * This method is an alias for RandomDataGenerator.integerInRange. + * @param min The minimum value in the range. + * @param max The maximum value in the range. */ - w: number; + between(min: number, max: number): number; /** - * Make a clone of this Vector4. + * Returns a random real number between min and max. + * @param min The minimum value in the range. + * @param max The maximum value in the range. */ - clone(): Phaser.Math.Vector4; + realInRange(min: number, max: number): number; /** - * Copy the components of a given Vector into this Vector. - * @param src The Vector to copy the components from. + * Returns a random real number between -1 and 1. */ - copy(src: Phaser.Math.Vector4): Phaser.Math.Vector4; + normal(): number; /** - * Check whether this Vector is equal to a given Vector. - * - * Performs a strict quality check against each Vector's components. - * @param v The vector to check equality with. + * Returns a valid RFC4122 version4 ID hex string from https://gist.github.com/1308368 */ - equals(v: Phaser.Math.Vector4): boolean; + uuid(): string; /** - * Set the `x`, `y`, `z` and `w` components of the this Vector to the given `x`, `y`, `z` and `w` values. - * @param x The x value to set for this Vector, or an object containing x, y, z and w components. - * @param y The y value to set for this Vector. - * @param z The z value to set for this Vector. - * @param w The z value to set for this Vector. + * Returns a random element from within the given array. + * @param array The array to pick a random element from. */ - set(x: number | object, y: number, z: number, w: number): Phaser.Math.Vector4; + pick(array: T[]): T; /** - * Add a given Vector to this Vector. Addition is component-wise. - * @param v The Vector to add to this Vector. + * Returns a sign to be used with multiplication operator. */ - add(v: Phaser.Math.Vector2 | Phaser.Math.Vector3 | Phaser.Math.Vector4): Phaser.Math.Vector4; + sign(): number; /** - * Subtract the given Vector from this Vector. Subtraction is component-wise. - * @param v The Vector to subtract from this Vector. + * Returns a random element from within the given array, favoring the earlier entries. + * @param array The array to pick a random element from. */ - subtract(v: Phaser.Math.Vector2 | Phaser.Math.Vector3 | Phaser.Math.Vector4): Phaser.Math.Vector4; + weightedPick(array: T[]): T; /** - * Scale this Vector by the given value. - * @param scale The value to scale this Vector by. + * Returns a random timestamp between min and max, or between the beginning of 2000 and the end of 2020 if min and max aren't specified. + * @param min The minimum value in the range. + * @param max The maximum value in the range. */ - scale(scale: number): Phaser.Math.Vector4; + timestamp(min: number, max: number): number; /** - * Calculate the length (or magnitude) of this Vector. + * Returns a random angle between -180 and 180. */ - length(): number; + angle(): number; /** - * Calculate the length of this Vector squared. + * Returns a random rotation in radians, between -3.141 and 3.141 */ - lengthSq(): number; + rotation(): number; /** - * Normalize this Vector. + * Gets or Sets the state of the generator. This allows you to retain the values + * that the generator is using between games, i.e. in a game save file. * - * Makes the vector a unit length vector (magnitude of 1) in the same direction. + * To seed this generator with a previously saved state you can pass it as the + * `seed` value in your game config, or call this method directly after Phaser has booted. + * + * Call this method with no parameters to return the current state. + * + * If providing a state it should match the same format that this method + * returns, which is a string with a header `!rnd` followed by the `c`, + * `s0`, `s1` and `s2` values respectively, each comma-delimited. + * @param state Generator state to be set. */ - normalize(): Phaser.Math.Vector4; + state(state?: string): string; /** - * Calculate the dot product of this Vector and the given Vector. - * @param v The Vector4 to dot product with this Vector4. + * Shuffles the given array, using the current seed. + * @param array The array to be shuffled. */ - dot(v: Phaser.Math.Vector4): number; + shuffle(array?: T[]): T[]; + + } + + /** + * Compute a random unit vector. + * + * Computes random values for the given vector between -1 and 1 that can be used to represent a direction. + * + * Optionally accepts a scale value to scale the resulting vector by. + * @param vector The Vector to compute random values for. + * @param scale The scale of the random values. Default 1. + */ + function RandomXY(vector: Phaser.Math.Vector2, scale?: number): Phaser.Math.Vector2; + + /** + * Compute a random position vector in a spherical area, optionally defined by the given radius. + * @param vec3 The Vector to compute random values for. + * @param radius The radius. Default 1. + */ + function RandomXYZ(vec3: Phaser.Math.Vector3, radius?: number): Phaser.Math.Vector3; + + /** + * Compute a random four-dimensional vector. + * @param vec4 The Vector to compute random values for. + * @param scale The scale of the random values. Default 1. + */ + function RandomXYZW(vec4: Phaser.Math.Vector4, scale?: number): Phaser.Math.Vector4; + + /** + * Rotate a given point by a given angle around the origin (0, 0), in an anti-clockwise direction. + * @param point The point to be rotated. + * @param angle The angle to be rotated by in an anticlockwise direction. + */ + function Rotate(point: Phaser.Geom.Point | object, angle: number): Phaser.Geom.Point; + + /** + * Rotate a `point` around `x` and `y` to the given `angle`, at the same distance. + * + * In polar notation, this maps a point from (r, t) to (r, angle), vs. the origin (x, y). + * @param point The point to be rotated. + * @param x The horizontal coordinate to rotate around. + * @param y The vertical coordinate to rotate around. + * @param angle The angle of rotation in radians. + */ + function RotateAround(point: T, x: number, y: number, angle: number): T; + + /** + * Rotate a `point` around `x` and `y` by the given `angle` and `distance`. + * + * In polar notation, this maps a point from (r, t) to (distance, t + angle), vs. the origin (x, y). + * @param point The point to be rotated. + * @param x The horizontal coordinate to rotate around. + * @param y The vertical coordinate to rotate around. + * @param angle The angle of rotation in radians. + * @param distance The distance from (x, y) to place the point at. + */ + function RotateAroundDistance(point: T, x: number, y: number, angle: number, distance: number): T; + + /** + * Position a `point` at the given `angle` and `distance` to (`x`, `y`). + * @param point The point to be positioned. + * @param x The horizontal coordinate to position from. + * @param y The vertical coordinate to position from. + * @param angle The angle of rotation in radians. + * @param distance The distance from (x, y) to place the point at. + */ + function RotateTo(point: T, x: number, y: number, angle: number, distance: number): T; + + /** + * Rotates a vector in place by axis angle. + * + * This is the same as transforming a point by an + * axis-angle quaternion, but it has higher precision. + * @param vec The vector to be rotated. + * @param axis The axis to rotate around. + * @param radians The angle of rotation in radians. + */ + function RotateVec3(vec: Phaser.Math.Vector3, axis: Phaser.Math.Vector3, radians: number): Phaser.Math.Vector3; + + /** + * Round a given number so it is further away from zero. That is, positive numbers are rounded up, and negative numbers are rounded down. + * @param value The number to round. + */ + function RoundAwayFromZero(value: number): number; + + /** + * Round a value to the given precision. + * + * For example: + * + * ```javascript + * RoundTo(123.456, 0) = 123 + * RoundTo(123.456, 1) = 120 + * RoundTo(123.456, 2) = 100 + * ``` + * + * To round the decimal, i.e. to round to precision, pass in a negative `place`: + * + * ```javascript + * RoundTo(123.456789, 0) = 123 + * RoundTo(123.456789, -1) = 123.5 + * RoundTo(123.456789, -2) = 123.46 + * RoundTo(123.456789, -3) = 123.457 + * ``` + * @param value The value to round. + * @param place The place to round to. Positive to round the units, negative to round the decimal. Default 0. + * @param base The base to round in. Default is 10 for decimal. Default 10. + */ + function RoundTo(value: number, place?: number, base?: number): number; + + /** + * Generate a series of sine and cosine values. + * @param length The number of values to generate. + * @param sinAmp The sine value amplitude. Default 1. + * @param cosAmp The cosine value amplitude. Default 1. + * @param frequency The frequency of the values. Default 1. + */ + function SinCosTableGenerator(length: number, sinAmp?: number, cosAmp?: number, frequency?: number): Phaser.Types.Math.SinCosTable; + + /** + * Calculate a smoother interpolation percentage of `x` between `min` and `max`. + * + * The function receives the number `x` as an argument and returns 0 if `x` is less than or equal to the left edge, + * 1 if `x` is greater than or equal to the right edge, and smoothly interpolates, using a Hermite polynomial, + * between 0 and 1 otherwise. + * + * Produces an even smoother interpolation than {@link Phaser.Math.SmoothStep}. + * @param x The input value. + * @param min The minimum value, also known as the 'left edge', assumed smaller than the 'right edge'. + * @param max The maximum value, also known as the 'right edge', assumed greater than the 'left edge'. + */ + function SmootherStep(x: number, min: number, max: number): number; + + /** + * Calculate a smooth interpolation percentage of `x` between `min` and `max`. + * + * The function receives the number `x` as an argument and returns 0 if `x` is less than or equal to the left edge, + * 1 if `x` is greater than or equal to the right edge, and smoothly interpolates, using a Hermite polynomial, + * between 0 and 1 otherwise. + * @param x The input value. + * @param min The minimum value, also known as the 'left edge', assumed smaller than the 'right edge'. + * @param max The maximum value, also known as the 'right edge', assumed greater than the 'left edge'. + */ + function SmoothStep(x: number, min: number, max: number): number; + namespace Snap { /** - * Linearly interpolate between this Vector and the given Vector. + * Snap a value to nearest grid slice, using ceil. * - * Interpolates this Vector towards the given Vector. - * @param v The Vector4 to interpolate towards. - * @param t The interpolation percentage, between 0 and 1. Default 0. + * Example: if you have an interval gap of `5` and a position of `12`... you will snap to `15`. + * As will `14` snap to `15`... but `16` will snap to `20`. + * @param value The value to snap. + * @param gap The interval gap of the grid. + * @param start Optional starting offset for gap. Default 0. + * @param divide If `true` it will divide the snapped value by the gap before returning. Default false. */ - lerp(v: Phaser.Math.Vector4, t?: number): Phaser.Math.Vector4; + function Ceil(value: number, gap: number, start?: number, divide?: boolean): number; /** - * Perform a component-wise multiplication between this Vector and the given Vector. + * Snap a value to nearest grid slice, using floor. * - * Multiplies this Vector by the given Vector. - * @param v The Vector to multiply this Vector by. + * Example: if you have an interval gap of `5` and a position of `12`... you will snap to `10`. + * As will `14` snap to `10`... but `16` will snap to `15`. + * @param value The value to snap. + * @param gap The interval gap of the grid. + * @param start Optional starting offset for gap. Default 0. + * @param divide If `true` it will divide the snapped value by the gap before returning. Default false. */ - multiply(v: Phaser.Math.Vector2 | Phaser.Math.Vector3 | Phaser.Math.Vector4): Phaser.Math.Vector4; + function Floor(value: number, gap: number, start?: number, divide?: boolean): number; /** - * Perform a component-wise division between this Vector and the given Vector. + * Snap a value to nearest grid slice, using rounding. * - * Divides this Vector by the given Vector. - * @param v The Vector to divide this Vector by. + * Example: if you have an interval gap of `5` and a position of `12`... you will snap to `10` whereas `14` will snap to `15`. + * @param value The value to snap. + * @param gap The interval gap of the grid. + * @param start Optional starting offset for gap. Default 0. + * @param divide If `true` it will divide the snapped value by the gap before returning. Default false. */ - divide(v: Phaser.Math.Vector2 | Phaser.Math.Vector3 | Phaser.Math.Vector4): Phaser.Math.Vector4; + function To(value: number, gap: number, start?: number, divide?: boolean): number; + + } + + /** + * Returns a Vector2 containing the x and y position of the given index in a `width` x `height` sized grid. + * + * For example, in a 6 x 4 grid, index 16 would equal x: 4 y: 2. + * + * If the given index is out of range an empty Vector2 is returned. + * @param index The position within the grid to get the x/y value for. + * @param width The width of the grid. + * @param height The height of the grid. + * @param out An optional Vector2 to store the result in. If not given, a new Vector2 instance will be created. + */ + function ToXY(index: number, width: number, height: number, out?: Phaser.Math.Vector2): Phaser.Math.Vector2; + + /** + * Takes the `x` and `y` coordinates and transforms them into the same space as + * defined by the position, rotation and scale values. + * @param x The x coordinate to be transformed. + * @param y The y coordinate to be transformed. + * @param positionX Horizontal position of the transform point. + * @param positionY Vertical position of the transform point. + * @param rotation Rotation of the transform point, in radians. + * @param scaleX Horizontal scale of the transform point. + * @param scaleY Vertical scale of the transform point. + * @param output The output vector, point or object for the translated coordinates. + */ + function TransformXY(x: number, y: number, positionX: number, positionY: number, rotation: number, scaleX: number, scaleY: number, output?: Phaser.Math.Vector2 | Phaser.Geom.Point | object): Phaser.Math.Vector2 | Phaser.Geom.Point | object; + /** + * A representation of a vector in 2D space. + * + * A two-component vector. + */ + class Vector2 { /** - * Calculate the distance between this Vector and the given Vector. - * @param v The Vector to calculate the distance to. + * + * @param x The x component, or an object with `x` and `y` properties. + * @param y The y component. */ - distance(v: Phaser.Math.Vector2 | Phaser.Math.Vector3 | Phaser.Math.Vector4): number; + constructor(x?: number | Phaser.Types.Math.Vector2Like, y?: number); /** - * Calculate the distance between this Vector and the given Vector, squared. - * @param v The Vector to calculate the distance to. + * The x component of this Vector. */ - distanceSq(v: Phaser.Math.Vector2 | Phaser.Math.Vector3 | Phaser.Math.Vector4): number; + x: number; /** - * Negate the `x`, `y`, `z` and `w` components of this Vector. + * The y component of this Vector. */ - negate(): Phaser.Math.Vector4; + y: number; /** - * Transform this Vector with the given Matrix. - * @param mat The Matrix4 to transform this Vector4 with. + * Make a clone of this Vector2. */ - transformMat4(mat: Phaser.Math.Matrix4): Phaser.Math.Vector4; + clone(): Phaser.Math.Vector2; /** - * Transform this Vector with the given Quaternion. - * @param q The Quaternion to transform this Vector with. + * Copy the components of a given Vector into this Vector. + * @param src The Vector to copy the components from. */ - transformQuat(q: Phaser.Math.Quaternion): Phaser.Math.Vector4; + copy(src: Phaser.Math.Vector2): Phaser.Math.Vector2; /** - * Make this Vector the zero vector (0, 0, 0, 0). + * Set the component values of this Vector from a given Vector2Like object. + * @param obj The object containing the component values to set for this Vector. */ - reset(): Phaser.Math.Vector4; + setFromObject(obj: Phaser.Types.Math.Vector2Like): Phaser.Math.Vector2; - } + /** + * Set the `x` and `y` components of the this Vector to the given `x` and `y` values. + * @param x The x value to set for this Vector. + * @param y The y value to set for this Vector. Default x. + */ + set(x: number, y?: number): Phaser.Math.Vector2; - /** - * Checks if the two values are within the given `tolerance` of each other. - * @param a The first value to use in the calculation. - * @param b The second value to use in the calculation. - * @param tolerance The tolerance. Anything equal to or less than this value is considered as being within range. - */ - function Within(a: number, b: number, tolerance: number): boolean; + /** + * This method is an alias for `Vector2.set`. + * @param x The x value to set for this Vector. + * @param y The y value to set for this Vector. Default x. + */ + setTo(x: number, y?: number): Phaser.Math.Vector2; - /** - * Wrap the given `value` between `min` and `max. - * @param value The value to wrap. - * @param min The minimum value. - * @param max The maximum value. - */ - function Wrap(value: number, min: number, max: number): number; + /** + * Sets the `x` and `y` values of this object from a given polar coordinate. + * @param azimuth The angular coordinate, in radians. + * @param radius The radial coordinate (length). Default 1. + */ + setToPolar(azimuth: number, radius?: number): Phaser.Math.Vector2; - } + /** + * Check whether this Vector is equal to a given Vector. + * + * Performs a strict equality check against each Vector's components. + * @param v The vector to compare with this Vector. + */ + equals(v: Phaser.Math.Vector2): boolean; - /** - * The root types namespace. - */ - namespace Types { - namespace Actions { - type CallCallback = (item: Phaser.GameObjects.GameObject)=>void; + /** + * Check whether this Vector is approximately equal to a given Vector. + * @param v The vector to compare with this Vector. + * @param epsilon The tolerance value. Default 0.0001. + */ + fuzzyEquals(v: Phaser.Math.Vector2, epsilon?: number): boolean; - type GridAlignConfig = { - /** - * The width of the grid in items (not pixels). -1 means lay all items out horizontally, regardless of quantity. - * If both this value and height are set to -1 then this value overrides it and the `height` value is ignored. - */ - width?: integer; - /** - * The height of the grid in items (not pixels). -1 means lay all items out vertically, regardless of quantity. - * If both this value and `width` are set to -1 then `width` overrides it and this value is ignored. - */ - height?: integer; - /** - * The width of the cell, in pixels, in which the item is positioned. - */ - cellWidth?: integer; - /** - * The height of the cell, in pixels, in which the item is positioned. - */ - cellHeight?: integer; - /** - * The alignment position. One of the Phaser.Display.Align consts such as `TOP_LEFT` or `RIGHT_CENTER`. - */ - position?: integer; - /** - * Optionally place the top-left of the final grid at this coordinate. - */ - x?: number; - /** - * Optionally place the top-left of the final grid at this coordinate. - */ - y?: number; - }; + /** + * Calculate the angle between this Vector and the positive x-axis, in radians. + */ + angle(): number; - } + /** + * Set the angle of this Vector. + * @param angle The angle, in radians. + */ + setAngle(angle: number): Phaser.Math.Vector2; - namespace Animations { - type Animation = { - /** - * The key that the animation will be associated with. i.e. sprite.animations.play(key) - */ - key?: string; - /** - * An object containing data used to generate the frames for the animation - */ - frames?: Phaser.Types.Animations.AnimationFrame[]; - /** - * The key of the texture all frames of the animation will use. Can be overridden on a per frame basis. - */ - defaultTextureKey?: string; - /** - * The frame rate of playback in frames per second (default 24 if duration is null) - */ - frameRate?: integer; - /** - * How long the animation should play for in milliseconds. If not given its derived from frameRate. - */ - duration?: integer; - /** - * Skip frames if the time lags, or always advanced anyway? - */ - skipMissedFrames?: boolean; - /** - * Delay before starting playback. Value given in milliseconds. - */ - delay?: integer; - /** - * Number of times to repeat the animation (-1 for infinity) - */ - repeat?: integer; - /** - * Delay before the animation repeats. Value given in milliseconds. - */ - repeatDelay?: integer; - /** - * Should the animation yoyo? (reverse back down to the start) before repeating? - */ - yoyo?: boolean; - /** - * Should sprite.visible = true when the animation starts to play? - */ - showOnStart?: boolean; - /** - * Should sprite.visible = false when the animation finishes? - */ - hideOnComplete?: boolean; - }; + /** + * Add a given Vector to this Vector. Addition is component-wise. + * @param src The Vector to add to this Vector. + */ + add(src: Phaser.Math.Vector2): Phaser.Math.Vector2; - type AnimationFrame = { - /** - * The key that the animation will be associated with. i.e. sprite.animations.play(key) - */ - key: string; - /** - * [description] - */ - frame: string | number; - /** - * [description] - */ - duration?: number; - /** - * [description] - */ - visible?: boolean; - }; + /** + * Subtract the given Vector from this Vector. Subtraction is component-wise. + * @param src The Vector to subtract from this Vector. + */ + subtract(src: Phaser.Math.Vector2): Phaser.Math.Vector2; - type GenerateFrameNames = { - /** - * The string to append to every resulting frame name if using a range or an array of `frames`. - */ - prefix?: string; - /** - * If `frames` is not provided, the number of the first frame to return. - */ - start?: integer; - /** - * If `frames` is not provided, the number of the last frame to return. - */ - end?: integer; - /** - * The string to append to every resulting frame name if using a range or an array of `frames`. - */ - suffix?: string; - /** - * The minimum expected lengths of each resulting frame's number. Numbers will be left-padded with zeroes until they are this long, then prepended and appended to create the resulting frame name. - */ - zeroPad?: integer; - /** - * The array to append the created configuration objects to. - */ - outputArray?: Phaser.Types.Animations.AnimationFrame[]; - /** - * If provided as an array, the range defined by `start` and `end` will be ignored and these frame numbers will be used. - */ - frames?: boolean | integer[]; - }; + /** + * Perform a component-wise multiplication between this Vector and the given Vector. + * + * Multiplies this Vector by the given Vector. + * @param src The Vector to multiply this Vector by. + */ + multiply(src: Phaser.Math.Vector2): Phaser.Math.Vector2; - type GenerateFrameNumbers = { - /** - * The starting frame of the animation. - */ - start?: integer; - /** - * The ending frame of the animation. - */ - end?: integer; - /** - * A frame to put at the beginning of the animation, before `start` or `outputArray` or `frames`. - */ - first?: boolean | integer; - /** - * An array to concatenate the output onto. - */ - outputArray?: Phaser.Types.Animations.AnimationFrame[]; - /** - * A custom sequence of frames. - */ - frames?: boolean | integer[]; - }; + /** + * Scale this Vector by the given value. + * @param value The value to scale this Vector by. + */ + scale(value: number): Phaser.Math.Vector2; - type JSONAnimation = { - /** - * The key that the animation will be associated with. i.e. sprite.animations.play(key) - */ - key: string; - /** - * A frame based animation (as opposed to a bone based animation) - */ - type: string; - /** - * [description] - */ - frames: Phaser.Types.Animations.JSONAnimationFrame[]; - /** - * The frame rate of playback in frames per second (default 24 if duration is null) - */ - frameRate: integer; - /** - * How long the animation should play for in milliseconds. If not given its derived from frameRate. - */ - duration: integer; - /** - * Skip frames if the time lags, or always advanced anyway? - */ - skipMissedFrames: boolean; - /** - * Delay before starting playback. Value given in milliseconds. - */ - delay: integer; - /** - * Number of times to repeat the animation (-1 for infinity) - */ - repeat: integer; - /** - * Delay before the animation repeats. Value given in milliseconds. - */ - repeatDelay: integer; - /** - * Should the animation yoyo? (reverse back down to the start) before repeating? - */ - yoyo: boolean; - /** - * Should sprite.visible = true when the animation starts to play? - */ - showOnStart: boolean; - /** - * Should sprite.visible = false when the animation finishes? - */ - hideOnComplete: boolean; - }; + /** + * Perform a component-wise division between this Vector and the given Vector. + * + * Divides this Vector by the given Vector. + * @param src The Vector to divide this Vector by. + */ + divide(src: Phaser.Math.Vector2): Phaser.Math.Vector2; - type JSONAnimationFrame = { - /** - * The key of the Texture this AnimationFrame uses. - */ - key: string; - /** - * The key of the Frame within the Texture that this AnimationFrame uses. - */ - frame: string | integer; - /** - * Additional time (in ms) that this frame should appear for during playback. - */ - duration: number; - }; + /** + * Negate the `x` and `y` components of this Vector. + */ + negate(): Phaser.Math.Vector2; - type JSONAnimations = { - /** - * An array of all Animations added to the Animation Manager. - */ - anims: Phaser.Types.Animations.JSONAnimation[]; - /** - * The global time scale of the Animation Manager. - */ - globalTimeScale: number; - }; + /** + * Calculate the distance between this Vector and the given Vector. + * @param src The Vector to calculate the distance to. + */ + distance(src: Phaser.Math.Vector2): number; - } + /** + * Calculate the distance between this Vector and the given Vector, squared. + * @param src The Vector to calculate the distance to. + */ + distanceSq(src: Phaser.Math.Vector2): number; - namespace Cameras { - namespace Scene2D { - type CameraConfig = { - /** - * The name of the Camera. - */ - name?: string; - /** - * The horizontal position of the Camera viewport. - */ - x?: integer; - /** - * The vertical position of the Camera viewport. - */ - y?: integer; - /** - * The width of the Camera viewport. - */ - width?: integer; - /** - * The height of the Camera viewport. - */ - height?: integer; - /** - * The default zoom level of the Camera. - */ - zoom?: number; - /** - * The rotation of the Camera, in radians. - */ - rotation?: number; - /** - * Should the Camera round pixels before rendering? - */ - roundPixels?: boolean; - /** - * The horizontal scroll position of the Camera. - */ - scrollX?: number; - /** - * The vertical scroll position of the Camera. - */ - scrollY?: number; - /** - * A CSS color string controlling the Camera background color. - */ - backgroundColor?: false | string; - /** - * Defines the Camera bounds. - */ - bounds?: object; - /** - * The top-left extent of the Camera bounds. - */ - "bounds.x"?: number; - /** - * The top-left extent of the Camera bounds. - */ - "bounds.y"?: number; - /** - * The width of the Camera bounds. - */ - "bounds.width"?: number; - /** - * The height of the Camera bounds. - */ - "bounds.height"?: number; - }; + /** + * Calculate the length (or magnitude) of this Vector. + */ + length(): number; - type CameraFadeCallback = (camera: Phaser.Cameras.Scene2D.Camera, progress: number)=>void; + /** + * Set the length (or magnitude) of this Vector. + */ + setLength(length: number): Phaser.Math.Vector2; - type CameraFlashCallback = (camera: Phaser.Cameras.Scene2D.Camera, progress: number)=>void; + /** + * Calculate the length of this Vector squared. + */ + lengthSq(): number; - type CameraPanCallback = (camera: Phaser.Cameras.Scene2D.Camera, progress: number, x: number, y: number)=>void; + /** + * Normalize this Vector. + * + * Makes the vector a unit length vector (magnitude of 1) in the same direction. + */ + normalize(): Phaser.Math.Vector2; - type CameraShakeCallback = (camera: Phaser.Cameras.Scene2D.Camera, progress: number)=>void; + /** + * Rotate this Vector to its perpendicular, in the positive direction. + */ + normalizeRightHand(): Phaser.Math.Vector2; - type CameraZoomCallback = (camera: Phaser.Cameras.Scene2D.Camera, progress: number, zoom: number)=>void; + /** + * Rotate this Vector to its perpendicular, in the negative direction. + */ + normalizeLeftHand(): Phaser.Math.Vector2; - type JSONCamera = { - /** - * The name of the camera - */ - name: string; - /** - * The horizontal position of camera - */ - x: number; - /** - * The vertical position of camera - */ - y: number; - /** - * The width size of camera - */ - width: number; - /** - * The height size of camera - */ - height: number; - /** - * The zoom of camera - */ - zoom: number; - /** - * The rotation of camera - */ - rotation: number; - /** - * The round pixels st status of camera - */ - roundPixels: boolean; - /** - * The horizontal scroll of camera - */ - scrollX: number; - /** - * The vertical scroll of camera - */ - scrollY: number; - /** - * The background color of camera - */ - backgroundColor: string; - /** - * The bounds of camera - */ - bounds?: Phaser.Types.Cameras.Scene2D.JSONCameraBounds | undefined; - }; + /** + * Calculate the dot product of this Vector and the given Vector. + * @param src The Vector2 to dot product with this Vector2. + */ + dot(src: Phaser.Math.Vector2): number; - type JSONCameraBounds = { - /** - * The horizontal position of camera - */ - x: number; - /** - * The vertical position of camera - */ - y: number; - /** - * The width size of camera - */ - width: number; - /** - * The height size of camera - */ - height: number; - }; + /** + * Calculate the cross product of this Vector and the given Vector. + * @param src The Vector2 to cross with this Vector2. + */ + cross(src: Phaser.Math.Vector2): number; - } + /** + * Linearly interpolate between this Vector and the given Vector. + * + * Interpolates this Vector towards the given Vector. + * @param src The Vector2 to interpolate towards. + * @param t The interpolation percentage, between 0 and 1. Default 0. + */ + lerp(src: Phaser.Math.Vector2, t?: number): Phaser.Math.Vector2; - namespace Controls { - type FixedKeyControlConfig = { - /** - * The Camera that this Control will update. - */ - camera?: Phaser.Cameras.Scene2D.Camera; - /** - * The Key to be pressed that will move the Camera left. - */ - left?: Phaser.Input.Keyboard.Key; - /** - * The Key to be pressed that will move the Camera right. - */ - right?: Phaser.Input.Keyboard.Key; - /** - * The Key to be pressed that will move the Camera up. - */ - up?: Phaser.Input.Keyboard.Key; - /** - * The Key to be pressed that will move the Camera down. - */ - down?: Phaser.Input.Keyboard.Key; - /** - * The Key to be pressed that will zoom the Camera in. - */ - zoomIn?: Phaser.Input.Keyboard.Key; - /** - * The Key to be pressed that will zoom the Camera out. - */ - zoomOut?: Phaser.Input.Keyboard.Key; - /** - * The speed at which the camera will zoom if the `zoomIn` or `zoomOut` keys are pressed. - */ - zoomSpeed?: number; - /** - * The horizontal and vertical speed the camera will move. - */ - speed?: number | Object; - }; + /** + * Transform this Vector with the given Matrix. + * @param mat The Matrix3 to transform this Vector2 with. + */ + transformMat3(mat: Phaser.Math.Matrix3): Phaser.Math.Vector2; - type SmoothedKeyControlConfig = { - /** - * The Camera that this Control will update. - */ - camera?: Phaser.Cameras.Scene2D.Camera; - /** - * The Key to be pressed that will move the Camera left. - */ - left?: Phaser.Input.Keyboard.Key; - /** - * The Key to be pressed that will move the Camera right. - */ - right?: Phaser.Input.Keyboard.Key; - /** - * The Key to be pressed that will move the Camera up. - */ - up?: Phaser.Input.Keyboard.Key; - /** - * The Key to be pressed that will zoom the Camera in. - */ - zoomIn?: Phaser.Input.Keyboard.Key; - /** - * The Key to be pressed that will zoom the Camera out. - */ - zoomOut?: Phaser.Input.Keyboard.Key; - /** - * The speed at which the camera will zoom if the `zoomIn` or `zoomOut` keys are pressed. - */ - zoomSpeed?: number; - /** - * The horizontal and vertical acceleration the camera will move. - */ - acceleration?: number | Object; - /** - * The horizontal and vertical drag applied to the camera when it is moving. - */ - drag?: number | Object; - /** - * The maximum horizontal and vertical speed the camera will move. - */ - maxSpeed?: number | Object; - }; + /** + * Transform this Vector with the given Matrix. + * @param mat The Matrix4 to transform this Vector2 with. + */ + transformMat4(mat: Phaser.Math.Matrix4): Phaser.Math.Vector2; - } + /** + * Make this Vector the zero vector (0, 0). + */ + reset(): Phaser.Math.Vector2; - } + /** + * Limit the length (or magnitude) of this Vector. + * @param max The maximum length. + */ + limit(max: number): Phaser.Math.Vector2; - namespace Core { /** - * Config object containing various sound settings. + * Reflect this Vector off a line defined by a normal. + * @param normal A vector perpendicular to the line. */ - type AudioConfig = { - /** - * Use HTML5 Audio instead of Web Audio. - */ - disableWebAudio?: boolean; - /** - * An existing Web Audio context. - */ - context?: AudioContext; - /** - * Disable all audio output. - */ - noAudio?: boolean; - }; + reflect(normal: Phaser.Math.Vector2): Phaser.Math.Vector2; - type BannerConfig = { - /** - * Omit Phaser's name and version from the banner. - */ - hidePhaser?: boolean; - /** - * The color of the banner text. - */ - text?: string; - /** - * The background colors of the banner. - */ - background?: string[]; - }; + /** + * Reflect this Vector across another. + * @param axis A vector to reflect across. + */ + mirror(axis: Phaser.Math.Vector2): Phaser.Math.Vector2; - type BootCallback = (game: Phaser.Game)=>void; + /** + * Rotate this Vector by an angle amount. + * @param delta The angle to rotate by, in radians. + */ + rotate(delta: number): Phaser.Math.Vector2; - type CallbacksConfig = { - /** - * A function to run at the start of the boot sequence. - */ - preBoot?: Phaser.Types.Core.BootCallback; - /** - * A function to run at the end of the boot sequence. At this point, all the game systems have started and plugins have been loaded. - */ - postBoot?: Phaser.Types.Core.BootCallback; - }; + /** + * A static zero Vector2 for use by reference. + * + * This constant is meant for comparison operations and should not be modified directly. + */ + static readonly ZERO: Phaser.Math.Vector2; - type DOMContainerConfig = { - /** - * Should the game create a div element to act as a DOM Container? Only enable if you're using DOM Element objects. You must provide a parent object if you use this feature. - */ - createContainer?: boolean; - /** - * Should the DOM Container that is created (if `dom.createContainer` is true) be positioned behind (true) or over the top (false, the default) of the game canvas? - */ - behindCanvas?: boolean; - }; + /** + * A static right Vector2 for use by reference. + * + * This constant is meant for comparison operations and should not be modified directly. + */ + static readonly RIGHT: Phaser.Math.Vector2; - type FPSConfig = { - /** - * The minimum acceptable rendering rate, in frames per second. - */ - min?: integer; - /** - * The optimum rendering rate, in frames per second. - */ - target?: integer; - /** - * Use setTimeout instead of requestAnimationFrame to run the game loop. - */ - forceSetTimeOut?: boolean; - /** - * Calculate the average frame delta from this many consecutive frame intervals. - */ - deltaHistory?: integer; - /** - * The amount of frames the time step counts before we trust the delta values again. - */ - panicMax?: integer; - /** - * Apply delta smoothing during the game update to help avoid spikes? - */ - smoothStep?: boolean; - }; + /** + * A static left Vector2 for use by reference. + * + * This constant is meant for comparison operations and should not be modified directly. + */ + static readonly LEFT: Phaser.Math.Vector2; - type GameConfig = { - /** - * The width of the game, in game pixels. - */ - width?: integer | string; - /** - * The height of the game, in game pixels. - */ - height?: integer | string; - /** - * Simple scale applied to the game canvas. 2 is double size, 0.5 is half size, etc. - */ - zoom?: number; - /** - * The size of each game pixel, in canvas pixels. Values larger than 1 are "high" resolution. - */ - resolution?: number; - /** - * Which renderer to use. Phaser.AUTO, Phaser.CANVAS, Phaser.HEADLESS, or Phaser.WEBGL. AUTO picks WEBGL if available, otherwise CANVAS. - */ - type?: number; - /** - * The DOM element that will contain the game canvas, or its `id`. If undefined or if the named element doesn't exist, the game canvas is inserted directly into the document body. If `null` no parent will be used and you are responsible for adding the canvas to your environment. - */ - parent?: HTMLElement | string; - /** - * Provide your own Canvas element for Phaser to use instead of creating one. - */ - canvas?: HTMLCanvasElement; - /** - * CSS styles to apply to the game canvas instead of Phasers default styles. - */ - canvasStyle?: string; - /** - * Is Phaser running under a custom (non-native web) environment? If so, set this to `true` to skip internal Feature detection. If `true` the `renderType` cannot be left as `AUTO`. - */ - customEnvironment?: boolean; - /** - * Provide your own Canvas Context for Phaser to use, instead of creating one. - */ - context?: CanvasRenderingContext2D; - /** - * A scene or scenes to add to the game. If several are given, the first is started; the remainder are started only if they have `{ active: true }`. See the `sceneConfig` argument in `Phaser.Scenes.SceneManager#add`. - */ - scene?: Phaser.Scene | Phaser.Scene[] | Phaser.Types.Scenes.SettingsConfig | Phaser.Types.Scenes.SettingsConfig[] | Phaser.Types.Scenes.CreateSceneFromObjectConfig | Phaser.Types.Scenes.CreateSceneFromObjectConfig[] | Function | Function[]; - /** - * Seed for the random number generator. - */ - seed?: string[]; - /** - * The title of the game. Shown in the browser console. - */ - title?: string; - /** - * The URL of the game. Shown in the browser console. - */ - url?: string; - /** - * The version of the game. Shown in the browser console. - */ - version?: string; - /** - * Automatically call window.focus() when the game boots. Usually necessary to capture input events if the game is in a separate frame. - */ - autoFocus?: boolean; - /** - * Input configuration, or `false` to disable all game input. - */ - input?: boolean | Phaser.Types.Core.InputConfig; - /** - * Disable the browser's default 'contextmenu' event (usually triggered by a right-button mouse click). - */ - disableContextMenu?: boolean; - /** - * Whether the game canvas will have a transparent background. - */ - transparent?: boolean; - /** - * Configuration for the banner printed in the browser console when the game starts. - */ - banner?: boolean | Phaser.Types.Core.BannerConfig; - /** - * The DOM Container configuration object. - */ - dom?: Phaser.Types.Core.DOMContainerConfig; - /** - * Game loop configuration. - */ - fps?: Phaser.Types.Core.FPSConfig; - /** - * Game renderer configuration. - */ - render?: Phaser.Types.Core.RenderConfig; - /** - * The background color of the game canvas. The default is black. - */ - backgroundColor?: string | number; - /** - * Optional callbacks to run before or after game boot. - */ - callbacks?: Phaser.Types.Core.CallbacksConfig; - /** - * Loader configuration. - */ - loader?: Phaser.Types.Core.LoaderConfig; - /** - * Images configuration. - */ - images?: Phaser.Types.Core.ImagesConfig; - /** - * Physics configuration. - */ - physics?: Phaser.Types.Core.PhysicsConfig; - /** - * Plugins to install. - */ - plugins?: Phaser.Types.Core.PluginObject | Phaser.Types.Core.PluginObjectItem[]; - /** - * The Scale Manager configuration. - */ - scale?: Phaser.Types.Core.ScaleConfig; - /** - * The Audio Configuration object. - */ - audio?: Phaser.Types.Core.AudioConfig; - }; + /** + * A static up Vector2 for use by reference. + * + * This constant is meant for comparison operations and should not be modified directly. + */ + static readonly UP: Phaser.Math.Vector2; - type GamepadInputConfig = { - /** - * Where the Gamepad Manager listens for gamepad input events. - */ - target?: any; - }; + /** + * A static down Vector2 for use by reference. + * + * This constant is meant for comparison operations and should not be modified directly. + */ + static readonly DOWN: Phaser.Math.Vector2; - type ImagesConfig = { - /** - * URL to use for the 'default' texture. - */ - default?: string; - /** - * URL to use for the 'missing' texture. - */ - missing?: string; - }; + /** + * A static one Vector2 for use by reference. + * + * This constant is meant for comparison operations and should not be modified directly. + */ + static readonly ONE: Phaser.Math.Vector2; - type InputConfig = { - /** - * Keyboard input configuration. `true` uses the default configuration and `false` disables keyboard input. - */ - keyboard?: boolean | Phaser.Types.Core.KeyboardInputConfig; - /** - * Mouse input configuration. `true` uses the default configuration and `false` disables mouse input. - */ - mouse?: boolean | Phaser.Types.Core.MouseInputConfig; - /** - * Touch input configuration. `true` uses the default configuration and `false` disables touch input. - */ - touch?: boolean | Phaser.Types.Core.TouchInputConfig; - /** - * Gamepad input configuration. `true` enables gamepad input. - */ - gamepad?: boolean | Phaser.Types.Core.GamepadInputConfig; - /** - * The maximum number of touch pointers. See {@link Phaser.Input.InputManager#pointers}. - */ - activePointers?: integer; - /** - * The smoothing factor to apply during Pointer movement. See {@link Phaser.Input.Pointer#smoothFactor}. - */ - smoothFactor?: number; - /** - * Should Phaser listen for input events on the Window? If you disable this, events like 'POINTER_UP_OUTSIDE' will no longer fire. - */ - windowEvents?: boolean; - }; + } - type KeyboardInputConfig = { - /** - * Where the Keyboard Manager listens for keyboard input events. - */ - target?: any; - /** - * `preventDefault` will be called on every non-modified key which has a key code in this array. By default it is empty. - */ - capture?: integer[]; - }; + /** + * A representation of a vector in 3D space. + * + * A three-component vector. + */ + class Vector3 { + /** + * + * @param x The x component. + * @param y The y component. + * @param z The z component. + */ + constructor(x?: number, y?: number, z?: number); - type LoaderConfig = { - /** - * A URL used to resolve paths given to the loader. Example: 'http://labs.phaser.io/assets/'. - */ - baseURL?: string; - /** - * A URL path used to resolve relative paths given to the loader. Example: 'images/sprites/'. - */ - path?: string; - /** - * The maximum number of resources the loader will start loading at once. - */ - maxParallelDownloads?: integer; - /** - * 'anonymous', 'use-credentials', or `undefined`. If you're not making cross-origin requests, leave this as `undefined`. See {@link https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes}. - */ - crossOrigin?: string | undefined; - /** - * The response type of the XHR request, e.g. `blob`, `text`, etc. - */ - responseType?: string; - /** - * Should the XHR request use async or not? - */ - async?: boolean; - /** - * Optional username for all XHR requests. - */ - user?: string; - /** - * Optional password for all XHR requests. - */ - password?: string; - /** - * Optional XHR timeout value, in ms. - */ - timeout?: integer; - }; + /** + * The x component of this Vector. + */ + x: number; - type MouseInputConfig = { - /** - * Where the Mouse Manager listens for mouse input events. The default is the game canvas. - */ - target?: any; - /** - * Whether mouse input events have `preventDefault` called on them. - */ - capture?: boolean; - }; + /** + * The y component of this Vector. + */ + y: number; /** - * This callback type is completely empty, a no-operation. + * The z component of this Vector. */ - type NOOP = ()=>void; + z: number; - type PhysicsConfig = { - /** - * The default physics system. It will be started for each scene. Phaser provides 'arcade', 'impact', and 'matter'. - */ - default?: string; - /** - * Arcade Physics configuration. - */ - arcade?: Phaser.Types.Physics.Arcade.ArcadeWorldConfig; - /** - * Impact Physics configuration. - */ - impact?: Phaser.Types.Physics.Impact.WorldConfig; - /** - * Matter Physics configuration. - */ - matter?: Phaser.Types.Physics.Matter.MatterWorldConfig; - }; + /** + * Set this Vector to point up. + * + * Sets the y component of the vector to 1, and the others to 0. + */ + up(): Phaser.Math.Vector3; - type PluginObject = { - /** - * Global plugins to install. - */ - global?: Phaser.Types.Core.PluginObjectItem[]; - /** - * Scene plugins to install. - */ - scene?: Phaser.Types.Core.PluginObjectItem[]; - /** - * The default set of scene plugins (names). - */ - default?: string[]; - /** - * Plugins to *add* to the default set of scene plugins. - */ - defaultMerge?: string[]; - }; + /** + * Sets the components of this Vector to be the `Math.min` result from the given vector. + * @param v The Vector3 to check the minimum values against. + */ + min(v: Phaser.Math.Vector3): Phaser.Math.Vector3; - type PluginObjectItem = { - /** - * A key to identify the plugin in the Plugin Manager. - */ - key?: string; - /** - * The plugin itself. Usually a class/constructor. - */ - plugin?: any; - /** - * Whether the plugin should be started automatically. - */ - start?: boolean; - /** - * For a scene plugin, add the plugin to the scene's systems object under this key (`this.sys.KEY`, from the scene). - */ - systemKey?: string; - /** - * For a scene plugin, add the plugin to the scene object under this key (`this.KEY`, from the scene). - */ - sceneKey?: string; - /** - * If this plugin is to be injected into the Scene Systems, this is the property key map used. - */ - mapping?: string; - /** - * Arbitrary data passed to the plugin's init() method. - */ - data?: any; - }; + /** + * Sets the components of this Vector to be the `Math.max` result from the given vector. + * @param v The Vector3 to check the maximum values against. + */ + max(v: Phaser.Math.Vector3): Phaser.Math.Vector3; - type RenderConfig = { - /** - * When set to `true`, WebGL uses linear interpolation to draw scaled or rotated textures, giving a smooth appearance. When set to `false`, WebGL uses nearest-neighbor interpolation, giving a crisper appearance. `false` also disables antialiasing of the game canvas itself, if the browser supports it, when the game canvas is scaled. - */ - antialias?: boolean; - /** - * Sets the `antialias` property when the WebGL context is created. Setting this value does not impact any subsequent textures that are created, or the canvas style attributes. - */ - antialiasGL?: boolean; - /** - * When set to `true` it will create a desynchronized context for both 2D and WebGL. See https://developers.google.com/web/updates/2019/05/desynchronized for details. - */ - desynchronized?: boolean; - /** - * Sets `antialias` and `roundPixels` to true. This is the best setting for pixel-art games. - */ - pixelArt?: boolean; - /** - * Draw texture-based Game Objects at only whole-integer positions. Game Objects without textures, like Graphics, ignore this property. - */ - roundPixels?: boolean; - /** - * Whether the game canvas will be transparent. Boolean that indicates if the canvas contains an alpha channel. If set to false, the browser now knows that the backdrop is always opaque, which can speed up drawing of transparent content and images. - */ - transparent?: boolean; - /** - * Whether the game canvas will be cleared between each rendering frame. - */ - clearBeforeRender?: boolean; - /** - * In WebGL mode, the drawing buffer contains colors with pre-multiplied alpha. + /** + * Make a clone of this Vector3. + */ + clone(): Phaser.Math.Vector3; + + /** + * Adds the two given Vector3s and sets the results into this Vector3. + * @param a The first Vector to add. + * @param b The second Vector to add. + */ + addVectors(a: Phaser.Math.Vector3, b: Phaser.Math.Vector3): Phaser.Math.Vector3; + + /** + * Calculate the cross (vector) product of two given Vectors. + * @param a The first Vector to multiply. + * @param b The second Vector to multiply. + */ + crossVectors(a: Phaser.Math.Vector3, b: Phaser.Math.Vector3): Phaser.Math.Vector3; + + /** + * Check whether this Vector is equal to a given Vector. + * + * Performs a strict equality check against each Vector's components. + * @param v The Vector3 to compare against. + */ + equals(v: Phaser.Math.Vector3): boolean; + + /** + * Copy the components of a given Vector into this Vector. + * @param src The Vector to copy the components from. + */ + copy(src: Phaser.Math.Vector2 | Phaser.Math.Vector3): Phaser.Math.Vector3; + + /** + * Set the `x`, `y`, and `z` components of this Vector to the given `x`, `y`, and `z` values. + * @param x The x value to set for this Vector, or an object containing x, y and z components. + * @param y The y value to set for this Vector. + * @param z The z value to set for this Vector. + */ + set(x: number | object, y?: number, z?: number): Phaser.Math.Vector3; + + /** + * Sets the components of this Vector3 from the position of the given Matrix4. + * @param mat4 The Matrix4 to get the position from. + */ + setFromMatrixPosition(mat4: Phaser.Math.Matrix4): Phaser.Math.Vector3; + + /** + * Sets the components of this Vector3 from the Matrix4 column specified. + * @param mat4 The Matrix4 to get the column from. + * @param index The column index. + */ + setFromMatrixColumn(mat4: Phaser.Math.Matrix4, index: number): Phaser.Math.Vector3; + + /** + * Sets the components of this Vector3 from the given array, based on the offset. + * + * Vector3.x = array[offset] + * Vector3.y = array[offset + 1] + * Vector3.z = array[offset + 2] + * @param array The array of values to get this Vector from. + * @param offset The offset index into the array. Default 0. + */ + fromArray(array: number[], offset?: number): Phaser.Math.Vector3; + + /** + * Add a given Vector to this Vector. Addition is component-wise. + * @param v The Vector to add to this Vector. + */ + add(v: Phaser.Math.Vector2 | Phaser.Math.Vector3): Phaser.Math.Vector3; + + /** + * Add the given value to each component of this Vector. + * @param s The amount to add to this Vector. + */ + addScalar(s: number): Phaser.Math.Vector3; + + /** + * Add and scale a given Vector to this Vector. Addition is component-wise. + * @param v The Vector to add to this Vector. + * @param scale The amount to scale `v` by. + */ + addScale(v: Phaser.Math.Vector2 | Phaser.Math.Vector3, scale: number): Phaser.Math.Vector3; + + /** + * Subtract the given Vector from this Vector. Subtraction is component-wise. + * @param v The Vector to subtract from this Vector. + */ + subtract(v: Phaser.Math.Vector2 | Phaser.Math.Vector3): Phaser.Math.Vector3; + + /** + * Perform a component-wise multiplication between this Vector and the given Vector. + * + * Multiplies this Vector by the given Vector. + * @param v The Vector to multiply this Vector by. + */ + multiply(v: Phaser.Math.Vector2 | Phaser.Math.Vector3): Phaser.Math.Vector3; + + /** + * Scale this Vector by the given value. + * @param scale The value to scale this Vector by. + */ + scale(scale: number): Phaser.Math.Vector3; + + /** + * Perform a component-wise division between this Vector and the given Vector. + * + * Divides this Vector by the given Vector. + * @param v The Vector to divide this Vector by. + */ + divide(v: Phaser.Math.Vector2 | Phaser.Math.Vector3): Phaser.Math.Vector3; + + /** + * Negate the `x`, `y` and `z` components of this Vector. + */ + negate(): Phaser.Math.Vector3; + + /** + * Calculate the distance between this Vector and the given Vector. + * @param v The Vector to calculate the distance to. + */ + distance(v: Phaser.Math.Vector2 | Phaser.Math.Vector3): number; + + /** + * Calculate the distance between this Vector and the given Vector, squared. + * @param v The Vector to calculate the distance to. + */ + distanceSq(v: Phaser.Math.Vector2 | Phaser.Math.Vector3): number; + + /** + * Calculate the length (or magnitude) of this Vector. + */ + length(): number; + + /** + * Calculate the length of this Vector squared. + */ + lengthSq(): number; + + /** + * Normalize this Vector. + * + * Makes the vector a unit length vector (magnitude of 1) in the same direction. + */ + normalize(): Phaser.Math.Vector3; + + /** + * Calculate the dot product of this Vector and the given Vector. + * @param v The Vector3 to dot product with this Vector3. + */ + dot(v: Phaser.Math.Vector3): number; + + /** + * Calculate the cross (vector) product of this Vector (which will be modified) and the given Vector. + * @param v The Vector to cross product with. + */ + cross(v: Phaser.Math.Vector3): Phaser.Math.Vector3; + + /** + * Linearly interpolate between this Vector and the given Vector. + * + * Interpolates this Vector towards the given Vector. + * @param v The Vector3 to interpolate towards. + * @param t The interpolation percentage, between 0 and 1. Default 0. + */ + lerp(v: Phaser.Math.Vector3, t?: number): Phaser.Math.Vector3; + + /** + * Takes a Matrix3 and applies it to this Vector3. + * @param mat3 The Matrix3 to apply to this Vector3. + */ + applyMatrix3(mat3: Phaser.Math.Matrix3): Phaser.Math.Vector3; + + /** + * Takes a Matrix4 and applies it to this Vector3. + * @param mat4 The Matrix4 to apply to this Vector3. + */ + applyMatrix4(mat4: Phaser.Math.Matrix4): Phaser.Math.Vector3; + + /** + * Transform this Vector with the given Matrix. + * @param mat The Matrix3 to transform this Vector3 with. + */ + transformMat3(mat: Phaser.Math.Matrix3): Phaser.Math.Vector3; + + /** + * Transform this Vector with the given Matrix4. + * @param mat The Matrix4 to transform this Vector3 with. + */ + transformMat4(mat: Phaser.Math.Matrix4): Phaser.Math.Vector3; + + /** + * Transforms the coordinates of this Vector3 with the given Matrix4. + * @param mat The Matrix4 to transform this Vector3 with. + */ + transformCoordinates(mat: Phaser.Math.Matrix4): Phaser.Math.Vector3; + + /** + * Transform this Vector with the given Quaternion. + * @param q The Quaternion to transform this Vector with. + */ + transformQuat(q: Phaser.Math.Quaternion): Phaser.Math.Vector3; + + /** + * Multiplies this Vector3 by the specified matrix, applying a W divide. This is useful for projection, + * e.g. unprojecting a 2D point into 3D space. + * @param mat The Matrix4 to multiply this Vector3 with. + */ + project(mat: Phaser.Math.Matrix4): Phaser.Math.Vector3; + + /** + * Multiplies this Vector3 by the given view and projection matrices. + * @param viewMatrix A View Matrix. + * @param projectionMatrix A Projection Matrix. + */ + projectViewMatrix(viewMatrix: Phaser.Math.Matrix4, projectionMatrix: Phaser.Math.Matrix4): Phaser.Math.Vector3; + + /** + * Multiplies this Vector3 by the given inversed projection matrix and world matrix. + * @param projectionMatrix An inversed Projection Matrix. + * @param worldMatrix A World View Matrix. + */ + unprojectViewMatrix(projectionMatrix: Phaser.Math.Matrix4, worldMatrix: Phaser.Math.Matrix4): Phaser.Math.Vector3; + + /** + * Unproject this point from 2D space to 3D space. + * The point should have its x and y properties set to + * 2D screen space, and the z either at 0 (near plane) + * or 1 (far plane). The provided matrix is assumed to already + * be combined, i.e. projection * view * model. + * + * After this operation, this vector's (x, y, z) components will + * represent the unprojected 3D coordinate. + * @param viewport Screen x, y, width and height in pixels. + * @param invProjectionView Combined projection and view matrix. + */ + unproject(viewport: Phaser.Math.Vector4, invProjectionView: Phaser.Math.Matrix4): Phaser.Math.Vector3; + + /** + * Make this Vector the zero vector (0, 0, 0). + */ + reset(): Phaser.Math.Vector3; + + /** + * A static zero Vector3 for use by reference. + * + * This constant is meant for comparison operations and should not be modified directly. + */ + static readonly ZERO: Phaser.Math.Vector3; + + /** + * A static right Vector3 for use by reference. + * + * This constant is meant for comparison operations and should not be modified directly. + */ + static readonly RIGHT: Phaser.Math.Vector3; + + /** + * A static left Vector3 for use by reference. + * + * This constant is meant for comparison operations and should not be modified directly. + */ + static readonly LEFT: Phaser.Math.Vector3; + + /** + * A static up Vector3 for use by reference. + * + * This constant is meant for comparison operations and should not be modified directly. + */ + static readonly UP: Phaser.Math.Vector3; + + /** + * A static down Vector3 for use by reference. + * + * This constant is meant for comparison operations and should not be modified directly. + */ + static readonly DOWN: Phaser.Math.Vector3; + + /** + * A static forward Vector3 for use by reference. + * + * This constant is meant for comparison operations and should not be modified directly. + */ + static readonly FORWARD: Phaser.Math.Vector3; + + /** + * A static back Vector3 for use by reference. + * + * This constant is meant for comparison operations and should not be modified directly. + */ + static readonly BACK: Phaser.Math.Vector3; + + /** + * A static one Vector3 for use by reference. + * + * This constant is meant for comparison operations and should not be modified directly. + */ + static readonly ONE: Phaser.Math.Vector3; + + } + + /** + * A representation of a vector in 4D space. + * + * A four-component vector. + */ + class Vector4 { + /** + * + * @param x The x component. + * @param y The y component. + * @param z The z component. + * @param w The w component. + */ + constructor(x?: number, y?: number, z?: number, w?: number); + + /** + * The x component of this Vector. + */ + x: number; + + /** + * The y component of this Vector. + */ + y: number; + + /** + * The z component of this Vector. + */ + z: number; + + /** + * The w component of this Vector. + */ + w: number; + + /** + * Make a clone of this Vector4. + */ + clone(): Phaser.Math.Vector4; + + /** + * Copy the components of a given Vector into this Vector. + * @param src The Vector to copy the components from. + */ + copy(src: Phaser.Math.Vector4): Phaser.Math.Vector4; + + /** + * Check whether this Vector is equal to a given Vector. + * + * Performs a strict quality check against each Vector's components. + * @param v The vector to check equality with. + */ + equals(v: Phaser.Math.Vector4): boolean; + + /** + * Set the `x`, `y`, `z` and `w` components of the this Vector to the given `x`, `y`, `z` and `w` values. + * @param x The x value to set for this Vector, or an object containing x, y, z and w components. + * @param y The y value to set for this Vector. + * @param z The z value to set for this Vector. + * @param w The z value to set for this Vector. + */ + set(x: number | object, y: number, z: number, w: number): Phaser.Math.Vector4; + + /** + * Add a given Vector to this Vector. Addition is component-wise. + * @param v The Vector to add to this Vector. + */ + add(v: Phaser.Math.Vector2 | Phaser.Math.Vector3 | Phaser.Math.Vector4): Phaser.Math.Vector4; + + /** + * Subtract the given Vector from this Vector. Subtraction is component-wise. + * @param v The Vector to subtract from this Vector. + */ + subtract(v: Phaser.Math.Vector2 | Phaser.Math.Vector3 | Phaser.Math.Vector4): Phaser.Math.Vector4; + + /** + * Scale this Vector by the given value. + * @param scale The value to scale this Vector by. + */ + scale(scale: number): Phaser.Math.Vector4; + + /** + * Calculate the length (or magnitude) of this Vector. + */ + length(): number; + + /** + * Calculate the length of this Vector squared. + */ + lengthSq(): number; + + /** + * Normalize this Vector. + * + * Makes the vector a unit length vector (magnitude of 1) in the same direction. + */ + normalize(): Phaser.Math.Vector4; + + /** + * Calculate the dot product of this Vector and the given Vector. + * @param v The Vector4 to dot product with this Vector4. + */ + dot(v: Phaser.Math.Vector4): number; + + /** + * Linearly interpolate between this Vector and the given Vector. + * + * Interpolates this Vector towards the given Vector. + * @param v The Vector4 to interpolate towards. + * @param t The interpolation percentage, between 0 and 1. Default 0. + */ + lerp(v: Phaser.Math.Vector4, t?: number): Phaser.Math.Vector4; + + /** + * Perform a component-wise multiplication between this Vector and the given Vector. + * + * Multiplies this Vector by the given Vector. + * @param v The Vector to multiply this Vector by. + */ + multiply(v: Phaser.Math.Vector2 | Phaser.Math.Vector3 | Phaser.Math.Vector4): Phaser.Math.Vector4; + + /** + * Perform a component-wise division between this Vector and the given Vector. + * + * Divides this Vector by the given Vector. + * @param v The Vector to divide this Vector by. + */ + divide(v: Phaser.Math.Vector2 | Phaser.Math.Vector3 | Phaser.Math.Vector4): Phaser.Math.Vector4; + + /** + * Calculate the distance between this Vector and the given Vector. + * @param v The Vector to calculate the distance to. + */ + distance(v: Phaser.Math.Vector2 | Phaser.Math.Vector3 | Phaser.Math.Vector4): number; + + /** + * Calculate the distance between this Vector and the given Vector, squared. + * @param v The Vector to calculate the distance to. + */ + distanceSq(v: Phaser.Math.Vector2 | Phaser.Math.Vector3 | Phaser.Math.Vector4): number; + + /** + * Negate the `x`, `y`, `z` and `w` components of this Vector. + */ + negate(): Phaser.Math.Vector4; + + /** + * Transform this Vector with the given Matrix. + * @param mat The Matrix4 to transform this Vector4 with. + */ + transformMat4(mat: Phaser.Math.Matrix4): Phaser.Math.Vector4; + + /** + * Transform this Vector with the given Quaternion. + * @param q The Quaternion to transform this Vector with. + */ + transformQuat(q: Phaser.Math.Quaternion): Phaser.Math.Vector4; + + /** + * Make this Vector the zero vector (0, 0, 0, 0). + */ + reset(): Phaser.Math.Vector4; + + } + + /** + * Checks if the two values are within the given `tolerance` of each other. + * @param a The first value to use in the calculation. + * @param b The second value to use in the calculation. + * @param tolerance The tolerance. Anything equal to or less than this value is considered as being within range. + */ + function Within(a: number, b: number, tolerance: number): boolean; + + /** + * Wrap the given `value` between `min` and `max. + * @param value The value to wrap. + * @param min The minimum value. + * @param max The maximum value. + */ + function Wrap(value: number, min: number, max: number): number; + + } + + /** + * The root types namespace. + */ + namespace Types { + namespace Actions { + type CallCallback = (item: Phaser.GameObjects.GameObject)=>void; + + type GridAlignConfig = { + /** + * The width of the grid in items (not pixels). -1 means lay all items out horizontally, regardless of quantity. + * If both this value and height are set to -1 then this value overrides it and the `height` value is ignored. */ - premultipliedAlpha?: boolean; + width?: number; /** - * Let the browser abort creating a WebGL context if it judges performance would be unacceptable. + * The height of the grid in items (not pixels). -1 means lay all items out vertically, regardless of quantity. + * If both this value and `width` are set to -1 then `width` overrides it and this value is ignored. */ - failIfMajorPerformanceCaveat?: boolean; + height?: number; /** - * "high-performance", "low-power" or "default". A hint to the browser on how much device power the game might use. + * The width of the cell, in pixels, in which the item is positioned. */ - powerPreference?: string; + cellWidth?: number; /** - * The default WebGL batch size. + * The height of the cell, in pixels, in which the item is positioned. */ - batchSize?: integer; + cellHeight?: number; /** - * The maximum number of lights allowed to be visible within range of a single Camera in the LightManager. + * The alignment position. One of the Phaser.Display.Align consts such as `TOP_LEFT` or `RIGHT_CENTER`. */ - maxLights?: integer; + position?: number; /** - * The mipmap magFilter to be used when creating WebGL textures. + * Optionally place the top-left of the final grid at this coordinate. */ - mipmapFilter?: string; + x?: number; + /** + * Optionally place the top-left of the final grid at this coordinate. + */ + y?: number; }; - type ScaleConfig = { + } + + namespace Animations { + type Animation = { /** - * The base width of your game. Can be an integer or a string: '100%'. If a string it will only work if you have set a parent element that has a size. + * The key that the animation will be associated with. i.e. sprite.animations.play(key) */ - width?: integer | string; + key?: string; /** - * The base height of your game. Can be an integer or a string: '100%'. If a string it will only work if you have set a parent element that has a size. + * Either a string, in which case it will use all frames from a texture with the matching key, or an array of Animation Frame configuration objects. */ - height?: integer | string; + frames?: string | Phaser.Types.Animations.AnimationFrame[]; /** - * The zoom value of the game canvas. + * If you provide a string for `frames` you can optionally have the frame names numerically sorted. */ - zoom?: Phaser.Scale.ZoomType | integer; + sortFrames?: boolean; /** - * The rendering resolution of the canvas. This is reserved for future use and is currently ignored. + * The key of the texture all frames of the animation will use. Can be overridden on a per frame basis. */ - resolution?: number; + defaultTextureKey?: string; /** - * The DOM element that will contain the game canvas, or its `id`. If undefined, or if the named element doesn't exist, the game canvas is inserted directly into the document body. If `null` no parent will be used and you are responsible for adding the canvas to your environment. + * The frame rate of playback in frames per second (default 24 if duration is null) */ - parent?: HTMLElement | string; + frameRate?: number; /** - * Is the Scale Manager allowed to adjust the CSS height property of the parent and/or document body to be 100%? + * How long the animation should play for in milliseconds. If not given its derived from frameRate. */ - expandParent?: boolean; + duration?: number; /** - * The scale mode. + * Skip frames if the time lags, or always advanced anyway? */ - mode?: Phaser.Scale.ScaleModeType; + skipMissedFrames?: boolean; /** - * The minimum width and height the canvas can be scaled down to. + * Delay before starting playback. Value given in milliseconds. */ - min?: WidthHeight; + delay?: number; /** - * The maximum width the canvas can be scaled up to. + * Number of times to repeat the animation (-1 for infinity) */ - max?: WidthHeight; + repeat?: number; /** - * Automatically round the display and style sizes of the canvas. This can help with performance in lower-powered devices. + * Delay before the animation repeats. Value given in milliseconds. */ - autoRound?: boolean; + repeatDelay?: number; /** - * Automatically center the canvas within the parent? + * Should the animation yoyo? (reverse back down to the start) before repeating? */ - autoCenter?: Phaser.Scale.CenterType; + yoyo?: boolean; /** - * How many ms should elapse before checking if the browser size has changed? + * Should sprite.visible = true when the animation starts to play? */ - resizeInterval?: integer; + showOnStart?: boolean; /** - * The DOM element that will be sent into full screen mode, or its `id`. If undefined Phaser will create its own div and insert the canvas into it when entering fullscreen mode. + * Should sprite.visible = false when the animation finishes? */ - fullscreenTarget?: HTMLElement | string; + hideOnComplete?: boolean; }; - type TimeStepCallback = (time: number, average: number, interpolation: number)=>void; - - type TouchInputConfig = { + type AnimationFrame = { /** - * Where the Touch Manager listens for touch input events. The default is the game canvas. + * The key of the texture within the Texture Manager to use for this Animation Frame. */ - target?: any; + key?: string; /** - * Whether touch input events have preventDefault() called on them. + * The key, or index number, of the frame within the texture to use for this Animation Frame. */ - capture?: boolean; - }; - - type WidthHeight = { + frame?: string | number; /** - * The width. + * The duration, in ms, of this frame of the animation. */ - width?: integer; + duration?: number; /** - * The height. + * Should the parent Game Object be visible during this frame of the animation? */ - height?: integer; + visible?: boolean; }; - } - - namespace Create { - type GenerateTextureCallback = (canvas: HTMLCanvasElement, context: CanvasRenderingContext2D)=>void; - - type GenerateTextureConfig = { - /** - * [description] - */ - data?: any[]; - /** - * [description] - */ - canvas?: HTMLCanvasElement; + type GenerateFrameNames = { /** - * [description] + * The string to append to every resulting frame name if using a range or an array of `frames`. */ - palette?: Phaser.Types.Create.Palette; + prefix?: string; /** - * The width of each 'pixel' in the generated texture. + * If `frames` is not provided, the number of the first frame to return. */ - pixelWidth?: number; + start?: number; /** - * The height of each 'pixel' in the generated texture. + * If `frames` is not provided, the number of the last frame to return. */ - pixelHeight?: number; + end?: number; /** - * [description] + * The string to append to every resulting frame name if using a range or an array of `frames`. */ - resizeCanvas?: boolean; + suffix?: string; /** - * [description] + * The minimum expected lengths of each resulting frame's number. Numbers will be left-padded with zeroes until they are this long, then prepended and appended to create the resulting frame name. */ - clearCanvas?: boolean; + zeroPad?: number; /** - * [description] + * The array to append the created configuration objects to. */ - preRender?: Phaser.Types.Create.GenerateTextureCallback; + outputArray?: Phaser.Types.Animations.AnimationFrame[]; /** - * [description] + * If provided as an array, the range defined by `start` and `end` will be ignored and these frame numbers will be used. */ - postRender?: Phaser.Types.Create.GenerateTextureCallback; + frames?: boolean | number[]; }; - type Palette = { - /** - * Color value 1. - */ - "0": string; - /** - * Color value 2. - */ - "1": string; - /** - * Color value 3. - */ - "2": string; - /** - * Color value 4. - */ - "3": string; - /** - * Color value 5. - */ - "4": string; - /** - * Color value 6. - */ - "5": string; - /** - * Color value 7. - */ - "6": string; - /** - * Color value 8. - */ - "7": string; - /** - * Color value 9. - */ - "8": string; - /** - * Color value 10. - */ - "9": string; - /** - * Color value 11. - */ - A: string; + type GenerateFrameNumbers = { /** - * Color value 12. + * The starting frame of the animation. */ - B: string; + start?: number; /** - * Color value 13. + * The ending frame of the animation. */ - C: string; + end?: number; /** - * Color value 14. + * A frame to put at the beginning of the animation, before `start` or `outputArray` or `frames`. */ - D: string; + first?: boolean | number; /** - * Color value 15. + * An array to concatenate the output onto. */ - E: string; + outputArray?: Phaser.Types.Animations.AnimationFrame[]; /** - * Color value 16. + * A custom sequence of frames. */ - F: string; + frames?: boolean | number[]; }; - } - - namespace Curves { - type EllipseCurveConfig = { - /** - * The x coordinate of the ellipse. - */ - x?: number; - /** - * The y coordinate of the ellipse. - */ - y?: number; - /** - * The horizontal radius of the ellipse. - */ - xRadius?: number; - /** - * The vertical radius of the ellipse. - */ - yRadius?: number; - /** - * The start angle of the ellipse, in degrees. - */ - startAngle?: integer; - /** - * The end angle of the ellipse, in degrees. - */ - endAngle?: integer; - /** - * Sets if the the ellipse rotation is clockwise (true) or anti-clockwise (false) - */ - clockwise?: boolean; + type JSONAnimation = { /** - * The rotation of the ellipse, in degrees. + * The key that the animation will be associated with. i.e. sprite.animations.play(key) */ - rotation?: integer; - }; - - type JSONCurve = { + key: string; /** - * The of the curve + * A frame based animation (as opposed to a bone based animation) */ type: string; /** - * The arrays of points like `[x1, y1, x2, y2]` + * An array of the AnimationFrame objects inside this Animation. */ - points: number[]; - }; - - type JSONEllipseCurve = { + frames: Phaser.Types.Animations.JSONAnimationFrame[]; /** - * The of the curve. + * The frame rate of playback in frames per second (default 24 if duration is null) */ - type: string; + frameRate: number; /** - * The x coordinate of the ellipse. + * How long the animation should play for in milliseconds. If not given its derived from frameRate. */ - x: number; + duration: number; /** - * The y coordinate of the ellipse. + * Skip frames if the time lags, or always advanced anyway? */ - y: number; + skipMissedFrames: boolean; /** - * The horizontal radius of ellipse. + * Delay before starting playback. Value given in milliseconds. */ - xRadius: number; + delay: number; /** - * The vertical radius of ellipse. + * Number of times to repeat the animation (-1 for infinity) */ - yRadius: number; + repeat: number; /** - * The start angle of the ellipse, in degrees. + * Delay before the animation repeats. Value given in milliseconds. */ - startAngle: integer; + repeatDelay: number; /** - * The end angle of the ellipse, in degrees. + * Should the animation yoyo? (reverse back down to the start) before repeating? */ - endAngle: integer; + yoyo: boolean; /** - * Sets if the the ellipse rotation is clockwise (true) or anti-clockwise (false) + * Should sprite.visible = true when the animation starts to play? */ - clockwise: boolean; + showOnStart: boolean; /** - * The rotation of ellipse, in degrees. + * Should sprite.visible = false when the animation finishes? */ - rotation: integer; + hideOnComplete: boolean; }; - type JSONPath = { + type JSONAnimationFrame = { /** - * The of the curve. + * The key of the Texture this AnimationFrame uses. */ - type: string; + key: string; /** - * The X coordinate of the curve's starting point. + * The key of the Frame within the Texture that this AnimationFrame uses. */ - x: number; + frame: string | number; /** - * The Y coordinate of the path's starting point. + * Additional time (in ms) that this frame should appear for during playback. */ - y: number; + duration: number; + }; + + type JSONAnimations = { /** - * The path is auto closed. + * An array of all Animations added to the Animation Manager. */ - autoClose: boolean; + anims: Phaser.Types.Animations.JSONAnimation[]; /** - * The list of the curves + * The global time scale of the Animation Manager. */ - curves: Phaser.Types.Curves.JSONCurve[]; + globalTimeScale: number; }; - } - - namespace Display { - type ColorObject = { + type PlayAnimationConfig = { /** - * The red color value in the range 0 to 255. + * The string-based key of the animation to play, or an Animation instance. */ - r: number; + key: string | Phaser.Animations.Animation; /** - * The green color value in the range 0 to 255. + * The frame rate of playback in frames per second (default 24 if duration is null) */ - g: number; + frameRate?: number; /** - * The blue color value in the range 0 to 255. + * How long the animation should play for in milliseconds. If not given its derived from frameRate. */ - b: number; + duration?: number; /** - * The alpha color value in the range 0 to 255. + * Delay before starting playback. Value given in milliseconds. */ - a: number; - }; - - type HSVColorObject = { + delay?: number; /** - * The hue color value. A number between 0 and 1 + * Number of times to repeat the animation (-1 for infinity) */ - h: number; + repeat?: number; /** - * The saturation color value. A number between 0 and 1 + * Delay before the animation repeats. Value given in milliseconds. */ - s: number; + repeatDelay?: number; /** - * The lightness color value. A number between 0 and 1 + * Should the animation yoyo? (reverse back down to the start) before repeating? */ - v: number; - }; - - type InputColorObject = { + yoyo?: boolean; /** - * The red color value in the range 0 to 255. + * Should sprite.visible = true when the animation starts to play? */ - r?: number; + showOnStart?: boolean; /** - * The green color value in the range 0 to 255. + * Should sprite.visible = false when the animation finishes? */ - g?: number; + hideOnComplete?: boolean; /** - * The blue color value in the range 0 to 255. + * The frame of the animation to start playback from. */ - b?: number; + startFrame?: number; /** - * The alpha color value in the range 0 to 255. + * The time scale to be applied to playback of this animation. */ - a?: number; + timeScale?: number; }; } - namespace GameObjects { - namespace BitmapText { - /** - * The font data for an individual character of a Bitmap Font. - * - * Describes the character's position, size, offset and kerning. - */ - type BitmapFontCharacterData = { - /** - * The x position of the character. - */ - x: number; - /** - * The y position of the character. - */ - y: number; + namespace Cameras { + namespace Scene2D { + type CameraConfig = { /** - * The width of the character. + * The name of the Camera. */ - width: number; + name?: string; /** - * The height of the character. + * The horizontal position of the Camera viewport. */ - height: number; + x?: number; /** - * The center x position of the character. + * The vertical position of the Camera viewport. */ - centerX: number; + y?: number; /** - * The center y position of the character. + * The width of the Camera viewport. */ - centerY: number; + width?: number; /** - * The x offset of the character. + * The height of the Camera viewport. */ - xOffset: number; + height?: number; /** - * The y offset of the character. + * The default zoom level of the Camera. */ - yOffset: number; + zoom?: number; /** - * Extra data for the character. + * The rotation of the Camera, in radians. */ - data: object; + rotation?: number; /** - * Kerning values, keyed by character code. + * Should the Camera round pixels before rendering? */ - kerning: {[key: string]: number}; - }; - - /** - * Bitmap Font data that can be used by a BitmapText Game Object. - */ - type BitmapFontData = { + roundPixels?: boolean; /** - * The name of the font. + * The horizontal scroll position of the Camera. */ - font: string; + scrollX?: number; /** - * The size of the font. + * The vertical scroll position of the Camera. */ - size: number; + scrollY?: number; /** - * The line height of the font. + * A CSS color string controlling the Camera background color. */ - lineHeight: number; + backgroundColor?: false | string; /** - * Whether this font is a retro font (monospace). + * Defines the Camera bounds. */ - retroFont: boolean; + bounds?: object; /** - * The character data of the font, keyed by character code. Each character datum includes a position, size, offset and more. + * The top-left extent of the Camera bounds. */ - chars: {[key: number]: Phaser.Types.GameObjects.BitmapText.BitmapFontCharacterData}; - }; - - type BitmapTextConfig = Phaser.Types.GameObjects.GameObjectConfig & { + "bounds.x"?: number; /** - * The key of the font to use from the BitmapFont cache. + * The top-left extent of the Camera bounds. */ - font?: string; + "bounds.y"?: number; /** - * The string, or array of strings, to be set as the content of this Bitmap Text. + * The width of the Camera bounds. */ - text?: string; + "bounds.width"?: number; /** - * The font size to set. + * The height of the Camera bounds. */ - size?: number | false; + "bounds.height"?: number; }; - type BitmapTextSize = { + type CameraFadeCallback = (camera: Phaser.Cameras.Scene2D.Camera, progress: number)=>void; + + type CameraFlashCallback = (camera: Phaser.Cameras.Scene2D.Camera, progress: number)=>void; + + type CameraPanCallback = (camera: Phaser.Cameras.Scene2D.Camera, progress: number, x: number, y: number)=>void; + + type CameraShakeCallback = (camera: Phaser.Cameras.Scene2D.Camera, progress: number)=>void; + + type CameraZoomCallback = (camera: Phaser.Cameras.Scene2D.Camera, progress: number, zoom: number)=>void; + + type JSONCamera = { /** - * The position and size of the BitmapText, taking into account the position and scale of the Game Object. + * The name of the camera */ - global: Phaser.Types.GameObjects.BitmapText.GlobalBitmapTextSize; + name: string; /** - * The position and size of the BitmapText, taking just the font size into account. + * The horizontal position of camera */ - local: Phaser.Types.GameObjects.BitmapText.LocalBitmapTextSize; - }; - - type DisplayCallbackConfig = { + x: number; /** - * The Dynamic Bitmap Text object that owns this character being rendered. + * The vertical position of camera */ - parent: Phaser.GameObjects.DynamicBitmapText; + y: number; /** - * The tint of the character being rendered. Always zero in Canvas. + * The width size of camera */ - tint: Phaser.Types.GameObjects.BitmapText.TintConfig; + width: number; /** - * The index of the character being rendered. + * The height size of camera */ - index: number; + height: number; /** - * The character code of the character being rendered. + * The zoom of camera */ - charCode: number; + zoom: number; /** - * The x position of the character being rendered. + * The rotation of camera */ - x: number; + rotation: number; /** - * The y position of the character being rendered. + * The round pixels st status of camera */ - y: number; + roundPixels: boolean; /** - * The scale of the character being rendered. + * The horizontal scroll of camera */ - scale: number; + scrollX: number; /** - * The rotation of the character being rendered. + * The vertical scroll of camera */ - rotation: number; + scrollY: number; /** - * Custom data stored with the character being rendered. + * The background color of camera */ - data: any; + backgroundColor: string; + /** + * The bounds of camera + */ + bounds?: Phaser.Types.Cameras.Scene2D.JSONCameraBounds | undefined; }; - type DisplayCallback = (display: Phaser.Types.GameObjects.BitmapText.DisplayCallbackConfig)=>void; - - /** - * The position and size of the Bitmap Text in global space, taking into account the Game Object's scale and world position. - */ - type GlobalBitmapTextSize = { + type JSONCameraBounds = { /** - * The x position of the BitmapText, taking into account the x position and scale of the Game Object. + * The horizontal position of camera */ x: number; /** - * The y position of the BitmapText, taking into account the y position and scale of the Game Object. + * The vertical position of camera */ y: number; /** - * The width of the BitmapText, taking into account the x scale of the Game Object. + * The width size of camera */ width: number; /** - * The height of the BitmapText, taking into account the y scale of the Game Object. + * The height size of camera */ height: number; }; - type JSONBitmapText = Phaser.Types.GameObjects.JSONGameObject & { + } + + namespace Controls { + type FixedKeyControlConfig = { /** - * The name of the font. + * The Camera that this Control will update. */ - font: string; + camera?: Phaser.Cameras.Scene2D.Camera; /** - * The text that this Bitmap Text displays. + * The Key to be pressed that will move the Camera left. */ - text: string; + left?: Phaser.Input.Keyboard.Key; /** - * The size of the font. + * The Key to be pressed that will move the Camera right. */ - fontSize: number; + right?: Phaser.Input.Keyboard.Key; /** - * Adds / Removes spacing between characters. + * The Key to be pressed that will move the Camera up. */ - letterSpacing: number; + up?: Phaser.Input.Keyboard.Key; /** - * The alignment of the text in a multi-line BitmapText object. + * The Key to be pressed that will move the Camera down. */ - align: integer; - }; - - /** - * The position and size of the Bitmap Text in local space, taking just the font size into account. - */ - type LocalBitmapTextSize = { + down?: Phaser.Input.Keyboard.Key; /** - * The x position of the BitmapText. + * The Key to be pressed that will zoom the Camera in. */ - x: number; + zoomIn?: Phaser.Input.Keyboard.Key; /** - * The y position of the BitmapText. + * The Key to be pressed that will zoom the Camera out. */ - y: number; + zoomOut?: Phaser.Input.Keyboard.Key; /** - * The width of the BitmapText. + * The speed at which the camera will zoom if the `zoomIn` or `zoomOut` keys are pressed. */ - width: number; + zoomSpeed?: number; /** - * The height of the BitmapText. + * The horizontal and vertical speed the camera will move. */ - height: number; + speed?: number | Object; }; - type RetroFontConfig = { + type SmoothedKeyControlConfig = { /** - * The key of the image containing the font. + * The Camera that this Control will update. */ - image: string; + camera?: Phaser.Cameras.Scene2D.Camera; /** - * If the font set doesn't start at the top left of the given image, specify the X coordinate offset here. + * The Key to be pressed that will move the Camera left. */ - "offset.x": number; + left?: Phaser.Input.Keyboard.Key; /** - * If the font set doesn't start at the top left of the given image, specify the Y coordinate offset here. + * The Key to be pressed that will move the Camera right. */ - "offset.y": number; + right?: Phaser.Input.Keyboard.Key; /** - * The width of each character in the font set. + * The Key to be pressed that will move the Camera up. */ - width: number; + up?: Phaser.Input.Keyboard.Key; /** - * The height of each character in the font set. + * The Key to be pressed that will move the Camera down. */ - height: number; + down?: Phaser.Input.Keyboard.Key; /** - * The characters used in the font set, in display order. You can use the TEXT_SET consts for common font set arrangements. - */ - chars: string; - /** - * The number of characters per row in the font set. If not given charsPerRow will be the image width / characterWidth. - */ - charsPerRow: number; - /** - * If the characters in the font set have horizontal spacing between them set the required amount here. - */ - "spacing.x": number; - /** - * If the characters in the font set have vertical spacing between them set the required amount here. + * The Key to be pressed that will zoom the Camera in. */ - "spacing.y": number; + zoomIn?: Phaser.Input.Keyboard.Key; /** - * The amount of vertical space to add to the line height of the font. + * The Key to be pressed that will zoom the Camera out. */ - lineSpacing: number; - }; - - type TintConfig = { + zoomOut?: Phaser.Input.Keyboard.Key; /** - * The top left tint value. Always zero in canvas. + * The speed at which the camera will zoom if the `zoomIn` or `zoomOut` keys are pressed. */ - topLeft: number; + zoomSpeed?: number; /** - * The top right tint value. Always zero in canvas. + * The horizontal and vertical acceleration the camera will move. */ - topRight: number; + acceleration?: number | Object; /** - * The bottom left tint value. Always zero in canvas. + * The horizontal and vertical drag applied to the camera when it is moving. */ - bottomLeft: number; + drag?: number | Object; /** - * The bottom right tint value. Always zero in canvas. + * The maximum horizontal and vertical speed the camera will move. */ - bottomRight: number; + maxSpeed?: number | Object; }; } - namespace Graphics { + } + + namespace Core { + /** + * Config object containing various sound settings. + */ + type AudioConfig = { /** - * Graphics fill style settings. + * Use HTML5 Audio instead of Web Audio. */ - type FillStyle = { - /** - * The fill color. - */ - color?: number; - /** - * The fill alpha. - */ - alpha?: number; - }; - + disableWebAudio?: boolean; /** - * Graphics line style (or stroke style) settings. + * An existing Web Audio context. */ - type LineStyle = { - /** - * The stroke width. - */ - width?: number; - /** - * The stroke color. - */ - color?: number; - /** - * The stroke alpha. - */ - alpha?: number; - }; - + context?: AudioContext; /** - * Options for the Graphics game Object. + * Disable all audio output. */ - type Options = Phaser.Types.GameObjects.Graphics.Styles & { - /** - * The x coordinate of the Graphics. - */ - x?: number; - /** - * The y coordinate of the Graphics. - */ - y?: number; - }; - - type RoundedRectRadius = { - /** - * Top left - */ - tl?: number; - /** - * Top right - */ - tr?: number; - /** - * Bottom right - */ - br?: number; - /** - * Bottom left - */ - bl?: number; - }; + noAudio?: boolean; + }; + type BannerConfig = { /** - * Graphics style settings. + * Omit Phaser's name and version from the banner. */ - type Styles = { - /** - * The style applied to shape outlines. - */ - lineStyle?: Phaser.Types.GameObjects.Graphics.LineStyle; - /** - * The style applied to shape areas. - */ - fillStyle?: Phaser.Types.GameObjects.Graphics.FillStyle; - }; - - } - - namespace Group { - type GroupCallback = (item: Phaser.GameObjects.GameObject)=>void; - - type GroupConfig = { - /** - * Sets {@link Phaser.GameObjects.Group#classType}. - */ - classType?: Function; - /** - * Sets {@link Phaser.GameObjects.Group#name}. - */ - name?: string; - /** - * Sets {@link Phaser.GameObjects.Group#active}. - */ - active?: boolean; - /** - * Sets {@link Phaser.GameObjects.Group#maxSize}. - */ - maxSize?: number; - /** - * Sets {@link Phaser.GameObjects.Group#defaultKey}. - */ - defaultKey?: string; - /** - * Sets {@link Phaser.GameObjects.Group#defaultFrame}. - */ - defaultFrame?: string | integer; - /** - * Sets {@link Phaser.GameObjects.Group#runChildUpdate}. - */ - runChildUpdate?: boolean; - /** - * Sets {@link Phaser.GameObjects.Group#createCallback}. - */ - createCallback?: Phaser.Types.GameObjects.Group.GroupCallback; - /** - * Sets {@link Phaser.GameObjects.Group#removeCallback}. - */ - removeCallback?: Phaser.Types.GameObjects.Group.GroupCallback; - /** - * Sets {@link Phaser.GameObjects.Group#createMultipleCallback}. - */ - createMultipleCallback?: Phaser.Types.GameObjects.Group.GroupMultipleCreateCallback; - }; - + hidePhaser?: boolean; /** - * The total number of objects created will be - * - * key.length * frame.length * frameQuantity * (yoyo ? 2 : 1) * (1 + repeat) - * - * If `max` is nonzero, then the total created will not exceed `max`. - * - * `key` is required. {@link Phaser.GameObjects.Group#defaultKey} is not used. + * The color of the banner text. */ - type GroupCreateConfig = { - /** - * The class of each new Game Object. - */ - classType?: Function; - /** - * The texture key of each new Game Object. - */ - key?: string | string[]; - /** - * The texture frame of each new Game Object. - */ - frame?: string | string[] | integer | integer[]; - /** - * The number of Game Objects to create. If set, this overrides the `frameQuantity` value. Use `frameQuantity` for more advanced control. - */ - quantity?: integer; - /** - * The visible state of each new Game Object. - */ - visible?: boolean; - /** - * The active state of each new Game Object. - */ - active?: boolean; - /** - * The number of times each `key` × `frame` combination will be *repeated* (after the first combination). - */ - repeat?: integer; - /** - * Select a `key` at random. - */ - randomKey?: boolean; - /** - * Select a `frame` at random. - */ - randomFrame?: boolean; - /** - * Select keys and frames by moving forward then backward through `key` and `frame`. - */ - yoyo?: boolean; - /** - * The number of times each `frame` should be combined with one `key`. - */ - frameQuantity?: integer; - /** - * The maximum number of new Game Objects to create. 0 is no maximum. - */ - max?: integer; - setXY?: object; - /** - * The horizontal position of each new Game Object. - */ - "setXY.x"?: number; - /** - * The vertical position of each new Game Object. - */ - "setXY.y"?: number; - /** - * Increment each Game Object's horizontal position from the previous by this amount, starting from `setXY.x`. - */ - "setXY.stepX"?: number; - /** - * Increment each Game Object's vertical position from the previous by this amount, starting from `setXY.y`. - */ - "setXY.stepY"?: number; - setRotation?: object; - /** - * Rotation of each new Game Object. - */ - "setRotation.value"?: number; - /** - * Increment each Game Object's rotation from the previous by this amount, starting at `setRotation.value`. - */ - "setRotation.step"?: number; - setScale?: object; - /** - * The horizontal scale of each new Game Object. - */ - "setScale.x"?: number; - /** - * The vertical scale of each new Game Object. - */ - "setScale.y"?: number; - /** - * Increment each Game Object's horizontal scale from the previous by this amount, starting from `setScale.x`. - */ - "setScale.stepX"?: number; - /** - * Increment each Game object's vertical scale from the previous by this amount, starting from `setScale.y`. - */ - "setScale.stepY"?: number; - setAlpha?: object; - /** - * The alpha value of each new Game Object. - */ - "setAlpha.value"?: number; - /** - * Increment each Game Object's alpha from the previous by this amount, starting from `setAlpha.value`. - */ - "setAlpha.step"?: number; - setDepth?: object; - /** - * The depth value of each new Game Object. - */ - "setDepth.value"?: number; - /** - * Increment each Game Object's depth from the previous by this amount, starting from `setDepth.value`. - */ - "setDepth.step"?: number; - setScrollFactor?: object; - /** - * The horizontal scroll factor of each new Game Object. - */ - "setScrollFactor.x"?: number; - /** - * The vertical scroll factor of each new Game Object. - */ - "setScrollFactor.y"?: number; - /** - * Increment each Game Object's horizontal scroll factor from the previous by this amount, starting from `setScrollFactor.x`. - */ - "setScrollFactor.stepX"?: number; - /** - * Increment each Game object's vertical scroll factor from the previous by this amount, starting from `setScrollFactor.y`. - */ - "setScrollFactor.stepY"?: number; - /** - * A geometric shape that defines the hit area for the Game Object. - */ - hitArea?: any; - /** - * A callback to be invoked when the Game Object is interacted with. - */ - hitAreaCallback?: Phaser.Types.Input.HitAreaCallback; - /** - * Align the new Game Objects in a grid using these settings. - */ - gridAlign?: false | Phaser.Types.Actions.GridAlignConfig; - }; - - type GroupMultipleCreateCallback = (items: Phaser.GameObjects.GameObject[])=>void; - - } - - namespace Particles { - type DeathZoneSource = { - contains: Phaser.Types.GameObjects.Particles.DeathZoneSourceCallback; - }; - - type DeathZoneSourceCallback = (x: number, y: number)=>void; - - type EdgeZoneSource = { - /** - * A function placing points on the sources edge or edges. - */ - getPoints: Phaser.Types.GameObjects.Particles.EdgeZoneSourceCallback; - }; - - type EdgeZoneSourceCallback = (quantity: integer, stepRate?: number)=>void; - - type EmitterOpCustomEmitConfig = { - /** - * A callback that is invoked each time the emitter emits a particle. - */ - onEmit: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitCallback; - }; + text?: string; + /** + * The background colors of the banner. + */ + background?: string[]; + }; - type EmitterOpCustomUpdateConfig = { - /** - * A callback that is invoked each time the emitter emits a particle. - */ - onEmit?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitCallback; - /** - * A callback that is invoked each time the emitter updates. - */ - onUpdate: Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateCallback; - }; + type BootCallback = (game: Phaser.Game)=>void; + type CallbacksConfig = { /** - * Defines an operation yielding a value incremented continuously across a range. + * A function to run at the start of the boot sequence. */ - type EmitterOpEaseConfig = { - /** - * The starting value. - */ - start: number; - /** - * The ending value. - */ - end: number; - /** - * The name of the easing function. - */ - ease?: string; - }; - + preBoot?: Phaser.Types.Core.BootCallback; /** - * The returned value sets what the property will be at the START of the particle's life, on emit. + * A function to run at the end of the boot sequence. At this point, all the game systems have started and plugins have been loaded. */ - type EmitterOpOnEmitCallback = (particle: Phaser.GameObjects.Particles.Particle, key: string, value: number)=>void; - - type EmitterOpOnEmitType = number | number[] | Phaser.Types.GameObjects.Particles.EmitterOpOnEmitCallback | Phaser.Types.GameObjects.Particles.EmitterOpRandomConfig | Phaser.Types.GameObjects.Particles.EmitterOpRandomMinMaxConfig | Phaser.Types.GameObjects.Particles.EmitterOpRandomStartEndConfig | Phaser.Types.GameObjects.Particles.EmitterOpSteppedConfig | Phaser.Types.GameObjects.Particles.EmitterOpCustomEmitConfig; + postBoot?: Phaser.Types.Core.BootCallback; + }; + type DOMContainerConfig = { /** - * The returned value updates the property for the duration of the particle's life. + * Should the game create a div element to act as a DOM Container? Only enable if you're using DOM Element objects. You must provide a parent object if you use this feature. */ - type EmitterOpOnUpdateCallback = (particle: Phaser.GameObjects.Particles.Particle, key: string, t: number, value: number)=>void; - - type EmitterOpOnUpdateType = Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateCallback | Phaser.Types.GameObjects.Particles.EmitterOpEaseConfig | Phaser.Types.GameObjects.Particles.EmitterOpCustomUpdateConfig; - + createContainer?: boolean; /** - * Defines an operation yielding a random value within a range. + * Should the DOM Container that is created (if `dom.createContainer` is true) be positioned behind (true) or over the top (false, the default) of the game canvas? */ - type EmitterOpRandomConfig = { - /** - * The minimum and maximum values, as [min, max]. - */ - random: number[]; - }; + behindCanvas?: boolean; + }; + type FPSConfig = { /** - * Defines an operation yielding a random value within a range. + * The minimum acceptable rendering rate, in frames per second. */ - type EmitterOpRandomMinMaxConfig = { - /** - * The minimum value. - */ - min: number; - /** - * The maximum value. - */ - max: number; - }; - + min?: number; /** - * Defines an operation yielding a random value within a range. + * The optimum rendering rate, in frames per second. This does not enforce the fps rate, it merely tells Phaser what rate is considered optimal for this game. */ - type EmitterOpRandomStartEndConfig = { - /** - * The starting value. - */ - start: number; - /** - * The ending value. - */ - end: number; - /** - * If false, this becomes {@link EmitterOpEaseConfig}. - */ - random: boolean; - }; - + target?: number; /** - * Defines an operation yielding a value incremented by steps across a range. + * Use setTimeout instead of requestAnimationFrame to run the game loop. */ - type EmitterOpSteppedConfig = { - /** - * The starting value. - */ - start: number; - /** - * The ending value. - */ - end: number; - /** - * The number of steps between start and end. - */ - steps: number; - }; - - type GravityWellConfig = { - /** - * The x coordinate of the Gravity Well, in world space. - */ - x?: number; - /** - * The y coordinate of the Gravity Well, in world space. - */ - y?: number; - /** - * The strength of the gravity force - larger numbers produce a stronger force. - */ - power?: number; - /** - * The minimum distance for which the gravity force is calculated. - */ - epsilon?: number; - /** - * The gravitational force of this Gravity Well. - */ - gravity?: number; - }; - - type ParticleDeathCallback = (particle: Phaser.GameObjects.Particles.Particle)=>void; - - type ParticleEmitterBounds = { - /** - * The left edge of the rectangle. - */ - x: number; - /** - * The top edge of the rectangle. - */ - y: number; - /** - * The width of the rectangle. - */ - width: number; - /** - * The height of the rectangle. - */ - height: number; - }; + forceSetTimeOut?: boolean; + /** + * Calculate the average frame delta from this many consecutive frame intervals. + */ + deltaHistory?: number; + /** + * The amount of frames the time step counts before we trust the delta values again. + */ + panicMax?: number; + /** + * Apply delta smoothing during the game update to help avoid spikes? + */ + smoothStep?: boolean; + }; - type ParticleEmitterBoundsAlt = { - /** - * The left edge of the rectangle. - */ - x: number; - /** - * The top edge of the rectangle. - */ - y: number; - /** - * The width of the rectangle. - */ - w: number; - /** - * The height of the rectangle. - */ - h: number; - }; - - type ParticleEmitterCallback = (particle: Phaser.GameObjects.Particles.Particle, emitter: Phaser.GameObjects.Particles.ParticleEmitter)=>void; - - type ParticleEmitterConfig = { - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#active}. - */ - active?: boolean; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#blendMode}. - */ - blendMode?: Phaser.BlendModes | string; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#deathCallbackScope} and {@link Phaser.GameObjects.Particles.ParticleEmitter#emitCallbackScope}. - */ - callbackScope?: any; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#collideBottom}. - */ - collideBottom?: boolean; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#collideLeft}. - */ - collideLeft?: boolean; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#collideRight}. - */ - collideRight?: boolean; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#collideTop}. - */ - collideTop?: boolean; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#deathCallback}. - */ - deathCallback?: boolean; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#deathCallbackScope}. - */ - deathCallbackScope?: any; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#emitCallback}. - */ - emitCallback?: Function; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#emitCallbackScope}. - */ - emitCallbackScope?: any; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#follow}. - */ - follow?: Phaser.GameObjects.GameObject; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#frequency}. - */ - frequency?: number; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#gravityX}. - */ - gravityX?: number; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#gravityY}. - */ - gravityY?: number; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#maxParticles}. - */ - maxParticles?: integer; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#name}. - */ - name?: string; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#on}. - */ - on?: boolean; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#particleBringToTop}. - */ - particleBringToTop?: boolean; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#particleClass}. - */ - particleClass?: Phaser.GameObjects.Particles.Particle; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#radial}. - */ - radial?: boolean; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#timeScale}. - */ - timeScale?: number; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#trackVisible}. - */ - trackVisible?: boolean; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#visible}. - */ - visible?: boolean; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#accelerationX} (emit only). - */ - accelerationX?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#accelerationY} (emit only). - */ - accelerationY?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#alpha}. - */ - alpha?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType | Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateType; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#angle} (emit only). - */ - angle?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#bounce} (emit only). - */ - bounce?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#delay} (emit only). - */ - delay?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#lifespan} (emit only). - */ - lifespan?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#maxVelocityX} (emit only). - */ - maxVelocityX?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#maxVelocityY} (emit only). - */ - maxVelocityY?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#moveToX} (emit only). - */ - moveToX?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#moveToY} (emit only). - */ - moveToY?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#quantity} (emit only). - */ - quantity?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#rotate}. - */ - rotate?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType | Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateType; - /** - * As {@link Phaser.GameObjects.Particles.ParticleEmitter#setScale}. - */ - scale?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType | Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateType; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#scaleX}. - */ - scaleX?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType | Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateType; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#scaleY}. - */ - scaleY?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType | Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateType; - /** - * As {@link Phaser.GameObjects.Particles.ParticleEmitter#setSpeed} (emit only). - */ - speed?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#speedX} (emit only). - */ - speedX?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#speedY} (emit only). - */ - speedY?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#tint}. - */ - tint?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType | Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateType; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#x} (emit only). - */ - x?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#y} (emit only). - */ - y?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType; - /** - * As {@link Phaser.GameObjects.Particles.ParticleEmitter#setEmitZone}. - */ - emitZone?: object; - /** - * As {@link Phaser.GameObjects.Particles.ParticleEmitter#setBounds}. - */ - bounds?: Phaser.Types.GameObjects.Particles.ParticleEmitterBounds | Phaser.Types.GameObjects.Particles.ParticleEmitterBoundsAlt; - /** - * Assigns to {@link Phaser.GameObjects.Particles.ParticleEmitter#followOffset}. - */ - followOffset?: object; - /** - * x-coordinate of the offset. - */ - "followOffset.x"?: number; - /** - * y-coordinate of the offset. - */ - "followOffset.y"?: number; - /** - * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#frames}. - */ - frame?: number | number[] | string | string[] | Phaser.Textures.Frame | Phaser.Textures.Frame[] | Phaser.Types.GameObjects.Particles.ParticleEmitterFrameConfig; - }; - - type ParticleEmitterDeathZoneConfig = { - /** - * A shape representing the zone. See {@link Phaser.GameObjects.Particles.Zones.DeathZone#source}. - */ - source: Phaser.Types.GameObjects.Particles.DeathZoneSource; - /** - * 'onEnter' or 'onLeave'. - */ - type?: string; - }; - - type ParticleEmitterEdgeZoneConfig = { - /** - * A shape representing the zone. See {@link Phaser.GameObjects.Particles.Zones.EdgeZone#source}. - */ - source: Phaser.Types.GameObjects.Particles.EdgeZoneSource; - /** - * 'edge'. - */ - type: string; - /** - * The number of particles to place on the source edge. Set to 0 to use `stepRate` instead. - */ - quantity: integer; - /** - * The distance between each particle. When set, `quantity` is implied and should be set to 0. - */ - stepRate?: number; - /** - * Whether particles are placed from start to end and then end to start. - */ - yoyo?: boolean; - /** - * Whether one endpoint will be removed if it's identical to the other. - */ - seamless?: boolean; - }; - - type ParticleEmitterFrameConfig = { - /** - * One or more texture frames. - */ - frames?: number | number[] | string | string[] | Phaser.Textures.Frame | Phaser.Textures.Frame[]; - /** - * Whether texture frames will be assigned consecutively (true) or at random (false). - */ - cycle?: boolean; - /** - * The number of consecutive particles receiving each texture frame, when `cycle` is true. - */ - quantity?: integer; - }; - - type ParticleEmitterRandomZoneConfig = { - /** - * A shape representing the zone. See {@link Phaser.GameObjects.Particles.Zones.RandomZone#source}. - */ - source: Phaser.Types.GameObjects.Particles.RandomZoneSource; - /** - * 'random'. - */ - type?: string; - }; - - type RandomZoneSource = { - /** - * A function modifying its point argument. - */ - getRandomPoint: Phaser.Types.GameObjects.Particles.RandomZoneSourceCallback; - }; - - type RandomZoneSourceCallback = (point: Phaser.Math.Vector2)=>void; - - } - - namespace PathFollower { - /** - * Settings for a PathFollower. - */ - type PathConfig = { - /** - * The duration of the path follow in ms. Must be `> 0`. - */ - duration?: number; - /** - * The start position of the path follow, between 0 and 1. Must be less than `to`. - */ - from?: number; - /** - * The end position of the path follow, between 0 and 1. Must be more than `from`. - */ - to?: number; - /** - * Whether to position the PathFollower on the Path using its path offset. - */ - positionOnPath?: boolean; - /** - * Should the PathFollower automatically rotate to point in the direction of the Path? - */ - rotateToPath?: boolean; - /** - * If the PathFollower is rotating to match the Path, this value is added to the rotation value. This allows you to rotate objects to a path but control the angle of the rotation as well. - */ - rotationOffset?: number; - /** - * Current start position of the path follow, must be between `from` and `to`. - */ - startAt?: number; - }; - - } - - namespace RenderTexture { - type RenderTextureConfig = { - /** - * The x coordinate of the RenderTextures position. - */ - x?: number; - /** - * The y coordinate of the RenderTextures position. - */ - y?: number; - /** - * The width of the RenderTexture. - */ - width?: number; - /** - * The height of the RenderTexture. - */ - height?: number; - /** - * The texture key to make the RenderTexture from. - */ - key?: string; - /** - * the frame to make the RenderTexture from. - */ - frame?: string; - }; - - } - - namespace Sprite { - type SpriteConfig = Phaser.Types.GameObjects.GameObjectConfig & { - /** - * The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. - */ - key?: string; - /** - * An optional frame from the Texture this Game Object is rendering with. - */ - frame?: number | string; - }; - - } - - namespace Text { - /** - * Font metrics for a Text Style object. - */ - type TextMetrics = { - /** - * The ascent of the font. - */ - ascent: number; - /** - * The descent of the font. - */ - descent: number; - /** - * The size of the font. - */ - fontSize: number; - }; - - /** - * A Text Padding configuration object as used by the Text Style. - */ - type TextPadding = { - /** - * If set this value is used for both the left and right padding. - */ - x?: number; - /** - * If set this value is used for both the top and bottom padding. - */ - y?: number; - /** - * The amount of padding added to the left of the Text object. - */ - left?: number; - /** - * The amount of padding added to the right of the Text object. - */ - right?: number; - /** - * The amount of padding added to the top of the Text object. - */ - top?: number; - /** - * The amount of padding added to the bottom of the Text object. - */ - bottom?: number; - }; - - /** - * A Text Shadow configuration object as used by the Text Style. - */ - type TextShadow = { - /** - * The horizontal offset of the shadow. - */ - offsetX?: number; - /** - * The vertical offset of the shadow. - */ - offsetY?: number; - /** - * The color of the shadow, given as a CSS string value. - */ - color?: string; - /** - * The amount of blur applied to the shadow. Leave as zero for a hard shadow. - */ - blur?: number; - /** - * Apply the shadow to the stroke effect on the Text object? - */ - stroke?: boolean; - /** - * Apply the shadow to the fill effect on the Text object? - */ - fill?: boolean; - }; - - /** - * A Text Style configuration object as used by the Text Game Object. - */ - type TextStyle = { - /** - * The font the Text object will render with. This is a Canvas style font string. - */ - fontFamily?: string; - /** - * The font size, as a CSS size string. - */ - fontSize?: string; - /** - * Any addition font styles, such as 'strong'. - */ - fontStyle?: string; - /** - * A solid fill color that is rendered behind the Text object. Given as a CSS string color such as `#ff0`. - */ - backgroundColor?: string; - /** - * The color the Text is drawn in. Given as a CSS string color such as `#fff` or `rgb()`. - */ - color?: string; - /** - * The color used to stroke the Text if the `strokeThickness` property is greater than zero. - */ - stroke?: string; - /** - * The thickness of the stroke around the Text. Set to zero for no stroke. - */ - strokeThickness?: number; - /** - * The Text shadow configuration object. - */ - shadow?: Phaser.Types.GameObjects.Text.TextShadow; - /** - * A Text Padding object. - */ - padding?: Phaser.Types.GameObjects.Text.TextPadding; - /** - * The alignment of the Text. This only impacts multi-line text. Either `left`, `right`, `center` or `justify`. - */ - align?: string; - /** - * The maximum number of lines to display within the Text object. - */ - maxLines?: integer; - /** - * Force the Text object to have the exact width specified in this property. Leave as zero for it to change accordingly to content. - */ - fixedWidth?: number; - /** - * Force the Text object to have the exact height specified in this property. Leave as zero for it to change accordingly to content. - */ - fixedHeight?: number; - /** - * Sets the resolution (DPI setting) of the Text object. Leave at zero for it to use the game resolution. - */ - resolution?: number; - /** - * Set to `true` if this Text object should render from right-to-left. - */ - rtl?: boolean; - /** - * This is the string used to aid Canvas in calculating the height of the font. - */ - testString?: string; - /** - * The amount of horizontal padding added to the width of the text when calculating the font metrics. - */ - baselineX?: number; - /** - * The amount of vertical padding added to the height of the text when calculating the font metrics. - */ - baselineY?: number; - /** - * The Text Word wrap configuration object. - */ - wordWrap?: Phaser.Types.GameObjects.Text.TextWordWrap; - /** - * A Text Metrics object. Use this to avoid expensive font size calculations in text heavy games. - */ - metrics?: Phaser.Types.GameObjects.Text.TextMetrics; - }; - - /** - * A Text Word Wrap configuration object as used by the Text Style configuration. - */ - type TextWordWrap = { - /** - * The width at which text should be considered for word-wrapping. - */ - width?: number; - /** - * Provide a custom callback when word wrapping is enabled. - */ - callback?: TextStyleWordWrapCallback; - /** - * The context in which the word wrap callback is invoked. - */ - callbackScope?: any; - /** - * Use basic or advanced word wrapping? - */ - useAdvancedWrap?: boolean; - }; - - } - - namespace TileSprite { - type TileSpriteConfig = Phaser.Types.GameObjects.GameObjectConfig & { - /** - * The x coordinate of the Tile Sprite. - */ - x?: number; - /** - * The y coordinate of the Tile Sprite. - */ - y?: number; - /** - * The width of the Tile Sprite. If zero it will use the size of the texture frame. - */ - width?: integer; - /** - * The height of the Tile Sprite. If zero it will use the size of the texture frame. - */ - height?: integer; - /** - * The key of the Texture this Tile Sprite will use to render with, as stored in the Texture Manager. - */ - key?: string; - /** - * An optional frame from the Texture this Tile Sprite is rendering with. - */ - frame?: string; - }; - - } - - type GameObjectConfig = { - /** - * The x position of the Game Object. - */ - x?: number; - /** - * The y position of the Game Object. - */ - y?: number; - /** - * The depth of the GameObject. - */ - depth?: number; - /** - * The horizontally flipped state of the Game Object. - */ - flipX?: boolean; - /** - * The vertically flipped state of the Game Object. - */ - flipY?: boolean; - /** - * The scale of the GameObject. - */ - scale?: number | object; - /** - * The scroll factor of the GameObject. - */ - scrollFactor?: number | object; - /** - * The rotation angle of the Game Object, in radians. - */ - rotation?: number; - /** - * The rotation angle of the Game Object, in degrees. - */ - angle?: number; - /** - * The alpha (opacity) of the Game Object. - */ - alpha?: number; - /** - * The origin of the Game Object. - */ - origin?: number | object; - /** - * The scale mode of the GameObject. - */ - scaleMode?: number; - /** - * The blend mode of the GameObject. - */ - blendMode?: number; - /** - * The visible state of the Game Object. - */ - visible?: boolean; - /** - * Add the GameObject to the scene. - */ - add?: boolean; - }; - - type JSONGameObject = { - /** - * The name of this Game Object. - */ - name: string; - /** - * A textual representation of this Game Object, i.e. `sprite`. - */ - type: string; - /** - * The x position of this Game Object. - */ - x: number; - /** - * The y position of this Game Object. - */ - y: number; - /** - * The scale of this Game Object - */ - scale: object; - /** - * The horizontal scale of this Game Object. - */ - "scale.x": number; - /** - * The vertical scale of this Game Object. - */ - "scale.y": number; - /** - * The origin of this Game Object. - */ - origin: object; - /** - * The horizontal origin of this Game Object. - */ - "origin.x": number; - /** - * The vertical origin of this Game Object. - */ - "origin.y": number; - /** - * The horizontally flipped state of the Game Object. - */ - flipX: boolean; - /** - * The vertically flipped state of the Game Object. - */ - flipY: boolean; - /** - * The angle of this Game Object in radians. - */ - rotation: number; - /** - * The alpha value of the Game Object. - */ - alpha: number; - /** - * The visible state of the Game Object. - */ - visible: boolean; - /** - * The Scale Mode being used by this Game Object. - */ - scaleMode: integer; - /** - * Sets the Blend Mode being used by this Game Object. - */ - blendMode: integer | string; - /** - * The texture key of this Game Object. - */ - textureKey: string; - /** - * The frame key of this Game Object. - */ - frameKey: string; - /** - * The data of this Game Object. - */ - data: object; - }; - - } - - namespace Input { - namespace Gamepad { - /** - * The Gamepad object, as extracted from GamepadEvent. - */ - type Pad = { - /** - * The ID of the Gamepad. - */ - id: string; - /** - * The index of the Gamepad. - */ - index: integer; - }; - - } - - namespace Keyboard { - type CursorKeys = { - /** - * A Key object mapping to the UP arrow key. - */ - up?: Phaser.Input.Keyboard.Key; - /** - * A Key object mapping to the DOWN arrow key. - */ - down?: Phaser.Input.Keyboard.Key; - /** - * A Key object mapping to the LEFT arrow key. - */ - left?: Phaser.Input.Keyboard.Key; - /** - * A Key object mapping to the RIGHT arrow key. - */ - right?: Phaser.Input.Keyboard.Key; - /** - * A Key object mapping to the SPACE BAR key. - */ - space?: Phaser.Input.Keyboard.Key; - /** - * A Key object mapping to the SHIFT key. - */ - shift?: Phaser.Input.Keyboard.Key; - }; - - type KeyboardKeydownCallback = (event: KeyboardEvent)=>void; - - type KeyComboConfig = { - /** - * If they press the wrong key do we reset the combo? - */ - resetOnWrongKey?: boolean; - /** - * The max delay in ms between each key press. Above this the combo is reset. 0 means disabled. - */ - maxKeyDelay?: number; - /** - * If previously matched and they press the first key of the combo again, will it reset? - */ - resetOnMatch?: boolean; - /** - * If the combo matches, will it delete itself? - */ - deleteOnMatch?: boolean; - }; - - } - - /** - * A Phaser Input Event Data object. - * - * This object is passed to the registered event listeners and allows you to stop any further propagation. - */ - type EventData = { - /** - * The cancelled state of this Event. - */ - cancelled?: boolean; - /** - * Call this method to stop this event from passing any further down the event chain. - */ - stopPropagation: Function; - }; - - type HitAreaCallback = (hitArea: any, x: number, y: number, gameObject: Phaser.GameObjects.GameObject)=>void; - - type InputConfiguration = { - /** - * The object / shape to use as the Hit Area. If not given it will try to create a Rectangle based on the texture frame. - */ - hitArea?: any; - /** - * The callback that determines if the pointer is within the Hit Area shape or not. - */ - hitAreaCallback?: Function; - /** - * If `true` the Interactive Object will be set to be draggable and emit drag events. - */ - draggable?: boolean; - /** - * If `true` the Interactive Object will be set to be a drop zone for draggable objects. - */ - dropZone?: boolean; - /** - * If `true` the Interactive Object will set the `pointer` hand cursor when a pointer is over it. This is a short-cut for setting `cursor: 'pointer'`. - */ - useHandCursor?: boolean; - /** - * The CSS string to be used when the cursor is over this Interactive Object. - */ - cursor?: string; - /** - * If `true` the a pixel perfect function will be set for the hit area callback. Only works with texture based Game Objects. - */ - pixelPerfect?: boolean; - /** - * If `pixelPerfect` is set, this is the alpha tolerance threshold value used in the callback. - */ - alphaTolerance?: integer; - }; - - type InputPluginContainer = { - /** - * The unique name of this plugin in the input plugin cache. - */ - key: string; - /** - * The plugin to be stored. Should be the source object, not instantiated. - */ - plugin: Function; - /** - * If this plugin is to be injected into the Input Plugin, this is the property key map used. - */ - mapping?: string; - }; - - type InteractiveObject = { - /** - * The Game Object to which this Interactive Object is bound. - */ - gameObject: Phaser.GameObjects.GameObject; - /** - * Is this Interactive Object currently enabled for input events? - */ - enabled: boolean; - /** - * An Interactive Object that is 'always enabled' will receive input even if the parent object is invisible or won't render. - */ - alwaysEnabled: boolean; - /** - * Is this Interactive Object draggable? Enable with `InputPlugin.setDraggable`. - */ - draggable: boolean; - /** - * Is this Interactive Object a drag-targets drop zone? Set when the object is created. - */ - dropZone: boolean; - /** - * Should this Interactive Object change the cursor (via css) when over? (desktop only) - */ - cursor: boolean | string; - /** - * An optional drop target for a draggable Interactive Object. - */ - target: Phaser.GameObjects.GameObject; - /** - * The most recent Camera to be tested against this Interactive Object. - */ - camera: Phaser.Cameras.Scene2D.Camera; - /** - * The hit area for this Interactive Object. Typically a geometry shape, like a Rectangle or Circle. - */ - hitArea: any; - /** - * The 'contains' check callback that the hit area shape will use for all hit tests. - */ - hitAreaCallback: Phaser.Types.Input.HitAreaCallback; - /** - * If this Interactive Object has been enabled for debug, via `InputPlugin.enableDebug` then this property holds its debug shape. - */ - hitAreaDebug: Phaser.GameObjects.Shape; - /** - * Was the hitArea for this Interactive Object created based on texture size (false), or a custom shape? (true) - */ - customHitArea: boolean; - /** - * The x coordinate that the Pointer interacted with this object on, relative to the Game Object's top-left position. - */ - localX: number; - /** - * The y coordinate that the Pointer interacted with this object on, relative to the Game Object's top-left position. - */ - localY: number; - /** - * The current drag state of this Interactive Object. 0 = Not being dragged, 1 = being checked for drag, or 2 = being actively dragged. - */ - dragState: 0 | 1 | 2; - /** - * The x coordinate of the Game Object that owns this Interactive Object when the drag started. - */ - dragStartX: number; - /** - * The y coordinate of the Game Object that owns this Interactive Object when the drag started. - */ - dragStartY: number; - /** - * The x coordinate that the Pointer started dragging this Interactive Object from. - */ - dragStartXGlobal: number; - /** - * The y coordinate that the Pointer started dragging this Interactive Object from. - */ - dragStartYGlobal: number; - /** - * The x coordinate that this Interactive Object is currently being dragged to. - */ - dragX: number; - /** - * The y coordinate that this Interactive Object is currently being dragged to. - */ - dragY: number; - }; - - } - - namespace Loader { - namespace FileTypes { - type AtlasJSONFileConfig = { - /** - * The key of the file. Must be unique within both the Loader and the Texture Manager. - */ - key: string; - /** - * The absolute or relative URL to load the texture image file from. - */ - textureURL?: string; - /** - * The default file extension to use for the image texture if no url is provided. - */ - textureExtension?: string; - /** - * Extra XHR Settings specifically for the texture image file. - */ - textureXhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - /** - * The filename of an associated normal map. It uses the same path and url to load as the texture image. - */ - normalMap?: string; - /** - * The absolute or relative URL to load the atlas json file from. Or a well formed JSON object to use instead. - */ - atlasURL?: string; - /** - * The default file extension to use for the atlas json if no url is provided. - */ - atlasExtension?: string; - /** - * Extra XHR Settings specifically for the atlas json file. - */ - atlasXhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - }; - - type AtlasXMLFileConfig = { - /** - * The key of the file. Must be unique within both the Loader and the Texture Manager. - */ - key: string; - /** - * The absolute or relative URL to load the texture image file from. - */ - textureURL?: string; - /** - * The default file extension to use for the image texture if no url is provided. - */ - textureExtension?: string; - /** - * Extra XHR Settings specifically for the texture image file. - */ - textureXhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - /** - * The filename of an associated normal map. It uses the same path and url to load as the texture image. - */ - normalMap?: string; - /** - * The absolute or relative URL to load the atlas xml file from. - */ - atlasURL?: string; - /** - * The default file extension to use for the atlas xml if no url is provided. - */ - atlasExtension?: string; - /** - * Extra XHR Settings specifically for the atlas xml file. - */ - atlasXhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - }; - - type AudioFileConfig = { - /** - * The key of the file. Must be unique within the Loader and Audio Cache. - */ - key: string; - /** - * The absolute or relative URL to load the file from. - */ - urlConfig?: string; - /** - * Extra XHR Settings specifically for this file. - */ - xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - /** - * The AudioContext this file will use to process itself. - */ - audioContext?: AudioContext; - }; - - type AudioSpriteFileConfig = { - /** - * The key of the file. Must be unique within both the Loader and the Audio Cache. - */ - key: string; - /** - * The absolute or relative URL to load the json file from. Or a well formed JSON object to use instead. - */ - jsonURL: string; - /** - * Extra XHR Settings specifically for the json file. - */ - jsonXhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - /** - * The absolute or relative URL to load the audio file from. - */ - audioURL?: Object; - /** - * The audio configuration options. - */ - audioConfig?: any; - /** - * Extra XHR Settings specifically for the audio file. - */ - audioXhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - }; - - type BinaryFileConfig = { - /** - * The key of the file. Must be unique within both the Loader and the Binary Cache. - */ - key: string; - /** - * The absolute or relative URL to load the file from. - */ - url?: string; - /** - * The default file extension to use if no url is provided. - */ - extension?: string; - /** - * Extra XHR Settings specifically for this file. - */ - xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - /** - * Optional type to cast the binary file to once loaded. For example, `Uint8Array`. - */ - dataType?: any; - }; - - type BitmapFontFileConfig = { - /** - * The key of the file. Must be unique within both the Loader and the Texture Manager. - */ - key: string; - /** - * The absolute or relative URL to load the texture image file from. - */ - textureURL?: string; - /** - * The default file extension to use for the image texture if no url is provided. - */ - textureExtension?: string; - /** - * Extra XHR Settings specifically for the texture image file. - */ - textureXhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - /** - * The filename of an associated normal map. It uses the same path and url to load as the texture image. - */ - normalMap?: string; - /** - * The absolute or relative URL to load the font data xml file from. - */ - fontDataURL?: string; - /** - * The default file extension to use for the font data xml if no url is provided. - */ - fontDataExtension?: string; - /** - * Extra XHR Settings specifically for the font data xml file. - */ - fontDataXhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - }; - - type CSSFileConfig = { - /** - * The key of the file. Must be unique within the Loader. - */ - key: string; - /** - * The absolute or relative URL to load the file from. - */ - url?: string; - /** - * The default file extension to use if no url is provided. - */ - extension?: string; - /** - * Extra XHR Settings specifically for this file. - */ - xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - }; - - type GLSLFileConfig = { - /** - * The key of the file. Must be unique within both the Loader and the Text Cache. - */ - key: string; - /** - * The absolute or relative URL to load the file from. - */ - url?: string; - /** - * The type of shader. Either `fragment` for a fragment shader, or `vertex` for a vertex shader. This is ignored if you load a shader bundle. - */ - shaderType?: string; - /** - * The default file extension to use if no url is provided. - */ - extension?: string; - /** - * Extra XHR Settings specifically for this file. - */ - xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - }; - - type HTMLFileConfig = { - /** - * The key of the file. Must be unique within both the Loader and the Text Cache. - */ - key: string; - /** - * The absolute or relative URL to load the file from. - */ - url?: string; - /** - * The default file extension to use if no url is provided. - */ - extension?: string; - /** - * Extra XHR Settings specifically for this file. - */ - xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - }; - - type HTMLTextureFileConfig = { - /** - * The key of the file. Must be unique within both the Loader and the Texture Manager. - */ - key: string; - /** - * The absolute or relative URL to load the file from. - */ - url?: string; - /** - * The default file extension to use if no url is provided. - */ - extension?: string; - /** - * Extra XHR Settings specifically for this file. - */ - xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - /** - * The width of the texture the HTML will be rendered to. - */ - width?: integer; - /** - * The height of the texture the HTML will be rendered to. - */ - height?: integer; - }; - - type ImageFileConfig = { - /** - * The key of the file. Must be unique within both the Loader and the Texture Manager. - */ - key: string; - /** - * The absolute or relative URL to load the file from. - */ - url?: string; - /** - * The default file extension to use if no url is provided. - */ - extension?: string; - /** - * The filename of an associated normal map. It uses the same path and url to load as the image. - */ - normalMap?: string; - /** - * The frame configuration object. Only provided for, and used by, Sprite Sheets. - */ - frameConfig?: Phaser.Types.Loader.FileTypes.ImageFrameConfig; - /** - * Extra XHR Settings specifically for this file. - */ - xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - }; - - type ImageFrameConfig = { - /** - * The width of the frame in pixels. - */ - frameWidth: integer; - /** - * The height of the frame in pixels. Uses the `frameWidth` value if not provided. - */ - frameHeight?: integer; - /** - * The first frame to start parsing from. - */ - startFrame?: integer; - /** - * The frame to stop parsing at. If not provided it will calculate the value based on the image and frame dimensions. - */ - endFrame?: integer; - /** - * The margin in the image. This is the space around the edge of the frames. - */ - margin?: integer; - /** - * The spacing between each frame in the image. - */ - spacing?: integer; - }; - - type JSONFileConfig = { - /** - * The key of the file. Must be unique within both the Loader and the JSON Cache. - */ - key: string; - /** - * The absolute or relative URL to load the file from. Or can be a ready formed JSON object, in which case it will be directly added to the Cache. - */ - url?: string | any; - /** - * The default file extension to use if no url is provided. - */ - extension?: string; - /** - * If specified instead of the whole JSON file being parsed and added to the Cache, only the section corresponding to this property key will be added. If the property you want to extract is nested, use periods to divide it. - */ - dataKey?: string; - /** - * Extra XHR Settings specifically for this file. - */ - xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - }; - - type MultiAtlasFileConfig = { - /** - * The key of the file. Must be unique within both the Loader and the Texture Manager. - */ - key: string; - /** - * The absolute or relative URL to load the multi atlas json file from. Or, a well formed JSON object. - */ - atlasURL?: string; - /** - * An alias for 'atlasURL'. If given, it overrides anything set in 'atlasURL'. - */ - url?: string; - /** - * The default file extension to use for the atlas json if no url is provided. - */ - atlasExtension?: string; - /** - * Extra XHR Settings specifically for the atlas json file. - */ - atlasXhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - /** - * Optional path to use when loading the textures defined in the atlas data. - */ - path?: string; - /** - * Optional Base URL to use when loading the textures defined in the atlas data. - */ - baseURL?: string; - /** - * Extra XHR Settings specifically for the texture files. - */ - textureXhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - }; - - type MultiScriptFileConfig = { - /** - * The key of the file. Must be unique within the Loader. - */ - key: string; - /** - * An array of absolute or relative URLs to load the script files from. They are processed in the order given in the array. - */ - url?: string[]; - /** - * The default file extension to use if no url is provided. - */ - extension?: string; - /** - * Extra XHR Settings specifically for these files. - */ - xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - }; - - type PackFileConfig = { - /** - * The key of the file. Must be unique within both the Loader and the JSON Cache. - */ - key: string; - /** - * The absolute or relative URL to load the file from. Or can be a ready formed JSON object, in which case it will be directly processed. - */ - url?: string | any; - /** - * The default file extension to use if no url is provided. - */ - extension?: string; - /** - * If specified instead of the whole JSON file being parsed, only the section corresponding to this property key will be added. If the property you want to extract is nested, use periods to divide it. - */ - dataKey?: string; - /** - * Extra XHR Settings specifically for this file. - */ - xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - }; - - type PluginFileConfig = { - /** - * The key of the file. Must be unique within the Loader. - */ - key: string; - /** - * The absolute or relative URL to load the file from. - */ - url?: string; - /** - * The default file extension to use if no url is provided. - */ - extension?: string; - /** - * Automatically start the plugin after loading? - */ - start?: boolean; - /** - * If this plugin is to be injected into the Scene, this is the property key used. - */ - mapping?: string; - /** - * Extra XHR Settings specifically for this file. - */ - xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - }; - - type SceneFileConfig = { - /** - * The key of the file. Must be unique within both the Loader and the Text Cache. - */ - key: string; - /** - * The absolute or relative URL to load the file from. - */ - url?: string; - /** - * The default file extension to use if no url is provided. - */ - extension?: string; - /** - * Extra XHR Settings specifically for this file. - */ - xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - }; - - type ScenePluginFileConfig = { - /** - * The key of the file. Must be unique within the Loader. - */ - key: string; - /** - * The absolute or relative URL to load the file from. Or, a Scene Plugin. - */ - url?: string | Function; - /** - * The default file extension to use if no url is provided. - */ - extension?: string; - /** - * If this plugin is to be added to Scene.Systems, this is the property key for it. - */ - systemKey?: string; - /** - * If this plugin is to be added to the Scene, this is the property key for it. - */ - sceneKey?: string; - /** - * Extra XHR Settings specifically for this file. - */ - xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - }; - - type ScriptFileConfig = { - /** - * The key of the file. Must be unique within the Loader. - */ - key: string; - /** - * The absolute or relative URL to load the file from. - */ - url?: string; - /** - * The default file extension to use if no url is provided. - */ - extension?: string; - /** - * Extra XHR Settings specifically for this file. - */ - xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - }; - - type SpriteSheetFileConfig = { - /** - * The key of the file. Must be unique within both the Loader and the Texture Manager. - */ - key: string; - /** - * The absolute or relative URL to load the file from. - */ - url?: string; - /** - * The default file extension to use if no url is provided. - */ - extension?: string; - /** - * The filename of an associated normal map. It uses the same path and url to load as the image. - */ - normalMap?: string; - /** - * The frame configuration object. - */ - frameConfig?: Phaser.Types.Loader.FileTypes.ImageFrameConfig; - /** - * Extra XHR Settings specifically for this file. - */ - xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - }; - - type SVGFileConfig = { - /** - * The key of the file. Must be unique within both the Loader and the Texture Manager. - */ - key: string; - /** - * The absolute or relative URL to load the file from. - */ - url?: string; - /** - * The default file extension to use if no url is provided. - */ - extension?: string; - /** - * Extra XHR Settings specifically for this file. - */ - xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - /** - * The svg size configuration object. - */ - svgConfig?: Phaser.Types.Loader.FileTypes.SVGSizeConfig; - }; - - type SVGSizeConfig = { - /** - * An optional width. The SVG will be resized to this size before being rendered to a texture. - */ - width?: integer; - /** - * An optional height. The SVG will be resized to this size before being rendered to a texture. - */ - height?: integer; - /** - * An optional scale. If given it overrides the width / height properties. The SVG is scaled by the scale factor before being rendered to a texture. - */ - scale?: number; - }; - - type TextFileConfig = { - /** - * The key of the file. Must be unique within both the Loader and the Text Cache. - */ - key: string; - /** - * The absolute or relative URL to load the file from. - */ - url?: string; - /** - * The default file extension to use if no url is provided. - */ - extension?: string; - /** - * Extra XHR Settings specifically for this file. - */ - xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - }; - - type TilemapCSVFileConfig = { - /** - * The key of the file. Must be unique within both the Loader and the Tilemap Cache. - */ - key: string; - /** - * The absolute or relative URL to load the file from. - */ - url?: string; - /** - * The default file extension to use if no url is provided. - */ - extension?: string; - /** - * Extra XHR Settings specifically for this file. - */ - xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - }; - - type TilemapImpactFileConfig = { - /** - * The key of the file. Must be unique within both the Loader and the Tilemap Cache. - */ - key: string; - /** - * The absolute or relative URL to load the file from. - */ - url?: string; - /** - * The default file extension to use if no url is provided. - */ - extension?: string; - /** - * Extra XHR Settings specifically for this file. - */ - xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - }; - - type TilemapJSONFileConfig = { - /** - * The key of the file. Must be unique within both the Loader and the Tilemap Cache. - */ - key: string; - /** - * The absolute or relative URL to load the file from. - */ - url?: string; - /** - * The default file extension to use if no url is provided. - */ - extension?: string; - /** - * Extra XHR Settings specifically for this file. - */ - xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - }; - - type UnityAtlasFileConfig = { - /** - * The key of the file. Must be unique within both the Loader and the Texture Manager. - */ - key: string; - /** - * The absolute or relative URL to load the texture image file from. - */ - textureURL?: string; - /** - * The default file extension to use for the image texture if no url is provided. - */ - textureExtension?: string; - /** - * Extra XHR Settings specifically for the texture image file. - */ - textureXhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - /** - * The filename of an associated normal map. It uses the same path and url to load as the texture image. - */ - normalMap?: string; - /** - * The absolute or relative URL to load the atlas data file from. - */ - atlasURL?: string; - /** - * The default file extension to use for the atlas data if no url is provided. - */ - atlasExtension?: string; - /** - * Extra XHR Settings specifically for the atlas data file. - */ - atlasXhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - }; - - type VideoFileConfig = { - /** - * The key to use for this file, or a file configuration object. - */ - key: string | Phaser.Types.Loader.FileTypes.VideoFileConfig; - /** - * The absolute or relative URL to load this file from in a config object. - */ - urlConfig?: any; - /** - * The load event to listen for when _not_ loading as a blob. Either 'loadeddata', 'canplay' or 'canplaythrough'. - */ - loadEvent?: string; - /** - * Load the video as a data blob, or via the Video element? - */ - asBlob?: boolean; - /** - * Does the video have an audio track? If not you can enable auto-playing on it. - */ - noAudio?: boolean; - /** - * Extra XHR Settings specifically for this file. - */ - xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - }; - - type XMLFileConfig = { - /** - * The key of the file. Must be unique within both the Loader and the Text Cache. - */ - key: string; - /** - * The absolute or relative URL to load the file from. - */ - url?: string; - /** - * The default file extension to use if no url is provided. - */ - extension?: string; - /** - * Extra XHR Settings specifically for this file. - */ - xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; - }; - - } - - type FileConfig = { - /** - * The file type string (image, json, etc) for sorting within the Loader. - */ - type: string; - /** - * Unique cache key (unique within its file type) - */ - key: string; - /** - * The URL of the file, not including baseURL. - */ - url?: string; - /** - * The path of the file, not including the baseURL. - */ - path?: string; - /** - * The default extension this file uses. - */ - extension?: string; - /** - * The responseType to be used by the XHR request. - */ - responseType?: XMLHttpRequestResponseType; - /** - * Custom XHR Settings specific to this file and merged with the Loader defaults. - */ - xhrSettings?: Phaser.Types.Loader.XHRSettingsObject | false; - /** - * A config object that can be used by file types to store transitional data. - */ - config?: any; - }; - - type XHRSettingsObject = { - /** - * The response type of the XHR request, i.e. `blob`, `text`, etc. - */ - responseType: XMLHttpRequestResponseType; - /** - * Should the XHR request use async or not? - */ - async?: boolean; - /** - * Optional username for the XHR request. - */ - user?: string; - /** - * Optional password for the XHR request. - */ - password?: string; - /** - * Optional XHR timeout value. - */ - timeout?: integer; - /** - * This value is used to populate the XHR `setRequestHeader` and is undefined by default. - */ - header?: string | undefined; - /** - * This value is used to populate the XHR `setRequestHeader` and is undefined by default. - */ - headerValue?: string | undefined; - /** - * This value is used to populate the XHR `setRequestHeader` and is undefined by default. - */ - requestedWith?: string | undefined; - /** - * Provide a custom mime-type to use instead of the default. - */ - overrideMimeType?: string | undefined; - }; - - } - - namespace Math { - type SinCosTable = { - /** - * The sine value. - */ - sin: number; - /** - * The cosine value. - */ - cos: number; - /** - * The length. - */ - length: number; - }; - - type Vector2Like = { - /** - * The x component. - */ - x?: number; - /** - * The y component. - */ - y?: number; - }; - - } - - namespace Physics { - namespace Arcade { - type ArcadeBodyBounds = { - /** - * The left edge. - */ - x: number; - /** - * The upper edge. - */ - y: number; - /** - * The right edge. - */ - right: number; - /** - * The lower edge. - */ - bottom: number; - }; - - type ArcadeBodyCollision = { - /** - * True if the Body is not colliding. - */ - none: boolean; - /** - * True if the Body is colliding on its upper edge. - */ - up: boolean; - /** - * True if the Body is colliding on its lower edge. - */ - down: boolean; - /** - * True if the Body is colliding on its left edge. - */ - left: boolean; - /** - * True if the Body is colliding on its right edge. - */ - right: boolean; - }; - - /** - * An Arcade Physics Collider Type. - */ - type ArcadeColliderType = Phaser.GameObjects.GameObject | Phaser.GameObjects.Group | Phaser.Physics.Arcade.Sprite | Phaser.Physics.Arcade.Image | Phaser.Physics.Arcade.StaticGroup | Phaser.Physics.Arcade.Group | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer | Phaser.GameObjects.GameObject[] | Phaser.Physics.Arcade.Sprite[] | Phaser.Physics.Arcade.Image[] | Phaser.Physics.Arcade.StaticGroup[] | Phaser.Physics.Arcade.Group[] | Phaser.Tilemaps.DynamicTilemapLayer[] | Phaser.Tilemaps.StaticTilemapLayer[]; - - type ArcadeWorldConfig = { - /** - * Sets {@link Phaser.Physics.Arcade.World#fps}. - */ - fps?: number; - /** - * Sets {@link Phaser.Physics.Arcade.World#timeScale}. - */ - timeScale?: number; - /** - * Sets {@link Phaser.Physics.Arcade.World#gravity}. - */ - gravity?: Phaser.Types.Math.Vector2Like; - /** - * Sets {@link Phaser.Physics.Arcade.World#bounds bounds.x}. - */ - x?: number; - /** - * Sets {@link Phaser.Physics.Arcade.World#bounds bounds.y}. - */ - y?: number; - /** - * Sets {@link Phaser.Physics.Arcade.World#bounds bounds.width}. - */ - width?: number; - /** - * Sets {@link Phaser.Physics.Arcade.World#bounds bounds.height}. - */ - height?: number; - /** - * Sets {@link Phaser.Physics.Arcade.World#checkCollision}. - */ - checkCollision?: Phaser.Types.Physics.Arcade.CheckCollisionObject; - /** - * Sets {@link Phaser.Physics.Arcade.World#OVERLAP_BIAS}. - */ - overlapBias?: number; - /** - * Sets {@link Phaser.Physics.Arcade.World#TILE_BIAS}. - */ - tileBias?: number; - /** - * Sets {@link Phaser.Physics.Arcade.World#forceX}. - */ - forceX?: boolean; - /** - * Sets {@link Phaser.Physics.Arcade.World#isPaused}. - */ - isPaused?: boolean; - /** - * Sets {@link Phaser.Physics.Arcade.World#debug}. - */ - debug?: boolean; - /** - * Sets {@link Phaser.Physics.Arcade.World#defaults debugShowBody}. - */ - debugShowBody?: boolean; - /** - * Sets {@link Phaser.Physics.Arcade.World#defaults debugShowStaticBody}. - */ - debugShowStaticBody?: boolean; - /** - * Sets {@link Phaser.Physics.Arcade.World#defaults debugShowStaticBody}. - */ - debugShowVelocity?: boolean; - /** - * Sets {@link Phaser.Physics.Arcade.World#defaults debugBodyColor}. - */ - debugBodyColor?: number; - /** - * Sets {@link Phaser.Physics.Arcade.World#defaults debugStaticBodyColor}. - */ - debugStaticBodyColor?: number; - /** - * Sets {@link Phaser.Physics.Arcade.World#defaults debugVelocityColor}. - */ - debugVelocityColor?: number; - /** - * Sets {@link Phaser.Physics.Arcade.World#maxEntries}. - */ - maxEntries?: number; - /** - * Sets {@link Phaser.Physics.Arcade.World#useTree}. - */ - useTree?: boolean; - }; - - type ArcadeWorldDefaults = { - /** - * Set to `true` to render dynamic body outlines to the debug display. - */ - debugShowBody: boolean; - /** - * Set to `true` to render static body outlines to the debug display. - */ - debugShowStaticBody: boolean; - /** - * Set to `true` to render body velocity markers to the debug display. - */ - debugShowVelocity: boolean; - /** - * The color of dynamic body outlines when rendered to the debug display. - */ - bodyDebugColor: number; - /** - * The color of static body outlines when rendered to the debug display. - */ - staticBodyDebugColor: number; - /** - * The color of the velocity markers when rendered to the debug display. - */ - velocityDebugColor: number; - }; - - type ArcadeWorldTreeMinMax = { - /** - * The minimum x value used in RTree searches. - */ - minX: number; - /** - * The minimum y value used in RTree searches. - */ - minY: number; - /** - * The maximum x value used in RTree searches. - */ - maxX: number; - /** - * The maximum y value used in RTree searches. - */ - maxY: number; - }; - - type CheckCollisionObject = { - /** - * Will bodies collide with the top side of the world bounds? - */ - up: boolean; - /** - * Will bodies collide with the bottom side of the world bounds? - */ - down: boolean; - /** - * Will bodies collide with the left side of the world bounds? - */ - left: boolean; - /** - * Will bodies collide with the right side of the world bounds? - */ - right: boolean; - }; - - type PhysicsGroupConfig = Phaser.Types.GameObjects.Group.GroupConfig & { - /** - * Sets {@link Phaser.Physics.Arcade.Body#collideWorldBounds}. - */ - collideWorldBounds?: boolean; - /** - * Sets {@link Phaser.Physics.Arcade.Body#setBoundsRectangle setBoundsRectangle}. - */ - customBoundsRectangle?: Phaser.Geom.Rectangle; - /** - * Sets {@link Phaser.Physics.Arcade.Body#acceleration acceleration.x}. - */ - accelerationX?: number; - /** - * Sets {@link Phaser.Physics.Arcade.Body#acceleration acceleration.y}. - */ - accelerationY?: number; - /** - * Sets {@link Phaser.Physics.Arcade.Body#allowDrag}. - */ - allowDrag?: boolean; - /** - * Sets {@link Phaser.Physics.Arcade.Body#allowGravity}. - */ - allowGravity?: boolean; - /** - * Sets {@link Phaser.Physics.Arcade.Body#allowRotation}. - */ - allowRotation?: boolean; - /** - * Sets {@link Phaser.Physics.Arcade.Body#bounce bounce.x}. - */ - bounceX?: number; - /** - * Sets {@link Phaser.Physics.Arcade.Body#bounce bounce.y}. - */ - bounceY?: number; - /** - * Sets {@link Phaser.Physics.Arcade.Body#drag drag.x}. - */ - dragX?: number; - /** - * Sets {@link Phaser.Physics.Arcade.Body#drag drag.y}. - */ - dragY?: number; - /** - * Sets {@link Phaser.Physics.Arcade.Body#enable enable}. - */ - enable?: boolean; - /** - * Sets {@link Phaser.Physics.Arcade.Body#gravity gravity.x}. - */ - gravityX?: number; - /** - * Sets {@link Phaser.Physics.Arcade.Body#gravity gravity.y}. - */ - gravityY?: number; - /** - * Sets {@link Phaser.Physics.Arcade.Body#friction friction.x}. - */ - frictionX?: number; - /** - * Sets {@link Phaser.Physics.Arcade.Body#friction friction.y}. - */ - frictionY?: number; - /** - * Sets {@link Phaser.Physics.Arcade.Body#velocity velocity.x}. - */ - velocityX?: number; - /** - * Sets {@link Phaser.Physics.Arcade.Body#velocity velocity.y}. - */ - velocityY?: number; - /** - * Sets {@link Phaser.Physics.Arcade.Body#angularVelocity}. - */ - angularVelocity?: number; - /** - * Sets {@link Phaser.Physics.Arcade.Body#angularAcceleration}. - */ - angularAcceleration?: number; - /** - * Sets {@link Phaser.Physics.Arcade.Body#angularDrag}. - */ - angularDrag?: number; - /** - * Sets {@link Phaser.Physics.Arcade.Body#mass}. - */ - mass?: number; - /** - * Sets {@link Phaser.Physics.Arcade.Body#immovable}. - */ - immovable?: boolean; - }; - - type PhysicsGroupDefaults = { - /** - * As {@link Phaser.Physics.Arcade.Body#setCollideWorldBounds}. - */ - setCollideWorldBounds: boolean; - /** - * As {@link Phaser.Physics.Arcade.Body#setBoundsRectangle}. - */ - setBoundsRectangle: Phaser.Geom.Rectangle; - /** - * As {@link Phaser.Physics.Arcade.Body#setAccelerationX}. - */ - setAccelerationX: number; - /** - * As {@link Phaser.Physics.Arcade.Body#setAccelerationY}. - */ - setAccelerationY: number; - /** - * As {@link Phaser.Physics.Arcade.Body#setAllowDrag}. - */ - setAllowDrag: boolean; - /** - * As {@link Phaser.Physics.Arcade.Body#setAllowGravity}. - */ - setAllowGravity: boolean; - /** - * As {@link Phaser.Physics.Arcade.Body#setAllowRotation}. - */ - setAllowRotation: boolean; - /** - * As {@link Phaser.Physics.Arcade.Body#setBounceX}. - */ - setBounceX: number; - /** - * As {@link Phaser.Physics.Arcade.Body#setBounceY}. - */ - setBounceY: number; - /** - * As {@link Phaser.Physics.Arcade.Body#setDragX}. - */ - setDragX: number; - /** - * As {@link Phaser.Physics.Arcade.Body#setDragY}. - */ - setDragY: number; - /** - * As {@link Phaser.Physics.Arcade.Body#setEnable}. - */ - setEnable: boolean; - /** - * As {@link Phaser.Physics.Arcade.Body#setGravityX}. - */ - setGravityX: number; - /** - * As {@link Phaser.Physics.Arcade.Body#setGravityY}. - */ - setGravityY: number; - /** - * As {@link Phaser.Physics.Arcade.Body#setFrictionX}. - */ - setFrictionX: number; - /** - * As {@link Phaser.Physics.Arcade.Body#setFrictionY}. - */ - setFrictionY: number; - /** - * As {@link Phaser.Physics.Arcade.Body#setVelocityX}. - */ - setVelocityX: number; - /** - * As {@link Phaser.Physics.Arcade.Body#setVelocityY}. - */ - setVelocityY: number; - /** - * As {@link Phaser.Physics.Arcade.Body#setAngularVelocity}. - */ - setAngularVelocity: number; - /** - * As {@link Phaser.Physics.Arcade.Body#setAngularAcceleration}. - */ - setAngularAcceleration: number; - /** - * As {@link Phaser.Physics.Arcade.Body#setAngularDrag}. - */ - setAngularDrag: number; - /** - * As {@link Phaser.Physics.Arcade.Body#setMass}. - */ - setMass: number; - /** - * As {@link Phaser.Physics.Arcade.Body#setImmovable}. - */ - setImmovable: boolean; - }; - - } - - namespace Impact { - type BodyUpdateCallback = (body: Phaser.Physics.Impact.Body)=>void; - - type CollisionOptions = { - /** - * Slope IDs can be stored on tiles directly - * using Impacts tileset editor. If a tile has a property with the given slopeTileProperty string - * name, the value of that property for the tile will be used for its slope mapping. E.g. a 45 - * degree slope upward could be given a "slope" property with a value of 2. - */ - slopeTileProperty?: string; - /** - * A tile index to slope definition map. - */ - slopeMap?: object; - /** - * If specified, the default slope ID to - * assign to a colliding tile. If not specified, the tile's index is used. - */ - defaultCollidingSlope?: integer; - /** - * The default slope ID to assign to a - * non-colliding tile. - */ - defaultNonCollidingSlope?: integer; - }; - - type JSONImpactBody = { - /** - * [description] - */ - name: string; - /** - * [description] - */ - size: Phaser.Types.Math.Vector2Like; - /** - * The entity's position in the game world. - */ - pos: Phaser.Types.Math.Vector2Like; - /** - * Current velocity in pixels per second. - */ - vel: Phaser.Types.Math.Vector2Like; - /** - * Current acceleration to be added to the entity's velocity per second. E.g. an entity with a `vel.x` of 0 and `accel.x` of 10 will have a `vel.x` of 100 ten seconds later. - */ - accel: Phaser.Types.Math.Vector2Like; - /** - * Deceleration to be subtracted from the entity's velocity per second. Only applies if `accel` is 0. - */ - friction: Phaser.Types.Math.Vector2Like; - /** - * The maximum velocity a body can move. - */ - maxVel: Phaser.Types.Math.Vector2Like; - /** - * [description] - */ - gravityFactor: number; - /** - * [description] - */ - bounciness: number; - /** - * [description] - */ - minBounceVelocity: number; - /** - * [description] - */ - type: Phaser.Physics.Impact.TYPE; - /** - * [description] - */ - checkAgainst: Phaser.Physics.Impact.TYPE; - /** - * [description] - */ - collides: Phaser.Physics.Impact.COLLIDES; - }; - - type WorldConfig = { - /** - * Sets {@link Phaser.Physics.Impact.World#gravity} - */ - gravity?: number; - /** - * The size of the cells used for the broadphase pass. Increase this value if you have lots of large objects in the world. - */ - cellSize?: number; - /** - * A number that allows per-body time scaling, e.g. a force-field where bodies inside are in slow-motion, while others are at full speed. - */ - timeScale?: number; - /** - * [description] - */ - maxStep?: number; - /** - * Sets {@link Phaser.Physics.Impact.World#debug}. - */ - debug?: boolean; - /** - * The maximum velocity a body can move. - */ - maxVelocity?: number; - /** - * Whether the Body's boundary is drawn to the debug display. - */ - debugShowBody?: boolean; - /** - * Whether the Body's velocity is drawn to the debug display. - */ - debugShowVelocity?: boolean; - /** - * The color of this Body on the debug display. - */ - debugBodyColor?: number; - /** - * The color of the Body's velocity on the debug display. - */ - debugVelocityColor?: number; - /** - * Maximum X velocity objects can move. - */ - maxVelocityX?: number; - /** - * Maximum Y velocity objects can move. - */ - maxVelocityY?: number; - /** - * The minimum velocity an object can be moving at to be considered for bounce. - */ - minBounceVelocity?: number; - /** - * Gravity multiplier. Set to 0 for no gravity. - */ - gravityFactor?: number; - /** - * The default bounce, or restitution, of bodies in the world. - */ - bounciness?: number; - /** - * Should the world have bounds enabled by default? - */ - setBounds?: object | boolean; - /** - * The x coordinate of the world bounds. - */ - "setBounds.x"?: number; - /** - * The y coordinate of the world bounds. - */ - "setBounds.y"?: number; - /** - * The width of the world bounds. - */ - "setBounds.width"?: number; - /** - * The height of the world bounds. - */ - "setBounds.height"?: number; - /** - * The thickness of the walls of the world bounds. - */ - "setBounds.thickness"?: number; - /** - * Should the left-side world bounds wall be created? - */ - "setBounds.left"?: boolean; - /** - * Should the right-side world bounds wall be created? - */ - "setBounds.right"?: boolean; - /** - * Should the top world bounds wall be created? - */ - "setBounds.top"?: boolean; - /** - * Should the bottom world bounds wall be created? - */ - "setBounds.bottom"?: boolean; - }; - - /** - * An object containing the 4 wall bodies that bound the physics world. - */ - type WorldDefaults = { - /** - * Whether the Body's boundary is drawn to the debug display. - */ - debugShowBody: boolean; - /** - * Whether the Body's velocity is drawn to the debug display. - */ - debugShowVelocity: boolean; - /** - * The color of this Body on the debug display. - */ - bodyDebugColor: number; - /** - * The color of the Body's velocity on the debug display. - */ - velocityDebugColor: number; - /** - * Maximum X velocity objects can move. - */ - maxVelocityX: number; - /** - * Maximum Y velocity objects can move. - */ - maxVelocityY: number; - /** - * The minimum velocity an object can be moving at to be considered for bounce. - */ - minBounceVelocity: number; - /** - * Gravity multiplier. Set to 0 for no gravity. - */ - gravityFactor: number; - /** - * The default bounce, or restitution, of bodies in the world. - */ - bounciness: number; - }; - - type WorldWalls = { - /** - * The left-side wall of the world bounds. - */ - left: Phaser.Physics.Impact.Body; - /** - * The right-side wall of the world bounds. - */ - right: Phaser.Physics.Impact.Body; - /** - * The top wall of the world bounds. - */ - top: Phaser.Physics.Impact.Body; - /** - * The bottom wall of the world bounds. - */ - bottom: Phaser.Physics.Impact.Body; - }; - - } - - namespace Matter { - type MatterBody = MatterJS.BodyType | Phaser.GameObjects.GameObject | Phaser.Physics.Matter.Image | Phaser.Physics.Matter.Sprite | Phaser.Physics.Matter.TileBody; - - type MatterBodyConfig = { - /** - * An arbitrary string-based name to help identify this body. - */ - label?: string; - /** - * An array of bodies that make up this body. The first body in the array must always be a self reference to the current body instance. All bodies in the `parts` array together form a single rigid compound body. - */ - parts?: MatterJS.BodyType[]; - /** - * An object reserved for storing plugin-specific properties. - */ - plugin?: any; - /** - * A number specifying the angle of the body, in radians. - */ - angle?: number; - /** - * An array of `Vector` objects that specify the convex hull of the rigid body. These should be provided about the origin `(0, 0)`. - */ - vertices?: Phaser.Types.Math.Vector2Like[]; - /** - * A `Vector` that specifies the current world-space position of the body. - */ - position?: Phaser.Types.Math.Vector2Like; - /** - * A `Vector` that specifies the force to apply in the current step. It is zeroed after every `Body.update`. See also `Body.applyForce`. - */ - force?: Phaser.Types.Math.Vector2Like; - /** - * A `Number` that specifies the torque (turning force) to apply in the current step. It is zeroed after every `Body.update`. - */ - torque?: number; - /** - * A flag that indicates whether a body is a sensor. Sensor triggers collision events, but doesn't react with colliding body physically. - */ - isSensor?: boolean; - /** - * A flag that indicates whether a body is considered static. A static body can never change position or angle and is completely fixed. - */ - isStatic?: boolean; - /** - * A `Number` that defines the number of updates in which this body must have near-zero velocity before it is set as sleeping by the `Matter.Sleeping` module (if sleeping is enabled by the engine). - */ - sleepThreshold?: number; - /** - * A `Number` that defines the density of the body, that is its mass per unit area. If you pass the density via `Body.create` the `mass` property is automatically calculated for you based on the size (area) of the object. This is generally preferable to simply setting mass and allows for more intuitive definition of materials (e.g. rock has a higher density than wood). - */ - density?: number; - /** - * A `Number` that defines the restitution (elasticity) of the body. The value is always positive and is in the range `(0, 1)`. - */ - restitution?: number; - /** - * A `Number` that defines the friction of the body. The value is always positive and is in the range `(0, 1)`. A value of `0` means that the body may slide indefinitely. A value of `1` means the body may come to a stop almost instantly after a force is applied. - */ - friction?: number; - /** - * A `Number` that defines the static friction of the body (in the Coulomb friction model). A value of `0` means the body will never 'stick' when it is nearly stationary and only dynamic `friction` is used. The higher the value (e.g. `10`), the more force it will take to initially get the body moving when nearly stationary. This value is multiplied with the `friction` property to make it easier to change `friction` and maintain an appropriate amount of static friction. - */ - frictionStatic?: number; - /** - * A `Number` that defines the air friction of the body (air resistance). A value of `0` means the body will never slow as it moves through space. The higher the value, the faster a body slows when moving through space. - */ - frictionAir?: number; - /** - * An `Object` that specifies the collision filtering properties of this body. - */ - collisionFilter?: Phaser.Types.Physics.Matter.MatterCollisionFilter; - /** - * A `Number` that specifies a tolerance on how far a body is allowed to 'sink' or rotate into other bodies. Avoid changing this value unless you understand the purpose of `slop` in physics engines. The default should generally suffice, although very large bodies may require larger values for stable stacking. - */ - slop?: number; - /** - * A `Number` that allows per-body time scaling, e.g. a force-field where bodies inside are in slow-motion, while others are at full speed. - */ - timeScale?: number; - /** - * A number, or array of numbers, to chamfer the vertices of the body, or a full Chamfer configuration object. - */ - chamfer?: number | number[] | Phaser.Types.Physics.Matter.MatterChamferConfig; - /** - * The radius of this body if a circle. - */ - circleRadius?: number; - /** - * A `Number` that defines the mass of the body, although it may be more appropriate to specify the `density` property instead. If you modify this value, you must also modify the `body.inverseMass` property (`1 / mass`). - */ - mass?: number; - /** - * A `Number` that defines the inverse mass of the body (`1 / mass`). If you modify this value, you must also modify the `body.mass` property. - */ - inverseMass?: number; - /** - * A `Vector` that specifies the initial scale of the body. - */ - scale?: Phaser.Types.Math.Vector2Like; - /** - * A `Vector` that scales the influence of World gravity when applied to this body. - */ - gravityScale?: Phaser.Types.Math.Vector2Like; - /** - * A boolean that toggles if this body should ignore world gravity or not. - */ - ignoreGravity?: boolean; - /** - * A boolean that toggles if this body should ignore pointer / mouse constraints or not. - */ - ignorePointer?: boolean; - /** - * The Debug Render configuration object for this body. - */ - render?: Phaser.Types.Physics.Matter.MatterBodyRenderConfig; - /** - * A callback that is invoked when this Body starts colliding with any other Body. You can register callbacks by providing a function of type `( pair: Matter.Pair) => void`. - */ - onCollideCallback?: Function; - /** - * A callback that is invoked when this Body stops colliding with any other Body. You can register callbacks by providing a function of type `( pair: Matter.Pair) => void`. - */ - onCollideEndCallback?: Function; - /** - * A callback that is invoked for the duration that this Body is colliding with any other Body. You can register callbacks by providing a function of type `( pair: Matter.Pair) => void`. - */ - onCollideActiveCallback?: Function; - /** - * A collision callback dictionary used by the `Body.setOnCollideWith` function. - */ - onCollideWith?: any; - }; - - type MatterBodyRenderConfig = { - /** - * Should this body be rendered by the Debug Renderer? - */ - visible?: boolean; - /** - * The opacity of the body and all parts within it. - */ - opacity?: number; - /** - * The color value of the fill when rendering this body. - */ - fillColor?: number; - /** - * The opacity of the fill when rendering this body, a value between 0 and 1. - */ - fillOpacity?: number; - /** - * The color value of the line stroke when rendering this body. - */ - lineColor?: number; - /** - * The opacity of the line when rendering this body, a value between 0 and 1. - */ - lineOpacity?: number; - /** - * If rendering lines, the thickness of the line. - */ - lineThickness?: number; - /** - * Controls the offset between the body and the parent Game Object, if it has one. - */ - sprite?: object; - /** - * The horizontal offset between the body and the parent Game Object texture, if it has one. - */ - "sprite.xOffset"?: number; - /** - * The vertical offset between the body and the parent Game Object texture, if it has one. - */ - "sprite.yOffset"?: number; - }; - - type MatterBodyTileOptions = { - /** - * Whether or not the newly created body should be made static. This defaults to true since typically tiles should not be moved. - */ - isStatic?: boolean; - /** - * Whether or not to add the newly created body (or existing body if options.body is used) to the Matter world. - */ - addToWorld?: boolean; - }; - - type MatterChamferConfig = { - /** - * A single number, or an array, to specify the radius for each vertex. - */ - radius?: number | number[]; - /** - * The quality of the chamfering. -1 means 'auto'. - */ - quality?: number; - /** - * The minimum quality of the chamfering. The higher this value, the more vertices are created. - */ - qualityMin?: number; - /** - * The maximum quality of the chamfering. The higher this value, the more vertices are created. - */ - qualityMax?: number; - }; - - type MatterCollisionData = { - /** - * Have the pair collided or not? - */ - collided: boolean; - /** - * A reference to the first body involved in the collision. - */ - bodyA: MatterJS.BodyType; - /** - * A reference to the second body involved in the collision. - */ - bodyB: MatterJS.BodyType; - /** - * A reference to the dominant axis body. - */ - axisBody: MatterJS.BodyType; - /** - * The index of the dominant collision axis vector (edge normal) - */ - axisNumber: number; - /** - * The depth of the collision on the minimum overlap. - */ - depth: number; - /** - * A reference to the parent of Body A, or to Body A itself if it has no parent. - */ - parentA: MatterJS.BodyType; - /** - * A reference to the parent of Body B, or to Body B itself if it has no parent. - */ - parentB: MatterJS.BodyType; - /** - * The collision normal, facing away from Body A. - */ - normal: MatterJS.Vector; - /** - * The tangent of the collision normal. - */ - tangent: MatterJS.Vector; - /** - * The penetration distances between the two bodies. - */ - penetration: MatterJS.Vector; - /** - * An array of support points, either exactly one or two points. - */ - supports: MatterJS.Vector[]; - /** - * The resulting inverse mass from the collision. - */ - inverseMass: number; - /** - * The resulting friction from the collision. - */ - friction: number; - /** - * The resulting static friction from the collision. - */ - frictionStatic: number; - /** - * The resulting restitution from the collision. - */ - restitution: number; - /** - * The resulting slop from the collision. - */ - slop: number; - }; - - /** - * An `Object` that specifies the collision filtering properties of this body. - * - * Collisions between two bodies will obey the following rules: - * - If the two bodies have the same non-zero value of `collisionFilter.group`, - * they will always collide if the value is positive, and they will never collide - * if the value is negative. - * - If the two bodies have different values of `collisionFilter.group` or if one - * (or both) of the bodies has a value of 0, then the category/mask rules apply as follows: - * - * Each body belongs to a collision category, given by `collisionFilter.category`. This - * value is used as a bit field and the category should have only one bit set, meaning that - * the value of this property is a power of two in the range [1, 2^31]. Thus, there are 32 - * different collision categories available. - * - * Each body also defines a collision bitmask, given by `collisionFilter.mask` which specifies - * the categories it collides with (the value is the bitwise AND value of all these categories). - * - * Using the category/mask rules, two bodies `A` and `B` collide if each includes the other's - * category in its mask, i.e. `(categoryA & maskB) !== 0` and `(categoryB & maskA) !== 0` - * are both true. - */ - type MatterCollisionFilter = { - /** - * A bit field that specifies the collision category this body belongs to. The category value should have only one bit set, for example `0x0001`. This means there are up to 32 unique collision categories available. - */ - category?: number; - /** - * A bit mask that specifies the collision categories this body may collide with. - */ - mask?: number; - /** - * An Integer `Number`, that specifies the collision group this body belongs to. - */ - group?: number; - }; - - type MatterCollisionPair = { - /** - * The unique auto-generated collision pair id. A combination of the body A and B IDs. - */ - id: string; - /** - * A reference to the first body involved in the collision. - */ - bodyA: MatterJS.BodyType; - /** - * A reference to the second body involved in the collision. - */ - bodyB: MatterJS.BodyType; - /** - * An array containing all of the active contacts between bodies A and B. - */ - activeContacts: MatterJS.Vector[]; - /** - * The amount of separation that occured between bodies A and B. - */ - separation: number; - /** - * Is the collision still active or not? - */ - isActive: boolean; - /** - * Has Matter determined the collision are being active yet? - */ - confirmedActive: boolean; - /** - * Is either body A or B a sensor? - */ - isSensor: boolean; - /** - * The timestamp when the collision pair was created. - */ - timeCreated: number; - /** - * The timestamp when the collision pair was most recently updated. - */ - timeUpdated: number; - /** - * The collision data object. - */ - collision: Phaser.Types.Physics.Matter.MatterCollisionData; - /** - * The resulting inverse mass from the collision. - */ - inverseMass: number; - /** - * The resulting friction from the collision. - */ - friction: number; - /** - * The resulting static friction from the collision. - */ - frictionStatic: number; - /** - * The resulting restitution from the collision. - */ - restitution: number; - /** - * The resulting slop from the collision. - */ - slop: number; - }; - - type MatterConstraintConfig = { - /** - * An arbitrary string-based name to help identify this constraint. - */ - label?: string; - /** - * The first possible `Body` that this constraint is attached to. - */ - bodyA?: MatterJS.BodyType; - /** - * The second possible `Body` that this constraint is attached to. - */ - bodyB?: MatterJS.BodyType; - /** - * A `Vector` that specifies the offset of the constraint from center of the `constraint.bodyA` if defined, otherwise a world-space position. - */ - pointA?: Phaser.Types.Math.Vector2Like; - /** - * A `Vector` that specifies the offset of the constraint from center of the `constraint.bodyB` if defined, otherwise a world-space position. - */ - pointB?: Phaser.Types.Math.Vector2Like; - /** - * A `Number` that specifies the stiffness of the constraint, i.e. the rate at which it returns to its resting `constraint.length`. A value of `1` means the constraint should be very stiff. A value of `0.2` means the constraint acts like a soft spring. - */ - stiffness?: number; - /** - * A `Number` that specifies the angular stiffness of the constraint. - */ - angularStiffness?: number; - /** - * The angleA of the constraint. If bodyA is set, the angle of bodyA is used instead. - */ - angleA?: number; - /** - * The angleB of the constraint. If bodyB is set, the angle of bodyB is used instead. - */ - angleB?: number; - /** - * A `Number` that specifies the damping of the constraint, i.e. the amount of resistance applied to each body based on their velocities to limit the amount of oscillation. Damping will only be apparent when the constraint also has a very low `stiffness`. A value of `0.1` means the constraint will apply heavy damping, resulting in little to no oscillation. A value of `0` means the constraint will apply no damping. - */ - damping?: number; - /** - * A `Number` that specifies the target resting length of the constraint. It is calculated automatically in `Constraint.create` from initial positions of the `constraint.bodyA` and `constraint.bodyB`. - */ - length?: number; - /** - * An object reserved for storing plugin-specific properties. - */ - plugin?: any; - /** - * The Debug Render configuration object for this constraint. - */ - render?: Phaser.Types.Physics.Matter.MatterConstraintRenderConfig; - }; - - type MatterConstraintRenderConfig = { - /** - * Should this constraint be rendered by the Debug Renderer? - */ - visible?: boolean; - /** - * If this constraint has anchors, should they be rendered? Pin constraints never have anchors. - */ - anchors?: boolean; - /** - * The color value of the line stroke when rendering this constraint. - */ - lineColor?: number; - /** - * The opacity of the line when rendering this constraint, a value between 0 and 1. - */ - lineOpacity?: number; - /** - * If rendering lines, the thickness of the line. - */ - lineThickness?: number; - /** - * The size of the circles drawn when rendering pin constraints. - */ - pinSize?: number; - /** - * The size of the circles drawn as the constraint anchors. - */ - anchorSize?: number; - /** - * The color value of constraint anchors. - */ - anchorColor?: number; - }; - - type MatterDebugConfig = { - /** - * Render all of the body axes? - */ - showAxes?: boolean; - /** - * Render just a single body axis? - */ - showAngleIndicator?: boolean; - /** - * The color of the body angle / axes lines. - */ - angleColor?: boolean; - /** - * Render the broadphase grid? - */ - showBroadphase?: boolean; - /** - * The color of the broadphase grid. - */ - broadphaseColor?: boolean; - /** - * Render the bounds of the bodies in the world? - */ - showBounds?: boolean; - /** - * The color of the body bounds. - */ - boundsColor?: boolean; - /** - * Render the velocity of the bodies in the world? - */ - showVelocity?: boolean; - /** - * The color of the body velocity line. - */ - velocityColor?: boolean; - /** - * Render the collision points and normals for colliding pairs. - */ - showCollisions?: boolean; - /** - * The color of the collision points. - */ - collisionColor?: boolean; - /** - * Render lines showing the separation between bodies. - */ - showSeparation?: boolean; - /** - * The color of the body separation line. - */ - separationColor?: boolean; - /** - * Render the dynamic bodies in the world to the Graphics object? - */ - showBody?: boolean; - /** - * Render the static bodies in the world to the Graphics object? - */ - showStaticBody?: boolean; - /** - * When rendering bodies, render the internal edges as well? - */ - showInternalEdges?: boolean; - /** - * Render the bodies using a fill color. - */ - renderFill?: boolean; - /** - * Render the bodies using a line stroke. - */ - renderLine?: boolean; - /** - * The color value of the fill when rendering dynamic bodies. - */ - fillColor?: number; - /** - * The opacity of the fill when rendering dynamic bodies, a value between 0 and 1. - */ - fillOpacity?: number; - /** - * The color value of the line stroke when rendering dynamic bodies. - */ - lineColor?: number; - /** - * The opacity of the line when rendering dynamic bodies, a value between 0 and 1. - */ - lineOpacity?: number; - /** - * If rendering lines, the thickness of the line. - */ - lineThickness?: number; - /** - * The color value of the fill when rendering static bodies. - */ - staticFillColor?: number; - /** - * The color value of the line stroke when rendering static bodies. - */ - staticLineColor?: number; - /** - * Render any sleeping bodies (dynamic or static) in the world to the Graphics object? - */ - showSleeping?: boolean; - /** - * The amount to multiply the opacity of sleeping static bodies by. - */ - staticBodySleepOpacity?: number; - /** - * The color value of the fill when rendering sleeping dynamic bodies. - */ - sleepFillColor?: number; - /** - * The color value of the line stroke when rendering sleeping dynamic bodies. - */ - sleepLineColor?: number; - /** - * Render bodies or body parts that are flagged as being a sensor? - */ - showSensors?: boolean; - /** - * The fill color when rendering body sensors. - */ - sensorFillColor?: number; - /** - * The line color when rendering body sensors. - */ - sensorLineColor?: number; - /** - * Render the position of non-static bodies? - */ - showPositions?: boolean; - /** - * The size of the rectangle drawn when rendering the body position. - */ - positionSize?: number; - /** - * The color value of the rectangle drawn when rendering the body position. - */ - positionColor?: number; - /** - * Render all world constraints to the Graphics object? - */ - showJoint?: boolean; - /** - * The color value of joints when `showJoint` is set. - */ - jointColor?: number; - /** - * The line opacity when rendering joints, a value between 0 and 1. - */ - jointLineOpacity?: number; - /** - * The line thickness when rendering joints. - */ - jointLineThickness?: number; - /** - * The size of the circles drawn when rendering pin constraints. - */ - pinSize?: number; - /** - * The color value of the circles drawn when rendering pin constraints. - */ - pinColor?: number; - /** - * The color value of spring constraints. - */ - springColor?: number; - /** - * The color value of constraint anchors. - */ - anchorColor?: number; - /** - * The size of the circles drawn as the constraint anchors. - */ - anchorSize?: number; - /** - * When rendering polygon bodies, render the convex hull as well? - */ - showConvexHulls?: boolean; - /** - * The color value of hulls when `showConvexHulls` is set. - */ - hullColor?: number; - }; - - type MatterRunnerConfig = { - /** - * A boolean that specifies if the runner should use a fixed timestep (otherwise it is variable). If timing is fixed, then the apparent simulation speed will change depending on the frame rate (but behaviour will be deterministic). If the timing is variable, then the apparent simulation speed will be constant (approximately, but at the cost of determininism). - */ - isFixed?: boolean; - /** - * A number that specifies the frame rate in seconds. If you don't specify this, but do specify `delta`, those values set the fps rate. - */ - fps?: number; - /** - * A number that specifies the time correction factor to apply to the update. This can help improve the accuracy of the simulation in cases where delta is changing between updates. - */ - correction?: number; - /** - * The size of the delta smoothing array when `isFixed` is `false`. - */ - deltaSampleSize?: number; - /** - * A number that specifies the time step between updates in milliseconds. If you set the `fps` property, this value is set based on that. If `isFixed` is set to `true`, then `delta` is fixed. If it is `false`, then `delta` can dynamically change to maintain the correct apparent simulation speed. - */ - delta?: number; - /** - * A number that specifies the minimum time step between updates in milliseconds. - */ - deltaMin?: number; - /** - * A number that specifies the maximum time step between updates in milliseconds. - */ - deltaMax?: number; - }; - - type MatterSetBodyConfig = { - /** - * The shape type. Either `rectangle`, `circle`, `trapezoid`, `polygon`, `fromVertices`, `fromVerts` or `fromPhysicsEditor`. - */ - type?: string; - /** - * The horizontal world position to place the body at. - */ - x?: number; - /** - * The vertical world position to place the body at. - */ - y?: number; - /** - * The width of the body. - */ - width?: number; - /** - * The height of the body. - */ - height?: number; - /** - * The radius of the body. Used by `circle` and `polygon` shapes. - */ - radius?: number; - /** - * The max sizes of the body. Used by the `circle` shape. - */ - maxSides?: number; - /** - * Used by the `trapezoid` shape. The slope of the trapezoid. 0 creates a rectangle, while 1 creates a triangle. Positive values make the top side shorter, while negative values make the bottom side shorter. - */ - slope?: number; - /** - * Used by the `polygon` shape. The number of sides the polygon will have. - */ - sides?: number; - /** - * Used by the `fromVerts` shape. The vertices data. Either a path string or an array of vertices. - */ - verts?: string | any[]; - /** - * Used by the `fromVerts` shape. Flag internal edges (coincident part edges) - */ - flagInternal?: boolean; - /** - * Used by the `fromVerts` shape. Whether Matter.js will discard collinear edges (to improve performance). - */ - removeCollinear?: number; - /** - * Used by the `fromVerts` shape. During decomposition discard parts that have an area less than this. - */ - minimumArea?: number; - /** - * Should the new body be automatically added to the world? - */ - addToWorld?: boolean; - }; - - type MatterTileOptions = { - /** - * An existing Matter body to be used instead of creating a new one. - */ - body?: MatterJS.BodyType; - /** - * Whether or not the newly created body should be made static. This defaults to true since typically tiles should not be moved. - */ - isStatic?: boolean; - /** - * Whether or not to add the newly created body (or existing body if options.body is used) to the Matter world. - */ - addToWorld?: boolean; - }; - - type MatterWorldConfig = { - /** - * Sets {@link Phaser.Physics.Matter.World#gravity}. If `false` Gravity will be set to zero. - */ - gravity?: Phaser.Types.Math.Vector2Like | boolean; - /** - * Should the world have bounds enabled by default? - */ - setBounds?: object | boolean; - /** - * The x coordinate of the world bounds. - */ - "setBounds.x"?: number; - /** - * The y coordinate of the world bounds. - */ - "setBounds.y"?: number; - /** - * The width of the world bounds. - */ - "setBounds.width"?: number; - /** - * The height of the world bounds. - */ - "setBounds.height"?: number; - /** - * The thickness of the walls of the world bounds. - */ - "setBounds.thickness"?: number; - /** - * Should the left-side world bounds wall be created? - */ - "setBounds.left"?: boolean; - /** - * Should the right-side world bounds wall be created? - */ - "setBounds.right"?: boolean; - /** - * Should the top world bounds wall be created? - */ - "setBounds.top"?: boolean; - /** - * Should the bottom world bounds wall be created? - */ - "setBounds.bottom"?: boolean; - /** - * The number of position iterations to perform each update. The higher the value, the higher quality the simulation will be at the expense of performance. - */ - positionIterations?: number; - /** - * The number of velocity iterations to perform each update. The higher the value, the higher quality the simulation will be at the expense of performance. - */ - velocityIterations?: number; - /** - * The number of constraint iterations to perform each update. The higher the value, the higher quality the simulation will be at the expense of performance. - */ - constraintIterations?: number; - /** - * A flag that specifies whether the engine should allow sleeping via the `Matter.Sleeping` module. Sleeping can improve stability and performance, but often at the expense of accuracy. - */ - enableSleeping?: boolean; - /** - * A `Number` that specifies the current simulation-time in milliseconds starting from `0`. It is incremented on every `Engine.update` by the given `delta` argument. - */ - "timing.timestamp"?: number; - /** - * A `Number` that specifies the global scaling factor of time for all bodies. A value of `0` freezes the simulation. A value of `0.1` gives a slow-motion effect. A value of `1.2` gives a speed-up effect. - */ - "timing.timeScale"?: number; - /** - * Should the Matter Attractor Plugin be enabled? An attractors plugin that makes it easy to apply continual forces on bodies. It's possible to simulate effects such as wind, gravity and magnetism. - */ - "plugins.attractors"?: boolean; - /** - * Should the Matter Wrap Plugin be enabled? A coordinate wrapping plugin that automatically wraps the position of bodies such that they always stay within the given bounds. Upon crossing a boundary the body will appear on the opposite side of the bounds, while maintaining its velocity. - */ - "plugins.wrap"?: boolean; - /** - * Should the Matter Collision Events Plugin be enabled? - */ - "plugins.collisionevents"?: boolean; - /** - * Toggles if the world is enabled or not. - */ - enabled?: boolean; - /** - * An optional Number that specifies the time correction factor to apply to the update. - */ - correction?: number; - /** - * This function is called every time the core game loop steps, which is bound to the Request Animation Frame frequency unless otherwise modified. - */ - getDelta?: Function; - /** - * Automatically call Engine.update every time the game steps. - */ - autoUpdate?: boolean; - /** - * Sets the Resolver resting threshold property. - */ - restingThresh?: number; - /** - * Sets the Resolver resting threshold tangent property. - */ - restingThreshTangent?: number; - /** - * Sets the Resolver position dampen property. - */ - positionDampen?: number; - /** - * Sets the Resolver position warming property. - */ - positionWarming?: number; - /** - * Sets the Resolver friction normal multiplier property. - */ - frictionNormalMultiplier?: number; - /** - * Controls the Matter Debug Rendering options. If a boolean it will use the default values, otherwise, specify a Debug Config object. - */ - debug?: boolean | Phaser.Types.Physics.Matter.MatterDebugConfig; - /** - * Sets the Matter Runner options. - */ - runner?: Phaser.Types.Physics.Matter.MatterRunnerConfig; - }; - - } - - } - - namespace Plugins { - type CorePluginContainer = { + type GameConfig = { /** - * The unique name of this plugin in the core plugin cache. + * The width of the game, in game pixels. */ - key: string; + width?: number | string; /** - * The plugin to be stored. Should be the source object, not instantiated. + * The height of the game, in game pixels. */ - plugin: Function; + height?: number | string; /** - * If this plugin is to be injected into the Scene Systems, this is the property key map used. + * Simple scale applied to the game canvas. 2 is double size, 0.5 is half size, etc. */ - mapping?: string; + zoom?: number; /** - * Core Scene plugin or a Custom Scene plugin? + * Which renderer to use. Phaser.AUTO, Phaser.CANVAS, Phaser.HEADLESS, or Phaser.WEBGL. AUTO picks WEBGL if available, otherwise CANVAS. */ - custom?: boolean; - }; - - type CustomPluginContainer = { + type?: number; /** - * The unique name of this plugin in the custom plugin cache. + * The DOM element that will contain the game canvas, or its `id`. If undefined, or if the named element doesn't exist, the game canvas is appended to the document body. If `null` no parent will be used and you are responsible for adding the canvas to the dom. */ - key: string; + parent?: HTMLElement | string; /** - * The plugin to be stored. Should be the source object, not instantiated. + * Provide your own Canvas element for Phaser to use instead of creating one. */ - plugin: Function; - }; - - type GlobalPlugin = { + canvas?: HTMLCanvasElement; /** - * The unique name of this plugin within the plugin cache. + * CSS styles to apply to the game canvas instead of Phasers default styles. */ - key: string; + canvasStyle?: string; /** - * An instance of the plugin. + * Is Phaser running under a custom (non-native web) environment? If so, set this to `true` to skip internal Feature detection. If `true` the `renderType` cannot be left as `AUTO`. */ - plugin: Function; + customEnvironment?: boolean; /** - * Is the plugin active or not? + * Provide your own Canvas Context for Phaser to use, instead of creating one. */ - active?: boolean; + context?: CanvasRenderingContext2D; /** - * If this plugin is to be injected into the Scene Systems, this is the property key map used. + * A scene or scenes to add to the game. If several are given, the first is started; the remainder are started only if they have `{ active: true }`. See the `sceneConfig` argument in `Phaser.Scenes.SceneManager#add`. */ - mapping?: string; - }; - - } - - namespace Renderer { - namespace Snapshot { - type SnapshotCallback = (snapshot: Phaser.Display.Color | HTMLImageElement)=>void; - - type SnapshotState = { - /** - * The function to call after the snapshot is taken. - */ - callback: Phaser.Types.Renderer.Snapshot.SnapshotCallback; - /** - * The format of the image to create, usually `image/png` or `image/jpeg`. - */ - type?: string; - /** - * The image quality, between 0 and 1. Used for image formats with lossy compression, such as `image/jpeg`. - */ - encoderOptions?: number; - /** - * The x coordinate to start the snapshot from. - */ - x?: integer; - /** - * The y coordinate to start the snapshot from. - */ - y?: integer; - /** - * The width of the snapshot. - */ - width?: integer; - /** - * The height of the snapshot. - */ - height?: integer; - /** - * Is this a snapshot to get a single pixel, or an area? - */ - getPixel?: boolean; - /** - * Is this snapshot grabbing from a frame buffer or a canvas? - */ - isFramebuffer?: boolean; - /** - * The width of the frame buffer, if a frame buffer grab. - */ - bufferWidth?: integer; - /** - * The height of the frame buffer, if a frame buffer grab. - */ - bufferHeight?: integer; - }; - - } - - } - - namespace Scenes { - type CreateSceneFromObjectConfig = { + scene?: Phaser.Scene | Phaser.Scene[] | Phaser.Types.Scenes.SettingsConfig | Phaser.Types.Scenes.SettingsConfig[] | Phaser.Types.Scenes.CreateSceneFromObjectConfig | Phaser.Types.Scenes.CreateSceneFromObjectConfig[] | Function | Function[]; /** - * The scene's init callback. + * Seed for the random number generator. */ - init?: Phaser.Types.Scenes.SceneInitCallback; + seed?: string[]; /** - * The scene's preload callback. + * The title of the game. Shown in the browser console. */ - preload?: Phaser.Types.Scenes.ScenePreloadCallback; + title?: string; /** - * The scene's create callback. + * The URL of the game. Shown in the browser console. */ - create?: Phaser.Types.Scenes.SceneCreateCallback; + url?: string; /** - * The scene's update callback. See {@link Phaser.Scene#update}. + * The version of the game. Shown in the browser console. */ - update?: Function; + version?: string; /** - * Any additional properties, which will be copied to the Scene after it's created (except `data` or `sys`). + * Automatically call window.focus() when the game boots. Usually necessary to capture input events if the game is in a separate frame. */ - extend?: any; + autoFocus?: boolean; /** - * Any values, which will be merged into the Scene's Data Manager store. + * Input configuration, or `false` to disable all game input. */ - "extend.data"?: any; - }; - - /** - * Can be defined on your own Scenes. Use it to create your game objects. - * This method is called by the Scene Manager when the scene starts, after `init()` and `preload()`. - * If the LoaderPlugin started after `preload()`, then this method is called only after loading is complete. - */ - type SceneCreateCallback = (data: object)=>void; - - /** - * Can be defined on your own Scenes. - * This method is called by the Scene Manager when the scene starts, before `preload()` and `create()`. - */ - type SceneInitCallback = (data: object)=>void; - - /** - * Can be defined on your own Scenes. Use it to load assets. - * This method is called by the Scene Manager, after `init()` and before `create()`, only if the Scene has a LoaderPlugin. - * After this method completes, if the LoaderPlugin's queue isn't empty, the LoaderPlugin will start automatically. - */ - type ScenePreloadCallback = ()=>void; - - type SceneTransitionConfig = { + input?: boolean | Phaser.Types.Core.InputConfig; /** - * The Scene key to transition to. + * Disable the browser's default 'contextmenu' event (usually triggered by a right-button mouse click). */ - target: string; + disableContextMenu?: boolean; /** - * The duration, in ms, for the transition to last. + * Whether the game canvas will have a transparent background. */ - duration?: integer; + transparent?: boolean; /** - * Will the Scene responsible for the transition be sent to sleep on completion (`true`), or stopped? (`false`) + * Configuration for the banner printed in the browser console when the game starts. */ - sleep?: boolean; + banner?: boolean | Phaser.Types.Core.BannerConfig; /** - * Will the Scenes Input system be able to process events while it is transitioning in or out? + * The DOM Container configuration object. */ - allowInput?: boolean; + dom?: Phaser.Types.Core.DOMContainerConfig; /** - * Move the target Scene to be above this one before the transition starts. + * Game loop configuration. */ - moveAbove?: boolean; + fps?: Phaser.Types.Core.FPSConfig; /** - * Move the target Scene to be below this one before the transition starts. + * Game renderer configuration. */ - moveBelow?: boolean; + render?: Phaser.Types.Core.RenderConfig; /** - * This callback is invoked every frame for the duration of the transition. + * The background color of the game canvas. The default is black. */ - onUpdate?: Function; + backgroundColor?: string | number; /** - * The context in which the callback is invoked. + * Optional callbacks to run before or after game boot. */ - onUpdateScope?: any; + callbacks?: Phaser.Types.Core.CallbacksConfig; /** - * An object containing any data you wish to be passed to the target Scenes init / create methods. + * Loader configuration. */ - data?: any; - }; - - type SettingsConfig = { + loader?: Phaser.Types.Core.LoaderConfig; /** - * The unique key of this Scene. Must be unique within the entire Game instance. + * Images configuration. */ - key?: string; + images?: Phaser.Types.Core.ImagesConfig; /** - * Does the Scene start as active or not? An active Scene updates each step. + * Physics configuration. */ - active?: boolean; + physics?: Phaser.Types.Core.PhysicsConfig; /** - * Does the Scene start as visible or not? A visible Scene renders each step. + * Plugins to install. */ - visible?: boolean; + plugins?: Phaser.Types.Core.PluginObject | Phaser.Types.Core.PluginObjectItem[]; /** - * An optional Loader Packfile to be loaded before the Scene begins. + * The Scale Manager configuration. */ - pack?: false | Phaser.Types.Loader.FileTypes.PackFileConfig; + scale?: Phaser.Types.Core.ScaleConfig; /** - * An optional Camera configuration object. + * The Audio Configuration object. */ - cameras?: Phaser.Types.Cameras.Scene2D.JSONCamera | Phaser.Types.Cameras.Scene2D.JSONCamera[]; + audio?: Phaser.Types.Core.AudioConfig; /** - * Overwrites the default injection map for a scene. + * A WebGL Pipeline configuration object. Can also be part of the `RenderConfig`. */ - map?: {[key: string]: string}; + pipeline?: Phaser.Types.Core.PipelineConfig; + }; + + type GamepadInputConfig = { /** - * Extends the injection map for a scene. + * Where the Gamepad Manager listens for gamepad input events. */ - mapAdd?: {[key: string]: string}; + target?: any; + }; + + type ImagesConfig = { /** - * The physics configuration object for the Scene. + * A base64 encoded image file to use as the 'default' texture. */ - physics?: Phaser.Types.Core.PhysicsConfig; + default?: string; /** - * The loader configuration object for the Scene. + * A base64 encoded image file to use as the 'missing' texture. */ - loader?: Phaser.Types.Core.LoaderConfig; + missing?: string; /** - * The plugin configuration object for the Scene. + * A base64 encoded image file to use as the 'white' texture. */ - plugins?: false | any; + white?: string; }; - type SettingsObject = { - /** - * The current status of the Scene. Maps to the Scene constants. - */ - status: number; + type InputConfig = { /** - * The unique key of this Scene. Unique within the entire Game instance. + * Keyboard input configuration. `true` uses the default configuration and `false` disables keyboard input. */ - key: string; + keyboard?: boolean | Phaser.Types.Core.KeyboardInputConfig; /** - * The active state of this Scene. An active Scene updates each step. + * Mouse input configuration. `true` uses the default configuration and `false` disables mouse input. */ - active: boolean; + mouse?: boolean | Phaser.Types.Core.MouseInputConfig; /** - * The visible state of this Scene. A visible Scene renders each step. + * Touch input configuration. `true` uses the default configuration and `false` disables touch input. */ - visible: boolean; + touch?: boolean | Phaser.Types.Core.TouchInputConfig; /** - * Has the Scene finished booting? + * Gamepad input configuration. `true` enables gamepad input. */ - isBooted: boolean; + gamepad?: boolean | Phaser.Types.Core.GamepadInputConfig; /** - * Is the Scene in a state of transition? + * The maximum number of touch pointers. See {@link Phaser.Input.InputManager#pointers}. */ - isTransition: boolean; + activePointers?: number; /** - * The Scene this Scene is transitioning from, if set. + * The smoothing factor to apply during Pointer movement. See {@link Phaser.Input.Pointer#smoothFactor}. */ - transitionFrom: Phaser.Scene; + smoothFactor?: number; /** - * The duration of the transition, if set. + * Should Phaser listen for input events on the Window? If you disable this, events like 'POINTER_UP_OUTSIDE' will no longer fire. */ - transitionDuration: integer; + windowEvents?: boolean; + }; + + type KeyboardInputConfig = { /** - * Is this Scene allowed to receive input during transitions? + * Where the Keyboard Manager listens for keyboard input events. */ - transitionAllowInput: boolean; + target?: any; /** - * a data bundle passed to this Scene from the Scene Manager. + * `preventDefault` will be called on every non-modified key which has a key code in this array. By default it is empty. */ - data: object; + capture?: number[]; + }; + + type LoaderConfig = { /** - * The Loader Packfile to be loaded before the Scene begins. + * A URL used to resolve paths given to the loader. Example: 'http://labs.phaser.io/assets/'. */ - pack: false | Phaser.Types.Loader.FileTypes.PackFileConfig; + baseURL?: string; /** - * The Camera configuration object. + * A URL path used to resolve relative paths given to the loader. Example: 'images/sprites/'. */ - cameras: Phaser.Types.Cameras.Scene2D.JSONCamera | Phaser.Types.Cameras.Scene2D.JSONCamera[]; + path?: string; /** - * The Scene's Injection Map. + * The maximum number of resources the loader will start loading at once. */ - map: {[key: string]: string}; + maxParallelDownloads?: number; /** - * The physics configuration object for the Scene. + * 'anonymous', 'use-credentials', or `undefined`. If you're not making cross-origin requests, leave this as `undefined`. See {@link https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes}. */ - physics: Phaser.Types.Core.PhysicsConfig; + crossOrigin?: string | undefined; /** - * The loader configuration object for the Scene. + * The response type of the XHR request, e.g. `blob`, `text`, etc. */ - loader: Phaser.Types.Core.LoaderConfig; + responseType?: string; /** - * The plugin configuration object for the Scene. + * Should the XHR request use async or not? */ - plugins: false | any; - }; - - } - - namespace Sound { - /** - * Audio sprite sound type. - */ - type AudioSpriteSound = { + async?: boolean; /** - * Local reference to 'spritemap' object form json file generated by audiosprite tool. + * Optional username for all XHR requests. */ - spritemap: object; - }; - - /** - * A Audio Data object. - * - * You can pass an array of these objects to the WebAudioSoundManager `decodeAudio` method to have it decode - * them all at once. - */ - type DecodeAudioConfig = { + user?: string; /** - * The string-based key to be used to reference the decoded audio in the audio cache. + * Optional password for all XHR requests. */ - key: string; + password?: string; /** - * The audio data, either a base64 encoded string, an audio media-type data uri, or an ArrayBuffer instance. + * Optional XHR timeout value, in ms. */ - data: ArrayBuffer | string; + timeout?: number; }; - type EachActiveSoundCallback = (manager: Phaser.Sound.BaseSoundManager, sound: Phaser.Sound.BaseSound, index: number, sounds: Phaser.Sound.BaseSound[])=>void; - - /** - * Config object containing various sound settings. - */ - type SoundConfig = { - /** - * Boolean indicating whether the sound should be muted or not. - */ - mute?: boolean; - /** - * A value between 0 (silence) and 1 (full volume). - */ - volume?: number; + type MouseInputConfig = { /** - * Defines the speed at which the sound should be played. + * Where the Mouse Manager listens for mouse input events. The default is the game canvas. */ - rate?: number; + target?: any; /** - * Represents detuning of sound in [cents](https://en.wikipedia.org/wiki/Cent_%28music%29). + * If `true` the DOM `mousedown` event will have `preventDefault` set. */ - detune?: number; + preventDefaultDown?: boolean; /** - * Position of playback for this sound, in seconds. + * If `true` the DOM `mouseup` event will have `preventDefault` set. */ - seek?: number; + preventDefaultUp?: boolean; /** - * Whether or not the sound or current sound marker should loop. + * If `true` the DOM `mousemove` event will have `preventDefault` set. */ - loop?: boolean; + preventDefaultMove?: boolean; /** - * Time, in seconds, that should elapse before the sound actually starts its playback. + * If `true` the DOM `wheel` event will have `preventDefault` set. */ - delay?: number; + preventDefaultWheel?: boolean; }; /** - * Marked section of a sound represented by name, and optionally start time, duration, and config object. + * This callback type is completely empty, a no-operation. */ - type SoundMarker = { - /** - * Unique identifier of a sound marker. - */ - name: string; + type NOOP = ()=>void; + + type PhysicsConfig = { /** - * Sound position offset at witch playback should start. + * The default physics system. It will be started for each scene. Phaser provides 'arcade', 'impact', and 'matter'. */ - start?: number; + default?: string; /** - * Playback duration of this marker. + * Arcade Physics configuration. */ - duration?: number; + arcade?: Phaser.Types.Physics.Arcade.ArcadeWorldConfig; /** - * An optional config object containing default marker settings. + * Matter Physics configuration. */ - config?: Phaser.Types.Sound.SoundConfig; + matter?: Phaser.Types.Physics.Matter.MatterWorldConfig; }; - } - - namespace Textures { - /** - * An object containing the position and color data for a single pixel in a CanvasTexture. - */ - type PixelConfig = { - /** - * The x-coordinate of the pixel. - */ - x: integer; - /** - * The y-coordinate of the pixel. - */ - y: integer; + type PipelineConfig = { /** - * The color of the pixel, not including the alpha channel. + * The name of the pipeline. Must be unique within the Pipeline Manager. */ - color: integer; + name: string; /** - * The alpha of the pixel, between 0 and 1. + * The pipeline class. This should be a constructable object, **not** an instance of a class. */ - alpha: number; + pipeline: Phaser.Renderer.WebGL.WebGLPipeline; }; - type SpriteSheetConfig = { - /** - * The fixed width of each frame. - */ - frameWidth: integer; - /** - * The fixed height of each frame. If not set it will use the frameWidth as the height. - */ - frameHeight?: integer; + type PluginObject = { /** - * Skip a number of frames. Useful when there are multiple sprite sheets in one Texture. + * Global plugins to install. */ - startFrame?: integer; + global?: Phaser.Types.Core.PluginObjectItem[]; /** - * The total number of frames to extract from the Sprite Sheet. The default value of -1 means "extract all frames". + * Scene plugins to install. */ - endFrame?: integer; + scene?: Phaser.Types.Core.PluginObjectItem[]; /** - * If the frames have been drawn with a margin, specify the amount here. + * The default set of scene plugins (names). */ - margin?: integer; + default?: string[]; /** - * If the frames have been drawn with spacing between them, specify the amount here. + * Plugins to *add* to the default set of scene plugins. */ - spacing?: integer; + defaultMerge?: string[]; }; - type SpriteSheetFromAtlasConfig = { - /** - * The key of the Texture Atlas in which this Sprite Sheet can be found. - */ - atlas: string; - /** - * The key of the Texture Atlas Frame in which this Sprite Sheet can be found. - */ - frame: string; - /** - * The fixed width of each frame. - */ - frameWidth: integer; - /** - * The fixed height of each frame. If not set it will use the frameWidth as the height. - */ - frameHeight?: integer; + type PluginObjectItem = { /** - * Skip a number of frames. Useful when there are multiple sprite sheets in one Texture. + * A key to identify the plugin in the Plugin Manager. */ - startFrame?: integer; + key?: string; /** - * The total number of frames to extract from the Sprite Sheet. The default value of -1 means "extract all frames". + * The plugin itself. Usually a class/constructor. */ - endFrame?: integer; + plugin?: any; /** - * If the frames have been drawn with a margin, specify the amount here. + * Whether the plugin should be started automatically. */ - margin?: integer; + start?: boolean; /** - * If the frames have been drawn with spacing between them, specify the amount here. + * For a scene plugin, add the plugin to the scene's systems object under this key (`this.sys.KEY`, from the scene). */ - spacing?: integer; - }; - - } - - namespace Tilemaps { - type FilteringOptions = { + systemKey?: string; /** - * If true, only return tiles that don't have -1 for an index. + * For a scene plugin, add the plugin to the scene object under this key (`this.KEY`, from the scene). */ - isNotEmpty?: boolean; + sceneKey?: string; /** - * If true, only return tiles that collide on at least one side. + * If this plugin is to be injected into the Scene Systems, this is the property key map used. */ - isColliding?: boolean; + mapping?: string; /** - * If true, only return tiles that have at least one interesting face. + * Arbitrary data passed to the plugin's init() method. */ - hasInterestingFace?: boolean; + data?: any; }; - type GetTilesWithinFilteringOptions = { + type RenderConfig = { /** - * If true, only return tiles that don't have -1 for an index. + * When set to `true`, WebGL uses linear interpolation to draw scaled or rotated textures, giving a smooth appearance. When set to `false`, WebGL uses nearest-neighbor interpolation, giving a crisper appearance. `false` also disables antialiasing of the game canvas itself, if the browser supports it, when the game canvas is scaled. */ - isNotEmpty?: boolean; + antialias?: boolean; /** - * If true, only return tiles that collide on at least one side. + * Sets the `antialias` property when the WebGL context is created. Setting this value does not impact any subsequent textures that are created, or the canvas style attributes. */ - isColliding?: boolean; + antialiasGL?: boolean; /** - * If true, only return tiles that have at least one interesting face. + * When set to `true` it will create a desynchronized context for both 2D and WebGL. See https://developers.google.com/web/updates/2019/05/desynchronized for details. */ - hasInterestingFace?: boolean; - }; - - type MapDataConfig = { + desynchronized?: boolean; /** - * The key in the Phaser cache that corresponds to the loaded tilemap data. + * Sets `antialias` to false and `roundPixels` to true. This is the best setting for pixel-art games. */ - name?: string; + pixelArt?: boolean; /** - * The width of the entire tilemap. + * Draw texture-based Game Objects at only whole-integer positions. Game Objects without textures, like Graphics, ignore this property. */ - width?: number; + roundPixels?: boolean; /** - * The height of the entire tilemap. + * Whether the game canvas will be transparent. Boolean that indicates if the canvas contains an alpha channel. If set to false, the browser now knows that the backdrop is always opaque, which can speed up drawing of transparent content and images. */ - height?: number; + transparent?: boolean; /** - * The width of the tiles. + * Whether the game canvas will be cleared between each rendering frame. */ - tileWidth?: number; + clearBeforeRender?: boolean; /** - * The height of the tiles. + * In WebGL mode, the drawing buffer contains colors with pre-multiplied alpha. */ - tileHeight?: number; + premultipliedAlpha?: boolean; /** - * The width in pixels of the entire tilemap. + * Let the browser abort creating a WebGL context if it judges performance would be unacceptable. */ - widthInPixels?: number; + failIfMajorPerformanceCaveat?: boolean; /** - * The height in pixels of the entire tilemap. + * "high-performance", "low-power" or "default". A hint to the browser on how much device power the game might use. */ - heightInPixels?: number; + powerPreference?: string; /** - * The format of the Tilemap, as defined in Tiled. + * The default WebGL batch size. Represents the number of _quads_ that can be added to a single batch. */ - format?: integer; + batchSize?: number; /** - * The orientation of the map data (i.e. orthogonal, isometric, hexagonal), default 'orthogonal'. + * The maximum number of lights allowed to be visible within range of a single Camera in the LightManager. */ - orientation?: string; + maxLights?: number; /** - * Determines the draw order of tilemap. Default is right-down. + * When in WebGL mode, this sets the maximum number of GPU Textures to use. The default, -1, will use all available units. The WebGL1 spec says all browsers should provide a minimum of 8. */ - renderOrder?: string; + maxTextures?: number; /** - * The version of Tiled the map uses. + * The mipmap magFilter to be used when creating WebGL textures. */ - version?: number; + mipmapFilter?: string; /** - * Map specific properties (can be specified in Tiled). + * The WebGL Pipeline configuration object. */ - properties?: number; + pipline?: Phaser.Types.Core.PipelineConfig; + }; + + type ScaleConfig = { /** - * The layers of the tilemap. + * The base width of your game. Can be an integer or a string: '100%'. If a string it will only work if you have set a parent element that has a size. */ - layers?: Phaser.Tilemaps.LayerData[]; + width?: number | string; /** - * An array with all the layers configured to the MapData. + * The base height of your game. Can be an integer or a string: '100%'. If a string it will only work if you have set a parent element that has a size. */ - images?: any[]; + height?: number | string; /** - * An array of Tiled Image Layers. + * The zoom value of the game canvas. */ - objects?: object; + zoom?: Phaser.Scale.ZoomType | number; /** - * An object of Tiled Object Layers. + * The DOM element that will contain the game canvas, or its `id`. If undefined, or if the named element doesn't exist, the game canvas is inserted directly into the document body. If `null` no parent will be used and you are responsible for adding the canvas to your environment. */ - collision?: object; + parent?: HTMLElement | string; /** - * The tilesets the map uses. + * Is the Scale Manager allowed to adjust the CSS height property of the parent and/or document body to be 100%? */ - tilesets?: Phaser.Tilemaps.Tileset[]; + expandParent?: boolean; /** - * The collection of images the map uses(specified in Tiled). + * The scale mode. */ - imageCollections?: any[]; + mode?: Phaser.Scale.ScaleModeType; /** - * [description] + * The minimum width and height the canvas can be scaled down to. */ - tiles?: any[]; - }; - - type ObjectLayerConfig = { + min?: WidthHeight; /** - * The name of the Object Layer. + * The maximum width the canvas can be scaled up to. */ - name?: string; + max?: WidthHeight; /** - * The opacity of the layer, between 0 and 1. + * Automatically round the display and style sizes of the canvas. This can help with performance in lower-powered devices. */ - opacity?: number; + autoRound?: boolean; /** - * The custom properties defined on the Object Layer, keyed by their name. + * Automatically center the canvas within the parent? */ - properties?: any; + autoCenter?: Phaser.Scale.CenterType; /** - * The type of each custom property defined on the Object Layer, keyed by its name. + * How many ms should elapse before checking if the browser size has changed? */ - propertytypes?: any; + resizeInterval?: number; /** - * The type of the layer, which should be `objectgroup`. + * The DOM element that will be sent into full screen mode, or its `id`. If undefined Phaser will create its own div and insert the canvas into it when entering fullscreen mode. */ - type?: string; + fullscreenTarget?: HTMLElement | string; + }; + + type TimeStepCallback = (time: number, average: number, interpolation: number)=>void; + + type TouchInputConfig = { /** - * Whether the layer is shown (`true`) or hidden (`false`). + * Where the Touch Manager listens for touch input events. The default is the game canvas. */ - visible?: boolean; + target?: any; /** - * An array of all objects on this Object Layer. + * Whether touch input events have preventDefault() called on them. */ - objects?: any[]; + capture?: boolean; }; - type StyleConfig = { - /** - * Color to use for drawing a filled rectangle at non-colliding tile locations. If set to null, non-colliding tiles will not be drawn. - */ - tileColor?: Phaser.Display.Color | number | null; + type WidthHeight = { /** - * Color to use for drawing a filled rectangle at colliding tile locations. If set to null, colliding tiles will not be drawn. + * The width. */ - collidingTileColor?: Phaser.Display.Color | number | null; + width?: number; /** - * Color to use for drawing a line at interesting tile faces. If set to null, interesting tile faces will not be drawn. + * The height. */ - faceColor?: Phaser.Display.Color | number | null; + height?: number; }; - type TiledObject = { - /** - * The unique object ID. - */ - id: integer; + } + + namespace Create { + type GenerateTextureCallback = (canvas: HTMLCanvasElement, context: CanvasRenderingContext2D)=>void; + + type GenerateTextureConfig = { /** - * The name this object was assigned in Tiled. + * An array of data, where each row is a string of single values 0-9A-F, or the period character. */ - name: string; + data?: any[]; /** - * The type, as assigned in Tiled. + * The HTML Canvas to draw the texture to. */ - type: string; + canvas?: HTMLCanvasElement; /** - * The visible state of this object. + * The indexed palette that the data cell values map to. */ - visible?: boolean; + palette?: Phaser.Types.Create.Palette; /** - * The horizontal position of this object, in pixels, relative to the tilemap. + * The width of each 'pixel' in the generated texture. */ - x?: number; + pixelWidth?: number; /** - * The vertical position of this object, in pixels, relative to the tilemap. + * The height of each 'pixel' in the generated texture. */ - y?: number; + pixelHeight?: number; /** - * The width of this object, in pixels. + * Should the canvas be resized before the texture is drawn? */ - width?: number; + resizeCanvas?: boolean; /** - * The height of this object, in pixels. + * Should the canvas be cleared before the texture is drawn? */ - height?: number; + clearCanvas?: boolean; /** - * The rotation of the object in clockwise degrees. + * A callback to send the canvas to prior to the texture being drawn. */ - rotation?: number; + preRender?: Phaser.Types.Create.GenerateTextureCallback; /** - * Custom properties object. + * A callback to send the canvas to after the texture has been drawn. */ - properties?: any; + postRender?: Phaser.Types.Create.GenerateTextureCallback; + }; + + type Palette = { /** - * Only set if of type 'tile'. + * Color value 1. */ - gid?: integer; + "0": string; /** - * Only set if a tile object. The horizontal flip value. + * Color value 2. */ - flippedHorizontal?: boolean; + "1": string; /** - * Only set if a tile object. The vertical flip value. + * Color value 3. */ - flippedVertical?: boolean; + "2": string; /** - * Only set if a tile object. The diagonal flip value. + * Color value 4. */ - flippedAntiDiagonal?: boolean; + "3": string; /** - * Only set if a polyline object. An array of objects corresponding to points, where each point has an `x` property and a `y` property. + * Color value 5. */ - polyline?: Phaser.Types.Math.Vector2Like[]; + "4": string; /** - * Only set if a polygon object. An array of objects corresponding to points, where each point has an `x` property and a `y` property. + * Color value 6. */ - polygon?: Phaser.Types.Math.Vector2Like[]; + "5": string; /** - * Only set if a text object. Contains the text objects properties. + * Color value 7. */ - text?: any; + "6": string; /** - * Only set, and set to `true`, if a rectangle object. + * Color value 8. */ - rectangle?: boolean; + "7": string; /** - * Only set, and set to `true`, if a ellipse object. + * Color value 9. */ - ellipse?: boolean; - }; - - type TilemapConfig = { + "8": string; /** - * The key in the Phaser cache that corresponds to the loaded tilemap data. + * Color value 10. */ - key?: string; + "9": string; /** - * Instead of loading from the cache, you can also load directly from a 2D array of tile indexes. + * Color value 11. */ - data?: integer[][]; + A: string; /** - * The width of a tile in pixels. + * Color value 12. */ - tileWidth?: integer; + B: string; /** - * The height of a tile in pixels. + * Color value 13. */ - tileHeight?: integer; + C: string; /** - * The width of the map in tiles. + * Color value 14. */ - width?: integer; + D: string; /** - * The height of the map in tiles. + * Color value 15. */ - height?: integer; + E: string; /** - * Controls how empty tiles, tiles with an index of -1, - * in the map data are handled. If `true`, empty locations will get a value of `null`. If `false`, - * empty location will get a Tile object with an index of -1. If you've a large sparsely populated - * map and the tile data doesn't need to change then setting this value to `true` will help with - * memory consumption. However if your map is small or you need to update the tiles dynamically, - * then leave the default value set. + * Color value 16. */ - insertNull?: boolean; + F: string; }; } - namespace Time { - type TimerEventConfig = { - /** - * The delay after which the Timer Event should fire, in milliseconds. - */ - delay?: number; + namespace Curves { + type EllipseCurveConfig = { /** - * The total number of times the Timer Event will repeat before finishing. + * The x coordinate of the ellipse. */ - repeat?: number; + x?: number; /** - * `true` if the Timer Event should repeat indefinitely. + * The y coordinate of the ellipse. */ - loop?: boolean; + y?: number; /** - * The callback which will be called when the Timer Event fires. + * The horizontal radius of the ellipse. */ - callback?: Function; + xRadius?: number; /** - * The scope (`this` object) with which to invoke the `callback`. + * The vertical radius of the ellipse. */ - callbackScope?: any; + yRadius?: number; /** - * Additional arguments to be passed to the `callback`. + * The start angle of the ellipse, in degrees. */ - args?: any[]; + startAngle?: number; /** - * The scale of the elapsed time. + * The end angle of the ellipse, in degrees. */ - timeScale?: number; + endAngle?: number; /** - * The initial elapsed time in milliseconds. Useful if you want a long duration with repeat, but for the first loop to fire quickly. + * Sets if the the ellipse rotation is clockwise (true) or anti-clockwise (false) */ - startAt?: number; + clockwise?: boolean; /** - * `true` if the Timer Event should be paused. + * The rotation of the ellipse, in degrees. */ - paused?: boolean; + rotation?: number; }; - } - - namespace Tweens { - type TweenConfigDefaults = { + type JSONCurve = { /** - * The object, or an array of objects, to run the tween on. + * The of the curve */ - targets: object | object[]; + type: string; /** - * The number of milliseconds to delay before the tween will start. + * The arrays of points like `[x1, y1, x2, y2]` */ - delay?: number; + points: number[]; + }; + + type JSONEllipseCurve = { /** - * The duration of the tween in milliseconds. + * The of the curve. */ - duration?: number; + type: string; /** - * The easing equation to use for the tween. + * The x coordinate of the ellipse. */ - ease?: string; + x: number; /** - * Optional easing parameters. + * The y coordinate of the ellipse. */ - easeParams?: any[]; + y: number; /** - * The number of milliseconds to hold the tween for before yoyo'ing. + * The horizontal radius of ellipse. */ - hold?: number; + xRadius: number; /** - * The number of times to repeat the tween. + * The vertical radius of ellipse. */ - repeat?: number; + yRadius: number; /** - * The number of milliseconds to pause before a tween will repeat. + * The start angle of the ellipse, in degrees. */ - repeatDelay?: number; + startAngle: number; /** - * Should the tween complete, then reverse the values incrementally to get back to the starting tween values? The reverse tweening will also take `duration` milliseconds to complete. + * The end angle of the ellipse, in degrees. */ - yoyo?: boolean; + endAngle: number; /** - * Horizontally flip the target of the Tween when it completes (before it yoyos, if set to do so). Only works for targets that support the `flipX` property. + * Sets if the the ellipse rotation is clockwise (true) or anti-clockwise (false) */ - flipX?: boolean; + clockwise: boolean; /** - * Vertically flip the target of the Tween when it completes (before it yoyos, if set to do so). Only works for targets that support the `flipY` property. + * The rotation of ellipse, in degrees. */ - flipY?: boolean; + rotation: number; }; - /** - * A Tween Event. - */ - type Event = string; - - type GetActiveCallback = (target: any, key: string, value: number, targetIndex: integer, totalTargets: integer, tween: Phaser.Tweens.Tween)=>void; - - type GetEndCallback = (target: any, key: string, value: number, targetIndex: integer, totalTargets: integer, tween: Phaser.Tweens.Tween)=>void; - - type GetStartCallback = (target: any, key: string, value: number, targetIndex: integer, totalTargets: integer, tween: Phaser.Tweens.Tween)=>void; - - type NumberTweenBuilderConfig = { + type JSONPath = { /** - * The start number. + * The of the curve. */ - from?: number; + type: string; /** - * The end number. + * The X coordinate of the curve's starting point. */ - to?: number; + x: number; /** - * The number of milliseconds to delay before the tween will start. + * The Y coordinate of the path's starting point. */ - delay?: number; + y: number; /** - * The duration of the tween in milliseconds. + * The path is auto closed. */ - duration?: number; + autoClose: boolean; /** - * The easing equation to use for the tween. + * The list of the curves */ - ease?: string | Function; + curves: Phaser.Types.Curves.JSONCurve[]; + }; + + } + + namespace Display { + type ColorObject = { /** - * Optional easing parameters. + * The red color value in the range 0 to 255. */ - easeParams?: any[]; + r: number; /** - * The number of milliseconds to hold the tween for before yoyo'ing. + * The green color value in the range 0 to 255. */ - hold?: number; + g: number; /** - * The number of times to repeat the tween. + * The blue color value in the range 0 to 255. */ - repeat?: number; + b: number; /** - * The number of milliseconds to pause before a tween will repeat. + * The alpha color value in the range 0 to 255. */ - repeatDelay?: number; + a: number; + }; + + type HSVColorObject = { /** - * Should the tween complete, then reverse the values incrementally to get back to the starting tween values? The reverse tweening will also take `duration` milliseconds to complete. + * The hue color value. A number between 0 and 1 */ - yoyo?: boolean; + h: number; /** - * Used when the Tween is part of a Timeline. + * The saturation color value. A number between 0 and 1 */ - offset?: number | Function | object | any[]; + s: number; /** - * The time the tween will wait before the onComplete event is dispatched once it has completed, in ms. + * The lightness color value. A number between 0 and 1 */ - completeDelay?: number | Function | object | any[]; + v: number; + }; + + type InputColorObject = { /** - * The number of times the tween will repeat. (A value of 1 means the tween will play twice, as it repeated once.) The first loop starts after every property tween has completed once. + * The red color value in the range 0 to 255. */ - loop?: number | Function | object | any[]; + r?: number; /** - * The time the tween will pause before starting either a yoyo or returning to the start for a repeat. + * The green color value in the range 0 to 255. */ - loopDelay?: number | Function | object | any[]; + g?: number; /** - * Does the tween start in a paused state (true) or playing (false)? + * The blue color value in the range 0 to 255. */ - paused?: boolean; + b?: number; /** - * Use frames or milliseconds? + * The alpha color value in the range 0 to 255. */ - useFrames?: boolean; + a?: number; + }; + + } + + namespace GameObjects { + namespace BitmapText { /** - * Scope (this) for the callbacks. The default scope is the tween. + * The font data for an individual character of a Bitmap Font. + * + * Describes the character's position, size, offset and kerning. + * + * As of version 3.50 it also includes the WebGL texture uv data. */ - callbackScope?: any; + type BitmapFontCharacterData = { + /** + * The x position of the character. + */ + x: number; + /** + * The y position of the character. + */ + y: number; + /** + * The width of the character. + */ + width: number; + /** + * The height of the character. + */ + height: number; + /** + * The center x position of the character. + */ + centerX: number; + /** + * The center y position of the character. + */ + centerY: number; + /** + * The x offset of the character. + */ + xOffset: number; + /** + * The y offset of the character. + */ + yOffset: number; + /** + * WebGL texture u0. + */ + u0: number; + /** + * WebGL texture v0. + */ + v0: number; + /** + * WebGL texture u1. + */ + u1: number; + /** + * WebGL texture v1. + */ + v1: number; + /** + * Extra data for the character. + */ + data: object; + /** + * Kerning values, keyed by character code. + */ + kerning: {[key: string]: number}; + }; + /** - * A function to call when the tween completes. + * Bitmap Font data that can be used by a BitmapText Game Object. */ - onComplete?: Phaser.Types.Tweens.TweenOnCompleteCallback; + type BitmapFontData = { + /** + * The name of the font. + */ + font: string; + /** + * The size of the font. + */ + size: number; + /** + * The line height of the font. + */ + lineHeight: number; + /** + * Whether this font is a retro font (monospace). + */ + retroFont: boolean; + /** + * The character data of the font, keyed by character code. Each character datum includes a position, size, offset and more. + */ + chars: {[key: number]: Phaser.Types.GameObjects.BitmapText.BitmapFontCharacterData}; + }; + /** - * Additional parameters to pass to `onComplete`. + * A single entry from the `BitmapTextSize` characters array. + * + * The position and dimensions take the font size into account, + * but are not translated into the local space of the Game Object itself. */ - onCompleteParams?: any[]; + type BitmapTextCharacter = { + /** + * The index of this character within the BitmapText text string. + */ + i: number; + /** + * The character. + */ + char: string; + /** + * The character code of the character. + */ + code: number; + /** + * The x position of the character in the BitmapText. + */ + x: number; + /** + * The y position of the character in the BitmapText. + */ + y: number; + /** + * The width of the character. + */ + w: number; + /** + * The height of the character. + */ + h: number; + /** + * The top of the line this character is on. + */ + t: number; + /** + * The right-most point of this character, including xAdvance. + */ + r: number; + /** + * The bottom of the line this character is on. + */ + b: number; + /** + * The line number the character appears on. + */ + line: number; + /** + * Reference to the glyph object this character is using. + */ + glyph: Phaser.Types.GameObjects.BitmapText.BitmapFontCharacterData; + }; + + type BitmapTextConfig = Phaser.Types.GameObjects.GameObjectConfig & { + /** + * The key of the font to use from the BitmapFont cache. + */ + font?: string; + /** + * The string, or array of strings, to be set as the content of this Bitmap Text. + */ + text?: string; + /** + * The font size to set. + */ + size?: number | false; + }; + /** - * Scope (this) for `onComplete`. + * Details about the line data in the `BitmapTextSize` object. */ - onCompleteScope?: any; + type BitmapTextLines = { + /** + * The width of the shortest line of text. + */ + shortest: number; + /** + * The width of the longest line of text. + */ + longest: number; + /** + * The height of a line of text. + */ + height: number; + /** + * An array where each entry contains the length of that line of text. + */ + lengths: number[]; + }; + + type BitmapTextSize = { + /** + * The position and size of the BitmapText, taking into account the position and scale of the Game Object. + */ + global: Phaser.Types.GameObjects.BitmapText.GlobalBitmapTextSize; + /** + * The position and size of the BitmapText, taking just the font size into account. + */ + local: Phaser.Types.GameObjects.BitmapText.LocalBitmapTextSize; + /** + * Data about the lines of text within the BitmapText. + */ + lines: Phaser.Types.GameObjects.BitmapText.BitmapTextLines; + /** + * An array containing per-character data. Only populated if `includeChars` is `true` in the `getTextBounds` call. + */ + characters: Phaser.Types.GameObjects.BitmapText.BitmapTextCharacter[]; + /** + * An array containing the word data from the BitmapText. + */ + words: Phaser.Types.GameObjects.BitmapText.BitmapTextWord[]; + /** + * The scale of the BitmapText font being rendered vs. font size in the text data. + */ + scale: number; + /** + * The scale X value of the BitmapText. + */ + scaleX: number; + /** + * The scale Y value of the BitmapText. + */ + scaleY: number; + /** + * The wrapped text, if wrapping enabled and required. + */ + wrappedText: string; + }; + /** - * A function to call each time the tween loops. + * Details about a single world entry in the `BitmapTextSize` object words array. */ - onLoop?: Phaser.Types.Tweens.TweenOnLoopCallback; + type BitmapTextWord = { + /** + * The x position of the word in the BitmapText. + */ + x: number; + /** + * The y position of the word in the BitmapText. + */ + y: number; + /** + * The width of the word. + */ + w: number; + /** + * The height of the word. + */ + h: number; + /** + * The index of the word within the line. + */ + i: number; + /** + * The word. + */ + word: string; + }; + + type DisplayCallbackConfig = { + /** + * The Dynamic Bitmap Text object that owns this character being rendered. + */ + parent: Phaser.GameObjects.DynamicBitmapText; + /** + * The tint of the character being rendered. Always zero in Canvas. + */ + tint: Phaser.Types.GameObjects.BitmapText.TintConfig; + /** + * The index of the character being rendered. + */ + index: number; + /** + * The character code of the character being rendered. + */ + charCode: number; + /** + * The x position of the character being rendered. + */ + x: number; + /** + * The y position of the character being rendered. + */ + y: number; + /** + * The scale of the character being rendered. + */ + scale: number; + /** + * The rotation of the character being rendered. + */ + rotation: number; + /** + * Custom data stored with the character being rendered. + */ + data: any; + }; + + type DisplayCallback = (display: Phaser.Types.GameObjects.BitmapText.DisplayCallbackConfig)=>void; + /** - * Additional parameters to pass to `onLoop`. + * The position and size of the Bitmap Text in global space, taking into account the Game Object's scale and world position. */ - onLoopParams?: any[]; + type GlobalBitmapTextSize = { + /** + * The x position of the BitmapText, taking into account the x position and scale of the Game Object. + */ + x: number; + /** + * The y position of the BitmapText, taking into account the y position and scale of the Game Object. + */ + y: number; + /** + * The width of the BitmapText, taking into account the x scale of the Game Object. + */ + width: number; + /** + * The height of the BitmapText, taking into account the y scale of the Game Object. + */ + height: number; + }; + + type JSONBitmapText = Phaser.Types.GameObjects.JSONGameObject & { + /** + * The name of the font. + */ + font: string; + /** + * The text that this Bitmap Text displays. + */ + text: string; + /** + * The size of the font. + */ + fontSize: number; + /** + * Adds / Removes spacing between characters. + */ + letterSpacing: number; + /** + * The alignment of the text in a multi-line BitmapText object. + */ + align: number; + }; + /** - * Scope (this) for `onLoop`. + * The position and size of the Bitmap Text in local space, taking just the font size into account. */ - onLoopScope?: any; + type LocalBitmapTextSize = { + /** + * The x position of the BitmapText. + */ + x: number; + /** + * The y position of the BitmapText. + */ + y: number; + /** + * The width of the BitmapText. + */ + width: number; + /** + * The height of the BitmapText. + */ + height: number; + }; + + type RetroFontConfig = { + /** + * The key of the image containing the font. + */ + image: string; + /** + * If the font set doesn't start at the top left of the given image, specify the X coordinate offset here. + */ + "offset.x": number; + /** + * If the font set doesn't start at the top left of the given image, specify the Y coordinate offset here. + */ + "offset.y": number; + /** + * The width of each character in the font set. + */ + width: number; + /** + * The height of each character in the font set. + */ + height: number; + /** + * The characters used in the font set, in display order. You can use the TEXT_SET consts for common font set arrangements. + */ + chars: string; + /** + * The number of characters per row in the font set. If not given charsPerRow will be the image width / characterWidth. + */ + charsPerRow: number; + /** + * If the characters in the font set have horizontal spacing between them set the required amount here. + */ + "spacing.x": number; + /** + * If the characters in the font set have vertical spacing between them set the required amount here. + */ + "spacing.y": number; + /** + * The amount of vertical space to add to the line height of the font. + */ + lineSpacing: number; + }; + + type TintConfig = { + /** + * The top left tint value. Always zero in canvas. + */ + topLeft: number; + /** + * The top right tint value. Always zero in canvas. + */ + topRight: number; + /** + * The bottom left tint value. Always zero in canvas. + */ + bottomLeft: number; + /** + * The bottom right tint value. Always zero in canvas. + */ + bottomRight: number; + }; + + } + + namespace Graphics { /** - * A function to call each time the tween repeats. Called once per property per target. + * Graphics fill style settings. */ - onRepeat?: Phaser.Types.Tweens.TweenOnRepeatCallback; + type FillStyle = { + /** + * The fill color. + */ + color?: number; + /** + * The fill alpha. + */ + alpha?: number; + }; + /** - * Additional parameters to pass to `onRepeat`. + * Graphics line style (or stroke style) settings. */ - onRepeatParams?: any[]; + type LineStyle = { + /** + * The stroke width. + */ + width?: number; + /** + * The stroke color. + */ + color?: number; + /** + * The stroke alpha. + */ + alpha?: number; + }; + /** - * Scope (this) for `onRepeat`. + * Options for the Graphics Game Object. */ - onRepeatScope?: any; + type Options = Phaser.Types.GameObjects.Graphics.Styles & { + /** + * The x coordinate of the Graphics. + */ + x?: number; + /** + * The y coordinate of the Graphics. + */ + y?: number; + }; + + type RoundedRectRadius = { + /** + * Top left corner radius. + */ + tl?: number; + /** + * Top right corner radius. + */ + tr?: number; + /** + * Bottom right corner radius. + */ + br?: number; + /** + * Bottom left corner radius. + */ + bl?: number; + }; + /** - * A function to call when the tween starts. + * Graphics style settings. */ - onStart?: Phaser.Types.Tweens.TweenOnStartCallback; + type Styles = { + /** + * The style applied to shape outlines. + */ + lineStyle?: Phaser.Types.GameObjects.Graphics.LineStyle; + /** + * The style applied to shape areas. + */ + fillStyle?: Phaser.Types.GameObjects.Graphics.FillStyle; + }; + + } + + namespace Group { + type GroupCallback = (item: Phaser.GameObjects.GameObject)=>void; + + type GroupConfig = { + /** + * Sets {@link Phaser.GameObjects.Group#classType}. + */ + classType?: Function; + /** + * Sets {@link Phaser.GameObjects.Group#name}. + */ + name?: string; + /** + * Sets {@link Phaser.GameObjects.Group#active}. + */ + active?: boolean; + /** + * Sets {@link Phaser.GameObjects.Group#maxSize}. + */ + maxSize?: number; + /** + * Sets {@link Phaser.GameObjects.Group#defaultKey}. + */ + defaultKey?: string; + /** + * Sets {@link Phaser.GameObjects.Group#defaultFrame}. + */ + defaultFrame?: string | number; + /** + * Sets {@link Phaser.GameObjects.Group#runChildUpdate}. + */ + runChildUpdate?: boolean; + /** + * Sets {@link Phaser.GameObjects.Group#createCallback}. + */ + createCallback?: Phaser.Types.GameObjects.Group.GroupCallback; + /** + * Sets {@link Phaser.GameObjects.Group#removeCallback}. + */ + removeCallback?: Phaser.Types.GameObjects.Group.GroupCallback; + /** + * Sets {@link Phaser.GameObjects.Group#createMultipleCallback}. + */ + createMultipleCallback?: Phaser.Types.GameObjects.Group.GroupMultipleCreateCallback; + }; + /** - * Additional parameters to pass to `onStart`. + * The total number of objects created will be + * + * key.length * frame.length * frameQuantity * (yoyo ? 2 : 1) * (1 + repeat) + * + * If `max` is nonzero, then the total created will not exceed `max`. + * + * `key` is required. {@link Phaser.GameObjects.Group#defaultKey} is not used. */ - onStartParams?: any[]; + type GroupCreateConfig = { + /** + * The class of each new Game Object. + */ + classType?: Function; + /** + * The texture key of each new Game Object. + */ + key?: string | string[]; + /** + * The texture frame of each new Game Object. + */ + frame?: string | string[] | number | number[]; + /** + * The number of Game Objects to create. If set, this overrides the `frameQuantity` value. Use `frameQuantity` for more advanced control. + */ + quantity?: number; + /** + * The visible state of each new Game Object. + */ + visible?: boolean; + /** + * The active state of each new Game Object. + */ + active?: boolean; + /** + * The number of times each `key` × `frame` combination will be *repeated* (after the first combination). + */ + repeat?: number; + /** + * Select a `key` at random. + */ + randomKey?: boolean; + /** + * Select a `frame` at random. + */ + randomFrame?: boolean; + /** + * Select keys and frames by moving forward then backward through `key` and `frame`. + */ + yoyo?: boolean; + /** + * The number of times each `frame` should be combined with one `key`. + */ + frameQuantity?: number; + /** + * The maximum number of new Game Objects to create. 0 is no maximum. + */ + max?: number; + setXY?: object; + /** + * The horizontal position of each new Game Object. + */ + "setXY.x"?: number; + /** + * The vertical position of each new Game Object. + */ + "setXY.y"?: number; + /** + * Increment each Game Object's horizontal position from the previous by this amount, starting from `setXY.x`. + */ + "setXY.stepX"?: number; + /** + * Increment each Game Object's vertical position from the previous by this amount, starting from `setXY.y`. + */ + "setXY.stepY"?: number; + setRotation?: object; + /** + * Rotation of each new Game Object. + */ + "setRotation.value"?: number; + /** + * Increment each Game Object's rotation from the previous by this amount, starting at `setRotation.value`. + */ + "setRotation.step"?: number; + setScale?: object; + /** + * The horizontal scale of each new Game Object. + */ + "setScale.x"?: number; + /** + * The vertical scale of each new Game Object. + */ + "setScale.y"?: number; + /** + * Increment each Game Object's horizontal scale from the previous by this amount, starting from `setScale.x`. + */ + "setScale.stepX"?: number; + /** + * Increment each Game object's vertical scale from the previous by this amount, starting from `setScale.y`. + */ + "setScale.stepY"?: number; + setOrigin?: object; + /** + * The horizontal origin of each new Game Object. + */ + "setOrigin.x"?: number; + /** + * The vertical origin of each new Game Object. + */ + "setOrigin.y"?: number; + /** + * Increment each Game Object's horizontal origin from the previous by this amount, starting from `setOrigin.x`. + */ + "setOrigin.stepX"?: number; + /** + * Increment each Game object's vertical origin from the previous by this amount, starting from `setOrigin.y`. + */ + "setOrigin.stepY"?: number; + setAlpha?: object; + /** + * The alpha value of each new Game Object. + */ + "setAlpha.value"?: number; + /** + * Increment each Game Object's alpha from the previous by this amount, starting from `setAlpha.value`. + */ + "setAlpha.step"?: number; + setDepth?: object; + /** + * The depth value of each new Game Object. + */ + "setDepth.value"?: number; + /** + * Increment each Game Object's depth from the previous by this amount, starting from `setDepth.value`. + */ + "setDepth.step"?: number; + setScrollFactor?: object; + /** + * The horizontal scroll factor of each new Game Object. + */ + "setScrollFactor.x"?: number; + /** + * The vertical scroll factor of each new Game Object. + */ + "setScrollFactor.y"?: number; + /** + * Increment each Game Object's horizontal scroll factor from the previous by this amount, starting from `setScrollFactor.x`. + */ + "setScrollFactor.stepX"?: number; + /** + * Increment each Game object's vertical scroll factor from the previous by this amount, starting from `setScrollFactor.y`. + */ + "setScrollFactor.stepY"?: number; + /** + * A geometric shape that defines the hit area for the Game Object. + */ + hitArea?: any; + /** + * A callback to be invoked when the Game Object is interacted with. + */ + hitAreaCallback?: Phaser.Types.Input.HitAreaCallback; + /** + * Align the new Game Objects in a grid using these settings. + */ + gridAlign?: false | Phaser.Types.Actions.GridAlignConfig; + }; + + type GroupMultipleCreateCallback = (items: Phaser.GameObjects.GameObject[])=>void; + + } + + namespace Particles { + type DeathZoneSource = { + contains: Phaser.Types.GameObjects.Particles.DeathZoneSourceCallback; + }; + + type DeathZoneSourceCallback = (x: number, y: number)=>void; + + type EdgeZoneSource = { + /** + * A function placing points on the sources edge or edges. + */ + getPoints: Phaser.Types.GameObjects.Particles.EdgeZoneSourceCallback; + }; + + type EdgeZoneSourceCallback = (quantity: number, stepRate?: number)=>void; + + type EmitterOpCustomEmitConfig = { + /** + * A callback that is invoked each time the emitter emits a particle. + */ + onEmit: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitCallback; + }; + + type EmitterOpCustomUpdateConfig = { + /** + * A callback that is invoked each time the emitter emits a particle. + */ + onEmit?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitCallback; + /** + * A callback that is invoked each time the emitter updates. + */ + onUpdate: Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateCallback; + }; + /** - * Scope (this) for `onStart`. + * Defines an operation yielding a value incremented continuously across a range. */ - onStartScope?: any; + type EmitterOpEaseConfig = { + /** + * The starting value. + */ + start: number; + /** + * The ending value. + */ + end: number; + /** + * The ease to find. This can be either a string from the EaseMap, or a custom function. + */ + ease?: string | Function; + /** + * An optional array of ease parameters to go with the ease. + */ + easeParams?: number[]; + }; + /** - * A function to call each time the tween steps. Called once per property per target. + * The returned value sets what the property will be at the START of the particle's life, on emit. */ - onUpdate?: Phaser.Types.Tweens.TweenOnUpdateCallback; + type EmitterOpOnEmitCallback = (particle: Phaser.GameObjects.Particles.Particle, key: string, value: number)=>void; + + type EmitterOpOnEmitType = number | number[] | Phaser.Types.GameObjects.Particles.EmitterOpOnEmitCallback | Phaser.Types.GameObjects.Particles.EmitterOpRandomConfig | Phaser.Types.GameObjects.Particles.EmitterOpRandomMinMaxConfig | Phaser.Types.GameObjects.Particles.EmitterOpRandomStartEndConfig | Phaser.Types.GameObjects.Particles.EmitterOpSteppedConfig | Phaser.Types.GameObjects.Particles.EmitterOpCustomEmitConfig; + /** - * Additional parameters to pass to `onUpdate`. + * The returned value updates the property for the duration of the particle's life. */ - onUpdateParams?: any[]; + type EmitterOpOnUpdateCallback = (particle: Phaser.GameObjects.Particles.Particle, key: string, t: number, value: number)=>void; + + type EmitterOpOnUpdateType = Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateCallback | Phaser.Types.GameObjects.Particles.EmitterOpEaseConfig | Phaser.Types.GameObjects.Particles.EmitterOpCustomUpdateConfig; + /** - * Scope (this) for `onUpdate`. + * Defines an operation yielding a random value within a range. */ - onUpdateScope?: any; + type EmitterOpRandomConfig = { + /** + * The minimum and maximum values, as [min, max]. + */ + random: number[]; + }; + /** - * A function to call each time the tween yoyos. Called once per property per target. + * Defines an operation yielding a random value within a range. */ - onYoyo?: Phaser.Types.Tweens.TweenOnYoyoCallback; + type EmitterOpRandomMinMaxConfig = { + /** + * The minimum value. + */ + min: number; + /** + * The maximum value. + */ + max: number; + }; + /** - * Additional parameters to pass to `onYoyo`. + * Defines an operation yielding a random value within a range. */ - onYoyoParams?: any[]; + type EmitterOpRandomStartEndConfig = { + /** + * The starting value. + */ + start: number; + /** + * The ending value. + */ + end: number; + /** + * If false, this becomes {@link EmitterOpEaseConfig}. + */ + random: boolean; + }; + /** - * Scope (this) for `onYoyo`. + * Defines an operation yielding a value incremented by steps across a range. */ - onYoyoScope?: any; - }; + type EmitterOpSteppedConfig = { + /** + * The starting value. + */ + start: number; + /** + * The ending value. + */ + end: number; + /** + * The number of steps between start and end. + */ + steps: number; + }; + + type GravityWellConfig = { + /** + * The x coordinate of the Gravity Well, in world space. + */ + x?: number; + /** + * The y coordinate of the Gravity Well, in world space. + */ + y?: number; + /** + * The strength of the gravity force - larger numbers produce a stronger force. + */ + power?: number; + /** + * The minimum distance for which the gravity force is calculated. + */ + epsilon?: number; + /** + * The gravitational force of this Gravity Well. + */ + gravity?: number; + }; + + type ParticleDeathCallback = (particle: Phaser.GameObjects.Particles.Particle)=>void; + + type ParticleEmitterBounds = { + /** + * The left edge of the rectangle. + */ + x: number; + /** + * The top edge of the rectangle. + */ + y: number; + /** + * The width of the rectangle. + */ + width: number; + /** + * The height of the rectangle. + */ + height: number; + }; + + type ParticleEmitterBoundsAlt = { + /** + * The left edge of the rectangle. + */ + x: number; + /** + * The top edge of the rectangle. + */ + y: number; + /** + * The width of the rectangle. + */ + w: number; + /** + * The height of the rectangle. + */ + h: number; + }; + + type ParticleEmitterCallback = (particle: Phaser.GameObjects.Particles.Particle, emitter: Phaser.GameObjects.Particles.ParticleEmitter)=>void; + + type ParticleEmitterConfig = { + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#active}. + */ + active?: boolean; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#blendMode}. + */ + blendMode?: Phaser.BlendModes | string; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#deathCallbackScope} and {@link Phaser.GameObjects.Particles.ParticleEmitter#emitCallbackScope}. + */ + callbackScope?: any; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#collideBottom}. + */ + collideBottom?: boolean; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#collideLeft}. + */ + collideLeft?: boolean; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#collideRight}. + */ + collideRight?: boolean; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#collideTop}. + */ + collideTop?: boolean; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#deathCallback}. + */ + deathCallback?: boolean; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#deathCallbackScope}. + */ + deathCallbackScope?: any; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#emitCallback}. + */ + emitCallback?: Function; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#emitCallbackScope}. + */ + emitCallbackScope?: any; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#follow}. + */ + follow?: Phaser.GameObjects.GameObject; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#frequency}. + */ + frequency?: number; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#gravityX}. + */ + gravityX?: number; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#gravityY}. + */ + gravityY?: number; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#maxParticles}. + */ + maxParticles?: number; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#name}. + */ + name?: string; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#on}. + */ + on?: boolean; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#particleBringToTop}. + */ + particleBringToTop?: boolean; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#particleClass}. + */ + particleClass?: Phaser.GameObjects.Particles.Particle; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#radial}. + */ + radial?: boolean; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#timeScale}. + */ + timeScale?: number; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#trackVisible}. + */ + trackVisible?: boolean; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#visible}. + */ + visible?: boolean; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#accelerationX} (emit only). + */ + accelerationX?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#accelerationY} (emit only). + */ + accelerationY?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#alpha}. + */ + alpha?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType | Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateType; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#angle} (emit only). + */ + angle?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#bounce} (emit only). + */ + bounce?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#delay} (emit only). + */ + delay?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#lifespan} (emit only). + */ + lifespan?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#maxVelocityX} (emit only). + */ + maxVelocityX?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#maxVelocityY} (emit only). + */ + maxVelocityY?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#moveToX} (emit only). + */ + moveToX?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#moveToY} (emit only). + */ + moveToY?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#quantity} (emit only). + */ + quantity?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#rotate}. + */ + rotate?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType | Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateType; + /** + * As {@link Phaser.GameObjects.Particles.ParticleEmitter#setScale}. + */ + scale?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType | Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateType; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#scaleX}. + */ + scaleX?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType | Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateType; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#scaleY}. + */ + scaleY?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType | Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateType; + /** + * As {@link Phaser.GameObjects.Particles.ParticleEmitter#setSpeed} (emit only). + */ + speed?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#speedX} (emit only). + */ + speedX?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#speedY} (emit only). + */ + speedY?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#tint}. + */ + tint?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType | Phaser.Types.GameObjects.Particles.EmitterOpOnUpdateType; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#x} (emit only). + */ + x?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#y} (emit only). + */ + y?: Phaser.Types.GameObjects.Particles.EmitterOpOnEmitType; + /** + * As {@link Phaser.GameObjects.Particles.ParticleEmitter#setEmitZone}. + */ + emitZone?: Phaser.Types.GameObjects.Particles.ParticleEmitterEdgeZoneConfig | Phaser.Types.GameObjects.Particles.ParticleEmitterRandomZoneConfig; + /** + * As {@link Phaser.GameObjects.Particles.ParticleEmitter#setDeathZone}. + */ + deathZone?: Phaser.Types.GameObjects.Particles.ParticleEmitterDeathZoneConfig; + /** + * As {@link Phaser.GameObjects.Particles.ParticleEmitter#setBounds}. + */ + bounds?: Phaser.Types.GameObjects.Particles.ParticleEmitterBounds | Phaser.Types.GameObjects.Particles.ParticleEmitterBoundsAlt; + /** + * Assigns to {@link Phaser.GameObjects.Particles.ParticleEmitter#followOffset}. + */ + followOffset?: object; + /** + * x-coordinate of the offset. + */ + "followOffset.x"?: number; + /** + * y-coordinate of the offset. + */ + "followOffset.y"?: number; + /** + * Sets {@link Phaser.GameObjects.Particles.ParticleEmitter#frames}. + */ + frame?: number | number[] | string | string[] | Phaser.Textures.Frame | Phaser.Textures.Frame[] | Phaser.Types.GameObjects.Particles.ParticleEmitterFrameConfig; + /** + * Creates specified number of inactive particles and adds them to this emitter's pool. {@link Phaser.GameObjects.Particles.ParticleEmitter#reserve} + */ + reserve?: number; + }; + + type ParticleEmitterDeathZoneConfig = { + /** + * A shape representing the zone. See {@link Phaser.GameObjects.Particles.Zones.DeathZone#source}. + */ + source: Phaser.Types.GameObjects.Particles.DeathZoneSource; + /** + * 'onEnter' or 'onLeave'. + */ + type?: string; + }; + + type ParticleEmitterEdgeZoneConfig = { + /** + * A shape representing the zone. See {@link Phaser.GameObjects.Particles.Zones.EdgeZone#source}. + */ + source: Phaser.Types.GameObjects.Particles.EdgeZoneSource; + /** + * 'edge'. + */ + type: string; + /** + * The number of particles to place on the source edge. Set to 0 to use `stepRate` instead. + */ + quantity: number; + /** + * The distance between each particle. When set, `quantity` is implied and should be set to 0. + */ + stepRate?: number; + /** + * Whether particles are placed from start to end and then end to start. + */ + yoyo?: boolean; + /** + * Whether one endpoint will be removed if it's identical to the other. + */ + seamless?: boolean; + }; + + type ParticleEmitterFrameConfig = { + /** + * One or more texture frames. + */ + frames?: number | number[] | string | string[] | Phaser.Textures.Frame | Phaser.Textures.Frame[]; + /** + * Whether texture frames will be assigned consecutively (true) or at random (false). + */ + cycle?: boolean; + /** + * The number of consecutive particles receiving each texture frame, when `cycle` is true. + */ + quantity?: number; + }; + + type ParticleEmitterRandomZoneConfig = { + /** + * A shape representing the zone. See {@link Phaser.GameObjects.Particles.Zones.RandomZone#source}. + */ + source: Phaser.Types.GameObjects.Particles.RandomZoneSource; + /** + * 'random'. + */ + type?: string; + }; - type StaggerConfig = { - /** - * The value to start the stagger from. Can be used as a way to offset the stagger while still using a range for the value. - */ - start?: number; - /** - * An ease to apply across the staggered values. Can either be a string, such as 'sine.inout', or a function. - */ - ease?: string | Function; - /** - * The index to start the stagger from. Can be the strings `first`, `last` or `center`, or an integer representing the stagger position. - */ - from?: string | integer; - /** - * Set the stagger to run across a grid by providing an array where element 0 is the width of the grid and element 1 is the height. Combine with the 'from' property to control direction. - */ - grid?: integer[]; - }; + type RandomZoneSource = { + /** + * A function modifying its point argument. + */ + getRandomPoint: Phaser.Types.GameObjects.Particles.RandomZoneSourceCallback; + }; - type TimelineBuilderConfig = { - /** - * An array of tween configuration objects to create and add into the new Timeline. If this doesn't exist or is empty, the Timeline will start off paused and none of the other configuration settings will be read. If it's a function, it will be called and its return value will be used as the array. - */ - tweens?: Phaser.Types.Tweens.TweenBuilderConfig[] | object[] | Function; - /** - * An array (or function which returns one) of default targets to which to apply the Timeline. Each individual Tween configuration can override this value. - */ - targets?: any; - /** - * If specified, each Tween in the Timeline will get an equal portion of this duration, usually in milliseconds, by default. Each individual Tween configuration can override the Tween's duration. - */ - totalDuration?: number; - /** - * If `totalDuration` is not specified, the default duration, usually in milliseconds, of each Tween which will be created. Each individual Tween configuration can override the Tween's duration. - */ - duration?: number; - /** - * The number of milliseconds to delay before the tween will start. Each individual Tween configuration can override this value. - */ - delay?: number; - /** - * Optional easing parameters. Each individual Tween configuration can override this value. - */ - easeParams?: any[]; - /** - * The easing equation to use for each tween. Each individual Tween configuration can override this value. - */ - ease?: string | Function; - /** - * The number of milliseconds to hold each tween before yoyo'ing. Each individual Tween configuration can override this value. - */ - hold?: number; - /** - * The number of times to repeat each tween. Each individual Tween configuration can override this value. - */ - repeat?: integer; - /** - * The number of milliseconds to pause before each tween will repeat. Each individual Tween configuration can override this value. - */ - repeatDelay?: number; - /** - * Should each tween complete, then reverse the values incrementally to get back to the starting tween values? The reverse tweening will also take `duration` milliseconds to complete. Each individual Tween configuration can override this value. - */ - yoyo?: boolean; - /** - * Horizontally flip the target of the Tween when it completes (before it yoyos, if set to do so). Only works for targets that support the `flipX` property. Each individual Tween configuration can override this value. - */ - flipX?: boolean; - /** - * Vertically flip the target of the Tween when it completes (before it yoyos, if set to do so). Only works for targets that support the `flipY` property. Each individual Tween configuration can override this value. - */ - flipY?: boolean; - /** - * If specified, the time to wait, usually in milliseconds, before the Timeline completes. - */ - completeDelay?: number | Function | object | any[]; - /** - * How many times the Timeline should loop, or -1 to loop indefinitely. - */ - loop?: number | Function | object | any[]; - /** - * The time, usually in milliseconds, between each loop. - */ - loopDelay?: number | Function | object | any[]; - /** - * If `true`, the Timeline will start paused. - */ - paused?: boolean; - /** - * If `true`, all duration in the Timeline will be in frames instead of milliseconds. - */ - useFrames?: boolean; - /** - * The default scope (`this` value) to use for each callback registered by the Timeline Builder. If not specified, the Timeline itself will be used. - */ - callbackScope?: any; - /** - * If specified, the `onStart` callback for the Timeline, called every time it starts playing. - */ - onStart?: Phaser.Types.Tweens.TimelineOnStartCallback; - /** - * The scope (`this` value) to use for the `onStart` callback. If not specified, the `callbackScope` will be used. - */ - onStartScope?: any; - /** - * Additional arguments to pass to the `onStart` callback. The Timeline will always be the first argument. - */ - onStartParams?: any[]; - /** - * If specified, the `onUpdate` callback for the Timeline, called every frame it's active, regardless of its Tweens. - */ - onUpdate?: Phaser.Types.Tweens.TimelineOnUpdateCallback; - /** - * The scope (`this` value) to use for the `onUpdate` callback. If not specified, the `callbackScope` will be used. - */ - onUpdateScope?: any; - /** - * Additional arguments to pass to the `onUpdate` callback. The Timeline will always be the first argument. - */ - onUpdateParams?: any[]; - /** - * If specified, the `onLoop` callback for the Timeline, called every time it loops. - */ - onLoop?: Phaser.Types.Tweens.TimelineOnLoopCallback; - /** - * The scope (`this` value) to use for the `onLoop` callback. If not specified, the `callbackScope` will be used. - */ - onLoopScope?: any; - /** - * Additional arguments to pass to the `onLoop` callback. The Timeline will always be the first argument. - */ - onLoopParams?: any[]; - /** - * If specified, the `onYoyo` callback for the Timeline, called every time it yoyos. - */ - onYoyo?: Phaser.Types.Tweens.TimelineOnYoyoCallback; - /** - * The scope (`this` value) to use for the `onYoyo` callback. If not specified, the `callbackScope` will be used. - */ - onYoyoScope?: any; - /** - * Additional arguments to pass to the `onYoyo` callback. The first argument will always be `null`, while the Timeline will always be the second argument. - */ - onYoyoParams?: any[]; - /** - * If specified, the `onComplete` callback for the Timeline, called after it completes. - */ - onComplete?: Phaser.Types.Tweens.TimelineOnCompleteCallback; - /** - * The scope (`this` value) to use for the `onComplete` callback. If not specified, the `callbackScope` will be used. - */ - onCompleteScope?: any; + type RandomZoneSourceCallback = (point: Phaser.Types.Math.Vector2Like)=>void; + + } + + namespace PathFollower { /** - * Additional arguments to pass to the `onComplete` callback. The Timeline will always be the first argument. + * Settings for a PathFollower. */ - onCompleteParams?: any[]; - }; + type PathConfig = { + /** + * The duration of the path follow in ms. Must be `> 0`. + */ + duration?: number; + /** + * The start position of the path follow, between 0 and 1. Must be less than `to`. + */ + from?: number; + /** + * The end position of the path follow, between 0 and 1. Must be more than `from`. + */ + to?: number; + /** + * Whether to position the PathFollower on the Path using its path offset. + */ + positionOnPath?: boolean; + /** + * Should the PathFollower automatically rotate to point in the direction of the Path? + */ + rotateToPath?: boolean; + /** + * If the PathFollower is rotating to match the Path, this value is added to the rotation value. This allows you to rotate objects to a path but control the angle of the rotation as well. + */ + rotationOffset?: number; + /** + * Current start position of the path follow, must be between `from` and `to`. + */ + startAt?: number; + }; - type TimelineOnCompleteCallback = (timeline: Phaser.Tweens.Timeline, ...param: any[])=>void; + } - type TimelineOnLoopCallback = (timeline: Phaser.Tweens.Timeline, ...param: any[])=>void; + namespace RenderTexture { + type RenderTextureConfig = { + /** + * The x coordinate of the RenderTextures position. + */ + x?: number; + /** + * The y coordinate of the RenderTextures position. + */ + y?: number; + /** + * The width of the RenderTexture. + */ + width?: number; + /** + * The height of the RenderTexture. + */ + height?: number; + /** + * The texture key to make the RenderTexture from. + */ + key?: string; + /** + * the frame to make the RenderTexture from. + */ + frame?: string; + }; - type TimelineOnStartCallback = (timeline: Phaser.Tweens.Timeline, ...param: any[])=>void; + } - type TimelineOnUpdateCallback = (timeline: Phaser.Tweens.Timeline, ...param: any[])=>void; + namespace Sprite { + type SpriteConfig = Phaser.Types.GameObjects.GameObjectConfig & { + /** + * The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. + */ + key?: string; + /** + * An optional frame from the Texture this Game Object is rendering with. + */ + frame?: number | string; + }; - type TimelineOnYoyoCallback = (timeline: Phaser.Tweens.Timeline, ...param: any[])=>void; + } - type TweenBuilderConfig = { - /** - * The object, or an array of objects, to run the tween on. - */ - targets: any; - /** - * The number of milliseconds to delay before the tween will start. - */ - delay?: number | Function; - /** - * The duration of the tween in milliseconds. - */ - duration?: number; - /** - * The easing equation to use for the tween. - */ - ease?: string | Function; - /** - * Optional easing parameters. - */ - easeParams?: any[]; - /** - * The number of milliseconds to hold the tween for before yoyo'ing. - */ - hold?: number; - /** - * The number of times each property tween repeats. - */ - repeat?: number; - /** - * The number of milliseconds to pause before a repeat. - */ - repeatDelay?: number; - /** - * Should the tween complete, then reverse the values incrementally to get back to the starting tween values? The reverse tweening will also take `duration` milliseconds to complete. - */ - yoyo?: boolean; - /** - * Horizontally flip the target of the Tween when it completes (before it yoyos, if set to do so). Only works for targets that support the `flipX` property. - */ - flipX?: boolean; - /** - * Vertically flip the target of the Tween when it completes (before it yoyos, if set to do so). Only works for targets that support the `flipY` property. - */ - flipY?: boolean; - /** - * Used when the Tween is part of a Timeline. - */ - offset?: number | Function | object | any[]; - /** - * The time the tween will wait before the onComplete event is dispatched once it has completed, in ms. - */ - completeDelay?: number | Function | object | any[]; - /** - * The number of times the tween will repeat. (A value of 1 means the tween will play twice, as it repeated once.) The first loop starts after every property tween has completed once. - */ - loop?: number | Function | object | any[]; - /** - * The time the tween will pause before starting either a yoyo or returning to the start for a repeat. - */ - loopDelay?: number | Function | object | any[]; + namespace Text { /** - * Does the tween start in a paused state (true) or playing (false)? + * Results object from a call to GetTextSize. */ - paused?: boolean; + type GetTextSizeObject = { + /** + * The width of the longest line in the Text object. + */ + width: number; + /** + * The height of the Text object. + */ + height: number; + /** + * The number of lines in the Text object. + */ + lines: number; + /** + * An array of the lines for each line in the Text object. + */ + lineWidths: number[]; + /** + * The line spacing of the Text object. + */ + lineSpacing: number; + /** + * The height of a line factoring in font and stroke. + */ + lineHeight: number; + }; + + type TextConfig = Phaser.Types.GameObjects.GameObjectConfig & { + /** + * The text this Text object will display. + */ + text?: string | string[]; + /** + * The Text style configuration object. + */ + style?: Phaser.Types.GameObjects.Text.TextStyle; + /** + * A Text Padding object. + */ + padding?: Phaser.Types.GameObjects.Text.TextPadding; + }; + /** - * The properties to tween. + * Font metrics for a Text Style object. */ - props?: {[key: string]: (number|string|Phaser.Types.Tweens.GetEndCallback|Phaser.Types.Tweens.TweenPropConfig)}; + type TextMetrics = { + /** + * The ascent of the font. + */ + ascent: number; + /** + * The descent of the font. + */ + descent: number; + /** + * The size of the font. + */ + fontSize: number; + }; + /** - * Use frames or milliseconds? + * A Text Padding configuration object as used by the Text Style. */ - useFrames?: boolean; + type TextPadding = { + /** + * If set this value is used for both the left and right padding. + */ + x?: number; + /** + * If set this value is used for both the top and bottom padding. + */ + y?: number; + /** + * The amount of padding added to the left of the Text object. + */ + left?: number; + /** + * The amount of padding added to the right of the Text object. + */ + right?: number; + /** + * The amount of padding added to the top of the Text object. + */ + top?: number; + /** + * The amount of padding added to the bottom of the Text object. + */ + bottom?: number; + }; + /** - * Scope (this) for the callbacks. The default scope is the tween. + * A Text Shadow configuration object as used by the Text Style. */ - callbackScope?: any; + type TextShadow = { + /** + * The horizontal offset of the shadow. + */ + offsetX?: number; + /** + * The vertical offset of the shadow. + */ + offsetY?: number; + /** + * The color of the shadow, given as a CSS string value. + */ + color?: string; + /** + * The amount of blur applied to the shadow. Leave as zero for a hard shadow. + */ + blur?: number; + /** + * Apply the shadow to the stroke effect on the Text object? + */ + stroke?: boolean; + /** + * Apply the shadow to the fill effect on the Text object? + */ + fill?: boolean; + }; + /** - * A function to call when the tween completes. + * A Text Style configuration object as used by the Text Game Object. */ - onComplete?: Phaser.Types.Tweens.TweenOnCompleteCallback; + type TextStyle = { + /** + * The font the Text object will render with. This is a Canvas style font string. + */ + fontFamily?: string; + /** + * The font size, as a CSS size string. + */ + fontSize?: string; + /** + * Any addition font styles, such as 'strong'. + */ + fontStyle?: string; + /** + * The font family or font settings to set. Overrides the other font settings. + */ + font?: string; + /** + * A solid fill color that is rendered behind the Text object. Given as a CSS string color such as `#ff0`. + */ + backgroundColor?: string; + /** + * The color the Text is drawn in. Given as a CSS string color such as `#fff` or `rgb()`. + */ + color?: string; + /** + * The color used to stroke the Text if the `strokeThickness` property is greater than zero. + */ + stroke?: string; + /** + * The thickness of the stroke around the Text. Set to zero for no stroke. + */ + strokeThickness?: number; + /** + * The Text shadow configuration object. + */ + shadow?: Phaser.Types.GameObjects.Text.TextShadow; + /** + * A Text Padding object. + */ + padding?: Phaser.Types.GameObjects.Text.TextPadding; + /** + * The alignment of the Text. This only impacts multi-line text. Either `left`, `right`, `center` or `justify`. + */ + align?: string; + /** + * The maximum number of lines to display within the Text object. + */ + maxLines?: number; + /** + * Force the Text object to have the exact width specified in this property. Leave as zero for it to change accordingly to content. + */ + fixedWidth?: number; + /** + * Force the Text object to have the exact height specified in this property. Leave as zero for it to change accordingly to content. + */ + fixedHeight?: number; + /** + * Sets the resolution (DPI setting) of the Text object. Leave at zero for it to use the game resolution. + */ + resolution?: number; + /** + * Set to `true` if this Text object should render from right-to-left. + */ + rtl?: boolean; + /** + * This is the string used to aid Canvas in calculating the height of the font. + */ + testString?: string; + /** + * The amount of horizontal padding added to the width of the text when calculating the font metrics. + */ + baselineX?: number; + /** + * The amount of vertical padding added to the height of the text when calculating the font metrics. + */ + baselineY?: number; + /** + * The Text Word wrap configuration object. + */ + wordWrap?: Phaser.Types.GameObjects.Text.TextWordWrap; + /** + * A Text Metrics object. Use this to avoid expensive font size calculations in text heavy games. + */ + metrics?: Phaser.Types.GameObjects.Text.TextMetrics; + }; + /** - * Additional parameters to pass to `onComplete`. + * A Text Word Wrap configuration object as used by the Text Style configuration. */ - onCompleteParams?: any[]; + type TextWordWrap = { + /** + * The width at which text should be considered for word-wrapping. + */ + width?: number; + /** + * Provide a custom callback when word wrapping is enabled. + */ + callback?: TextStyleWordWrapCallback; + /** + * The context in which the word wrap callback is invoked. + */ + callbackScope?: any; + /** + * Use basic or advanced word wrapping? + */ + useAdvancedWrap?: boolean; + }; + + } + + namespace TileSprite { + type TileSpriteConfig = Phaser.Types.GameObjects.GameObjectConfig & { + /** + * The x coordinate of the Tile Sprite. + */ + x?: number; + /** + * The y coordinate of the Tile Sprite. + */ + y?: number; + /** + * The width of the Tile Sprite. If zero it will use the size of the texture frame. + */ + width?: number; + /** + * The height of the Tile Sprite. If zero it will use the size of the texture frame. + */ + height?: number; + /** + * The key of the Texture this Tile Sprite will use to render with, as stored in the Texture Manager. + */ + key?: string; + /** + * An optional frame from the Texture this Tile Sprite is rendering with. + */ + frame?: string; + }; + + } + + type Face = { /** - * Scope (this) for `onComplete`. + * The first face vertex. */ - onCompleteScope?: any; + vertex1: Phaser.Types.GameObjects.Vertex; /** - * A function to call each time the tween loops. + * The second face vertex. */ - onLoop?: Phaser.Types.Tweens.TweenOnLoopCallback; + vertex2: Phaser.Types.GameObjects.Vertex; /** - * Additional parameters to pass to `onLoop`. + * The third face vertex. */ - onLoopParams?: any[]; + vertex3: Phaser.Types.GameObjects.Vertex; /** - * Scope (this) for `onLoop`. + * Are the vertices counter-clockwise? */ - onLoopScope?: any; + isCounterClockwise: boolean; + }; + + type GameObjectConfig = { /** - * A function to call each time the tween repeats. Called once per property per target. + * The x position of the Game Object. */ - onRepeat?: Phaser.Types.Tweens.TweenOnRepeatCallback; + x?: number; /** - * Additional parameters to pass to `onRepeat`. + * The y position of the Game Object. */ - onRepeatParams?: any[]; + y?: number; /** - * Scope (this) for `onRepeat`. + * The depth of the GameObject. */ - onRepeatScope?: any; + depth?: number; /** - * A function to call when the tween starts playback, after any delays have expired. + * The horizontally flipped state of the Game Object. */ - onStart?: Phaser.Types.Tweens.TweenOnStartCallback; + flipX?: boolean; /** - * Additional parameters to pass to `onStart`. + * The vertically flipped state of the Game Object. */ - onStartParams?: any[]; + flipY?: boolean; /** - * Scope (this) for `onStart`. + * The scale of the GameObject. */ - onStartScope?: any; + scale?: number | object; /** - * A function to call each time the tween steps. Called once per property per target. + * The scroll factor of the GameObject. */ - onUpdate?: Phaser.Types.Tweens.TweenOnUpdateCallback; + scrollFactor?: number | object; /** - * Additional parameters to pass to `onUpdate`. + * The rotation angle of the Game Object, in radians. */ - onUpdateParams?: any[]; + rotation?: number; /** - * Scope (this) for `onUpdate`. + * The rotation angle of the Game Object, in degrees. */ - onUpdateScope?: any; + angle?: number; /** - * A function to call each time the tween yoyos. Called once per property per target. + * The alpha (opacity) of the Game Object. */ - onYoyo?: Phaser.Types.Tweens.TweenOnYoyoCallback; + alpha?: number; /** - * Additional parameters to pass to `onYoyo`. + * The origin of the Game Object. */ - onYoyoParams?: any[]; + origin?: number | object; /** - * Scope (this) for `onYoyo`. + * The scale mode of the GameObject. */ - onYoyoScope?: any; + scaleMode?: number; /** - * A function to call when the tween becomes active within the Tween Manager. + * The blend mode of the GameObject. */ - onActive?: Phaser.Types.Tweens.TweenOnActiveCallback; + blendMode?: number; /** - * Additional parameters to pass to `onActive`. + * The visible state of the Game Object. */ - onActiveParams?: any[]; + visible?: boolean; /** - * Scope (this) for `onActive`. + * Add the GameObject to the scene. */ - onActiveScope?: any; + add?: boolean; }; - type TweenDataConfig = { + type GetCalcMatrixResults = { /** - * The target to tween. + * The calculated Camera matrix. */ - target: any; + camera: Phaser.GameObjects.Components.TransformMatrix; /** - * The target index within the Tween targets array. + * The calculated Sprite (Game Object) matrix. */ - index: integer; + sprite: Phaser.GameObjects.Components.TransformMatrix; /** - * The property of the target being tweened. + * The calculated results matrix, factoring all others in. */ - key: string; + calc: Phaser.GameObjects.Components.TransformMatrix; + }; + + type JSONGameObject = { /** - * If not null, is invoked _immediately_ as soon as the TweenData is running, and is set on the target property. + * The name of this Game Object. */ - getActiveValue: Phaser.Types.Tweens.GetActiveCallback; + name: string; /** - * The returned value sets what the property will be at the END of the Tween. + * A textual representation of this Game Object, i.e. `sprite`. */ - getEndValue: Phaser.Types.Tweens.GetEndCallback; + type: string; /** - * The returned value sets what the property will be at the START of the Tween. + * The x position of this Game Object. */ - getStartValue: Phaser.Types.Tweens.GetStartCallback; + x: number; /** - * The ease function this tween uses. + * The y position of this Game Object. */ - ease: Function; + y: number; /** - * Duration of the tween in ms/frames, excludes time for yoyo or repeats. + * The scale of this Game Object */ - duration?: number; + scale: object; /** - * The total calculated duration of this TweenData (based on duration, repeat, delay and yoyo) + * The horizontal scale of this Game Object. */ - totalDuration?: number; + "scale.x": number; /** - * Time in ms/frames before tween will start. + * The vertical scale of this Game Object. */ - delay?: number; + "scale.y": number; /** - * Cause the tween to return back to its start value after hold has expired. + * The origin of this Game Object. */ - yoyo?: boolean; + origin: object; /** - * Time in ms/frames the tween will pause before running the yoyo or starting a repeat. + * The horizontal origin of this Game Object. */ - hold?: number; + "origin.x": number; /** - * Number of times to repeat the tween. The tween will always run once regardless, so a repeat value of '1' will play the tween twice. + * The vertical origin of this Game Object. */ - repeat?: integer; + "origin.y": number; /** - * Time in ms/frames before the repeat will start. + * The horizontally flipped state of the Game Object. */ - repeatDelay?: number; + flipX: boolean; /** - * Automatically call toggleFlipX when the TweenData yoyos or repeats + * The vertically flipped state of the Game Object. */ - flipX?: boolean; + flipY: boolean; /** - * Automatically call toggleFlipY when the TweenData yoyos or repeats + * The angle of this Game Object in radians. */ - flipY?: boolean; + rotation: number; /** - * Between 0 and 1 showing completion of this TweenData. + * The alpha value of the Game Object. */ - progress?: number; + alpha: number; /** - * Delta counter + * The visible state of the Game Object. */ - elapsed?: number; + visible: boolean; /** - * How many repeats are left to run? + * The Scale Mode being used by this Game Object. */ - repeatCounter?: integer; + scaleMode: number; /** - * The property value at the start of the ease. + * Sets the Blend Mode being used by this Game Object. */ - start?: number; + blendMode: number | string; /** - * The current propety value. + * The texture key of this Game Object. */ - current?: number; + textureKey: string; /** - * The previous property value. + * The frame key of this Game Object. */ - previous?: number; + frameKey: string; /** - * The property value at the end of the ease. + * The data of this Game Object. */ - end?: number; + data: object; + }; + + type Vertex = { /** - * Time duration 1. + * The x coordinate of the vertex. */ - t1?: number; + x: number; /** - * Time duration 2. + * The y coordinate of the vertex. */ - t2?: number; + y: number; /** - * LoadValue generation functions. + * The z coordinate of the vertex. */ - gen?: Phaser.Types.Tweens.TweenDataGenConfig; + z: number; /** - * TWEEN_CONST.CREATED + * The x normal of the vertex. */ - state?: integer; - }; - - type TweenDataGenConfig = { + normalX: number; /** - * Time in ms/frames before tween will start. + * The y normal of the vertex. */ - delay: Function; + normalY: number; /** - * Duration of the tween in ms/frames, excludes time for yoyo or repeats. + * The z normal of the vertex. */ - duration: Function; + normalZ: number; /** - * Time in ms/frames the tween will pause before running the yoyo or starting a repeat. + * UV u texture coordinate of the vertex. */ - hold: Function; + u: number; /** - * Number of times to repeat the tween. The tween will always run once regardless, so a repeat value of '1' will play the tween twice. + * UV v texture coordinate of the vertex. */ - repeat: Function; + v: number; /** - * Time in ms/frames before the repeat will start. + * The alpha value of the vertex. */ - repeatDelay: Function; + alpha: number; }; - type TweenOnActiveCallback = (tween: Phaser.Tweens.Tween, target: any, ...param: any[])=>void; + } - type TweenOnCompleteCallback = (tween: Phaser.Tweens.Tween, targets: any[], ...param: any[])=>void; + namespace Geom { + namespace Mesh { + type GenerateGridConfig = { + /** + * The texture to be used for this Grid. Must be a Texture instance. Can also be a string but only if the `mesh` property is set. + */ + texture: string | Phaser.Textures.Texture; + /** + * The name or index of the frame within the Texture. + */ + frame?: string | number; + /** + * If specified, the vertices of the generated grid will be added to this Mesh Game Object. + */ + mesh?: Phaser.GameObjects.Mesh; + /** + * The width of the grid in 3D units. If you wish to get a pixel accurate grid based on a texture, you can use an Ortho Mesh or the `isOrtho` parameter. + */ + width?: number; + /** + * The height of the grid in 3D units. + */ + height?: number; + /** + * The number of segments to split the grid horizontally in to. + */ + widthSegments?: number; + /** + * The number of segments to split the grid vertically in to. + */ + heightSegments?: number; + /** + * Offset the grid x position by this amount. + */ + x?: number; + /** + * Offset the grid y position by this amount. + */ + y?: number; + /** + * An array of colors, one per vertex, or a single color value applied to all vertices. + */ + colors?: number | number[]; + /** + * An array of alpha values, one per vertex, or a single alpha value applied to all vertices. + */ + alphas?: number | number[]; + /** + * Should the texture tile (repeat) across the grid segments, or display as a single texture? + */ + tile?: boolean; + /** + * If set and using a texture with an ortho Mesh, the `width` and `height` parameters will be calculated based on the frame size for you. + */ + isOrtho?: boolean; + /** + * If set and using a texture, vertically flipping render result. + */ + flipY?: boolean; + }; - type TweenOnLoopCallback = (tween: Phaser.Tweens.Tween, targets: any[], ...param: any[])=>void; + type GenerateGridVertsResult = { + /** + * An array of vertex values in x, y pairs. + */ + verts: number[]; + /** + * An array of vertex indexes. This array will be empty if the `tile` parameter was `true`. + */ + indices: number[]; + /** + * An array of UV values, two per vertex. + */ + uvs: number[]; + /** + * An array of colors, one per vertex, or a single color value applied to all vertices. + */ + colors?: number | number[]; + /** + * An array of alpha values, one per vertex, or a single alpha value applied to all vertices. + */ + alphas?: number | number[]; + }; - type TweenOnRepeatCallback = (tween: Phaser.Tweens.Tween, target: any, ...param: any[])=>void; + type GenerateVertsResult = { + /** + * An array of Face objects generated from the OBJ Data. + */ + faces: Phaser.Geom.Mesh.Face[]; + /** + * An array of Vertex objects generated from the OBJ Data. + */ + verts: Phaser.Geom.Mesh.Vertex[]; + }; - type TweenOnStartCallback = (tween: Phaser.Tweens.Tween, targets: any[], ...param: any[])=>void; + type OBJData = { + /** + * An array of material library filenames found in the OBJ file. + */ + materialLibraries: string[]; + /** + * If the obj was loaded with an mtl file, the parsed material names are stored in this object. + */ + materials: object; + /** + * An array of parsed models extracted from the OBJ file. + */ + models: Phaser.Types.Geom.Mesh.OBJModel[]; + }; - type TweenOnUpdateCallback = (tween: Phaser.Tweens.Tween, target: any, ...param: any[])=>void; + type OBJFace = { + /** + * The name of the Group this Face is in. + */ + group: string; + /** + * The name of the material this Face uses. + */ + material: string; + /** + * An array of vertices in this Face. + */ + vertices: Phaser.Types.Geom.Mesh.OBJFaceVertice[]; + }; - type TweenOnYoyoCallback = (tween: Phaser.Tweens.Tween, target: any, ...param: any[])=>void; + type OBJFaceVertice = { + /** + * The index in the `textureCoords` array that this vertex uses. + */ + textureCoordsIndex: number; + /** + * The index in the `vertices` array that this vertex uses. + */ + vertexIndex: number; + /** + * The index in the `vertexNormals` array that this vertex uses. + */ + vertexNormalIndex: number; + }; - type TweenPropConfig = { + type OBJModel = { + /** + * An array of Faces. + */ + faces: Phaser.Types.Geom.Mesh.OBJFace[]; + /** + * The name of the model. + */ + name: string; + /** + * An array of texture coordinates. + */ + textureCoords: Phaser.Types.Geom.Mesh.UV[]; + /** + * An array of vertex normals. + */ + vertexNormals: Phaser.Types.Math.Vector3Like[]; + /** + * An array of vertices in the model. + */ + vertices: Phaser.Types.Math.Vector3Like[]; + }; + + type UV = { + /** + * The u component. + */ + u: number; + /** + * The v component. + */ + v: number; + /** + * The w component. + */ + w: number; + }; + + } + + } + + namespace Input { + namespace Gamepad { /** - * What the property will be at the END of the Tween. + * The Gamepad object, as extracted from GamepadEvent. */ - value?: number | string | Phaser.Types.Tweens.GetEndCallback | Phaser.Types.Tweens.TweenPropConfig; + type Pad = { + /** + * The ID of the Gamepad. + */ + id: string; + /** + * The index of the Gamepad. + */ + index: number; + }; + + } + + namespace Keyboard { + type CursorKeys = { + /** + * A Key object mapping to the UP arrow key. + */ + up: Phaser.Input.Keyboard.Key; + /** + * A Key object mapping to the DOWN arrow key. + */ + down: Phaser.Input.Keyboard.Key; + /** + * A Key object mapping to the LEFT arrow key. + */ + left: Phaser.Input.Keyboard.Key; + /** + * A Key object mapping to the RIGHT arrow key. + */ + right: Phaser.Input.Keyboard.Key; + /** + * A Key object mapping to the SPACE BAR key. + */ + space: Phaser.Input.Keyboard.Key; + /** + * A Key object mapping to the SHIFT key. + */ + shift: Phaser.Input.Keyboard.Key; + }; + + type KeyboardKeydownCallback = (event: KeyboardEvent)=>void; + + type KeyComboConfig = { + /** + * If they press the wrong key do we reset the combo? + */ + resetOnWrongKey?: boolean; + /** + * The max delay in ms between each key press. Above this the combo is reset. 0 means disabled. + */ + maxKeyDelay?: number; + /** + * If previously matched and they press the first key of the combo again, will it reset? + */ + resetOnMatch?: boolean; + /** + * If the combo matches, will it delete itself? + */ + deleteOnMatch?: boolean; + }; + + } + + /** + * A Phaser Input Event Data object. + * + * This object is passed to the registered event listeners and allows you to stop any further propagation. + */ + type EventData = { /** - * What the property will be set to immediately when this tween becomes active. + * The cancelled state of this Event. */ - getActive?: Phaser.Types.Tweens.GetActiveCallback; + cancelled?: boolean; /** - * What the property will be at the END of the Tween. + * Call this method to stop this event from passing any further down the event chain. */ - getEnd?: Phaser.Types.Tweens.GetEndCallback; + stopPropagation: Function; + }; + + type HitAreaCallback = (hitArea: any, x: number, y: number, gameObject: Phaser.GameObjects.GameObject)=>void; + + type InputConfiguration = { /** - * What the property will be at the START of the Tween. + * The object / shape to use as the Hit Area. If not given it will try to create a Rectangle based on the texture frame. */ - getStart?: Phaser.Types.Tweens.GetStartCallback; + hitArea?: any; /** - * The ease function this tween uses. + * The callback that determines if the pointer is within the Hit Area shape or not. */ - ease?: string | Function; + hitAreaCallback?: Phaser.Types.Input.HitAreaCallback; /** - * Time in ms/frames before tween will start. + * If `true` the Interactive Object will be set to be draggable and emit drag events. */ - delay?: number; + draggable?: boolean; /** - * Duration of the tween in ms/frames. + * If `true` the Interactive Object will be set to be a drop zone for draggable objects. */ - duration?: number; + dropZone?: boolean; /** - * Determines whether the tween should return back to its start value after hold has expired. + * If `true` the Interactive Object will set the `pointer` hand cursor when a pointer is over it. This is a short-cut for setting `cursor: 'pointer'`. */ - yoyo?: boolean; + useHandCursor?: boolean; /** - * Time in ms/frames the tween will pause before repeating or returning to its starting value if yoyo is set to true. + * The CSS string to be used when the cursor is over this Interactive Object. */ - hold?: number; + cursor?: string; /** - * Number of times to repeat the tween. The tween will always run once regardless, so a repeat value of '1' will play the tween twice. + * If `true` the a pixel perfect function will be set for the hit area callback. Only works with texture based Game Objects. */ - repeat?: number; + pixelPerfect?: boolean; /** - * Time in ms/frames before the repeat will start. + * If `pixelPerfect` is set, this is the alpha tolerance threshold value used in the callback. */ - repeatDelay?: number; + alphaTolerance?: number; + }; + + type InputPluginContainer = { /** - * Should toggleFlipX be called when yoyo or repeat happens? + * The unique name of this plugin in the input plugin cache. */ - flipX?: boolean; + key: string; /** - * Should toggleFlipY be called when yoyo or repeat happens? + * The plugin to be stored. Should be the source object, not instantiated. */ - flipY?: boolean; + plugin: Function; + /** + * If this plugin is to be injected into the Input Plugin, this is the property key map used. + */ + mapping?: string; }; - } - - } - - namespace Physics { - namespace Arcade { - /** - * An Arcade Physics Image is an Image with an Arcade Physics body and related components. - * The body can be dynamic or static. - * - * The main difference between an Arcade Image and an Arcade Sprite is that you cannot animate an Arcade Image. - */ - class Image extends Phaser.GameObjects.Image implements Phaser.Physics.Arcade.Components.Acceleration, Phaser.Physics.Arcade.Components.Angular, Phaser.Physics.Arcade.Components.Bounce, Phaser.Physics.Arcade.Components.Debug, Phaser.Physics.Arcade.Components.Drag, Phaser.Physics.Arcade.Components.Enable, Phaser.Physics.Arcade.Components.Friction, Phaser.Physics.Arcade.Components.Gravity, Phaser.Physics.Arcade.Components.Immovable, Phaser.Physics.Arcade.Components.Mass, Phaser.Physics.Arcade.Components.Size, Phaser.Physics.Arcade.Components.Velocity, Phaser.GameObjects.Components.Alpha, Phaser.GameObjects.Components.BlendMode, Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.Flip, Phaser.GameObjects.Components.GetBounds, Phaser.GameObjects.Components.Origin, Phaser.GameObjects.Components.Pipeline, Phaser.GameObjects.Components.ScrollFactor, Phaser.GameObjects.Components.Size, Phaser.GameObjects.Components.Texture, Phaser.GameObjects.Components.Tint, Phaser.GameObjects.Components.Transform, Phaser.GameObjects.Components.Visible { + type InteractiveObject = { /** - * - * @param scene The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. - * @param x The horizontal position of this Game Object in the world. - * @param y The vertical position of this Game Object in the world. - * @param texture The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. - * @param frame An optional frame from the Texture this Game Object is rendering with. + * The Game Object to which this Interactive Object is bound. */ - constructor(scene: Phaser.Scene, x: number, y: number, texture: string, frame?: string | integer); - + gameObject: Phaser.GameObjects.GameObject; /** - * This Game Object's Physics Body. + * Is this Interactive Object currently enabled for input events? */ - body: Phaser.Physics.Arcade.Body | Phaser.Physics.Arcade.StaticBody; - + enabled: boolean; /** - * Clears all alpha values associated with this Game Object. - * - * Immediately sets the alpha levels back to 1 (fully opaque). + * An Interactive Object that is 'always enabled' will receive input even if the parent object is invisible or won't render. */ - clearAlpha(): this; - + alwaysEnabled: boolean; /** - * Set the Alpha level of this Game Object. The alpha controls the opacity of the Game Object as it renders. - * Alpha values are provided as a float between 0, fully transparent, and 1, fully opaque. - * - * If your game is running under WebGL you can optionally specify four different alpha values, each of which - * correspond to the four corners of the Game Object. Under Canvas only the `topLeft` value given is used. - * @param topLeft The alpha value used for the top-left of the Game Object. If this is the only value given it's applied across the whole Game Object. Default 1. - * @param topRight The alpha value used for the top-right of the Game Object. WebGL only. - * @param bottomLeft The alpha value used for the bottom-left of the Game Object. WebGL only. - * @param bottomRight The alpha value used for the bottom-right of the Game Object. WebGL only. + * Is this Interactive Object draggable? Enable with `InputPlugin.setDraggable`. + */ + draggable: boolean; + /** + * Is this Interactive Object a drag-targets drop zone? Set when the object is created. + */ + dropZone: boolean; + /** + * Should this Interactive Object change the cursor (via css) when over? (desktop only) + */ + cursor: boolean | string; + /** + * An optional drop target for a draggable Interactive Object. + */ + target: Phaser.GameObjects.GameObject; + /** + * The most recent Camera to be tested against this Interactive Object. */ - setAlpha(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; - + camera: Phaser.Cameras.Scene2D.Camera; /** - * The alpha value of the Game Object. - * - * This is a global value, impacting the entire Game Object, not just a region of it. + * The hit area for this Interactive Object. Typically a geometry shape, like a Rectangle or Circle. */ - alpha: number; - + hitArea: any; /** - * The alpha value starting from the top-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * The 'contains' check callback that the hit area shape will use for all hit tests. */ - alphaTopLeft: number; - + hitAreaCallback: Phaser.Types.Input.HitAreaCallback; /** - * The alpha value starting from the top-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * If this Interactive Object has been enabled for debug, via `InputPlugin.enableDebug` then this property holds its debug shape. */ - alphaTopRight: number; - + hitAreaDebug: Phaser.GameObjects.Shape; /** - * The alpha value starting from the bottom-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * Was the hitArea for this Interactive Object created based on texture size (false), or a custom shape? (true) */ - alphaBottomLeft: number; - + customHitArea: boolean; /** - * The alpha value starting from the bottom-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * The x coordinate that the Pointer interacted with this object on, relative to the Game Object's top-left position. */ - alphaBottomRight: number; - + localX: number; /** - * Sets the Blend Mode being used by this Game Object. - * - * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) - * - * Under WebGL only the following Blend Modes are available: - * - * * ADD - * * MULTIPLY - * * SCREEN - * * ERASE - * - * Canvas has more available depending on browser support. - * - * You can also create your own custom Blend Modes in WebGL. - * - * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending - * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these - * reasons try to be careful about the construction of your Scene and the frequency of which blend modes - * are used. + * The y coordinate that the Pointer interacted with this object on, relative to the Game Object's top-left position. */ - blendMode: Phaser.BlendModes | string; - + localY: number; /** - * Sets the Blend Mode being used by this Game Object. - * - * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) - * - * Under WebGL only the following Blend Modes are available: - * - * * ADD - * * MULTIPLY - * * SCREEN - * * ERASE (only works when rendering to a framebuffer, like a Render Texture) - * - * Canvas has more available depending on browser support. - * - * You can also create your own custom Blend Modes in WebGL. - * - * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending - * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these - * reasons try to be careful about the construction of your Scene and the frequency in which blend modes - * are used. - * @param value The BlendMode value. Either a string or a CONST. + * The current drag state of this Interactive Object. 0 = Not being dragged, 1 = being checked for drag, or 2 = being actively dragged. */ - setBlendMode(value: string | Phaser.BlendModes): this; - + dragState: 0 | 1 | 2; /** - * The depth of this Game Object within the Scene. - * - * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order - * of Game Objects, without actually moving their position in the display list. - * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth - * value will always render in front of one with a lower value. - * - * Setting the depth will queue a depth sort event within the Scene. + * The x coordinate of the Game Object that owns this Interactive Object when the drag started. */ - depth: number; - + dragStartX: number; /** - * The depth of this Game Object within the Scene. - * - * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order - * of Game Objects, without actually moving their position in the display list. - * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth - * value will always render in front of one with a lower value. - * - * Setting the depth will queue a depth sort event within the Scene. - * @param value The depth of this Game Object. + * The y coordinate of the Game Object that owns this Interactive Object when the drag started. */ - setDepth(value: integer): this; - + dragStartY: number; /** - * The horizontally flipped state of the Game Object. - * - * A Game Object that is flipped horizontally will render inversed on the horizontal axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * The x coordinate that the Pointer started dragging this Interactive Object from. */ - flipX: boolean; - + dragStartXGlobal: number; /** - * The vertically flipped state of the Game Object. - * - * A Game Object that is flipped vertically will render inversed on the vertical axis (i.e. upside down) - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * The y coordinate that the Pointer started dragging this Interactive Object from. */ - flipY: boolean; + dragStartYGlobal: number; + /** + * The x coordinate that this Interactive Object is currently being dragged to. + */ + dragX: number; + /** + * The y coordinate that this Interactive Object is currently being dragged to. + */ + dragY: number; + }; + + } + + namespace Loader { + namespace FileTypes { + type AsepriteFileConfig = { + /** + * The key of the file. Must be unique within both the Loader and the Texture Manager. + */ + key: string; + /** + * The absolute or relative URL to load the texture image file from. + */ + textureURL?: string; + /** + * The default file extension to use for the image texture if no url is provided. + */ + textureExtension?: string; + /** + * Extra XHR Settings specifically for the texture image file. + */ + textureXhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + /** + * The absolute or relative URL to load the atlas json file from. Or, a well formed JSON object to use instead. + */ + atlasURL?: object | string; + /** + * The default file extension to use for the atlas json if no url is provided. + */ + atlasExtension?: string; + /** + * Extra XHR Settings specifically for the atlas json file. + */ + atlasXhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + }; + + type AtlasJSONFileConfig = { + /** + * The key of the file. Must be unique within both the Loader and the Texture Manager. + */ + key: string; + /** + * The absolute or relative URL to load the texture image file from. + */ + textureURL?: string; + /** + * The default file extension to use for the image texture if no url is provided. + */ + textureExtension?: string; + /** + * Extra XHR Settings specifically for the texture image file. + */ + textureXhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + /** + * The filename of an associated normal map. It uses the same path and url to load as the texture image. + */ + normalMap?: string; + /** + * The absolute or relative URL to load the atlas json file from. Or, a well formed JSON object to use instead. + */ + atlasURL?: object | string; + /** + * The default file extension to use for the atlas json if no url is provided. + */ + atlasExtension?: string; + /** + * Extra XHR Settings specifically for the atlas json file. + */ + atlasXhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + }; + + type AtlasXMLFileConfig = { + /** + * The key of the file. Must be unique within both the Loader and the Texture Manager. + */ + key: string; + /** + * The absolute or relative URL to load the texture image file from. + */ + textureURL?: string; + /** + * The default file extension to use for the image texture if no url is provided. + */ + textureExtension?: string; + /** + * Extra XHR Settings specifically for the texture image file. + */ + textureXhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + /** + * The filename of an associated normal map. It uses the same path and url to load as the texture image. + */ + normalMap?: string; + /** + * The absolute or relative URL to load the atlas xml file from. + */ + atlasURL?: string; + /** + * The default file extension to use for the atlas xml if no url is provided. + */ + atlasExtension?: string; + /** + * Extra XHR Settings specifically for the atlas xml file. + */ + atlasXhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + }; + + type AudioFileConfig = { + /** + * The key of the file. Must be unique within the Loader and Audio Cache. + */ + key: string; + /** + * The absolute or relative URLs to load the audio files from. + */ + url?: string | string[]; + /** + * Extra XHR Settings specifically for this file. + */ + xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + /** + * The optional AudioContext this file will use to process itself. + */ + context?: AudioContext; + }; + + type AudioSpriteFileConfig = { + /** + * The key of the file. Must be unique within both the Loader and the Audio Cache. + */ + key: string; + /** + * The absolute or relative URL to load the json file from. Or a well formed JSON object to use instead. + */ + jsonURL: string; + /** + * Extra XHR Settings specifically for the json file. + */ + jsonXhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + /** + * The absolute or relative URL to load the audio file from. + */ + audioURL?: Object; + /** + * The audio configuration options. + */ + audioConfig?: any; + /** + * Extra XHR Settings specifically for the audio file. + */ + audioXhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + }; + + type BinaryFileConfig = { + /** + * The key of the file. Must be unique within both the Loader and the Binary Cache. + */ + key: string; + /** + * The absolute or relative URL to load the file from. + */ + url?: string; + /** + * The default file extension to use if no url is provided. + */ + extension?: string; + /** + * Extra XHR Settings specifically for this file. + */ + xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + /** + * Optional type to cast the binary file to once loaded. For example, `Uint8Array`. + */ + dataType?: any; + }; + + type BitmapFontFileConfig = { + /** + * The key of the file. Must be unique within both the Loader and the Texture Manager. + */ + key: string; + /** + * The absolute or relative URL to load the texture image file from. + */ + textureURL?: string; + /** + * The default file extension to use for the image texture if no url is provided. + */ + textureExtension?: string; + /** + * Extra XHR Settings specifically for the texture image file. + */ + textureXhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + /** + * The filename of an associated normal map. It uses the same path and url to load as the texture image. + */ + normalMap?: string; + /** + * The absolute or relative URL to load the font data xml file from. + */ + fontDataURL?: string; + /** + * The default file extension to use for the font data xml if no url is provided. + */ + fontDataExtension?: string; + /** + * Extra XHR Settings specifically for the font data xml file. + */ + fontDataXhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + }; + + type CSSFileConfig = { + /** + * The key of the file. Must be unique within the Loader. + */ + key: string; + /** + * The absolute or relative URL to load the file from. + */ + url?: string; + /** + * The default file extension to use if no url is provided. + */ + extension?: string; + /** + * Extra XHR Settings specifically for this file. + */ + xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + }; + + type GLSLFileConfig = { + /** + * The key of the file. Must be unique within both the Loader and the Text Cache. + */ + key: string; + /** + * The absolute or relative URL to load the file from. + */ + url?: string; + /** + * The type of shader. Either `fragment` for a fragment shader, or `vertex` for a vertex shader. This is ignored if you load a shader bundle. + */ + shaderType?: string; + /** + * The default file extension to use if no url is provided. + */ + extension?: string; + /** + * Extra XHR Settings specifically for this file. + */ + xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + }; + + type HTMLFileConfig = { + /** + * The key of the file. Must be unique within both the Loader and the Text Cache. + */ + key: string; + /** + * The absolute or relative URL to load the file from. + */ + url?: string; + /** + * The default file extension to use if no url is provided. + */ + extension?: string; + /** + * Extra XHR Settings specifically for this file. + */ + xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + }; + + type HTMLTextureFileConfig = { + /** + * The key of the file. Must be unique within both the Loader and the Texture Manager. + */ + key: string; + /** + * The absolute or relative URL to load the file from. + */ + url?: string; + /** + * The default file extension to use if no url is provided. + */ + extension?: string; + /** + * Extra XHR Settings specifically for this file. + */ + xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + /** + * The width of the texture the HTML will be rendered to. + */ + width?: number; + /** + * The height of the texture the HTML will be rendered to. + */ + height?: number; + }; + + type ImageFileConfig = { + /** + * The key of the file. Must be unique within both the Loader and the Texture Manager. + */ + key: string; + /** + * The absolute or relative URL to load the file from. + */ + url?: string; + /** + * The default file extension to use if no url is provided. + */ + extension?: string; + /** + * The filename of an associated normal map. It uses the same path and url to load as the image. + */ + normalMap?: string; + /** + * The frame configuration object. Only provided for, and used by, Sprite Sheets. + */ + frameConfig?: Phaser.Types.Loader.FileTypes.ImageFrameConfig; + /** + * Extra XHR Settings specifically for this file. + */ + xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + }; + + type ImageFrameConfig = { + /** + * The width of the frame in pixels. + */ + frameWidth: number; + /** + * The height of the frame in pixels. Uses the `frameWidth` value if not provided. + */ + frameHeight?: number; + /** + * The first frame to start parsing from. + */ + startFrame?: number; + /** + * The frame to stop parsing at. If not provided it will calculate the value based on the image and frame dimensions. + */ + endFrame?: number; + /** + * The margin in the image. This is the space around the edge of the frames. + */ + margin?: number; + /** + * The spacing between each frame in the image. + */ + spacing?: number; + }; + + type JSONFileConfig = { + /** + * The key of the file. Must be unique within both the Loader and the JSON Cache. + */ + key: string; + /** + * The absolute or relative URL to load the file from. Or can be a ready formed JSON object, in which case it will be directly added to the Cache. + */ + url?: string | any; + /** + * The default file extension to use if no url is provided. + */ + extension?: string; + /** + * If specified instead of the whole JSON file being parsed and added to the Cache, only the section corresponding to this property key will be added. If the property you want to extract is nested, use periods to divide it. + */ + dataKey?: string; + /** + * Extra XHR Settings specifically for this file. + */ + xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + }; + + type MultiAtlasFileConfig = { + /** + * The key of the file. Must be unique within both the Loader and the Texture Manager. + */ + key: string; + /** + * The absolute or relative URL to load the multi atlas json file from. Or, a well formed JSON object. + */ + atlasURL?: string; + /** + * An alias for 'atlasURL'. If given, it overrides anything set in 'atlasURL'. + */ + url?: string; + /** + * The default file extension to use for the atlas json if no url is provided. + */ + atlasExtension?: string; + /** + * Extra XHR Settings specifically for the atlas json file. + */ + atlasXhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + /** + * Optional path to use when loading the textures defined in the atlas data. + */ + path?: string; + /** + * Optional Base URL to use when loading the textures defined in the atlas data. + */ + baseURL?: string; + /** + * Extra XHR Settings specifically for the texture files. + */ + textureXhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + }; - /** - * Toggles the horizontal flipped state of this Game Object. - * - * A Game Object that is flipped horizontally will render inversed on the horizontal axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. - */ - toggleFlipX(): this; + type MultiScriptFileConfig = { + /** + * The key of the file. Must be unique within the Loader. + */ + key: string; + /** + * An array of absolute or relative URLs to load the script files from. They are processed in the order given in the array. + */ + url?: string[]; + /** + * The default file extension to use if no url is provided. + */ + extension?: string; + /** + * Extra XHR Settings specifically for these files. + */ + xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + }; - /** - * Toggles the vertical flipped state of this Game Object. - */ - toggleFlipY(): this; + type OBJFileConfig = { + /** + * The key of the file. Must be unique within both the Loader and the OBJ Cache. + */ + key: string; + /** + * The absolute or relative URL to load this file from. If undefined or `null` it will be set to `.obj`, i.e. if `key` was "alien" then the URL will be "alien.obj". + */ + url?: string; + /** + * The default file extension to use if no url is provided. + */ + extension?: string; + /** + * Flip the UV coordinates stored in the model data? + */ + flipUV?: boolean; + /** + * An optional absolute or relative URL to the object material file from. If undefined or `null`, no material file will be loaded. + */ + matURL?: string; + /** + * The default material file extension to use if no url is provided. + */ + matExtension?: string; + /** + * Extra XHR Settings specifically for this file. + */ + xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + }; - /** - * Sets the horizontal flipped state of this Game Object. - * - * A Game Object that is flipped horizontally will render inversed on the horizontal axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. - * @param value The flipped state. `false` for no flip, or `true` to be flipped. - */ - setFlipX(value: boolean): this; + type PackFileConfig = { + /** + * The key of the file. Must be unique within both the Loader and the JSON Cache. + */ + key: string; + /** + * The absolute or relative URL to load the file from. Or can be a ready formed JSON object, in which case it will be directly processed. + */ + url?: string | any; + /** + * The default file extension to use if no url is provided. + */ + extension?: string; + /** + * If specified instead of the whole JSON file being parsed, only the section corresponding to this property key will be added. If the property you want to extract is nested, use periods to divide it. + */ + dataKey?: string; + /** + * Extra XHR Settings specifically for this file. + */ + xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + }; - /** - * Sets the vertical flipped state of this Game Object. - * @param value The flipped state. `false` for no flip, or `true` to be flipped. - */ - setFlipY(value: boolean): this; + type PackFileSection = { + /** + * The files to load. See {@link Phaser.Types.Loader.FileTypes}. + */ + files: Phaser.Types.Loader.FileConfig[]; + /** + * A URL used to resolve paths in `files`. Example: 'http://labs.phaser.io/assets/'. + */ + baseURL?: string; + /** + * The default {@link Phaser.Types.Loader.FileConfig} `type`. + */ + defaultType?: string; + /** + * A URL path used to resolve relative paths in `files`. Example: 'images/sprites/'. + */ + path?: string; + /** + * An optional prefix that is automatically prepended to each file key. + */ + prefix?: string; + }; - /** - * Sets the horizontal and vertical flipped state of this Game Object. - * - * A Game Object that is flipped will render inversed on the flipped axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. - * @param x The horizontal flipped state. `false` for no flip, or `true` to be flipped. - * @param y The horizontal flipped state. `false` for no flip, or `true` to be flipped. - */ - setFlip(x: boolean, y: boolean): this; + type PluginFileConfig = { + /** + * The key of the file. Must be unique within the Loader. + */ + key: string; + /** + * The absolute or relative URL to load the file from. + */ + url?: string; + /** + * The default file extension to use if no url is provided. + */ + extension?: string; + /** + * Automatically start the plugin after loading? + */ + start?: boolean; + /** + * If this plugin is to be injected into the Scene, this is the property key used. + */ + mapping?: string; + /** + * Extra XHR Settings specifically for this file. + */ + xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + }; - /** - * Resets the horizontal and vertical flipped state of this Game Object back to their default un-flipped state. - */ - resetFlip(): this; + type SceneFileConfig = { + /** + * The key of the file. Must be unique within both the Loader and the Text Cache. + */ + key: string; + /** + * The absolute or relative URL to load the file from. + */ + url?: string; + /** + * The default file extension to use if no url is provided. + */ + extension?: string; + /** + * Extra XHR Settings specifically for this file. + */ + xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + }; - /** - * Gets the center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - */ - getCenter(output?: O): O; + type ScenePluginFileConfig = { + /** + * The key of the file. Must be unique within the Loader. + */ + key: string; + /** + * The absolute or relative URL to load the file from. Or, a Scene Plugin. + */ + url?: string | Function; + /** + * The default file extension to use if no url is provided. + */ + extension?: string; + /** + * If this plugin is to be added to Scene.Systems, this is the property key for it. + */ + systemKey?: string; + /** + * If this plugin is to be added to the Scene, this is the property key for it. + */ + sceneKey?: string; + /** + * Extra XHR Settings specifically for this file. + */ + xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + }; - /** - * Gets the top-left corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. - */ - getTopLeft(output?: O, includeParent?: boolean): O; + type ScriptFileConfig = { + /** + * The key of the file. Must be unique within the Loader. + */ + key: string; + /** + * The absolute or relative URL to load the file from. + */ + url?: string; + /** + * The default file extension to use if no url is provided. + */ + extension?: string; + /** + * Extra XHR Settings specifically for this file. + */ + xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + }; - /** - * Gets the top-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. - */ - getTopCenter(output?: O, includeParent?: boolean): O; + type SpriteSheetFileConfig = { + /** + * The key of the file. Must be unique within both the Loader and the Texture Manager. + */ + key: string; + /** + * The absolute or relative URL to load the file from. + */ + url?: string; + /** + * The default file extension to use if no url is provided. + */ + extension?: string; + /** + * The filename of an associated normal map. It uses the same path and url to load as the image. + */ + normalMap?: string; + /** + * The frame configuration object. + */ + frameConfig?: Phaser.Types.Loader.FileTypes.ImageFrameConfig; + /** + * Extra XHR Settings specifically for this file. + */ + xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + }; - /** - * Gets the top-right corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. - */ - getTopRight(output?: O, includeParent?: boolean): O; + type SVGFileConfig = { + /** + * The key of the file. Must be unique within both the Loader and the Texture Manager. + */ + key: string; + /** + * The absolute or relative URL to load the file from. + */ + url?: string; + /** + * The default file extension to use if no url is provided. + */ + extension?: string; + /** + * Extra XHR Settings specifically for this file. + */ + xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + /** + * The svg size configuration object. + */ + svgConfig?: Phaser.Types.Loader.FileTypes.SVGSizeConfig; + }; - /** - * Gets the left-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. - */ - getLeftCenter(output?: O, includeParent?: boolean): O; + type SVGSizeConfig = { + /** + * An optional width. The SVG will be resized to this size before being rendered to a texture. + */ + width?: number; + /** + * An optional height. The SVG will be resized to this size before being rendered to a texture. + */ + height?: number; + /** + * An optional scale. If given it overrides the width / height properties. The SVG is scaled by the scale factor before being rendered to a texture. + */ + scale?: number; + }; - /** - * Gets the right-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. - */ - getRightCenter(output?: O, includeParent?: boolean): O; + type TextFileConfig = { + /** + * The key of the file. Must be unique within both the Loader and the Text Cache. + */ + key: string; + /** + * The absolute or relative URL to load the file from. + */ + url?: string; + /** + * The default file extension to use if no url is provided. + */ + extension?: string; + /** + * Extra XHR Settings specifically for this file. + */ + xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + }; - /** - * Gets the bottom-left corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. - */ - getBottomLeft(output?: O, includeParent?: boolean): O; + type TilemapCSVFileConfig = { + /** + * The key of the file. Must be unique within both the Loader and the Tilemap Cache. + */ + key: string; + /** + * The absolute or relative URL to load the file from. + */ + url?: string; + /** + * The default file extension to use if no url is provided. + */ + extension?: string; + /** + * Extra XHR Settings specifically for this file. + */ + xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + }; - /** - * Gets the bottom-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. - */ - getBottomCenter(output?: O, includeParent?: boolean): O; + type TilemapImpactFileConfig = { + /** + * The key of the file. Must be unique within both the Loader and the Tilemap Cache. + */ + key: string; + /** + * The absolute or relative URL to load the file from. + */ + url?: string; + /** + * The default file extension to use if no url is provided. + */ + extension?: string; + /** + * Extra XHR Settings specifically for this file. + */ + xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + }; - /** - * Gets the bottom-right corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. - */ - getBottomRight(output?: O, includeParent?: boolean): O; + type TilemapJSONFileConfig = { + /** + * The key of the file. Must be unique within both the Loader and the Tilemap Cache. + */ + key: string; + /** + * The absolute or relative URL to load the file from. Or, a well formed JSON object. + */ + url?: object | string; + /** + * The default file extension to use if no url is provided. + */ + extension?: string; + /** + * Extra XHR Settings specifically for this file. + */ + xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + }; - /** - * Gets the bounds of this Game Object, regardless of origin. - * The values are stored and returned in a Rectangle, or Rectangle-like, object. - * @param output An object to store the values in. If not provided a new Rectangle will be created. - */ - getBounds(output?: O): O; + type UnityAtlasFileConfig = { + /** + * The key of the file. Must be unique within both the Loader and the Texture Manager. + */ + key: string; + /** + * The absolute or relative URL to load the texture image file from. + */ + textureURL?: string; + /** + * The default file extension to use for the image texture if no url is provided. + */ + textureExtension?: string; + /** + * Extra XHR Settings specifically for the texture image file. + */ + textureXhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + /** + * The filename of an associated normal map. It uses the same path and url to load as the texture image. + */ + normalMap?: string; + /** + * The absolute or relative URL to load the atlas data file from. + */ + atlasURL?: string; + /** + * The default file extension to use for the atlas data if no url is provided. + */ + atlasExtension?: string; + /** + * Extra XHR Settings specifically for the atlas data file. + */ + atlasXhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + }; - /** - * The Mask this Game Object is using during render. - */ - mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask; + type VideoFileConfig = { + /** + * The key to use for this file, or a file configuration object. + */ + key: string | Phaser.Types.Loader.FileTypes.VideoFileConfig; + /** + * The absolute or relative URLs to load the video files from. + */ + url?: string | string[]; + /** + * The load event to listen for when _not_ loading as a blob. Either 'loadeddata', 'canplay' or 'canplaythrough'. + */ + loadEvent?: string; + /** + * Load the video as a data blob, or via the Video element? + */ + asBlob?: boolean; + /** + * Does the video have an audio track? If not you can enable auto-playing on it. + */ + noAudio?: boolean; + /** + * Extra XHR Settings specifically for this file. + */ + xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + }; - /** - * Sets the mask that this Game Object will use to render with. - * - * The mask must have been previously created and can be either a GeometryMask or a BitmapMask. - * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. - * - * If a mask is already set on this Game Object it will be immediately replaced. - * - * Masks are positioned in global space and are not relative to the Game Object to which they - * are applied. The reason for this is that multiple Game Objects can all share the same mask. - * - * Masks have no impact on physics or input detection. They are purely a rendering component - * that allows you to limit what is visible during the render pass. - * @param mask The mask this Game Object will use when rendering. - */ - setMask(mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask): this; + type XMLFileConfig = { + /** + * The key of the file. Must be unique within both the Loader and the Text Cache. + */ + key: string; + /** + * The absolute or relative URL to load the file from. + */ + url?: string; + /** + * The default file extension to use if no url is provided. + */ + extension?: string; + /** + * Extra XHR Settings specifically for this file. + */ + xhrSettings?: Phaser.Types.Loader.XHRSettingsObject; + }; - /** - * Clears the mask that this Game Object was using. - * @param destroyMask Destroy the mask before clearing it? Default false. - */ - clearMask(destroyMask?: boolean): this; + } + type FileConfig = { /** - * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, - * including this one. - * - * To create the mask you need to pass in a reference to a renderable Game Object. - * A renderable Game Object is one that uses a texture to render with, such as an - * Image, Sprite, Render Texture or BitmapText. - * - * If you do not provide a renderable object, and this Game Object has a texture, - * it will use itself as the object. This means you can call this method to create - * a Bitmap Mask from any renderable Game Object. - * @param renderable A renderable Game Object that uses a texture, such as a Sprite. + * The file type string (image, json, etc) for sorting within the Loader. */ - createBitmapMask(renderable?: Phaser.GameObjects.GameObject): Phaser.Display.Masks.BitmapMask; - + type: string; /** - * Creates and returns a Geometry Mask. This mask can be used by any Game Object, - * including this one. - * - * To create the mask you need to pass in a reference to a Graphics Game Object. - * - * If you do not provide a graphics object, and this Game Object is an instance - * of a Graphics object, then it will use itself to create the mask. - * - * This means you can call this method to create a Geometry Mask from any Graphics Game Object. - * @param graphics A Graphics Game Object. The geometry within it will be used as the mask. + * Unique cache key (unique within its file type) */ - createGeometryMask(graphics?: Phaser.GameObjects.Graphics): Phaser.Display.Masks.GeometryMask; - + key: string; /** - * The horizontal origin of this Game Object. - * The origin maps the relationship between the size and position of the Game Object. - * The default value is 0.5, meaning all Game Objects are positioned based on their center. - * Setting the value to 0 means the position now relates to the left of the Game Object. + * The URL of the file, not including baseURL. */ - originX: number; - + url?: string; /** - * The vertical origin of this Game Object. - * The origin maps the relationship between the size and position of the Game Object. - * The default value is 0.5, meaning all Game Objects are positioned based on their center. - * Setting the value to 0 means the position now relates to the top of the Game Object. + * The path of the file, not including the baseURL. */ - originY: number; - + path?: string; /** - * The horizontal display origin of this Game Object. - * The origin is a normalized value between 0 and 1. - * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. + * The default extension this file uses. */ - displayOriginX: number; - + extension?: string; /** - * The vertical display origin of this Game Object. - * The origin is a normalized value between 0 and 1. - * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. + * The responseType to be used by the XHR request. */ - displayOriginY: number; - + responseType?: XMLHttpRequestResponseType; /** - * Sets the origin of this Game Object. - * - * The values are given in the range 0 to 1. - * @param x The horizontal origin value. Default 0.5. - * @param y The vertical origin value. If not defined it will be set to the value of `x`. Default x. + * Custom XHR Settings specific to this file and merged with the Loader defaults. */ - setOrigin(x?: number, y?: number): this; - + xhrSettings?: Phaser.Types.Loader.XHRSettingsObject | false; /** - * Sets the origin of this Game Object based on the Pivot values in its Frame. + * A config object that can be used by file types to store transitional data. */ - setOriginFromFrame(): this; + config?: any; + }; + type XHRSettingsObject = { /** - * Sets the display origin of this Game Object. - * The difference between this and setting the origin is that you can use pixel values for setting the display origin. - * @param x The horizontal display origin value. Default 0. - * @param y The vertical display origin value. If not defined it will be set to the value of `x`. Default x. + * The response type of the XHR request, i.e. `blob`, `text`, etc. */ - setDisplayOrigin(x?: number, y?: number): this; - + responseType: XMLHttpRequestResponseType; /** - * Updates the Display Origin cached values internally stored on this Game Object. - * You don't usually call this directly, but it is exposed for edge-cases where you may. + * Should the XHR request use async or not? */ - updateDisplayOrigin(): this; - + async?: boolean; /** - * The initial WebGL pipeline of this Game Object. + * Optional username for the XHR request. */ - defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; - + user?: string; /** - * The current WebGL pipeline of this Game Object. + * Optional password for the XHR request. */ - pipeline: Phaser.Renderer.WebGL.WebGLPipeline; - + password?: string; /** - * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. + * Optional XHR timeout value. */ - initPipeline(pipelineName?: string): boolean; - + timeout?: number; /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. + * This value is used to populate the XHR `setRequestHeader` and is undefined by default. */ - setPipeline(pipelineName: string): this; - + headers?: object | undefined; /** - * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * This value is used to populate the XHR `setRequestHeader` and is undefined by default. */ - resetPipeline(): boolean; - + header?: string | undefined; /** - * Gets the name of the WebGL Pipeline this Game Object is currently using. + * This value is used to populate the XHR `setRequestHeader` and is undefined by default. */ - getPipelineName(): string; - + headerValue?: string | undefined; /** - * The horizontal scroll factor of this Game Object. - * - * The scroll factor controls the influence of the movement of a Camera upon this Game Object. - * - * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. - * It does not change the Game Objects actual position values. - * - * A value of 1 means it will move exactly in sync with a camera. - * A value of 0 means it will not move at all, even if the camera moves. - * Other values control the degree to which the camera movement is mapped to this Game Object. - * - * Please be aware that scroll factor values other than 1 are not taken in to consideration when - * calculating physics collisions. Bodies always collide based on their world position, but changing - * the scroll factor is a visual adjustment to where the textures are rendered, which can offset - * them from physics bodies if not accounted for in your code. + * This value is used to populate the XHR `setRequestHeader` and is undefined by default. */ - scrollFactorX: number; - + requestedWith?: string | undefined; /** - * The vertical scroll factor of this Game Object. - * - * The scroll factor controls the influence of the movement of a Camera upon this Game Object. - * - * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. - * It does not change the Game Objects actual position values. - * - * A value of 1 means it will move exactly in sync with a camera. - * A value of 0 means it will not move at all, even if the camera moves. - * Other values control the degree to which the camera movement is mapped to this Game Object. - * - * Please be aware that scroll factor values other than 1 are not taken in to consideration when - * calculating physics collisions. Bodies always collide based on their world position, but changing - * the scroll factor is a visual adjustment to where the textures are rendered, which can offset - * them from physics bodies if not accounted for in your code. + * Provide a custom mime-type to use instead of the default. */ - scrollFactorY: number; - + overrideMimeType?: string | undefined; /** - * Sets the scroll factor of this Game Object. - * - * The scroll factor controls the influence of the movement of a Camera upon this Game Object. - * - * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. - * It does not change the Game Objects actual position values. - * - * A value of 1 means it will move exactly in sync with a camera. - * A value of 0 means it will not move at all, even if the camera moves. - * Other values control the degree to which the camera movement is mapped to this Game Object. - * - * Please be aware that scroll factor values other than 1 are not taken in to consideration when - * calculating physics collisions. Bodies always collide based on their world position, but changing - * the scroll factor is a visual adjustment to where the textures are rendered, which can offset - * them from physics bodies if not accounted for in your code. - * @param x The horizontal scroll factor of this Game Object. - * @param y The vertical scroll factor of this Game Object. If not set it will use the `x` value. Default x. + * The withCredentials property indicates whether or not cross-site Access-Control requests should be made using credentials such as cookies, authorization headers or TLS client certificates. Setting withCredentials has no effect on same-site requests. */ - setScrollFactor(x: number, y?: number): this; + withCredentials?: boolean; + }; - /** - * The native (un-scaled) width of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayWidth` property. - */ - width: number; + } + namespace Math { + type SinCosTable = { /** - * The native (un-scaled) height of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayHeight` property. + * The sine value. */ - height: number; - + sin: number; /** - * The displayed width of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. + * The cosine value. */ - displayWidth: number; - + cos: number; /** - * The displayed height of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. + * The length. */ - displayHeight: number; + length: number; + }; + type Vector2Like = { /** - * Sets the size of this Game Object to be that of the given Frame. - * - * This will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or call the - * `setDisplaySize` method, which is the same thing as changing the scale but allows you - * to do so by giving pixel values. - * - * If you have enabled this Game Object for input, changing the size will _not_ change the - * size of the hit area. To do this you should adjust the `input.hitArea` object directly. - * @param frame The frame to base the size of this Game Object on. + * The x component. */ - setSizeToFrame(frame: Phaser.Textures.Frame): this; - + x?: number; /** - * Sets the internal size of this Game Object, as used for frame or physics body creation. - * - * This will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or call the - * `setDisplaySize` method, which is the same thing as changing the scale but allows you - * to do so by giving pixel values. - * - * If you have enabled this Game Object for input, changing the size will _not_ change the - * size of the hit area. To do this you should adjust the `input.hitArea` object directly. - * @param width The width of this Game Object. - * @param height The height of this Game Object. + * The y component. */ - setSize(width: number, height: number): this; + y?: number; + }; + type Vector3Like = { /** - * Sets the display size of this Game Object. - * - * Calling this will adjust the scale. - * @param width The width of this Game Object. - * @param height The height of this Game Object. + * The x component. */ - setDisplaySize(width: number, height: number): this; - + x?: number; /** - * The Texture this Game Object is using to render with. + * The y component. */ - texture: Phaser.Textures.Texture | Phaser.Textures.CanvasTexture; - + y?: number; /** - * The Texture Frame this Game Object is using to render with. + * The z component. */ - frame: Phaser.Textures.Frame; + z?: number; + }; + type Vector4Like = { /** - * A boolean flag indicating if this Game Object is being cropped or not. - * You can toggle this at any time after `setCrop` has been called, to turn cropping on or off. - * Equally, calling `setCrop` with no arguments will reset the crop and disable it. + * The x component. */ - isCropped: boolean; - + x?: number; /** - * Applies a crop to a texture based Game Object, such as a Sprite or Image. - * - * The crop is a rectangle that limits the area of the texture frame that is visible during rendering. - * - * Cropping a Game Object does not change its size, dimensions, physics body or hit area, it just - * changes what is shown when rendered. - * - * The crop coordinates are relative to the texture frame, not the Game Object, meaning 0 x 0 is the top-left. - * - * Therefore, if you had a Game Object that had an 800x600 sized texture, and you wanted to show only the left - * half of it, you could call `setCrop(0, 0, 400, 600)`. - * - * It is also scaled to match the Game Object scale automatically. Therefore a crop rect of 100x50 would crop - * an area of 200x100 when applied to a Game Object that had a scale factor of 2. - * - * You can either pass in numeric values directly, or you can provide a single Rectangle object as the first argument. - * - * Call this method with no arguments at all to reset the crop, or toggle the property `isCropped` to `false`. - * - * You should do this if the crop rectangle becomes the same size as the frame itself, as it will allow - * the renderer to skip several internal calculations. - * @param x The x coordinate to start the crop from. Or a Phaser.Geom.Rectangle object, in which case the rest of the arguments are ignored. - * @param y The y coordinate to start the crop from. - * @param width The width of the crop rectangle in pixels. - * @param height The height of the crop rectangle in pixels. + * The y component. */ - setCrop(x?: number | Phaser.Geom.Rectangle, y?: number, width?: number, height?: number): this; - + y?: number; /** - * Sets the texture and frame this Game Object will use to render with. - * - * Textures are referenced by their string-based keys, as stored in the Texture Manager. - * @param key The key of the texture to be used, as stored in the Texture Manager. - * @param frame The name or index of the frame within the Texture. + * The z component. */ - setTexture(key: string, frame?: string | integer): this; - + z?: number; /** - * Sets the frame this Game Object will use to render with. - * - * The Frame has to belong to the current Texture being used. - * - * It can be either a string or an index. - * - * Calling `setFrame` will modify the `width` and `height` properties of your Game Object. - * It will also change the `origin` if the Frame has a custom pivot point, as exported from packages like Texture Packer. - * @param frame The name or index of the frame within the Texture. - * @param updateSize Should this call adjust the size of the Game Object? Default true. - * @param updateOrigin Should this call adjust the origin of the Game Object? Default true. + * The w component. */ - setFrame(frame: string | integer, updateSize?: boolean, updateOrigin?: boolean): this; + w?: number; + }; + + } + + namespace Physics { + namespace Arcade { + type ArcadeBodyBounds = { + /** + * The left edge. + */ + x: number; + /** + * The upper edge. + */ + y: number; + /** + * The right edge. + */ + right: number; + /** + * The lower edge. + */ + bottom: number; + }; + + type ArcadeBodyCollision = { + /** + * True if the Body is not colliding. + */ + none: boolean; + /** + * True if the Body is colliding on its upper edge. + */ + up: boolean; + /** + * True if the Body is colliding on its lower edge. + */ + down: boolean; + /** + * True if the Body is colliding on its left edge. + */ + left: boolean; + /** + * True if the Body is colliding on its right edge. + */ + right: boolean; + }; /** - * Fill or additive? + * An Arcade Physics Collider Type. */ - tintFill: boolean; + type ArcadeColliderType = Phaser.GameObjects.GameObject | Phaser.GameObjects.Group | Phaser.Physics.Arcade.Sprite | Phaser.Physics.Arcade.Image | Phaser.Physics.Arcade.StaticGroup | Phaser.Physics.Arcade.Group | Phaser.Tilemaps.TilemapLayer | Phaser.GameObjects.GameObject[] | Phaser.Physics.Arcade.Sprite[] | Phaser.Physics.Arcade.Image[] | Phaser.Physics.Arcade.StaticGroup[] | Phaser.Physics.Arcade.Group[] | Phaser.Tilemaps.TilemapLayer[]; + + type ArcadeWorldConfig = { + /** + * Sets {@link Phaser.Physics.Arcade.World#fps}. + */ + fps?: number; + /** + * Sets {@link Phaser.Physics.Arcade.World#fixedStep}. + */ + fixedStep?: boolean; + /** + * Sets {@link Phaser.Physics.Arcade.World#timeScale}. + */ + timeScale?: number; + /** + * Sets {@link Phaser.Physics.Arcade.World#gravity}. + */ + gravity?: Phaser.Types.Math.Vector2Like; + /** + * Sets {@link Phaser.Physics.Arcade.World#bounds bounds.x}. + */ + x?: number; + /** + * Sets {@link Phaser.Physics.Arcade.World#bounds bounds.y}. + */ + y?: number; + /** + * Sets {@link Phaser.Physics.Arcade.World#bounds bounds.width}. + */ + width?: number; + /** + * Sets {@link Phaser.Physics.Arcade.World#bounds bounds.height}. + */ + height?: number; + /** + * Sets {@link Phaser.Physics.Arcade.World#checkCollision}. + */ + checkCollision?: Phaser.Types.Physics.Arcade.CheckCollisionObject; + /** + * Sets {@link Phaser.Physics.Arcade.World#OVERLAP_BIAS}. + */ + overlapBias?: number; + /** + * Sets {@link Phaser.Physics.Arcade.World#TILE_BIAS}. + */ + tileBias?: number; + /** + * Sets {@link Phaser.Physics.Arcade.World#forceX}. + */ + forceX?: boolean; + /** + * Sets {@link Phaser.Physics.Arcade.World#isPaused}. + */ + isPaused?: boolean; + /** + * Sets {@link Phaser.Physics.Arcade.World#debug}. + */ + debug?: boolean; + /** + * Sets {@link Phaser.Physics.Arcade.World#defaults debugShowBody}. + */ + debugShowBody?: boolean; + /** + * Sets {@link Phaser.Physics.Arcade.World#defaults debugShowStaticBody}. + */ + debugShowStaticBody?: boolean; + /** + * Sets {@link Phaser.Physics.Arcade.World#defaults debugShowStaticBody}. + */ + debugShowVelocity?: boolean; + /** + * Sets {@link Phaser.Physics.Arcade.World#defaults bodyDebugColor}. + */ + debugBodyColor?: number; + /** + * Sets {@link Phaser.Physics.Arcade.World#defaults staticBodyDebugColor}. + */ + debugStaticBodyColor?: number; + /** + * Sets {@link Phaser.Physics.Arcade.World#defaults velocityDebugColor}. + */ + debugVelocityColor?: number; + /** + * Sets {@link Phaser.Physics.Arcade.World#maxEntries}. + */ + maxEntries?: number; + /** + * Sets {@link Phaser.Physics.Arcade.World#useTree}. + */ + useTree?: boolean; + /** + * If enabled, you need to call `World.update` yourself. + */ + customUpdate?: boolean; + }; + + type ArcadeWorldDefaults = { + /** + * Set to `true` to render dynamic body outlines to the debug display. + */ + debugShowBody: boolean; + /** + * Set to `true` to render static body outlines to the debug display. + */ + debugShowStaticBody: boolean; + /** + * Set to `true` to render body velocity markers to the debug display. + */ + debugShowVelocity: boolean; + /** + * The color of dynamic body outlines when rendered to the debug display. + */ + bodyDebugColor: number; + /** + * The color of static body outlines when rendered to the debug display. + */ + staticBodyDebugColor: number; + /** + * The color of the velocity markers when rendered to the debug display. + */ + velocityDebugColor: number; + }; + + type ArcadeWorldTreeMinMax = { + /** + * The minimum x value used in RTree searches. + */ + minX: number; + /** + * The minimum y value used in RTree searches. + */ + minY: number; + /** + * The maximum x value used in RTree searches. + */ + maxX: number; + /** + * The maximum y value used in RTree searches. + */ + maxY: number; + }; + + type CheckCollisionObject = { + /** + * Will bodies collide with the top side of the world bounds? + */ + up: boolean; + /** + * Will bodies collide with the bottom side of the world bounds? + */ + down: boolean; + /** + * Will bodies collide with the left side of the world bounds? + */ + left: boolean; + /** + * Will bodies collide with the right side of the world bounds? + */ + right: boolean; + }; - /** - * Clears all tint values associated with this Game Object. - * - * Immediately sets the color values back to 0xffffff and the tint type to 'additive', - * which results in no visible change to the texture. - */ - clearTint(): this; + type GameObjectWithBody = Phaser.GameObjects.GameObject & { + body: Phaser.Physics.Arcade.Body | Phaser.Physics.Arcade.StaticBody; + }; - /** - * Sets an additive tint on this Game Object. - * - * The tint works by taking the pixel color values from the Game Objects texture, and then - * multiplying it by the color value of the tint. You can provide either one color value, - * in which case the whole Game Object will be tinted in that color. Or you can provide a color - * per corner. The colors are blended together across the extent of the Game Object. - * - * To modify the tint color once set, either call this method again with new values or use the - * `tint` property to set all colors at once. Or, use the properties `tintTopLeft`, `tintTopRight, - * `tintBottomLeft` and `tintBottomRight` to set the corner color values independently. - * - * To remove a tint call `clearTint`. - * - * To swap this from being an additive tint to a fill based tint set the property `tintFill` to `true`. - * @param topLeft The tint being applied to the top-left of the Game Object. If no other values are given this value is applied evenly, tinting the whole Game Object. Default 0xffffff. - * @param topRight The tint being applied to the top-right of the Game Object. - * @param bottomLeft The tint being applied to the bottom-left of the Game Object. - * @param bottomRight The tint being applied to the bottom-right of the Game Object. - */ - setTint(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; + type GameObjectWithDynamicBody = Phaser.GameObjects.GameObject & { + body: Phaser.Physics.Arcade.Body; + }; - /** - * Sets a fill-based tint on this Game Object. - * - * Unlike an additive tint, a fill-tint literally replaces the pixel colors from the texture - * with those in the tint. You can use this for effects such as making a player flash 'white' - * if hit by something. You can provide either one color value, in which case the whole - * Game Object will be rendered in that color. Or you can provide a color per corner. The colors - * are blended together across the extent of the Game Object. - * - * To modify the tint color once set, either call this method again with new values or use the - * `tint` property to set all colors at once. Or, use the properties `tintTopLeft`, `tintTopRight, - * `tintBottomLeft` and `tintBottomRight` to set the corner color values independently. - * - * To remove a tint call `clearTint`. - * - * To swap this from being a fill-tint to an additive tint set the property `tintFill` to `false`. - * @param topLeft The tint being applied to the top-left of the Game Object. If not other values are given this value is applied evenly, tinting the whole Game Object. Default 0xffffff. - * @param topRight The tint being applied to the top-right of the Game Object. - * @param bottomLeft The tint being applied to the bottom-left of the Game Object. - * @param bottomRight The tint being applied to the bottom-right of the Game Object. - */ - setTintFill(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; + type GameObjectWithStaticBody = Phaser.GameObjects.GameObject & { + body: Phaser.Physics.Arcade.StaticBody; + }; - /** - * The tint value being applied to the top-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintTopLeft: integer; + type ImageWithDynamicBody = Phaser.Physics.Arcade.Image & { + body: Phaser.Physics.Arcade.Body; + }; - /** - * The tint value being applied to the top-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintTopRight: integer; + type ImageWithStaticBody = Phaser.Physics.Arcade.Image & { + body: Phaser.Physics.Arcade.StaticBody; + }; - /** - * The tint value being applied to the bottom-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintBottomLeft: integer; + type PhysicsGroupConfig = Phaser.Types.GameObjects.Group.GroupConfig & { + /** + * Sets {@link Phaser.Physics.Arcade.Body#collideWorldBounds}. + */ + collideWorldBounds?: boolean; + /** + * Sets {@link Phaser.Physics.Arcade.Body#setBoundsRectangle setBoundsRectangle}. + */ + customBoundsRectangle?: Phaser.Geom.Rectangle; + /** + * Sets {@link Phaser.Physics.Arcade.Body#acceleration acceleration.x}. + */ + accelerationX?: number; + /** + * Sets {@link Phaser.Physics.Arcade.Body#acceleration acceleration.y}. + */ + accelerationY?: number; + /** + * Sets {@link Phaser.Physics.Arcade.Body#allowDrag}. + */ + allowDrag?: boolean; + /** + * Sets {@link Phaser.Physics.Arcade.Body#allowGravity}. + */ + allowGravity?: boolean; + /** + * Sets {@link Phaser.Physics.Arcade.Body#allowRotation}. + */ + allowRotation?: boolean; + /** + * Sets {@link Phaser.Physics.Arcade.Body#bounce bounce.x}. + */ + bounceX?: number; + /** + * Sets {@link Phaser.Physics.Arcade.Body#bounce bounce.y}. + */ + bounceY?: number; + /** + * Sets {@link Phaser.Physics.Arcade.Body#drag drag.x}. + */ + dragX?: number; + /** + * Sets {@link Phaser.Physics.Arcade.Body#drag drag.y}. + */ + dragY?: number; + /** + * Sets {@link Phaser.Physics.Arcade.Body#enable enable}. + */ + enable?: boolean; + /** + * Sets {@link Phaser.Physics.Arcade.Body#gravity gravity.x}. + */ + gravityX?: number; + /** + * Sets {@link Phaser.Physics.Arcade.Body#gravity gravity.y}. + */ + gravityY?: number; + /** + * Sets {@link Phaser.Physics.Arcade.Body#friction friction.x}. + */ + frictionX?: number; + /** + * Sets {@link Phaser.Physics.Arcade.Body#friction friction.y}. + */ + frictionY?: number; + /** + * Sets {@link Phaser.Physics.Arcade.Body#maxVelocity maxVelocity.x}. + */ + maxVelocityX?: number; + /** + * Sets {@link Phaser.Physics.Arcade.Body#maxVelocity maxVelocity.y}. + */ + maxVelocityY?: number; + /** + * Sets {@link Phaser.Physics.Arcade.Body#velocity velocity.x}. + */ + velocityX?: number; + /** + * Sets {@link Phaser.Physics.Arcade.Body#velocity velocity.y}. + */ + velocityY?: number; + /** + * Sets {@link Phaser.Physics.Arcade.Body#angularVelocity}. + */ + angularVelocity?: number; + /** + * Sets {@link Phaser.Physics.Arcade.Body#angularAcceleration}. + */ + angularAcceleration?: number; + /** + * Sets {@link Phaser.Physics.Arcade.Body#angularDrag}. + */ + angularDrag?: number; + /** + * Sets {@link Phaser.Physics.Arcade.Body#mass}. + */ + mass?: number; + /** + * Sets {@link Phaser.Physics.Arcade.Body#immovable}. + */ + immovable?: boolean; + }; - /** - * The tint value being applied to the bottom-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintBottomRight: integer; + type PhysicsGroupDefaults = { + /** + * As {@link Phaser.Physics.Arcade.Body#setCollideWorldBounds}. + */ + setCollideWorldBounds: boolean; + /** + * As {@link Phaser.Physics.Arcade.Body#setBoundsRectangle}. + */ + setBoundsRectangle: Phaser.Geom.Rectangle; + /** + * As {@link Phaser.Physics.Arcade.Body#setAccelerationX}. + */ + setAccelerationX: number; + /** + * As {@link Phaser.Physics.Arcade.Body#setAccelerationY}. + */ + setAccelerationY: number; + /** + * As {@link Phaser.Physics.Arcade.Body#setAllowDrag}. + */ + setAllowDrag: boolean; + /** + * As {@link Phaser.Physics.Arcade.Body#setAllowGravity}. + */ + setAllowGravity: boolean; + /** + * As {@link Phaser.Physics.Arcade.Body#setAllowRotation}. + */ + setAllowRotation: boolean; + /** + * As {@link Phaser.Physics.Arcade.Body#setBounceX}. + */ + setBounceX: number; + /** + * As {@link Phaser.Physics.Arcade.Body#setBounceY}. + */ + setBounceY: number; + /** + * As {@link Phaser.Physics.Arcade.Body#setDragX}. + */ + setDragX: number; + /** + * As {@link Phaser.Physics.Arcade.Body#setDragY}. + */ + setDragY: number; + /** + * As {@link Phaser.Physics.Arcade.Body#setEnable}. + */ + setEnable: boolean; + /** + * As {@link Phaser.Physics.Arcade.Body#setGravityX}. + */ + setGravityX: number; + /** + * As {@link Phaser.Physics.Arcade.Body#setGravityY}. + */ + setGravityY: number; + /** + * As {@link Phaser.Physics.Arcade.Body#setFrictionX}. + */ + setFrictionX: number; + /** + * As {@link Phaser.Physics.Arcade.Body#setFrictionY}. + */ + setFrictionY: number; + /** + * As {@link Phaser.Physics.Arcade.Body#setVelocityX}. + */ + setVelocityX: number; + /** + * As {@link Phaser.Physics.Arcade.Body#setVelocityY}. + */ + setVelocityY: number; + /** + * As {@link Phaser.Physics.Arcade.Body#setAngularVelocity}. + */ + setAngularVelocity: number; + /** + * As {@link Phaser.Physics.Arcade.Body#setAngularAcceleration}. + */ + setAngularAcceleration: number; + /** + * As {@link Phaser.Physics.Arcade.Body#setAngularDrag}. + */ + setAngularDrag: number; + /** + * As {@link Phaser.Physics.Arcade.Body#setMass}. + */ + setMass: number; + /** + * As {@link Phaser.Physics.Arcade.Body#setImmovable}. + */ + setImmovable: boolean; + }; - /** - * The tint value being applied to the whole of the Game Object. - * This property is a setter-only. Use the properties `tintTopLeft` etc to read the current tint value. - */ - tint: integer; + type SpriteWithDynamicBody = Phaser.Physics.Arcade.Sprite & { + body: Phaser.Physics.Arcade.Body; + }; - /** - * Does this Game Object have a tint applied to it or not? - */ - readonly isTinted: boolean; + type SpriteWithStaticBody = Phaser.Physics.Arcade.Sprite & { + body: Phaser.Physics.Arcade.StaticBody; + }; - /** - * The x position of this Game Object. - */ - x: number; + } - /** - * The y position of this Game Object. - */ - y: number; + namespace Matter { + type MatterBody = MatterJS.BodyType | Phaser.GameObjects.GameObject | Phaser.Physics.Matter.Image | Phaser.Physics.Matter.Sprite | Phaser.Physics.Matter.TileBody; - /** - * The z position of this Game Object. - * - * Note: The z position does not control the rendering order of 2D Game Objects. Use - * {@link Phaser.GameObjects.Components.Depth#depth} instead. - */ - z: number; + type MatterBodyConfig = { + /** + * An arbitrary string-based name to help identify this body. + */ + label?: string; + /** + * An array of bodies that make up this body. The first body in the array must always be a self reference to the current body instance. All bodies in the `parts` array together form a single rigid compound body. + */ + parts?: MatterJS.BodyType[]; + /** + * An object reserved for storing plugin-specific properties. + */ + plugin?: any; + /** + * A number specifying the angle of the body, in radians. + */ + angle?: number; + /** + * An array of `Vector` objects that specify the convex hull of the rigid body. These should be provided about the origin `(0, 0)`. + */ + vertices?: Phaser.Types.Math.Vector2Like[]; + /** + * A `Vector` that specifies the current world-space position of the body. + */ + position?: Phaser.Types.Math.Vector2Like; + /** + * A `Vector` that specifies the force to apply in the current step. It is zeroed after every `Body.update`. See also `Body.applyForce`. + */ + force?: Phaser.Types.Math.Vector2Like; + /** + * A `Number` that specifies the torque (turning force) to apply in the current step. It is zeroed after every `Body.update`. + */ + torque?: number; + /** + * A flag that indicates whether a body is a sensor. Sensor triggers collision events, but doesn't react with colliding body physically. + */ + isSensor?: boolean; + /** + * A flag that indicates whether a body is considered static. A static body can never change position or angle and is completely fixed. + */ + isStatic?: boolean; + /** + * A `Number` that defines the number of updates in which this body must have near-zero velocity before it is set as sleeping by the `Matter.Sleeping` module (if sleeping is enabled by the engine). + */ + sleepThreshold?: number; + /** + * A `Number` that defines the density of the body, that is its mass per unit area. If you pass the density via `Body.create` the `mass` property is automatically calculated for you based on the size (area) of the object. This is generally preferable to simply setting mass and allows for more intuitive definition of materials (e.g. rock has a higher density than wood). + */ + density?: number; + /** + * A `Number` that defines the restitution (elasticity) of the body. The value is always positive and is in the range `(0, 1)`. + */ + restitution?: number; + /** + * A `Number` that defines the friction of the body. The value is always positive and is in the range `(0, 1)`. A value of `0` means that the body may slide indefinitely. A value of `1` means the body may come to a stop almost instantly after a force is applied. + */ + friction?: number; + /** + * A `Number` that defines the static friction of the body (in the Coulomb friction model). A value of `0` means the body will never 'stick' when it is nearly stationary and only dynamic `friction` is used. The higher the value (e.g. `10`), the more force it will take to initially get the body moving when nearly stationary. This value is multiplied with the `friction` property to make it easier to change `friction` and maintain an appropriate amount of static friction. + */ + frictionStatic?: number; + /** + * A `Number` that defines the air friction of the body (air resistance). A value of `0` means the body will never slow as it moves through space. The higher the value, the faster a body slows when moving through space. + */ + frictionAir?: number; + /** + * An `Object` that specifies the collision filtering properties of this body. + */ + collisionFilter?: Phaser.Types.Physics.Matter.MatterCollisionFilter; + /** + * A `Number` that specifies a tolerance on how far a body is allowed to 'sink' or rotate into other bodies. Avoid changing this value unless you understand the purpose of `slop` in physics engines. The default should generally suffice, although very large bodies may require larger values for stable stacking. + */ + slop?: number; + /** + * A `Number` that allows per-body time scaling, e.g. a force-field where bodies inside are in slow-motion, while others are at full speed. + */ + timeScale?: number; + /** + * A number, or array of numbers, to chamfer the vertices of the body, or a full Chamfer configuration object. + */ + chamfer?: number | number[] | Phaser.Types.Physics.Matter.MatterChamferConfig; + /** + * The radius of this body if a circle. + */ + circleRadius?: number; + /** + * A `Number` that defines the mass of the body, although it may be more appropriate to specify the `density` property instead. If you modify this value, you must also modify the `body.inverseMass` property (`1 / mass`). + */ + mass?: number; + /** + * A `Number` that defines the inverse mass of the body (`1 / mass`). If you modify this value, you must also modify the `body.mass` property. + */ + inverseMass?: number; + /** + * A `Vector` that specifies the initial scale of the body. + */ + scale?: Phaser.Types.Math.Vector2Like; + /** + * A `Vector` that scales the influence of World gravity when applied to this body. + */ + gravityScale?: Phaser.Types.Math.Vector2Like; + /** + * A boolean that toggles if this body should ignore world gravity or not. + */ + ignoreGravity?: boolean; + /** + * A boolean that toggles if this body should ignore pointer / mouse constraints or not. + */ + ignorePointer?: boolean; + /** + * The Debug Render configuration object for this body. + */ + render?: Phaser.Types.Physics.Matter.MatterBodyRenderConfig; + /** + * A callback that is invoked when this Body starts colliding with any other Body. You can register callbacks by providing a function of type `( pair: Matter.Pair) => void`. + */ + onCollideCallback?: Function; + /** + * A callback that is invoked when this Body stops colliding with any other Body. You can register callbacks by providing a function of type `( pair: Matter.Pair) => void`. + */ + onCollideEndCallback?: Function; + /** + * A callback that is invoked for the duration that this Body is colliding with any other Body. You can register callbacks by providing a function of type `( pair: Matter.Pair) => void`. + */ + onCollideActiveCallback?: Function; + /** + * A collision callback dictionary used by the `Body.setOnCollideWith` function. + */ + onCollideWith?: any; + }; - /** - * The w position of this Game Object. - */ - w: number; + type MatterBodyRenderConfig = { + /** + * Should this body be rendered by the Debug Renderer? + */ + visible?: boolean; + /** + * The opacity of the body and all parts within it. + */ + opacity?: number; + /** + * The color value of the fill when rendering this body. + */ + fillColor?: number; + /** + * The opacity of the fill when rendering this body, a value between 0 and 1. + */ + fillOpacity?: number; + /** + * The color value of the line stroke when rendering this body. + */ + lineColor?: number; + /** + * The opacity of the line when rendering this body, a value between 0 and 1. + */ + lineOpacity?: number; + /** + * If rendering lines, the thickness of the line. + */ + lineThickness?: number; + /** + * Controls the offset between the body and the parent Game Object, if it has one. + */ + sprite?: object; + /** + * The horizontal offset between the body and the parent Game Object texture, if it has one. + */ + "sprite.xOffset"?: number; + /** + * The vertical offset between the body and the parent Game Object texture, if it has one. + */ + "sprite.yOffset"?: number; + }; - /** - * This is a special setter that allows you to set both the horizontal and vertical scale of this Game Object - * to the same value, at the same time. When reading this value the result returned is `(scaleX + scaleY) / 2`. - * - * Use of this property implies you wish the horizontal and vertical scales to be equal to each other. If this - * isn't the case, use the `scaleX` or `scaleY` properties instead. - */ - scale: number; + type MatterBodyTileOptions = { + /** + * Whether or not the newly created body should be made static. This defaults to true since typically tiles should not be moved. + */ + isStatic?: boolean; + /** + * Whether or not to add the newly created body (or existing body if options.body is used) to the Matter world. + */ + addToWorld?: boolean; + }; - /** - * The horizontal scale of this Game Object. - */ - scaleX: number; + type MatterChamferConfig = { + /** + * A single number, or an array, to specify the radius for each vertex. + */ + radius?: number | number[]; + /** + * The quality of the chamfering. -1 means 'auto'. + */ + quality?: number; + /** + * The minimum quality of the chamfering. The higher this value, the more vertices are created. + */ + qualityMin?: number; + /** + * The maximum quality of the chamfering. The higher this value, the more vertices are created. + */ + qualityMax?: number; + }; - /** - * The vertical scale of this Game Object. - */ - scaleY: number; + type MatterCollisionData = { + /** + * Have the pair collided or not? + */ + collided: boolean; + /** + * A reference to the first body involved in the collision. + */ + bodyA: MatterJS.BodyType; + /** + * A reference to the second body involved in the collision. + */ + bodyB: MatterJS.BodyType; + /** + * A reference to the dominant axis body. + */ + axisBody: MatterJS.BodyType; + /** + * The index of the dominant collision axis vector (edge normal) + */ + axisNumber: number; + /** + * The depth of the collision on the minimum overlap. + */ + depth: number; + /** + * A reference to the parent of Body A, or to Body A itself if it has no parent. + */ + parentA: MatterJS.BodyType; + /** + * A reference to the parent of Body B, or to Body B itself if it has no parent. + */ + parentB: MatterJS.BodyType; + /** + * The collision normal, facing away from Body A. + */ + normal: MatterJS.Vector; + /** + * The tangent of the collision normal. + */ + tangent: MatterJS.Vector; + /** + * The penetration distances between the two bodies. + */ + penetration: MatterJS.Vector; + /** + * An array of support points, either exactly one or two points. + */ + supports: MatterJS.Vector[]; + /** + * The resulting inverse mass from the collision. + */ + inverseMass: number; + /** + * The resulting friction from the collision. + */ + friction: number; + /** + * The resulting static friction from the collision. + */ + frictionStatic: number; + /** + * The resulting restitution from the collision. + */ + restitution: number; + /** + * The resulting slop from the collision. + */ + slop: number; + }; /** - * The angle of this Game Object as expressed in degrees. + * An `Object` that specifies the collision filtering properties of this body. * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Collisions between two bodies will obey the following rules: + * - If the two bodies have the same non-zero value of `collisionFilter.group`, + * they will always collide if the value is positive, and they will never collide + * if the value is negative. + * - If the two bodies have different values of `collisionFilter.group` or if one + * (or both) of the bodies has a value of 0, then the category/mask rules apply as follows: * - * If you prefer to work in radians, see the `rotation` property instead. - */ - angle: integer; - - /** - * The angle of this Game Object in radians. + * Each body belongs to a collision category, given by `collisionFilter.category`. This + * value is used as a bit field and the category should have only one bit set, meaning that + * the value of this property is a power of two in the range [1, 2^31]. Thus, there are 32 + * different collision categories available. * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Each body also defines a collision bitmask, given by `collisionFilter.mask` which specifies + * the categories it collides with (the value is the bitwise AND value of all these categories). * - * If you prefer to work in degrees, see the `angle` property instead. + * Using the category/mask rules, two bodies `A` and `B` collide if each includes the other's + * category in its mask, i.e. `(categoryA & maskB) !== 0` and `(categoryB & maskA) !== 0` + * are both true. */ - rotation: number; + type MatterCollisionFilter = { + /** + * A bit field that specifies the collision category this body belongs to. The category value should have only one bit set, for example `0x0001`. This means there are up to 32 unique collision categories available. + */ + category?: number; + /** + * A bit mask that specifies the collision categories this body may collide with. + */ + mask?: number; + /** + * An Integer `Number`, that specifies the collision group this body belongs to. + */ + group?: number; + }; - /** - * Sets the position of this Game Object. - * @param x The x position of this Game Object. Default 0. - * @param y The y position of this Game Object. If not set it will use the `x` value. Default x. - * @param z The z position of this Game Object. Default 0. - * @param w The w position of this Game Object. Default 0. - */ - setPosition(x?: number, y?: number, z?: number, w?: number): this; + type MatterCollisionPair = { + /** + * The unique auto-generated collision pair id. A combination of the body A and B IDs. + */ + id: string; + /** + * A reference to the first body involved in the collision. + */ + bodyA: MatterJS.BodyType; + /** + * A reference to the second body involved in the collision. + */ + bodyB: MatterJS.BodyType; + /** + * An array containing all of the active contacts between bodies A and B. + */ + activeContacts: MatterJS.Vector[]; + /** + * The amount of separation that occured between bodies A and B. + */ + separation: number; + /** + * Is the collision still active or not? + */ + isActive: boolean; + /** + * Has Matter determined the collision are being active yet? + */ + confirmedActive: boolean; + /** + * Is either body A or B a sensor? + */ + isSensor: boolean; + /** + * The timestamp when the collision pair was created. + */ + timeCreated: number; + /** + * The timestamp when the collision pair was most recently updated. + */ + timeUpdated: number; + /** + * The collision data object. + */ + collision: Phaser.Types.Physics.Matter.MatterCollisionData; + /** + * The resulting inverse mass from the collision. + */ + inverseMass: number; + /** + * The resulting friction from the collision. + */ + friction: number; + /** + * The resulting static friction from the collision. + */ + frictionStatic: number; + /** + * The resulting restitution from the collision. + */ + restitution: number; + /** + * The resulting slop from the collision. + */ + slop: number; + }; - /** - * Sets the position of this Game Object to be a random position within the confines of - * the given area. - * - * If no area is specified a random position between 0 x 0 and the game width x height is used instead. - * - * The position does not factor in the size of this Game Object, meaning that only the origin is - * guaranteed to be within the area. - * @param x The x position of the top-left of the random area. Default 0. - * @param y The y position of the top-left of the random area. Default 0. - * @param width The width of the random area. - * @param height The height of the random area. - */ - setRandomPosition(x?: number, y?: number, width?: number, height?: number): this; + type MatterConstraintConfig = { + /** + * An arbitrary string-based name to help identify this constraint. + */ + label?: string; + /** + * The first possible `Body` that this constraint is attached to. + */ + bodyA?: MatterJS.BodyType; + /** + * The second possible `Body` that this constraint is attached to. + */ + bodyB?: MatterJS.BodyType; + /** + * A `Vector` that specifies the offset of the constraint from center of the `constraint.bodyA` if defined, otherwise a world-space position. + */ + pointA?: Phaser.Types.Math.Vector2Like; + /** + * A `Vector` that specifies the offset of the constraint from center of the `constraint.bodyB` if defined, otherwise a world-space position. + */ + pointB?: Phaser.Types.Math.Vector2Like; + /** + * A `Number` that specifies the stiffness of the constraint, i.e. the rate at which it returns to its resting `constraint.length`. A value of `1` means the constraint should be very stiff. A value of `0.2` means the constraint acts like a soft spring. + */ + stiffness?: number; + /** + * A `Number` that specifies the angular stiffness of the constraint. + */ + angularStiffness?: number; + /** + * The angleA of the constraint. If bodyA is set, the angle of bodyA is used instead. + */ + angleA?: number; + /** + * The angleB of the constraint. If bodyB is set, the angle of bodyB is used instead. + */ + angleB?: number; + /** + * A `Number` that specifies the damping of the constraint, i.e. the amount of resistance applied to each body based on their velocities to limit the amount of oscillation. Damping will only be apparent when the constraint also has a very low `stiffness`. A value of `0.1` means the constraint will apply heavy damping, resulting in little to no oscillation. A value of `0` means the constraint will apply no damping. + */ + damping?: number; + /** + * A `Number` that specifies the target resting length of the constraint. It is calculated automatically in `Constraint.create` from initial positions of the `constraint.bodyA` and `constraint.bodyB`. + */ + length?: number; + /** + * An object reserved for storing plugin-specific properties. + */ + plugin?: any; + /** + * The Debug Render configuration object for this constraint. + */ + render?: Phaser.Types.Physics.Matter.MatterConstraintRenderConfig; + }; - /** - * Sets the rotation of this Game Object. - * @param radians The rotation of this Game Object, in radians. Default 0. - */ - setRotation(radians?: number): this; + type MatterConstraintRenderConfig = { + /** + * Should this constraint be rendered by the Debug Renderer? + */ + visible?: boolean; + /** + * If this constraint has anchors, should they be rendered? Pin constraints never have anchors. + */ + anchors?: boolean; + /** + * The color value of the line stroke when rendering this constraint. + */ + lineColor?: number; + /** + * The opacity of the line when rendering this constraint, a value between 0 and 1. + */ + lineOpacity?: number; + /** + * If rendering lines, the thickness of the line. + */ + lineThickness?: number; + /** + * The size of the circles drawn when rendering pin constraints. + */ + pinSize?: number; + /** + * The size of the circles drawn as the constraint anchors. + */ + anchorSize?: number; + /** + * The color value of constraint anchors. + */ + anchorColor?: number; + }; - /** - * Sets the angle of this Game Object. - * @param degrees The rotation of this Game Object, in degrees. Default 0. - */ - setAngle(degrees?: number): this; + type MatterDebugConfig = { + /** + * Render all of the body axes? + */ + showAxes?: boolean; + /** + * Render just a single body axis? + */ + showAngleIndicator?: boolean; + /** + * The color of the body angle / axes lines. + */ + angleColor?: number; + /** + * Render the broadphase grid? + */ + showBroadphase?: boolean; + /** + * The color of the broadphase grid. + */ + broadphaseColor?: number; + /** + * Render the bounds of the bodies in the world? + */ + showBounds?: boolean; + /** + * The color of the body bounds. + */ + boundsColor?: number; + /** + * Render the velocity of the bodies in the world? + */ + showVelocity?: boolean; + /** + * The color of the body velocity line. + */ + velocityColor?: number; + /** + * Render the collision points and normals for colliding pairs. + */ + showCollisions?: boolean; + /** + * The color of the collision points. + */ + collisionColor?: number; + /** + * Render lines showing the separation between bodies. + */ + showSeparation?: boolean; + /** + * The color of the body separation line. + */ + separationColor?: number; + /** + * Render the dynamic bodies in the world to the Graphics object? + */ + showBody?: boolean; + /** + * Render the static bodies in the world to the Graphics object? + */ + showStaticBody?: boolean; + /** + * When rendering bodies, render the internal edges as well? + */ + showInternalEdges?: boolean; + /** + * Render the bodies using a fill color. + */ + renderFill?: boolean; + /** + * Render the bodies using a line stroke. + */ + renderLine?: boolean; + /** + * The color value of the fill when rendering dynamic bodies. + */ + fillColor?: number; + /** + * The opacity of the fill when rendering dynamic bodies, a value between 0 and 1. + */ + fillOpacity?: number; + /** + * The color value of the line stroke when rendering dynamic bodies. + */ + lineColor?: number; + /** + * The opacity of the line when rendering dynamic bodies, a value between 0 and 1. + */ + lineOpacity?: number; + /** + * If rendering lines, the thickness of the line. + */ + lineThickness?: number; + /** + * The color value of the fill when rendering static bodies. + */ + staticFillColor?: number; + /** + * The color value of the line stroke when rendering static bodies. + */ + staticLineColor?: number; + /** + * Render any sleeping bodies (dynamic or static) in the world to the Graphics object? + */ + showSleeping?: boolean; + /** + * The amount to multiply the opacity of sleeping static bodies by. + */ + staticBodySleepOpacity?: number; + /** + * The color value of the fill when rendering sleeping dynamic bodies. + */ + sleepFillColor?: number; + /** + * The color value of the line stroke when rendering sleeping dynamic bodies. + */ + sleepLineColor?: number; + /** + * Render bodies or body parts that are flagged as being a sensor? + */ + showSensors?: boolean; + /** + * The fill color when rendering body sensors. + */ + sensorFillColor?: number; + /** + * The line color when rendering body sensors. + */ + sensorLineColor?: number; + /** + * Render the position of non-static bodies? + */ + showPositions?: boolean; + /** + * The size of the rectangle drawn when rendering the body position. + */ + positionSize?: number; + /** + * The color value of the rectangle drawn when rendering the body position. + */ + positionColor?: number; + /** + * Render all world constraints to the Graphics object? + */ + showJoint?: boolean; + /** + * The color value of joints when `showJoint` is set. + */ + jointColor?: number; + /** + * The line opacity when rendering joints, a value between 0 and 1. + */ + jointLineOpacity?: number; + /** + * The line thickness when rendering joints. + */ + jointLineThickness?: number; + /** + * The size of the circles drawn when rendering pin constraints. + */ + pinSize?: number; + /** + * The color value of the circles drawn when rendering pin constraints. + */ + pinColor?: number; + /** + * The color value of spring constraints. + */ + springColor?: number; + /** + * The color value of constraint anchors. + */ + anchorColor?: number; + /** + * The size of the circles drawn as the constraint anchors. + */ + anchorSize?: number; + /** + * When rendering polygon bodies, render the convex hull as well? + */ + showConvexHulls?: boolean; + /** + * The color value of hulls when `showConvexHulls` is set. + */ + hullColor?: number; + }; - /** - * Sets the scale of this Game Object. - * @param x The horizontal scale of this Game Object. - * @param y The vertical scale of this Game Object. If not set it will use the `x` value. Default x. - */ - setScale(x: number, y?: number): this; + type MatterRunnerConfig = { + /** + * A boolean that specifies if the runner should use a fixed timestep (otherwise it is variable). If timing is fixed, then the apparent simulation speed will change depending on the frame rate (but behaviour will be deterministic). If the timing is variable, then the apparent simulation speed will be constant (approximately, but at the cost of determininism). + */ + isFixed?: boolean; + /** + * A number that specifies the frame rate in seconds. If you don't specify this, but do specify `delta`, those values set the fps rate. + */ + fps?: number; + /** + * A number that specifies the time correction factor to apply to the update. This can help improve the accuracy of the simulation in cases where delta is changing between updates. + */ + correction?: number; + /** + * The size of the delta smoothing array when `isFixed` is `false`. + */ + deltaSampleSize?: number; + /** + * A number that specifies the time step between updates in milliseconds. If you set the `fps` property, this value is set based on that. If `isFixed` is set to `true`, then `delta` is fixed. If it is `false`, then `delta` can dynamically change to maintain the correct apparent simulation speed. + */ + delta?: number; + /** + * A number that specifies the minimum time step between updates in milliseconds. + */ + deltaMin?: number; + /** + * A number that specifies the maximum time step between updates in milliseconds. + */ + deltaMax?: number; + }; - /** - * Sets the x position of this Game Object. - * @param value The x position of this Game Object. Default 0. - */ - setX(value?: number): this; + type MatterSetBodyConfig = { + /** + * The shape type. Either `rectangle`, `circle`, `trapezoid`, `polygon`, `fromVertices`, `fromVerts` or `fromPhysicsEditor`. + */ + type?: string; + /** + * The horizontal world position to place the body at. + */ + x?: number; + /** + * The vertical world position to place the body at. + */ + y?: number; + /** + * The width of the body. + */ + width?: number; + /** + * The height of the body. + */ + height?: number; + /** + * The radius of the body. Used by `circle` and `polygon` shapes. + */ + radius?: number; + /** + * The max sizes of the body. Used by the `circle` shape. + */ + maxSides?: number; + /** + * Used by the `trapezoid` shape. The slope of the trapezoid. 0 creates a rectangle, while 1 creates a triangle. Positive values make the top side shorter, while negative values make the bottom side shorter. + */ + slope?: number; + /** + * Used by the `polygon` shape. The number of sides the polygon will have. + */ + sides?: number; + /** + * Used by the `fromVerts` shape. The vertices data. Either a path string or an array of vertices. + */ + verts?: string | any[]; + /** + * Used by the `fromVerts` shape. Flag internal edges (coincident part edges) + */ + flagInternal?: boolean; + /** + * Used by the `fromVerts` shape. Whether Matter.js will discard collinear edges (to improve performance). + */ + removeCollinear?: number; + /** + * Used by the `fromVerts` shape. During decomposition discard parts that have an area less than this. + */ + minimumArea?: number; + /** + * Should the new body be automatically added to the world? + */ + addToWorld?: boolean; + }; - /** - * Sets the y position of this Game Object. - * @param value The y position of this Game Object. Default 0. - */ - setY(value?: number): this; + type MatterTileOptions = { + /** + * An existing Matter body to be used instead of creating a new one. + */ + body?: MatterJS.BodyType; + /** + * Whether or not the newly created body should be made static. This defaults to true since typically tiles should not be moved. + */ + isStatic?: boolean; + /** + * Whether or not to add the newly created body (or existing body if options.body is used) to the Matter world. + */ + addToWorld?: boolean; + }; - /** - * Sets the z position of this Game Object. - * - * Note: The z position does not control the rendering order of 2D Game Objects. Use - * {@link Phaser.GameObjects.Components.Depth#setDepth} instead. - * @param value The z position of this Game Object. Default 0. - */ - setZ(value?: number): this; + type MatterWorldConfig = { + /** + * Sets {@link Phaser.Physics.Matter.World#gravity}. If `false` Gravity will be set to zero. + */ + gravity?: Phaser.Types.Math.Vector2Like | boolean; + /** + * Should the world have bounds enabled by default? + */ + setBounds?: object | boolean; + /** + * The x coordinate of the world bounds. + */ + "setBounds.x"?: number; + /** + * The y coordinate of the world bounds. + */ + "setBounds.y"?: number; + /** + * The width of the world bounds. + */ + "setBounds.width"?: number; + /** + * The height of the world bounds. + */ + "setBounds.height"?: number; + /** + * The thickness of the walls of the world bounds. + */ + "setBounds.thickness"?: number; + /** + * Should the left-side world bounds wall be created? + */ + "setBounds.left"?: boolean; + /** + * Should the right-side world bounds wall be created? + */ + "setBounds.right"?: boolean; + /** + * Should the top world bounds wall be created? + */ + "setBounds.top"?: boolean; + /** + * Should the bottom world bounds wall be created? + */ + "setBounds.bottom"?: boolean; + /** + * The number of position iterations to perform each update. The higher the value, the higher quality the simulation will be at the expense of performance. + */ + positionIterations?: number; + /** + * The number of velocity iterations to perform each update. The higher the value, the higher quality the simulation will be at the expense of performance. + */ + velocityIterations?: number; + /** + * The number of constraint iterations to perform each update. The higher the value, the higher quality the simulation will be at the expense of performance. + */ + constraintIterations?: number; + /** + * A flag that specifies whether the engine should allow sleeping via the `Matter.Sleeping` module. Sleeping can improve stability and performance, but often at the expense of accuracy. + */ + enableSleeping?: boolean; + /** + * A `Number` that specifies the current simulation-time in milliseconds starting from `0`. It is incremented on every `Engine.update` by the given `delta` argument. + */ + "timing.timestamp"?: number; + /** + * A `Number` that specifies the global scaling factor of time for all bodies. A value of `0` freezes the simulation. A value of `0.1` gives a slow-motion effect. A value of `1.2` gives a speed-up effect. + */ + "timing.timeScale"?: number; + /** + * Should the Matter Attractor Plugin be enabled? An attractors plugin that makes it easy to apply continual forces on bodies. It's possible to simulate effects such as wind, gravity and magnetism. + */ + "plugins.attractors"?: boolean; + /** + * Should the Matter Wrap Plugin be enabled? A coordinate wrapping plugin that automatically wraps the position of bodies such that they always stay within the given bounds. Upon crossing a boundary the body will appear on the opposite side of the bounds, while maintaining its velocity. + */ + "plugins.wrap"?: boolean; + /** + * Should the Matter Collision Events Plugin be enabled? + */ + "plugins.collisionevents"?: boolean; + /** + * Toggles if the world is enabled or not. + */ + enabled?: boolean; + /** + * An optional Number that specifies the time correction factor to apply to the update. + */ + correction?: number; + /** + * This function is called every time the core game loop steps, which is bound to the Request Animation Frame frequency unless otherwise modified. + */ + getDelta?: Function; + /** + * Automatically call Engine.update every time the game steps. + */ + autoUpdate?: boolean; + /** + * Sets the Resolver resting threshold property. + */ + restingThresh?: number; + /** + * Sets the Resolver resting threshold tangent property. + */ + restingThreshTangent?: number; + /** + * Sets the Resolver position dampen property. + */ + positionDampen?: number; + /** + * Sets the Resolver position warming property. + */ + positionWarming?: number; + /** + * Sets the Resolver friction normal multiplier property. + */ + frictionNormalMultiplier?: number; + /** + * Controls the Matter Debug Rendering options. If a boolean it will use the default values, otherwise, specify a Debug Config object. + */ + debug?: boolean | Phaser.Types.Physics.Matter.MatterDebugConfig; + /** + * Sets the Matter Runner options. + */ + runner?: Phaser.Types.Physics.Matter.MatterRunnerConfig; + }; - /** - * Sets the w position of this Game Object. - * @param value The w position of this Game Object. Default 0. - */ - setW(value?: number): this; + } - /** - * Gets the local transform matrix for this Game Object. - * @param tempMatrix The matrix to populate with the values from this Game Object. - */ - getLocalTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + } + namespace Plugins { + type CorePluginContainer = { /** - * Gets the world transform matrix for this Game Object, factoring in any parent Containers. - * @param tempMatrix The matrix to populate with the values from this Game Object. - * @param parentMatrix A temporary matrix to hold parent values during the calculations. + * The unique name of this plugin in the core plugin cache. */ - getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; - + key: string; /** - * Gets the sum total rotation of all of this Game Objects parent Containers. - * - * The returned value is in radians and will be zero if this Game Object has no parent container. + * The plugin to be stored. Should be the source object, not instantiated. */ - getParentRotation(): number; - + plugin: Function; /** - * The visible state of the Game Object. - * - * An invisible Game Object will skip rendering, but will still process update logic. + * If this plugin is to be injected into the Scene Systems, this is the property key map used. */ - visible: boolean; - + mapping?: string; /** - * Sets the visibility of this Game Object. - * - * An invisible Game Object will skip rendering, but will still process update logic. - * @param value The visible state of the Game Object. + * Core Scene plugin or a Custom Scene plugin? */ - setVisible(value: boolean): this; + custom?: boolean; + }; + type CustomPluginContainer = { /** - * Sets the body's horizontal and vertical acceleration. If the vertical acceleration value is not provided, the vertical acceleration is set to the same value as the horizontal acceleration. - * @param x The horizontal acceleration - * @param y The vertical acceleration Default x. + * The unique name of this plugin in the custom plugin cache. */ - setAcceleration(x: number, y?: number): this; - + key: string; /** - * Sets the body's horizontal acceleration. - * @param value The horizontal acceleration + * The plugin to be stored. Should be the source object, not instantiated. */ - setAccelerationX(value: number): this; + plugin: Function; + }; + type GlobalPlugin = { /** - * Sets the body's vertical acceleration. - * @param value The vertical acceleration + * The unique name of this plugin within the plugin cache. */ - setAccelerationY(value: number): this; - + key: string; /** - * Sets the angular velocity of the body. - * - * In Arcade Physics, bodies cannot rotate. They are always axis-aligned. - * However, they can have angular motion, which is passed on to the Game Object bound to the body, - * causing them to visually rotate, even though the body remains axis-aligned. - * @param value The amount of angular velocity. + * An instance of the plugin. */ - setAngularVelocity(value: number): this; - + plugin: Function; /** - * Sets the angular acceleration of the body. - * - * In Arcade Physics, bodies cannot rotate. They are always axis-aligned. - * However, they can have angular motion, which is passed on to the Game Object bound to the body, - * causing them to visually rotate, even though the body remains axis-aligned. - * @param value The amount of angular acceleration. + * Is the plugin active or not? */ - setAngularAcceleration(value: number): this; - + active?: boolean; /** - * Sets the angular drag of the body. Drag is applied to the current velocity, providing a form of deceleration. - * @param value The amount of drag. + * If this plugin is to be injected into the Scene Systems, this is the property key map used. */ - setAngularDrag(value: number): this; + mapping?: string; + }; - /** - * Sets the bounce values of this body. - * - * Bounce is the amount of restitution, or elasticity, the body has when it collides with another object. - * A value of 1 means that it will retain its full velocity after the rebound. A value of 0 means it will not rebound at all. - * @param x The amount of horizontal bounce to apply on collision. A float, typically between 0 and 1. - * @param y The amount of vertical bounce to apply on collision. A float, typically between 0 and 1. Default x. - */ - setBounce(x: number, y?: number): this; + } - /** - * Sets the horizontal bounce value for this body. - * @param value The amount of horizontal bounce to apply on collision. A float, typically between 0 and 1. - */ - setBounceX(value: number): this; + namespace Renderer { + namespace Snapshot { + type SnapshotCallback = (snapshot: Phaser.Display.Color | HTMLImageElement)=>void; - /** - * Sets the vertical bounce value for this body. - * @param value The amount of vertical bounce to apply on collision. A float, typically between 0 and 1. - */ - setBounceY(value: number): this; + type SnapshotState = { + /** + * The function to call after the snapshot is taken. + */ + callback: Phaser.Types.Renderer.Snapshot.SnapshotCallback; + /** + * The format of the image to create, usually `image/png` or `image/jpeg`. + */ + type?: string; + /** + * The image quality, between 0 and 1. Used for image formats with lossy compression, such as `image/jpeg`. + */ + encoderOptions?: number; + /** + * The x coordinate to start the snapshot from. + */ + x?: number; + /** + * The y coordinate to start the snapshot from. + */ + y?: number; + /** + * The width of the snapshot. + */ + width?: number; + /** + * The height of the snapshot. + */ + height?: number; + /** + * Is this a snapshot to get a single pixel, or an area? + */ + getPixel?: boolean; + /** + * Is this snapshot grabbing from a frame buffer or a canvas? + */ + isFramebuffer?: boolean; + /** + * The width of the frame buffer, if a frame buffer grab. + */ + bufferWidth?: number; + /** + * The height of the frame buffer, if a frame buffer grab. + */ + bufferHeight?: number; + }; - /** - * Sets whether this Body collides with the world boundary. - * - * Optionally also sets the World Bounce values. If the `Body.worldBounce` is null, it's set to a new Phaser.Math.Vector2 first. - * @param value `true` if this body should collide with the world bounds, otherwise `false`. Default true. - * @param bounceX If given this will be replace the `worldBounce.x` value. - * @param bounceY If given this will be replace the `worldBounce.y` value. - */ - setCollideWorldBounds(value?: boolean, bounceX?: number, bounceY?: number): this; + } - /** - * Sets the debug values of this body. - * - * Bodies will only draw their debug if debug has been enabled for Arcade Physics as a whole. - * Note that there is a performance cost in drawing debug displays. It should never be used in production. - * @param showBody Set to `true` to have this body render its outline to the debug display. - * @param showVelocity Set to `true` to have this body render a velocity marker to the debug display. - * @param bodyColor The color of the body outline when rendered to the debug display. - */ - setDebug(showBody: boolean, showVelocity: boolean, bodyColor: number): this; + namespace WebGL { + type RenderTargetConfig = { + /** + * A value between 0 and 1. Controls the size of this Render Target in relation to the Renderer. A value of 1 matches it. 0.5 makes the Render Target half the size of the renderer, etc. + */ + scale?: number; + /** + * The minFilter mode of the texture. 0 is `LINEAR`, 1 is `NEAREST`. + */ + minFilter?: number; + /** + * Controls if this Render Target is automatically cleared (via `gl.COLOR_BUFFER_BIT`) during the bind. + */ + autoClear?: boolean; + }; - /** - * Sets the color of the body outline when it renders to the debug display. - * @param value The color of the body outline when rendered to the debug display. - */ - setDebugBodyColor(value: number): this; + type WebGLConst = { + /** + * The data type of the attribute, i.e. `gl.BYTE`, `gl.SHORT`, `gl.UNSIGNED_BYTE`, `gl.FLOAT`, etc. + */ + enum: GLenum; + /** + * The size, in bytes, of the data type. + */ + size: number; + }; - /** - * Set to `true` to have this body render its outline to the debug display. - */ - debugShowBody: boolean; + type WebGLPipelineAttribute = { + /** + * The name of the attribute as defined in the vertex shader. + */ + name: string; + /** + * The number of components in the attribute, i.e. 1 for a float, 2 for a vec2, 3 for a vec3, etc. + */ + size: number; + /** + * The data type of the attribute. Either `gl.BYTE`, `gl.SHORT`, `gl.UNSIGNED_BYTE`, `gl.UNSIGNED_SHORT` or `gl.FLOAT`. + */ + type: GLenum; + /** + * The offset, in bytes, of this attribute data in the vertex array. Equivalent to `offsetof(vertex, attrib)` in C. + */ + offset: number; + /** + * Should the attribute data be normalized? + */ + normalized: boolean; + /** + * You should set this to `false` by default. The pipeline will enable it on boot. + */ + enabled: boolean; + /** + * You should set this to `-1` by default. The pipeline will set it on boot. + */ + location: number; + }; - /** - * Set to `true` to have this body render a velocity marker to the debug display. - */ - debugShowVelocity: boolean; + type WebGLPipelineAttributesConfig = { + /** + * The name of the attribute as defined in the vertex shader. + */ + name: string; + /** + * The number of components in the attribute, i.e. 1 for a float, 2 for a vec2, 3 for a vec3, etc. + */ + size: number; + /** + * The data type of the attribute, one of the `WEBGL_CONST` values, i.e. `WEBGL_CONST.FLOAT`, `WEBGL_CONST.UNSIGNED_BYTE`, etc. + */ + type: Phaser.Types.Renderer.WebGL.WebGLConst; + /** + * Should the attribute data be normalized? + */ + normalized?: boolean; + }; - /** - * The color of the body outline when it renders to the debug display. - */ - debugBodyColor: number; + type WebGLPipelineConfig = { + /** + * The Phaser.Game instance that owns this pipeline. + */ + game: Phaser.Game; + /** + * The name of the pipeline. + */ + name?: string; + /** + * How the primitives are rendered. The default value is GL_TRIANGLES. Here is the full list of rendering primitives: (https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Constants). + */ + topology?: GLenum; + /** + * The source code, as a string, for the vertex shader. If you need to assign multiple shaders, see the `shaders` property. + */ + vertShader?: string; + /** + * The source code, as a string, for the fragment shader. Can include `%count%` and `%forloop%` declarations for multi-texture support. If you need to assign multiple shaders, see the `shaders` property. + */ + fragShader?: string; + /** + * The number of quads to hold in the batch. Defaults to `RenderConfig.batchSize`. This amount * 6 gives the vertex capacity. + */ + batchSize?: number; + /** + * The size, in bytes, of a single entry in the vertex buffer. Defaults to Float32Array.BYTES_PER_ELEMENT * 6 + Uint8Array.BYTES_PER_ELEMENT * 4. + */ + vertexSize?: number; + /** + * An optional Array or Typed Array of pre-calculated vertices data that is copied into the vertex data. + */ + vertices?: number[] | Float32Array; + /** + * An array of shader attribute data. All shaders bound to this pipeline must use the same attributes. + */ + attributes?: Phaser.Types.Renderer.WebGL.WebGLPipelineAttributesConfig; + /** + * An array of shaders, all of which are created for this one pipeline. Uses the `vertShader`, `fragShader`, `attributes` and `uniforms` properties of this object as defaults. + */ + shaders?: Phaser.Types.Renderer.WebGL.WebGLPipelineShaderConfig[]; + /** + * Force the shader to use just a single sampler2d? Set for anything that extends the Single Pipeline. + */ + forceZero?: boolean; + /** + * Create Render Targets for this pipeline. Can be a number, which determines the quantity, a boolean (sets quantity to 1), or an array of Render Target configuration objects. + */ + renderTarget?: boolean | number | Phaser.Types.Renderer.WebGL.RenderTargetConfig[]; + }; - /** - * Sets the body's horizontal and vertical drag. If the vertical drag value is not provided, the vertical drag is set to the same value as the horizontal drag. - * - * Drag can be considered as a form of deceleration that will return the velocity of a body back to zero over time. - * It is the absolute loss of velocity due to movement, in pixels per second squared. - * The x and y components are applied separately. - * - * When `useDamping` is true, this is 1 minus the damping factor. - * A value of 1 means the Body loses no velocity. - * A value of 0.95 means the Body loses 5% of its velocity per step. - * A value of 0.5 means the Body loses 50% of its velocity per step. - * - * Drag is applied only when `acceleration` is zero. - * @param x The amount of horizontal drag to apply. - * @param y The amount of vertical drag to apply. Default x. - */ - setDrag(x: number, y?: number): this; + type WebGLPipelineShaderConfig = { + /** + * The name of the shader. Doesn't have to be unique, but makes shader look-up easier if it is. + */ + name?: string; + /** + * The source code, as a string, for the vertex shader. If not given, uses the `Phaser.Types.Renderer.WebGL.WebGLPipelineConfig.vertShader` property instead. + */ + vertShader?: string; + /** + * The source code, as a string, for the fragment shader. Can include `%count%` and `%forloop%` declarations for multi-texture support. If not given, uses the `Phaser.Types.Renderer.WebGL.WebGLPipelineConfig.fragShader` property instead. + */ + fragShader?: string; + /** + * An array of shader attribute data. All shaders bound to this pipeline must use the same attributes. + */ + attributes?: Phaser.Types.Renderer.WebGL.WebGLPipelineAttributesConfig; + }; + + type WebGLPipelineUniformsConfig = { + /** + * The name of the uniform as defined in the shaders. + */ + name: string; + /** + * The pipeline will set it when the program is linked. + */ + location: WebGLUniformLocation; + /** + * The cached value1. + */ + value1: any; + /** + * The cached value2. + */ + value2: any; + /** + * The cached value3. + */ + value3: any; + /** + * The cached value4. + */ + value4: any; + }; + } + + } + + namespace Scenes { + type CreateSceneFromObjectConfig = { /** - * Sets the body's horizontal drag. - * - * Drag can be considered as a form of deceleration that will return the velocity of a body back to zero over time. - * It is the absolute loss of velocity due to movement, in pixels per second squared. - * The x and y components are applied separately. - * - * When `useDamping` is true, this is 1 minus the damping factor. - * A value of 1 means the Body loses no velocity. - * A value of 0.95 means the Body loses 5% of its velocity per step. - * A value of 0.5 means the Body loses 50% of its velocity per step. - * - * Drag is applied only when `acceleration` is zero. - * @param value The amount of horizontal drag to apply. + * The scene's init callback. */ - setDragX(value: number): this; - + init?: Phaser.Types.Scenes.SceneInitCallback; /** - * Sets the body's vertical drag. - * - * Drag can be considered as a form of deceleration that will return the velocity of a body back to zero over time. - * It is the absolute loss of velocity due to movement, in pixels per second squared. - * The x and y components are applied separately. - * - * When `useDamping` is true, this is 1 minus the damping factor. - * A value of 1 means the Body loses no velocity. - * A value of 0.95 means the Body loses 5% of its velocity per step. - * A value of 0.5 means the Body loses 50% of its velocity per step. - * - * Drag is applied only when `acceleration` is zero. - * @param value The amount of vertical drag to apply. + * The scene's preload callback. */ - setDragY(value: number): this; - + preload?: Phaser.Types.Scenes.ScenePreloadCallback; /** - * If this Body is using `drag` for deceleration this function controls how the drag is applied. - * If set to `true` drag will use a damping effect rather than a linear approach. If you are - * creating a game where the Body moves freely at any angle (i.e. like the way the ship moves in - * the game Asteroids) then you will get a far smoother and more visually correct deceleration - * by using damping, avoiding the axis-drift that is prone with linear deceleration. - * - * If you enable this property then you should use far smaller `drag` values than with linear, as - * they are used as a multiplier on the velocity. Values such as 0.95 will give a nice slow - * deceleration, where-as smaller values, such as 0.5 will stop an object almost immediately. - * @param value `true` to use damping for deceleration, or `false` to use linear deceleration. + * The scene's create callback. */ - setDamping(value: boolean): this; - + create?: Phaser.Types.Scenes.SceneCreateCallback; /** - * Enables this Game Object's Body. - * @param reset Also reset the Body and place it at (x, y). - * @param x The horizontal position to place the Game Object and Body. - * @param y The horizontal position to place the Game Object and Body. - * @param enableGameObject Also activate this Game Object. - * @param showGameObject Also show this Game Object. + * The scene's update callback. See {@link Phaser.Scene#update}. */ - enableBody(reset: boolean, x: number, y: number, enableGameObject: boolean, showGameObject: boolean): this; - + update?: Function; /** - * Stops and disables this Game Object's Body. - * @param disableGameObject Also deactivate this Game Object. Default false. - * @param hideGameObject Also hide this Game Object. Default false. + * Any additional properties, which will be copied to the Scene after it's created (except `data` or `sys`). */ - disableBody(disableGameObject?: boolean, hideGameObject?: boolean): this; - + extend?: any; /** - * Syncs the Body's position and size with its parent Game Object. - * You don't need to call this for Dynamic Bodies, as it happens automatically. - * But for Static bodies it's a useful way of modifying the position of a Static Body - * in the Physics World, based on its Game Object. + * Any values, which will be merged into the Scene's Data Manager store. */ - refreshBody(): this; + "extend.data"?: any; + }; + + /** + * Can be defined on your own Scenes. Use it to create your game objects. + * This method is called by the Scene Manager when the scene starts, after `init()` and `preload()`. + * If the LoaderPlugin started after `preload()`, then this method is called only after loading is complete. + */ + type SceneCreateCallback = (data: object)=>void; + + /** + * Can be defined on your own Scenes. + * This method is called by the Scene Manager when the scene starts, before `preload()` and `create()`. + */ + type SceneInitCallback = (data: object)=>void; + + /** + * Can be defined on your own Scenes. Use it to load assets. + * This method is called by the Scene Manager, after `init()` and before `create()`, only if the Scene has a LoaderPlugin. + * After this method completes, if the LoaderPlugin's queue isn't empty, the LoaderPlugin will start automatically. + */ + type ScenePreloadCallback = ()=>void; + type SceneTransitionConfig = { /** - * Sets the friction (e.g. the amount of velocity reduced over time) of the physics body when moving. - * The higher than friction, the faster the body will slow down once force stops being applied to it. - * @param x The amount of horizontal friction to apply. - * @param y The amount of vertical friction to apply. Default x. + * The Scene key to transition to. */ - setFriction(x: number, y?: number): this; - + target: string; /** - * Sets the friction (e.g. the amount of velocity reduced over time) of the physics body when moving horizontally in the X axis. - * The higher than friction, the faster the body will slow down once force stops being applied to it. - * @param x The amount of friction to apply. + * The duration, in ms, for the transition to last. */ - setFrictionX(x: number): this; - + duration?: number; /** - * Sets the friction (e.g. the amount of velocity reduced over time) of the physics body when moving vertically in the Y axis. - * The higher than friction, the faster the body will slow down once force stops being applied to it. - * @param x The amount of friction to apply. + * Will the Scene responsible for the transition be sent to sleep on completion (`true`), or stopped? (`false`) */ - setFrictionY(x: number): this; - + sleep?: boolean; /** - * Set the X and Y values of the gravitational pull to act upon this Arcade Physics Game Object. Values can be positive or negative. Larger values result in a stronger effect. - * - * If only one value is provided, this value will be used for both the X and Y axis. - * @param x The gravitational force to be applied to the X-axis. - * @param y The gravitational force to be applied to the Y-axis. If this is not specified, the X value will be used. Default x. + * Will the Scene responsible for the transition be removed from the Scene Manager after the transition completes? */ - setGravity(x: number, y?: number): this; - + remove?: boolean; /** - * Set the gravitational force to be applied to the X axis. Value can be positive or negative. Larger values result in a stronger effect. - * @param x The gravitational force to be applied to the X-axis. + * Will the Scenes Input system be able to process events while it is transitioning in or out? */ - setGravityX(x: number): this; - + allowInput?: boolean; /** - * Set the gravitational force to be applied to the Y axis. Value can be positive or negative. Larger values result in a stronger effect. - * @param y The gravitational force to be applied to the Y-axis. + * Move the target Scene to be above this one before the transition starts. */ - setGravityY(y: number): this; - + moveAbove?: boolean; /** - * Sets Whether this Body can be moved by collisions with another Body. - * @param value Sets if this body can be moved by collisions with another Body. Default true. + * Move the target Scene to be below this one before the transition starts. */ - setImmovable(value?: boolean): this; - + moveBelow?: boolean; /** - * Sets the mass of the physics body - * @param value New value for the mass of the body. + * This callback is invoked every frame for the duration of the transition. */ - setMass(value: number): this; - + onUpdate?: Function; /** - * Sets the body offset. This allows you to adjust the difference between the center of the body - * and the x and y coordinates of the parent Game Object. - * @param x The amount to offset the body from the parent Game Object along the x-axis. - * @param y The amount to offset the body from the parent Game Object along the y-axis. Defaults to the value given for the x-axis. Default x. + * The context in which the callback is invoked. */ - setOffset(x: number, y?: number): this; - + onUpdateScope?: any; /** - * Sets this physics body to use a circle for collision instead of a rectangle. - * @param radius The radius of the physics body, in pixels. - * @param offsetX The amount to offset the body from the parent Game Object along the x-axis. - * @param offsetY The amount to offset the body from the parent Game Object along the y-axis. + * An object containing any data you wish to be passed to the target scene's init / create methods (if sleep is false) or to the target scene's wake event callback (if sleep is true). */ - setCircle(radius: number, offsetX?: number, offsetY?: number): this; + data?: any; + }; + type SettingsConfig = { /** - * Sets the velocity of the Body. - * @param x The horizontal velocity of the body. Positive values move the body to the right, while negative values move it to the left. - * @param y The vertical velocity of the body. Positive values move the body down, while negative values move it up. Default x. + * The unique key of this Scene. Must be unique within the entire Game instance. */ - setVelocity(x: number, y?: number): this; - + key?: string; /** - * Sets the horizontal component of the body's velocity. - * - * Positive values move the body to the right, while negative values move it to the left. - * @param x The new horizontal velocity. + * Does the Scene start as active or not? An active Scene updates each step. */ - setVelocityX(x: number): this; - + active?: boolean; /** - * Sets the vertical component of the body's velocity. - * - * Positive values move the body down, while negative values move it up. - * @param y The new vertical velocity of the body. + * Does the Scene start as visible or not? A visible Scene renders each step. */ - setVelocityY(y: number): this; - + visible?: boolean; /** - * Sets the maximum velocity of the body. - * @param x The new maximum horizontal velocity. - * @param y The new maximum vertical velocity. Default x. + * Files to be loaded before the Scene begins. */ - setMaxVelocity(x: number, y?: number): this; - - } - - /** - * The Arcade Physics Plugin belongs to a Scene and sets up and manages the Scene's physics simulation. - * It also holds some useful methods for moving and rotating Arcade Physics Bodies. - * - * You can access it from within a Scene using `this.physics`. - * - * Arcade Physics uses the Projection Method of collision resolution and separation. While it's fast and suitable - * for 'arcade' style games it lacks stability when multiple objects are in close proximity or resting upon each other. - * The separation that stops two objects penetrating may create a new penetration against a different object. If you - * require a high level of stability please consider using an alternative physics system, such as Matter.js. - */ - class ArcadePhysics { + pack?: false | Phaser.Types.Loader.FileTypes.PackFileSection; /** - * - * @param scene The Scene that this Plugin belongs to. + * An optional Camera configuration object. */ - constructor(scene: Phaser.Scene); - + cameras?: Phaser.Types.Cameras.Scene2D.JSONCamera | Phaser.Types.Cameras.Scene2D.JSONCamera[]; /** - * The Scene that this Plugin belongs to. + * Overwrites the default injection map for a scene. */ - scene: Phaser.Scene; - + map?: {[key: string]: string}; /** - * The Scene's Systems. + * Extends the injection map for a scene. */ - systems: Phaser.Scenes.Systems; - + mapAdd?: {[key: string]: string}; /** - * A configuration object. Union of the `physics.arcade.*` properties of the GameConfig and SceneConfig objects. + * The physics configuration object for the Scene. */ - config: object; - + physics?: Phaser.Types.Core.PhysicsConfig; /** - * The physics simulation. + * The loader configuration object for the Scene. */ - world: Phaser.Physics.Arcade.World; - + loader?: Phaser.Types.Core.LoaderConfig; /** - * An object holding the Arcade Physics factory methods. + * The plugin configuration object for the Scene. */ - add: Phaser.Physics.Arcade.Factory; + plugins?: false | any; + }; + type SettingsObject = { /** - * Creates the physics configuration for the current Scene. + * The current status of the Scene. Maps to the Scene constants. */ - getConfig(): object; - + status: number; /** - * Tests if Game Objects overlap. See {@link Phaser.Physics.Arcade.World#overlap} - * @param object1 The first object or array of objects to check. - * @param object2 The second object or array of objects to check, or `undefined`. - * @param collideCallback An optional callback function that is called if the objects collide. - * @param processCallback An optional callback function that lets you perform additional checks against the two objects if they overlap. If this is set then `collideCallback` will only be called if this callback returns `true`. - * @param callbackContext The context in which to run the callbacks. + * The unique key of this Scene. Unique within the entire Game instance. */ - overlap(object1: Phaser.Types.Physics.Arcade.ArcadeColliderType, object2?: Phaser.Types.Physics.Arcade.ArcadeColliderType, collideCallback?: ArcadePhysicsCallback, processCallback?: ArcadePhysicsCallback, callbackContext?: any): boolean; - + key: string; /** - * Performs a collision check and separation between the two physics enabled objects given, which can be single - * Game Objects, arrays of Game Objects, Physics Groups, arrays of Physics Groups or normal Groups. - * - * If you don't require separation then use {@link #overlap} instead. - * - * If two Groups or arrays are passed, each member of one will be tested against each member of the other. - * - * If **only** one Group is passed (as `object1`), each member of the Group will be collided against the other members. - * - * If **only** one Array is passed, the array is iterated and every element in it is tested against the others. - * - * Two callbacks can be provided. The `collideCallback` is invoked if a collision occurs and the two colliding - * objects are passed to it. - * - * Arcade Physics uses the Projection Method of collision resolution and separation. While it's fast and suitable - * for 'arcade' style games it lacks stability when multiple objects are in close proximity or resting upon each other. - * The separation that stops two objects penetrating may create a new penetration against a different object. If you - * require a high level of stability please consider using an alternative physics system, such as Matter.js. - * @param object1 The first object or array of objects to check. - * @param object2 The second object or array of objects to check, or `undefined`. - * @param collideCallback An optional callback function that is called if the objects collide. - * @param processCallback An optional callback function that lets you perform additional checks against the two objects if they collide. If this is set then `collideCallback` will only be called if this callback returns `true`. - * @param callbackContext The context in which to run the callbacks. + * The active state of this Scene. An active Scene updates each step. */ - collide(object1: Phaser.Types.Physics.Arcade.ArcadeColliderType, object2?: Phaser.Types.Physics.Arcade.ArcadeColliderType, collideCallback?: ArcadePhysicsCallback, processCallback?: ArcadePhysicsCallback, callbackContext?: any): boolean; - + active: boolean; /** - * This advanced method is specifically for testing for collision between a single Sprite and an array of Tile objects. - * - * You should generally use the `collide` method instead, with a Sprite vs. a Tilemap Layer, as that will perform - * tile filtering and culling for you, as well as handle the interesting face collision automatically. - * - * This method is offered for those who would like to check for collision with specific Tiles in a layer, without - * having to set any collision attributes on the tiles in question. This allows you to perform quick dynamic collisions - * on small sets of Tiles. As such, no culling or checks are made to the array of Tiles given to this method, - * you should filter them before passing them to this method. - * - * Important: Use of this method skips the `interesting faces` system that Tilemap Layers use. This means if you have - * say a row or column of tiles, and you jump into, or walk over them, it's possible to get stuck on the edges of the - * tiles as the interesting face calculations are skipped. However, for quick-fire small collision set tests on - * dynamic maps, this method can prove very useful. - * @param sprite The first object to check for collision. - * @param tiles An array of Tiles to check for collision against. - * @param collideCallback An optional callback function that is called if the objects collide. - * @param processCallback An optional callback function that lets you perform additional checks against the two objects if they collide. If this is set then `collideCallback` will only be called if this callback returns `true`. - * @param callbackContext The context in which to run the callbacks. + * The visible state of this Scene. A visible Scene renders each step. */ - collideTiles(sprite: Phaser.GameObjects.GameObject, tiles: Phaser.Tilemaps.Tile[], collideCallback?: ArcadePhysicsCallback, processCallback?: ArcadePhysicsCallback, callbackContext?: any): boolean; - + visible: boolean; /** - * This advanced method is specifically for testing for overlaps between a single Sprite and an array of Tile objects. - * - * You should generally use the `overlap` method instead, with a Sprite vs. a Tilemap Layer, as that will perform - * tile filtering and culling for you, as well as handle the interesting face collision automatically. - * - * This method is offered for those who would like to check for overlaps with specific Tiles in a layer, without - * having to set any collision attributes on the tiles in question. This allows you to perform quick dynamic overlap - * tests on small sets of Tiles. As such, no culling or checks are made to the array of Tiles given to this method, - * you should filter them before passing them to this method. - * @param sprite The first object to check for collision. - * @param tiles An array of Tiles to check for collision against. - * @param collideCallback An optional callback function that is called if the objects overlap. - * @param processCallback An optional callback function that lets you perform additional checks against the two objects if they collide. If this is set then `collideCallback` will only be called if this callback returns `true`. - * @param callbackContext The context in which to run the callbacks. + * Has the Scene finished booting? */ - overlapTiles(sprite: Phaser.GameObjects.GameObject, tiles: Phaser.Tilemaps.Tile[], collideCallback?: ArcadePhysicsCallback, processCallback?: ArcadePhysicsCallback, callbackContext?: any): boolean; - + isBooted: boolean; /** - * Pauses the simulation. + * Is the Scene in a state of transition? */ - pause(): Phaser.Physics.Arcade.World; - + isTransition: boolean; /** - * Resumes the simulation (if paused). + * The Scene this Scene is transitioning from, if set. */ - resume(): Phaser.Physics.Arcade.World; - + transitionFrom: Phaser.Scene; /** - * Sets the acceleration.x/y property on the game object so it will move towards the x/y coordinates at the given rate (in pixels per second squared) - * - * You must give a maximum speed value, beyond which the game object won't go any faster. - * - * Note: The game object does not continuously track the target. If the target changes location during transit the game object will not modify its course. - * Note: The game object doesn't stop moving once it reaches the destination coordinates. - * @param gameObject Any Game Object with an Arcade Physics body. - * @param x The x coordinate to accelerate towards. - * @param y The y coordinate to accelerate towards. - * @param speed The acceleration (change in speed) in pixels per second squared. Default 60. - * @param xSpeedMax The maximum x velocity the game object can reach. Default 500. - * @param ySpeedMax The maximum y velocity the game object can reach. Default 500. + * The duration of the transition, if set. */ - accelerateTo(gameObject: Phaser.GameObjects.GameObject, x: number, y: number, speed?: number, xSpeedMax?: number, ySpeedMax?: number): number; - + transitionDuration: number; /** - * Sets the acceleration.x/y property on the game object so it will move towards the x/y coordinates at the given rate (in pixels per second squared) - * - * You must give a maximum speed value, beyond which the game object won't go any faster. - * - * Note: The game object does not continuously track the target. If the target changes location during transit the game object will not modify its course. - * Note: The game object doesn't stop moving once it reaches the destination coordinates. - * @param gameObject Any Game Object with an Arcade Physics body. - * @param destination The Game Object to move towards. Can be any object but must have visible x/y properties. - * @param speed The acceleration (change in speed) in pixels per second squared. Default 60. - * @param xSpeedMax The maximum x velocity the game object can reach. Default 500. - * @param ySpeedMax The maximum y velocity the game object can reach. Default 500. + * Is this Scene allowed to receive input during transitions? */ - accelerateToObject(gameObject: Phaser.GameObjects.GameObject, destination: Phaser.GameObjects.GameObject, speed?: number, xSpeedMax?: number, ySpeedMax?: number): number; - + transitionAllowInput: boolean; /** - * Finds the Body or Game Object closest to a source point or object. - * - * If a `targets` argument is passed, this method finds the closest of those. - * The targets can be Arcade Physics Game Objects, Dynamic Bodies, or Static Bodies. - * - * If no `targets` argument is passed, this method finds the closest Dynamic Body. - * - * If two or more targets are the exact same distance from the source point, only the first target - * is returned. - * @param source Any object with public `x` and `y` properties, such as a Game Object or Geometry object. - * @param targets The targets. + * a data bundle passed to this Scene from the Scene Manager. */ - closest(source: any, targets?: Phaser.Physics.Arcade.Body[] | Phaser.Physics.Arcade.StaticBody[] | Phaser.GameObjects.GameObject[]): Phaser.Physics.Arcade.Body | Phaser.Physics.Arcade.StaticBody | Phaser.GameObjects.GameObject; - + data: object; /** - * Finds the Body or Game Object farthest from a source point or object. - * - * If a `targets` argument is passed, this method finds the farthest of those. - * The targets can be Arcade Physics Game Objects, Dynamic Bodies, or Static Bodies. - * - * If no `targets` argument is passed, this method finds the farthest Dynamic Body. - * - * If two or more targets are the exact same distance from the source point, only the first target - * is returned. - * @param source Any object with public `x` and `y` properties, such as a Game Object or Geometry object. - * @param targets The targets. + * Files to be loaded before the Scene begins. */ - furthest(source: any, targets?: Phaser.Physics.Arcade.Body[] | Phaser.Physics.Arcade.StaticBody[] | Phaser.GameObjects.GameObject[]): Phaser.Physics.Arcade.Body | Phaser.Physics.Arcade.StaticBody | Phaser.GameObjects.GameObject; - + pack: false | Phaser.Types.Loader.FileTypes.PackFileSection; /** - * Move the given display object towards the x/y coordinates at a steady velocity. - * If you specify a maxTime then it will adjust the speed (over-writing what you set) so it arrives at the destination in that number of seconds. - * Timings are approximate due to the way browser timers work. Allow for a variance of +- 50ms. - * Note: The display object does not continuously track the target. If the target changes location during transit the display object will not modify its course. - * Note: The display object doesn't stop moving once it reaches the destination coordinates. - * Note: Doesn't take into account acceleration, maxVelocity or drag (if you've set drag or acceleration too high this object may not move at all) - * @param gameObject Any Game Object with an Arcade Physics body. - * @param x The x coordinate to move towards. - * @param y The y coordinate to move towards. - * @param speed The speed it will move, in pixels per second (default is 60 pixels/sec) Default 60. - * @param maxTime Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the object will arrive at destination in the given number of ms. Default 0. + * The Camera configuration object. */ - moveTo(gameObject: Phaser.GameObjects.GameObject, x: number, y: number, speed?: number, maxTime?: number): number; - + cameras: Phaser.Types.Cameras.Scene2D.JSONCamera | Phaser.Types.Cameras.Scene2D.JSONCamera[]; /** - * Move the given display object towards the destination object at a steady velocity. - * If you specify a maxTime then it will adjust the speed (overwriting what you set) so it arrives at the destination in that number of seconds. - * Timings are approximate due to the way browser timers work. Allow for a variance of +- 50ms. - * Note: The display object does not continuously track the target. If the target changes location during transit the display object will not modify its course. - * Note: The display object doesn't stop moving once it reaches the destination coordinates. - * Note: Doesn't take into account acceleration, maxVelocity or drag (if you've set drag or acceleration too high this object may not move at all) - * @param gameObject Any Game Object with an Arcade Physics body. - * @param destination Any object with public `x` and `y` properties, such as a Game Object or Geometry object. - * @param speed The speed it will move, in pixels per second (default is 60 pixels/sec) Default 60. - * @param maxTime Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the object will arrive at destination in the given number of ms. Default 0. + * The Scene's Injection Map. */ - moveToObject(gameObject: Phaser.GameObjects.GameObject, destination: object, speed?: number, maxTime?: number): number; - + map: {[key: string]: string}; /** - * Given the angle (in degrees) and speed calculate the velocity and return it as a vector, or set it to the given vector object. - * One way to use this is: velocityFromAngle(angle, 200, sprite.body.velocity) which will set the values directly to the sprite's velocity and not create a new vector object. - * @param angle The angle in degrees calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative) - * @param speed The speed it will move, in pixels per second squared. Default 60. - * @param vec2 The Vector2 in which the x and y properties will be set to the calculated velocity. + * The physics configuration object for the Scene. */ - velocityFromAngle(angle: number, speed?: number, vec2?: Phaser.Math.Vector2): Phaser.Math.Vector2; - + physics: Phaser.Types.Core.PhysicsConfig; /** - * Given the rotation (in radians) and speed calculate the velocity and return it as a vector, or set it to the given vector object. - * One way to use this is: velocityFromRotation(rotation, 200, sprite.body.velocity) which will set the values directly to the sprite's velocity and not create a new vector object. - * @param rotation The angle in radians. - * @param speed The speed it will move, in pixels per second squared Default 60. - * @param vec2 The Vector2 in which the x and y properties will be set to the calculated velocity. + * The loader configuration object for the Scene. */ - velocityFromRotation(rotation: number, speed?: number, vec2?: Phaser.Math.Vector2): Phaser.Math.Vector2; - + loader: Phaser.Types.Core.LoaderConfig; /** - * This method will search the given rectangular area and return an array of all physics bodies that - * overlap with it. It can return either Dynamic, Static bodies or a mixture of both. - * - * A body only has to intersect with the search area to be considered, it doesn't have to be fully - * contained within it. - * - * If Arcade Physics is set to use the RTree (which it is by default) then the search for is extremely fast, - * otherwise the search is O(N) for Dynamic Bodies. - * @param x The top-left x coordinate of the area to search within. - * @param y The top-left y coordinate of the area to search within. - * @param width The width of the area to search within. - * @param height The height of the area to search within. - * @param includeDynamic Should the search include Dynamic Bodies? Default true. - * @param includeStatic Should the search include Static Bodies? Default false. + * The plugin configuration object for the Scene. */ - overlapRect(x: number, y: number, width: number, height: number, includeDynamic?: boolean, includeStatic?: boolean): Phaser.Physics.Arcade.Body[] | Phaser.Physics.Arcade.StaticBody[]; + plugins: false | any; + }; + + } + namespace Sound { + /** + * Audio sprite sound type. + */ + type AudioSpriteSound = { /** - * This method will search the given circular area and return an array of all physics bodies that - * overlap with it. It can return either Dynamic, Static bodies or a mixture of both. - * - * A body only has to intersect with the search area to be considered, it doesn't have to be fully - * contained within it. - * - * If Arcade Physics is set to use the RTree (which it is by default) then the search is rather fast, - * otherwise the search is O(N) for Dynamic Bodies. - * @param x The x coordinate of the center of the area to search within. - * @param y The y coordinate of the center of the area to search within. - * @param radius The radius of the area to search within. - * @param includeDynamic Should the search include Dynamic Bodies? Default true. - * @param includeStatic Should the search include Static Bodies? Default false. + * Local reference to 'spritemap' object form json file generated by audiosprite tool. */ - overlapCirc(x: number, y: number, radius: number, includeDynamic?: boolean, includeStatic?: boolean): Phaser.Physics.Arcade.Body[] | Phaser.Physics.Arcade.StaticBody[]; + spritemap: object; + }; + /** + * A Audio Data object. + * + * You can pass an array of these objects to the WebAudioSoundManager `decodeAudio` method to have it decode + * them all at once. + */ + type DecodeAudioConfig = { /** - * The Scene that owns this plugin is shutting down. - * We need to kill and reset all internal properties as well as stop listening to Scene events. + * The string-based key to be used to reference the decoded audio in the audio cache. */ - shutdown(): void; - + key: string; /** - * The Scene that owns this plugin is being destroyed. - * We need to shutdown and then kill off all external references. + * The audio data, either a base64 encoded string, an audio media-type data uri, or an ArrayBuffer instance. */ - destroy(): void; + data: ArrayBuffer | string; + }; - } + type EachActiveSoundCallback = (manager: Phaser.Sound.BaseSoundManager, sound: Phaser.Sound.BaseSound, index: number, sounds: Phaser.Sound.BaseSound[])=>void; /** - * An Arcade Physics Sprite is a Sprite with an Arcade Physics body and related components. - * The body can be dynamic or static. - * - * The main difference between an Arcade Sprite and an Arcade Image is that you cannot animate an Arcade Image. - * If you do not require animation then you can safely use Arcade Images instead of Arcade Sprites. + * Config object containing various sound settings. */ - class Sprite extends Phaser.GameObjects.Sprite implements Phaser.Physics.Arcade.Components.Acceleration, Phaser.Physics.Arcade.Components.Angular, Phaser.Physics.Arcade.Components.Bounce, Phaser.Physics.Arcade.Components.Debug, Phaser.Physics.Arcade.Components.Drag, Phaser.Physics.Arcade.Components.Enable, Phaser.Physics.Arcade.Components.Friction, Phaser.Physics.Arcade.Components.Gravity, Phaser.Physics.Arcade.Components.Immovable, Phaser.Physics.Arcade.Components.Mass, Phaser.Physics.Arcade.Components.Size, Phaser.Physics.Arcade.Components.Velocity, Phaser.GameObjects.Components.Alpha, Phaser.GameObjects.Components.BlendMode, Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.Flip, Phaser.GameObjects.Components.GetBounds, Phaser.GameObjects.Components.Origin, Phaser.GameObjects.Components.Pipeline, Phaser.GameObjects.Components.ScrollFactor, Phaser.GameObjects.Components.Size, Phaser.GameObjects.Components.Texture, Phaser.GameObjects.Components.Tint, Phaser.GameObjects.Components.Transform, Phaser.GameObjects.Components.Visible { + type SoundConfig = { /** - * - * @param scene The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. - * @param x The horizontal position of this Game Object in the world. - * @param y The vertical position of this Game Object in the world. - * @param texture The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. - * @param frame An optional frame from the Texture this Game Object is rendering with. + * Boolean indicating whether the sound should be muted or not. + */ + mute?: boolean; + /** + * A value between 0 (silence) and 1 (full volume). */ - constructor(scene: Phaser.Scene, x: number, y: number, texture: string, frame?: string | integer); - + volume?: number; /** - * This Game Object's Physics Body. + * Defines the speed at which the sound should be played. */ - body: Phaser.Physics.Arcade.Body | Phaser.Physics.Arcade.StaticBody; - + rate?: number; /** - * Clears all alpha values associated with this Game Object. - * - * Immediately sets the alpha levels back to 1 (fully opaque). + * Represents detuning of sound in [cents](https://en.wikipedia.org/wiki/Cent_%28music%29). */ - clearAlpha(): this; - + detune?: number; /** - * Set the Alpha level of this Game Object. The alpha controls the opacity of the Game Object as it renders. - * Alpha values are provided as a float between 0, fully transparent, and 1, fully opaque. - * - * If your game is running under WebGL you can optionally specify four different alpha values, each of which - * correspond to the four corners of the Game Object. Under Canvas only the `topLeft` value given is used. - * @param topLeft The alpha value used for the top-left of the Game Object. If this is the only value given it's applied across the whole Game Object. Default 1. - * @param topRight The alpha value used for the top-right of the Game Object. WebGL only. - * @param bottomLeft The alpha value used for the bottom-left of the Game Object. WebGL only. - * @param bottomRight The alpha value used for the bottom-right of the Game Object. WebGL only. + * Position of playback for this sound, in seconds. */ - setAlpha(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; - + seek?: number; /** - * The alpha value of the Game Object. - * - * This is a global value, impacting the entire Game Object, not just a region of it. + * Whether or not the sound or current sound marker should loop. */ - alpha: number; - + loop?: boolean; /** - * The alpha value starting from the top-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * Time, in seconds, that should elapse before the sound actually starts its playback. */ - alphaTopLeft: number; - + delay?: number; /** - * The alpha value starting from the top-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * A value between -1 (full left pan) and 1 (full right pan). 0 means no pan. */ - alphaTopRight: number; + pan?: number; + }; + /** + * Marked section of a sound represented by name, and optionally start time, duration, and config object. + */ + type SoundMarker = { /** - * The alpha value starting from the bottom-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * Unique identifier of a sound marker. */ - alphaBottomLeft: number; - + name: string; /** - * The alpha value starting from the bottom-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * Sound position offset at witch playback should start. */ - alphaBottomRight: number; - + start?: number; /** - * Sets the Blend Mode being used by this Game Object. - * - * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) - * - * Under WebGL only the following Blend Modes are available: - * - * * ADD - * * MULTIPLY - * * SCREEN - * * ERASE - * - * Canvas has more available depending on browser support. - * - * You can also create your own custom Blend Modes in WebGL. - * - * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending - * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these - * reasons try to be careful about the construction of your Scene and the frequency of which blend modes - * are used. + * Playback duration of this marker. */ - blendMode: Phaser.BlendModes | string; - + duration?: number; /** - * Sets the Blend Mode being used by this Game Object. - * - * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) - * - * Under WebGL only the following Blend Modes are available: - * - * * ADD - * * MULTIPLY - * * SCREEN - * * ERASE (only works when rendering to a framebuffer, like a Render Texture) - * - * Canvas has more available depending on browser support. - * - * You can also create your own custom Blend Modes in WebGL. - * - * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending - * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these - * reasons try to be careful about the construction of your Scene and the frequency in which blend modes - * are used. - * @param value The BlendMode value. Either a string or a CONST. + * An optional config object containing default marker settings. */ - setBlendMode(value: string | Phaser.BlendModes): this; + config?: Phaser.Types.Sound.SoundConfig; + }; + + } + namespace Textures { + /** + * An object containing the position and color data for a single pixel in a CanvasTexture. + */ + type PixelConfig = { /** - * The depth of this Game Object within the Scene. - * - * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order - * of Game Objects, without actually moving their position in the display list. - * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth - * value will always render in front of one with a lower value. - * - * Setting the depth will queue a depth sort event within the Scene. + * The x-coordinate of the pixel. */ - depth: number; - + x: number; /** - * The depth of this Game Object within the Scene. - * - * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order - * of Game Objects, without actually moving their position in the display list. - * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth - * value will always render in front of one with a lower value. - * - * Setting the depth will queue a depth sort event within the Scene. - * @param value The depth of this Game Object. + * The y-coordinate of the pixel. */ - setDepth(value: integer): this; - + y: number; /** - * The horizontally flipped state of the Game Object. - * - * A Game Object that is flipped horizontally will render inversed on the horizontal axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * The color of the pixel, not including the alpha channel. */ - flipX: boolean; - + color: number; /** - * The vertically flipped state of the Game Object. - * - * A Game Object that is flipped vertically will render inversed on the vertical axis (i.e. upside down) - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * The alpha of the pixel, between 0 and 1. */ - flipY: boolean; + alpha: number; + }; + type SpriteSheetConfig = { /** - * Toggles the horizontal flipped state of this Game Object. - * - * A Game Object that is flipped horizontally will render inversed on the horizontal axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * The fixed width of each frame. */ - toggleFlipX(): this; - + frameWidth: number; /** - * Toggles the vertical flipped state of this Game Object. + * The fixed height of each frame. If not set it will use the frameWidth as the height. */ - toggleFlipY(): this; - + frameHeight?: number; /** - * Sets the horizontal flipped state of this Game Object. - * - * A Game Object that is flipped horizontally will render inversed on the horizontal axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. - * @param value The flipped state. `false` for no flip, or `true` to be flipped. + * Skip a number of frames. Useful when there are multiple sprite sheets in one Texture. */ - setFlipX(value: boolean): this; - + startFrame?: number; /** - * Sets the vertical flipped state of this Game Object. - * @param value The flipped state. `false` for no flip, or `true` to be flipped. + * The total number of frames to extract from the Sprite Sheet. The default value of -1 means "extract all frames". */ - setFlipY(value: boolean): this; - + endFrame?: number; /** - * Sets the horizontal and vertical flipped state of this Game Object. - * - * A Game Object that is flipped will render inversed on the flipped axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. - * @param x The horizontal flipped state. `false` for no flip, or `true` to be flipped. - * @param y The horizontal flipped state. `false` for no flip, or `true` to be flipped. + * If the frames have been drawn with a margin, specify the amount here. */ - setFlip(x: boolean, y: boolean): this; - + margin?: number; /** - * Resets the horizontal and vertical flipped state of this Game Object back to their default un-flipped state. + * If the frames have been drawn with spacing between them, specify the amount here. */ - resetFlip(): this; + spacing?: number; + }; + type SpriteSheetFromAtlasConfig = { /** - * Gets the center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. + * The key of the Texture Atlas in which this Sprite Sheet can be found. */ - getCenter(output?: O): O; - + atlas: string; /** - * Gets the top-left corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * The key of the Texture Atlas Frame in which this Sprite Sheet can be found. */ - getTopLeft(output?: O, includeParent?: boolean): O; - + frame: string; /** - * Gets the top-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * The fixed width of each frame. */ - getTopCenter(output?: O, includeParent?: boolean): O; - + frameWidth: number; /** - * Gets the top-right corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * The fixed height of each frame. If not set it will use the frameWidth as the height. */ - getTopRight(output?: O, includeParent?: boolean): O; - + frameHeight?: number; /** - * Gets the left-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * Skip a number of frames. Useful when there are multiple sprite sheets in one Texture. */ - getLeftCenter(output?: O, includeParent?: boolean): O; - + startFrame?: number; /** - * Gets the right-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * The total number of frames to extract from the Sprite Sheet. The default value of -1 means "extract all frames". */ - getRightCenter(output?: O, includeParent?: boolean): O; - + endFrame?: number; /** - * Gets the bottom-left corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * If the frames have been drawn with a margin, specify the amount here. */ - getBottomLeft(output?: O, includeParent?: boolean): O; - + margin?: number; /** - * Gets the bottom-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * If the frames have been drawn with spacing between them, specify the amount here. */ - getBottomCenter(output?: O, includeParent?: boolean): O; + spacing?: number; + }; + + } + namespace Tilemaps { + type CreateFromObjectLayerConfig = { /** - * Gets the bottom-right corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * A unique Object ID to convert. */ - getBottomRight(output?: O, includeParent?: boolean): O; - + id?: number; /** - * Gets the bounds of this Game Object, regardless of origin. - * The values are stored and returned in a Rectangle, or Rectangle-like, object. - * @param output An object to store the values in. If not provided a new Rectangle will be created. + * An Object GID to convert. */ - getBounds(output?: O): O; - + gid?: number; /** - * The Mask this Game Object is using during render. + * An Object Name to convert. */ - mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask; - + name?: string; /** - * Sets the mask that this Game Object will use to render with. - * - * The mask must have been previously created and can be either a GeometryMask or a BitmapMask. - * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. - * - * If a mask is already set on this Game Object it will be immediately replaced. - * - * Masks are positioned in global space and are not relative to the Game Object to which they - * are applied. The reason for this is that multiple Game Objects can all share the same mask. - * - * Masks have no impact on physics or input detection. They are purely a rendering component - * that allows you to limit what is visible during the render pass. - * @param mask The mask this Game Object will use when rendering. + * A custom class type to convert the objects in to. */ - setMask(mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask): this; - + classType?: Phaser.GameObjects.GameObject; /** - * Clears the mask that this Game Object was using. - * @param destroyMask Destroy the mask before clearing it? Default false. + * A Scene reference, passed to the Game Objects constructors. */ - clearMask(destroyMask?: boolean): this; - + scene?: Phaser.Scene; /** - * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, - * including this one. - * - * To create the mask you need to pass in a reference to a renderable Game Object. - * A renderable Game Object is one that uses a texture to render with, such as an - * Image, Sprite, Render Texture or BitmapText. - * - * If you do not provide a renderable object, and this Game Object has a texture, - * it will use itself as the object. This means you can call this method to create - * a Bitmap Mask from any renderable Game Object. - * @param renderable A renderable Game Object that uses a texture, such as a Sprite. + * Optional Container to which the Game Objects are added. */ - createBitmapMask(renderable?: Phaser.GameObjects.GameObject): Phaser.Display.Masks.BitmapMask; - + container?: Phaser.GameObjects.Container; /** - * Creates and returns a Geometry Mask. This mask can be used by any Game Object, - * including this one. - * - * To create the mask you need to pass in a reference to a Graphics Game Object. - * - * If you do not provide a graphics object, and this Game Object is an instance - * of a Graphics object, then it will use itself to create the mask. - * - * This means you can call this method to create a Geometry Mask from any Graphics Game Object. - * @param graphics A Graphics Game Object. The geometry within it will be used as the mask. + * Optional key of a Texture to be used, as stored in the Texture Manager, or a Texture instance. */ - createGeometryMask(graphics?: Phaser.GameObjects.Graphics): Phaser.Display.Masks.GeometryMask; - + key?: string | Phaser.Textures.Texture; /** - * The horizontal origin of this Game Object. - * The origin maps the relationship between the size and position of the Game Object. - * The default value is 0.5, meaning all Game Objects are positioned based on their center. - * Setting the value to 0 means the position now relates to the left of the Game Object. + * Optional name or index of the frame within the Texture. */ - originX: number; + frame?: string | number; + }; + type DebugStyleOptions = { /** - * The vertical origin of this Game Object. - * The origin maps the relationship between the size and position of the Game Object. - * The default value is 0.5, meaning all Game Objects are positioned based on their center. - * Setting the value to 0 means the position now relates to the top of the Game Object. + * Color to use for drawing a filled rectangle at + * non-colliding tile locations. If set to null, non-colliding tiles will not be drawn. */ - originY: number; - + "styleConfig.tileColor"?: Phaser.Display.Color; /** - * The horizontal display origin of this Game Object. - * The origin is a normalized value between 0 and 1. - * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. + * Color to use for drawing a filled + * rectangle at colliding tile locations. If set to null, colliding tiles will not be drawn. */ - displayOriginX: number; - + "styleConfig.collidingTileColor"?: Phaser.Display.Color; /** - * The vertical display origin of this Game Object. - * The origin is a normalized value between 0 and 1. - * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. + * Color to use for drawing a line at interesting + * tile faces. If set to null, interesting tile faces will not be drawn. */ - displayOriginY: number; + "styleConfig.faceColor"?: Phaser.Display.Color; + }; + type FilteringOptions = { /** - * Sets the origin of this Game Object. - * - * The values are given in the range 0 to 1. - * @param x The horizontal origin value. Default 0.5. - * @param y The vertical origin value. If not defined it will be set to the value of `x`. Default x. + * If true, only return tiles that don't have -1 for an index. */ - setOrigin(x?: number, y?: number): this; - + isNotEmpty?: boolean; /** - * Sets the origin of this Game Object based on the Pivot values in its Frame. + * If true, only return tiles that collide on at least one side. */ - setOriginFromFrame(): this; - + isColliding?: boolean; /** - * Sets the display origin of this Game Object. - * The difference between this and setting the origin is that you can use pixel values for setting the display origin. - * @param x The horizontal display origin value. Default 0. - * @param y The vertical display origin value. If not defined it will be set to the value of `x`. Default x. + * If true, only return tiles that have at least one interesting face. */ - setDisplayOrigin(x?: number, y?: number): this; + hasInterestingFace?: boolean; + }; + type GIDData = { /** - * Updates the Display Origin cached values internally stored on this Game Object. - * You don't usually call this directly, but it is exposed for edge-cases where you may. + * The Tiled GID. */ - updateDisplayOrigin(): this; - + gid: number; /** - * The initial WebGL pipeline of this Game Object. + * Horizontal flip flag. */ - defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; - + flippedHorizontal: boolean; /** - * The current WebGL pipeline of this Game Object. + * Vertical flip flag. */ - pipeline: Phaser.Renderer.WebGL.WebGLPipeline; - + flippedVertical: boolean; /** - * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. + * Diagonal flip flag. */ - initPipeline(pipelineName?: string): boolean; - + flippedAntiDiagonal: boolean; /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. + * Amount of rotation. */ - setPipeline(pipelineName: string): this; - + rotation: number; /** - * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * Is flipped? */ - resetPipeline(): boolean; + flipped: boolean; + }; + type LayerDataConfig = { /** - * Gets the name of the WebGL Pipeline this Game Object is currently using. + * The name of the layer, if specified in Tiled. */ - getPipelineName(): string; - + name?: string; /** - * The horizontal scroll factor of this Game Object. - * - * The scroll factor controls the influence of the movement of a Camera upon this Game Object. - * - * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. - * It does not change the Game Objects actual position values. - * - * A value of 1 means it will move exactly in sync with a camera. - * A value of 0 means it will not move at all, even if the camera moves. - * Other values control the degree to which the camera movement is mapped to this Game Object. - * - * Please be aware that scroll factor values other than 1 are not taken in to consideration when - * calculating physics collisions. Bodies always collide based on their world position, but changing - * the scroll factor is a visual adjustment to where the textures are rendered, which can offset - * them from physics bodies if not accounted for in your code. + * The x offset of where to draw from the top left. */ - scrollFactorX: number; - + x?: number; /** - * The vertical scroll factor of this Game Object. - * - * The scroll factor controls the influence of the movement of a Camera upon this Game Object. - * - * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. - * It does not change the Game Objects actual position values. - * - * A value of 1 means it will move exactly in sync with a camera. - * A value of 0 means it will not move at all, even if the camera moves. - * Other values control the degree to which the camera movement is mapped to this Game Object. - * - * Please be aware that scroll factor values other than 1 are not taken in to consideration when - * calculating physics collisions. Bodies always collide based on their world position, but changing - * the scroll factor is a visual adjustment to where the textures are rendered, which can offset - * them from physics bodies if not accounted for in your code. + * The y offset of where to draw from the top left. */ - scrollFactorY: number; - + y?: number; /** - * Sets the scroll factor of this Game Object. - * - * The scroll factor controls the influence of the movement of a Camera upon this Game Object. - * - * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. - * It does not change the Game Objects actual position values. - * - * A value of 1 means it will move exactly in sync with a camera. - * A value of 0 means it will not move at all, even if the camera moves. - * Other values control the degree to which the camera movement is mapped to this Game Object. - * - * Please be aware that scroll factor values other than 1 are not taken in to consideration when - * calculating physics collisions. Bodies always collide based on their world position, but changing - * the scroll factor is a visual adjustment to where the textures are rendered, which can offset - * them from physics bodies if not accounted for in your code. - * @param x The horizontal scroll factor of this Game Object. - * @param y The vertical scroll factor of this Game Object. If not set it will use the `x` value. Default x. + * The width of the layer in tiles. */ - setScrollFactor(x: number, y?: number): this; - + width?: number; /** - * The native (un-scaled) width of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayWidth` property. + * The height of the layer in tiles. */ - width: number; - + height?: number; /** - * The native (un-scaled) height of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayHeight` property. + * The pixel width of the tiles. */ - height: number; - + tileWidth?: number; /** - * The displayed width of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. + * The pixel height of the tiles. */ - displayWidth: number; - + tileHeight?: number; /** - * The displayed height of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. + * The base tile width. */ - displayHeight: number; - + baseTileWidth?: number; /** - * Sets the size of this Game Object to be that of the given Frame. - * - * This will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or call the - * `setDisplaySize` method, which is the same thing as changing the scale but allows you - * to do so by giving pixel values. - * - * If you have enabled this Game Object for input, changing the size will _not_ change the - * size of the hit area. To do this you should adjust the `input.hitArea` object directly. - * @param frame The frame to base the size of this Game Object on. + * The base tile height. */ - setSizeToFrame(frame: Phaser.Textures.Frame): this; - + baseTileHeight?: number; /** - * Sets the internal size of this Game Object, as used for frame or physics body creation. - * - * This will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or call the - * `setDisplaySize` method, which is the same thing as changing the scale but allows you - * to do so by giving pixel values. - * - * If you have enabled this Game Object for input, changing the size will _not_ change the - * size of the hit area. To do this you should adjust the `input.hitArea` object directly. - * @param width The width of this Game Object. - * @param height The height of this Game Object. + * The width in pixels of the entire layer. */ - setSize(width: number, height: number): this; - + widthInPixels?: number; /** - * Sets the display size of this Game Object. - * - * Calling this will adjust the scale. - * @param width The width of this Game Object. - * @param height The height of this Game Object. + * The height in pixels of the entire layer. */ - setDisplaySize(width: number, height: number): this; - + heightInPixels?: number; /** - * The Texture this Game Object is using to render with. + * The alpha value of the layer. */ - texture: Phaser.Textures.Texture | Phaser.Textures.CanvasTexture; - + alpha?: number; /** - * The Texture Frame this Game Object is using to render with. + * Is the layer visible or not? */ - frame: Phaser.Textures.Frame; - + visible?: boolean; /** - * A boolean flag indicating if this Game Object is being cropped or not. - * You can toggle this at any time after `setCrop` has been called, to turn cropping on or off. - * Equally, calling `setCrop` with no arguments will reset the crop and disable it. + * Layer specific properties (can be specified in Tiled) */ - isCropped: boolean; - + properties?: object[]; /** - * Applies a crop to a texture based Game Object, such as a Sprite or Image. - * - * The crop is a rectangle that limits the area of the texture frame that is visible during rendering. - * - * Cropping a Game Object does not change its size, dimensions, physics body or hit area, it just - * changes what is shown when rendered. - * - * The crop coordinates are relative to the texture frame, not the Game Object, meaning 0 x 0 is the top-left. - * - * Therefore, if you had a Game Object that had an 800x600 sized texture, and you wanted to show only the left - * half of it, you could call `setCrop(0, 0, 400, 600)`. - * - * It is also scaled to match the Game Object scale automatically. Therefore a crop rect of 100x50 would crop - * an area of 200x100 when applied to a Game Object that had a scale factor of 2. - * - * You can either pass in numeric values directly, or you can provide a single Rectangle object as the first argument. - * - * Call this method with no arguments at all to reset the crop, or toggle the property `isCropped` to `false`. - * - * You should do this if the crop rectangle becomes the same size as the frame itself, as it will allow - * the renderer to skip several internal calculations. - * @param x The x coordinate to start the crop from. Or a Phaser.Geom.Rectangle object, in which case the rest of the arguments are ignored. - * @param y The y coordinate to start the crop from. - * @param width The width of the crop rectangle in pixels. - * @param height The height of the crop rectangle in pixels. + * Tile ID index map. */ - setCrop(x?: number | Phaser.Geom.Rectangle, y?: number, width?: number, height?: number): this; - + indexes?: any[]; /** - * Sets the texture and frame this Game Object will use to render with. - * - * Textures are referenced by their string-based keys, as stored in the Texture Manager. - * @param key The key of the texture to be used, as stored in the Texture Manager. - * @param frame The name or index of the frame within the Texture. + * Tile Collision ID index map. */ - setTexture(key: string, frame?: string | integer): this; - + collideIndexes?: any[]; /** - * Sets the frame this Game Object will use to render with. - * - * The Frame has to belong to the current Texture being used. - * - * It can be either a string or an index. - * - * Calling `setFrame` will modify the `width` and `height` properties of your Game Object. - * It will also change the `origin` if the Frame has a custom pivot point, as exported from packages like Texture Packer. - * @param frame The name or index of the frame within the Texture. - * @param updateSize Should this call adjust the size of the Game Object? Default true. - * @param updateOrigin Should this call adjust the origin of the Game Object? Default true. + * An array of callbacks. */ - setFrame(frame: string | integer, updateSize?: boolean, updateOrigin?: boolean): this; - + callbacks?: any[]; /** - * Fill or additive? + * An array of physics bodies. */ - tintFill: boolean; - + bodies?: any[]; /** - * Clears all tint values associated with this Game Object. - * - * Immediately sets the color values back to 0xffffff and the tint type to 'additive', - * which results in no visible change to the texture. + * An array of the tile data indexes. */ - clearTint(): this; - + data?: any[]; /** - * Sets an additive tint on this Game Object. - * - * The tint works by taking the pixel color values from the Game Objects texture, and then - * multiplying it by the color value of the tint. You can provide either one color value, - * in which case the whole Game Object will be tinted in that color. Or you can provide a color - * per corner. The colors are blended together across the extent of the Game Object. - * - * To modify the tint color once set, either call this method again with new values or use the - * `tint` property to set all colors at once. Or, use the properties `tintTopLeft`, `tintTopRight, - * `tintBottomLeft` and `tintBottomRight` to set the corner color values independently. - * - * To remove a tint call `clearTint`. - * - * To swap this from being an additive tint to a fill based tint set the property `tintFill` to `true`. - * @param topLeft The tint being applied to the top-left of the Game Object. If no other values are given this value is applied evenly, tinting the whole Game Object. Default 0xffffff. - * @param topRight The tint being applied to the top-right of the Game Object. - * @param bottomLeft The tint being applied to the bottom-left of the Game Object. - * @param bottomRight The tint being applied to the bottom-right of the Game Object. + * A reference to the Tilemap layer that owns this data. */ - setTint(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; + tilemapLayer?: Phaser.Tilemaps.TilemapLayer; + }; + type MapDataConfig = { /** - * Sets a fill-based tint on this Game Object. - * - * Unlike an additive tint, a fill-tint literally replaces the pixel colors from the texture - * with those in the tint. You can use this for effects such as making a player flash 'white' - * if hit by something. You can provide either one color value, in which case the whole - * Game Object will be rendered in that color. Or you can provide a color per corner. The colors - * are blended together across the extent of the Game Object. - * - * To modify the tint color once set, either call this method again with new values or use the - * `tint` property to set all colors at once. Or, use the properties `tintTopLeft`, `tintTopRight, - * `tintBottomLeft` and `tintBottomRight` to set the corner color values independently. - * - * To remove a tint call `clearTint`. - * - * To swap this from being a fill-tint to an additive tint set the property `tintFill` to `false`. - * @param topLeft The tint being applied to the top-left of the Game Object. If not other values are given this value is applied evenly, tinting the whole Game Object. Default 0xffffff. - * @param topRight The tint being applied to the top-right of the Game Object. - * @param bottomLeft The tint being applied to the bottom-left of the Game Object. - * @param bottomRight The tint being applied to the bottom-right of the Game Object. + * The key in the Phaser cache that corresponds to the loaded tilemap data. */ - setTintFill(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; - + name?: string; /** - * The tint value being applied to the top-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * The width of the entire tilemap. */ - tintTopLeft: integer; - + width?: number; /** - * The tint value being applied to the top-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * The height of the entire tilemap. */ - tintTopRight: integer; - + height?: number; /** - * The tint value being applied to the bottom-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * The width of the tiles. */ - tintBottomLeft: integer; - + tileWidth?: number; /** - * The tint value being applied to the bottom-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * The height of the tiles. */ - tintBottomRight: integer; - + tileHeight?: number; /** - * The tint value being applied to the whole of the Game Object. - * This property is a setter-only. Use the properties `tintTopLeft` etc to read the current tint value. + * The width in pixels of the entire tilemap. */ - tint: integer; - + widthInPixels?: number; /** - * Does this Game Object have a tint applied to it or not? + * The height in pixels of the entire tilemap. */ - readonly isTinted: boolean; - + heightInPixels?: number; /** - * The x position of this Game Object. + * The format of the Tilemap, as defined in Tiled. */ - x: number; - + format?: number; /** - * The y position of this Game Object. + * The orientation of the map data (i.e. orthogonal, isometric, hexagonal), default 'orthogonal'. */ - y: number; - + orientation?: string; /** - * The z position of this Game Object. - * - * Note: The z position does not control the rendering order of 2D Game Objects. Use - * {@link Phaser.GameObjects.Components.Depth#depth} instead. + * Determines the draw order of tilemap. Default is right-down. */ - z: number; - + renderOrder?: string; /** - * The w position of this Game Object. + * The version of Tiled the map uses. */ - w: number; - + version?: number; /** - * This is a special setter that allows you to set both the horizontal and vertical scale of this Game Object - * to the same value, at the same time. When reading this value the result returned is `(scaleX + scaleY) / 2`. - * - * Use of this property implies you wish the horizontal and vertical scales to be equal to each other. If this - * isn't the case, use the `scaleX` or `scaleY` properties instead. + * Map specific properties (can be specified in Tiled). */ - scale: number; - + properties?: number; /** - * The horizontal scale of this Game Object. + * The layers of the tilemap. */ - scaleX: number; - + layers?: Phaser.Tilemaps.LayerData[]; /** - * The vertical scale of this Game Object. + * An array with all the layers configured to the MapData. */ - scaleY: number; - + images?: any[]; /** - * The angle of this Game Object as expressed in degrees. - * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. - * - * If you prefer to work in radians, see the `rotation` property instead. + * An array of Tiled Image Layers. */ - angle: integer; - + objects?: object; /** - * The angle of this Game Object in radians. - * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. - * - * If you prefer to work in degrees, see the `angle` property instead. + * An object of Tiled Object Layers. */ - rotation: number; - + collision?: object; /** - * Sets the position of this Game Object. - * @param x The x position of this Game Object. Default 0. - * @param y The y position of this Game Object. If not set it will use the `x` value. Default x. - * @param z The z position of this Game Object. Default 0. - * @param w The w position of this Game Object. Default 0. + * The tilesets the map uses. */ - setPosition(x?: number, y?: number, z?: number, w?: number): this; - + tilesets?: Phaser.Tilemaps.Tileset[]; /** - * Sets the position of this Game Object to be a random position within the confines of - * the given area. - * - * If no area is specified a random position between 0 x 0 and the game width x height is used instead. - * - * The position does not factor in the size of this Game Object, meaning that only the origin is - * guaranteed to be within the area. - * @param x The x position of the top-left of the random area. Default 0. - * @param y The y position of the top-left of the random area. Default 0. - * @param width The width of the random area. - * @param height The height of the random area. + * The collection of images the map uses(specified in Tiled). */ - setRandomPosition(x?: number, y?: number, width?: number, height?: number): this; - + imageCollections?: any[]; /** - * Sets the rotation of this Game Object. - * @param radians The rotation of this Game Object, in radians. Default 0. + * Array of Tile instances. */ - setRotation(radians?: number): this; + tiles?: any[]; + }; + type ObjectLayerConfig = { /** - * Sets the angle of this Game Object. - * @param degrees The rotation of this Game Object, in degrees. Default 0. + * The name of the Object Layer. */ - setAngle(degrees?: number): this; - + name?: string; /** - * Sets the scale of this Game Object. - * @param x The horizontal scale of this Game Object. - * @param y The vertical scale of this Game Object. If not set it will use the `x` value. Default x. + * The opacity of the layer, between 0 and 1. */ - setScale(x: number, y?: number): this; - + opacity?: number; /** - * Sets the x position of this Game Object. - * @param value The x position of this Game Object. Default 0. + * The custom properties defined on the Object Layer, keyed by their name. */ - setX(value?: number): this; - + properties?: any; /** - * Sets the y position of this Game Object. - * @param value The y position of this Game Object. Default 0. + * The type of each custom property defined on the Object Layer, keyed by its name. */ - setY(value?: number): this; - + propertytypes?: any; /** - * Sets the z position of this Game Object. - * - * Note: The z position does not control the rendering order of 2D Game Objects. Use - * {@link Phaser.GameObjects.Components.Depth#setDepth} instead. - * @param value The z position of this Game Object. Default 0. + * The type of the layer, which should be `objectgroup`. */ - setZ(value?: number): this; - + type?: string; /** - * Sets the w position of this Game Object. - * @param value The w position of this Game Object. Default 0. + * Whether the layer is shown (`true`) or hidden (`false`). */ - setW(value?: number): this; - + visible?: boolean; /** - * Gets the local transform matrix for this Game Object. - * @param tempMatrix The matrix to populate with the values from this Game Object. + * An array of all objects on this Object Layer. */ - getLocalTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + objects?: any[]; + }; + type StyleConfig = { /** - * Gets the world transform matrix for this Game Object, factoring in any parent Containers. - * @param tempMatrix The matrix to populate with the values from this Game Object. - * @param parentMatrix A temporary matrix to hold parent values during the calculations. + * Color to use for drawing a filled rectangle at non-colliding tile locations. If set to null, non-colliding tiles will not be drawn. */ - getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; - + tileColor?: Phaser.Display.Color | number | null; /** - * Gets the sum total rotation of all of this Game Objects parent Containers. - * - * The returned value is in radians and will be zero if this Game Object has no parent container. + * Color to use for drawing a filled rectangle at colliding tile locations. If set to null, colliding tiles will not be drawn. */ - getParentRotation(): number; - + collidingTileColor?: Phaser.Display.Color | number | null; /** - * The visible state of the Game Object. - * - * An invisible Game Object will skip rendering, but will still process update logic. + * Color to use for drawing a line at interesting tile faces. If set to null, interesting tile faces will not be drawn. */ - visible: boolean; + faceColor?: Phaser.Display.Color | number | null; + }; + type TiledObject = { /** - * Sets the visibility of this Game Object. - * - * An invisible Game Object will skip rendering, but will still process update logic. - * @param value The visible state of the Game Object. + * The unique object ID. */ - setVisible(value: boolean): this; - + id: number; /** - * Sets the body's horizontal and vertical acceleration. If the vertical acceleration value is not provided, the vertical acceleration is set to the same value as the horizontal acceleration. - * @param x The horizontal acceleration - * @param y The vertical acceleration Default x. + * The name this object was assigned in Tiled. */ - setAcceleration(x: number, y?: number): this; - + name: string; /** - * Sets the body's horizontal acceleration. - * @param value The horizontal acceleration + * The type, as assigned in Tiled. */ - setAccelerationX(value: number): this; - + type: string; /** - * Sets the body's vertical acceleration. - * @param value The vertical acceleration + * The visible state of this object. */ - setAccelerationY(value: number): this; - + visible?: boolean; /** - * Sets the angular velocity of the body. - * - * In Arcade Physics, bodies cannot rotate. They are always axis-aligned. - * However, they can have angular motion, which is passed on to the Game Object bound to the body, - * causing them to visually rotate, even though the body remains axis-aligned. - * @param value The amount of angular velocity. + * The horizontal position of this object, in pixels, relative to the tilemap. */ - setAngularVelocity(value: number): this; - + x?: number; /** - * Sets the angular acceleration of the body. - * - * In Arcade Physics, bodies cannot rotate. They are always axis-aligned. - * However, they can have angular motion, which is passed on to the Game Object bound to the body, - * causing them to visually rotate, even though the body remains axis-aligned. - * @param value The amount of angular acceleration. + * The vertical position of this object, in pixels, relative to the tilemap. */ - setAngularAcceleration(value: number): this; - + y?: number; /** - * Sets the angular drag of the body. Drag is applied to the current velocity, providing a form of deceleration. - * @param value The amount of drag. + * The width of this object, in pixels. */ - setAngularDrag(value: number): this; - + width?: number; /** - * Sets the bounce values of this body. - * - * Bounce is the amount of restitution, or elasticity, the body has when it collides with another object. - * A value of 1 means that it will retain its full velocity after the rebound. A value of 0 means it will not rebound at all. - * @param x The amount of horizontal bounce to apply on collision. A float, typically between 0 and 1. - * @param y The amount of vertical bounce to apply on collision. A float, typically between 0 and 1. Default x. + * The height of this object, in pixels. */ - setBounce(x: number, y?: number): this; - + height?: number; /** - * Sets the horizontal bounce value for this body. - * @param value The amount of horizontal bounce to apply on collision. A float, typically between 0 and 1. + * The rotation of the object in clockwise degrees. */ - setBounceX(value: number): this; - + rotation?: number; /** - * Sets the vertical bounce value for this body. - * @param value The amount of vertical bounce to apply on collision. A float, typically between 0 and 1. + * Custom properties object. */ - setBounceY(value: number): this; - + properties?: any; /** - * Sets whether this Body collides with the world boundary. - * - * Optionally also sets the World Bounce values. If the `Body.worldBounce` is null, it's set to a new Phaser.Math.Vector2 first. - * @param value `true` if this body should collide with the world bounds, otherwise `false`. Default true. - * @param bounceX If given this will be replace the `worldBounce.x` value. - * @param bounceY If given this will be replace the `worldBounce.y` value. + * Only set if of type 'tile'. */ - setCollideWorldBounds(value?: boolean, bounceX?: number, bounceY?: number): this; - + gid?: number; /** - * Sets the debug values of this body. - * - * Bodies will only draw their debug if debug has been enabled for Arcade Physics as a whole. - * Note that there is a performance cost in drawing debug displays. It should never be used in production. - * @param showBody Set to `true` to have this body render its outline to the debug display. - * @param showVelocity Set to `true` to have this body render a velocity marker to the debug display. - * @param bodyColor The color of the body outline when rendered to the debug display. + * Only set if a tile object. The horizontal flip value. */ - setDebug(showBody: boolean, showVelocity: boolean, bodyColor: number): this; - + flippedHorizontal?: boolean; /** - * Sets the color of the body outline when it renders to the debug display. - * @param value The color of the body outline when rendered to the debug display. + * Only set if a tile object. The vertical flip value. */ - setDebugBodyColor(value: number): this; - + flippedVertical?: boolean; /** - * Set to `true` to have this body render its outline to the debug display. + * Only set if a tile object. The diagonal flip value. */ - debugShowBody: boolean; - + flippedAntiDiagonal?: boolean; /** - * Set to `true` to have this body render a velocity marker to the debug display. + * Only set if a polyline object. An array of objects corresponding to points, where each point has an `x` property and a `y` property. */ - debugShowVelocity: boolean; - + polyline?: Phaser.Types.Math.Vector2Like[]; /** - * The color of the body outline when it renders to the debug display. + * Only set if a polygon object. An array of objects corresponding to points, where each point has an `x` property and a `y` property. */ - debugBodyColor: number; - + polygon?: Phaser.Types.Math.Vector2Like[]; /** - * Sets the body's horizontal and vertical drag. If the vertical drag value is not provided, the vertical drag is set to the same value as the horizontal drag. - * - * Drag can be considered as a form of deceleration that will return the velocity of a body back to zero over time. - * It is the absolute loss of velocity due to movement, in pixels per second squared. - * The x and y components are applied separately. - * - * When `useDamping` is true, this is 1 minus the damping factor. - * A value of 1 means the Body loses no velocity. - * A value of 0.95 means the Body loses 5% of its velocity per step. - * A value of 0.5 means the Body loses 50% of its velocity per step. - * - * Drag is applied only when `acceleration` is zero. - * @param x The amount of horizontal drag to apply. - * @param y The amount of vertical drag to apply. Default x. + * Only set if a text object. Contains the text objects properties. */ - setDrag(x: number, y?: number): this; - + text?: any; /** - * Sets the body's horizontal drag. - * - * Drag can be considered as a form of deceleration that will return the velocity of a body back to zero over time. - * It is the absolute loss of velocity due to movement, in pixels per second squared. - * The x and y components are applied separately. - * - * When `useDamping` is true, this is 1 minus the damping factor. - * A value of 1 means the Body loses no velocity. - * A value of 0.95 means the Body loses 5% of its velocity per step. - * A value of 0.5 means the Body loses 50% of its velocity per step. - * - * Drag is applied only when `acceleration` is zero. - * @param value The amount of horizontal drag to apply. + * Only set, and set to `true`, if a rectangle object. */ - setDragX(value: number): this; - + rectangle?: boolean; /** - * Sets the body's vertical drag. - * - * Drag can be considered as a form of deceleration that will return the velocity of a body back to zero over time. - * It is the absolute loss of velocity due to movement, in pixels per second squared. - * The x and y components are applied separately. - * - * When `useDamping` is true, this is 1 minus the damping factor. - * A value of 1 means the Body loses no velocity. - * A value of 0.95 means the Body loses 5% of its velocity per step. - * A value of 0.5 means the Body loses 50% of its velocity per step. - * - * Drag is applied only when `acceleration` is zero. - * @param value The amount of vertical drag to apply. + * Only set, and set to `true`, if a ellipse object. */ - setDragY(value: number): this; - + ellipse?: boolean; /** - * If this Body is using `drag` for deceleration this function controls how the drag is applied. - * If set to `true` drag will use a damping effect rather than a linear approach. If you are - * creating a game where the Body moves freely at any angle (i.e. like the way the ship moves in - * the game Asteroids) then you will get a far smoother and more visually correct deceleration - * by using damping, avoiding the axis-drift that is prone with linear deceleration. - * - * If you enable this property then you should use far smaller `drag` values than with linear, as - * they are used as a multiplier on the velocity. Values such as 0.95 will give a nice slow - * deceleration, where-as smaller values, such as 0.5 will stop an object almost immediately. - * @param value `true` to use damping for deceleration, or `false` to use linear deceleration. + * Only set, and set to `true`, if a point object. */ - setDamping(value: boolean): this; + point?: boolean; + }; + type TilemapConfig = { /** - * Enables this Game Object's Body. - * @param reset Also reset the Body and place it at (x, y). - * @param x The horizontal position to place the Game Object and Body. - * @param y The horizontal position to place the Game Object and Body. - * @param enableGameObject Also activate this Game Object. - * @param showGameObject Also show this Game Object. + * The key in the Phaser cache that corresponds to the loaded tilemap data. */ - enableBody(reset: boolean, x: number, y: number, enableGameObject: boolean, showGameObject: boolean): this; - + key?: string; /** - * Stops and disables this Game Object's Body. - * @param disableGameObject Also deactivate this Game Object. Default false. - * @param hideGameObject Also hide this Game Object. Default false. + * Instead of loading from the cache, you can also load directly from a 2D array of tile indexes. */ - disableBody(disableGameObject?: boolean, hideGameObject?: boolean): this; - + data?: number[][]; /** - * Syncs the Body's position and size with its parent Game Object. - * You don't need to call this for Dynamic Bodies, as it happens automatically. - * But for Static bodies it's a useful way of modifying the position of a Static Body - * in the Physics World, based on its Game Object. + * The width of a tile in pixels. */ - refreshBody(): this; - + tileWidth?: number; /** - * Sets the friction (e.g. the amount of velocity reduced over time) of the physics body when moving. - * The higher than friction, the faster the body will slow down once force stops being applied to it. - * @param x The amount of horizontal friction to apply. - * @param y The amount of vertical friction to apply. Default x. + * The height of a tile in pixels. */ - setFriction(x: number, y?: number): this; - + tileHeight?: number; /** - * Sets the friction (e.g. the amount of velocity reduced over time) of the physics body when moving horizontally in the X axis. - * The higher than friction, the faster the body will slow down once force stops being applied to it. - * @param x The amount of friction to apply. + * The width of the map in tiles. */ - setFrictionX(x: number): this; - + width?: number; /** - * Sets the friction (e.g. the amount of velocity reduced over time) of the physics body when moving vertically in the Y axis. - * The higher than friction, the faster the body will slow down once force stops being applied to it. - * @param x The amount of friction to apply. + * The height of the map in tiles. */ - setFrictionY(x: number): this; - + height?: number; /** - * Set the X and Y values of the gravitational pull to act upon this Arcade Physics Game Object. Values can be positive or negative. Larger values result in a stronger effect. - * - * If only one value is provided, this value will be used for both the X and Y axis. - * @param x The gravitational force to be applied to the X-axis. - * @param y The gravitational force to be applied to the Y-axis. If this is not specified, the X value will be used. Default x. + * Controls how empty tiles, tiles with an index of -1, + * in the map data are handled. If `true`, empty locations will get a value of `null`. If `false`, + * empty location will get a Tile object with an index of -1. If you've a large sparsely populated + * map and the tile data doesn't need to change then setting this value to `true` will help with + * memory consumption. However if your map is small or you need to update the tiles dynamically, + * then leave the default value set. */ - setGravity(x: number, y?: number): this; + insertNull?: boolean; + }; - /** - * Set the gravitational force to be applied to the X axis. Value can be positive or negative. Larger values result in a stronger effect. - * @param x The gravitational force to be applied to the X-axis. - */ - setGravityX(x: number): this; + } + namespace Time { + type TimerEventConfig = { /** - * Set the gravitational force to be applied to the Y axis. Value can be positive or negative. Larger values result in a stronger effect. - * @param y The gravitational force to be applied to the Y-axis. + * The delay after which the Timer Event should fire, in milliseconds. */ - setGravityY(y: number): this; - + delay?: number; /** - * Sets Whether this Body can be moved by collisions with another Body. - * @param value Sets if this body can be moved by collisions with another Body. Default true. + * The total number of times the Timer Event will repeat before finishing. */ - setImmovable(value?: boolean): this; - + repeat?: number; /** - * Sets the mass of the physics body - * @param value New value for the mass of the body. + * `true` if the Timer Event should repeat indefinitely. */ - setMass(value: number): this; - + loop?: boolean; /** - * Sets the body offset. This allows you to adjust the difference between the center of the body - * and the x and y coordinates of the parent Game Object. - * @param x The amount to offset the body from the parent Game Object along the x-axis. - * @param y The amount to offset the body from the parent Game Object along the y-axis. Defaults to the value given for the x-axis. Default x. + * The callback which will be called when the Timer Event fires. */ - setOffset(x: number, y?: number): this; - + callback?: Function; /** - * Sets this physics body to use a circle for collision instead of a rectangle. - * @param radius The radius of the physics body, in pixels. - * @param offsetX The amount to offset the body from the parent Game Object along the x-axis. - * @param offsetY The amount to offset the body from the parent Game Object along the y-axis. + * The scope (`this` object) with which to invoke the `callback`. */ - setCircle(radius: number, offsetX?: number, offsetY?: number): this; - + callbackScope?: any; /** - * Sets the velocity of the Body. - * @param x The horizontal velocity of the body. Positive values move the body to the right, while negative values move it to the left. - * @param y The vertical velocity of the body. Positive values move the body down, while negative values move it up. Default x. + * Additional arguments to be passed to the `callback`. */ - setVelocity(x: number, y?: number): this; - + args?: any[]; /** - * Sets the horizontal component of the body's velocity. - * - * Positive values move the body to the right, while negative values move it to the left. - * @param x The new horizontal velocity. + * The scale of the elapsed time. */ - setVelocityX(x: number): this; - + timeScale?: number; /** - * Sets the vertical component of the body's velocity. - * - * Positive values move the body down, while negative values move it up. - * @param y The new vertical velocity of the body. + * The initial elapsed time in milliseconds. Useful if you want a long duration with repeat, but for the first loop to fire quickly. */ - setVelocityY(y: number): this; - + startAt?: number; /** - * Sets the maximum velocity of the body. - * @param x The new maximum horizontal velocity. - * @param y The new maximum vertical velocity. Default x. + * `true` if the Timer Event should be paused. */ - setMaxVelocity(x: number, y?: number): this; + paused?: boolean; + }; - } + } - /** - * A Dynamic Arcade Body. - * - * Its static counterpart is {@link Phaser.Physics.Arcade.StaticBody}. - */ - class Body { + namespace Tweens { + type TweenConfigDefaults = { /** - * - * @param world The Arcade Physics simulation this Body belongs to. - * @param gameObject The Game Object this Body belongs to. + * The object, or an array of objects, to run the tween on. */ - constructor(world: Phaser.Physics.Arcade.World, gameObject: Phaser.GameObjects.GameObject); - + targets: object | object[]; /** - * The Arcade Physics simulation this Body belongs to. + * The number of milliseconds to delay before the tween will start. */ - world: Phaser.Physics.Arcade.World; - + delay?: number; /** - * The Game Object this Body belongs to. + * The duration of the tween in milliseconds. */ - gameObject: Phaser.GameObjects.GameObject; - + duration?: number; /** - * Transformations applied to this Body. + * The easing equation to use for the tween. */ - transform: object; - + ease?: string; /** - * Whether the Body's boundary is drawn to the debug display. + * Optional easing parameters. */ - debugShowBody: boolean; - + easeParams?: any[]; /** - * Whether the Body's velocity is drawn to the debug display. + * The number of milliseconds to hold the tween for before yoyo'ing. */ - debugShowVelocity: boolean; - + hold?: number; /** - * The color of this Body on the debug display. + * The number of times to repeat the tween. */ - debugBodyColor: integer; - + repeat?: number; /** - * Whether this Body is updated by the physics simulation. + * The number of milliseconds to pause before a tween will repeat. */ - enable: boolean; - + repeatDelay?: number; /** - * Whether this Body's boundary is circular (true) or rectangular (false). + * Should the tween complete, then reverse the values incrementally to get back to the starting tween values? The reverse tweening will also take `duration` milliseconds to complete. */ - isCircle: boolean; - + yoyo?: boolean; /** - * If this Body is circular, this is the unscaled radius of the Body's boundary, as set by setCircle(), in source pixels. - * The true radius is equal to `halfWidth`. + * Horizontally flip the target of the Tween when it completes (before it yoyos, if set to do so). Only works for targets that support the `flipX` property. */ - radius: number; - + flipX?: boolean; /** - * The offset of this Body's position from its Game Object's position, in source pixels. + * Vertically flip the target of the Tween when it completes (before it yoyos, if set to do so). Only works for targets that support the `flipY` property. */ - offset: Phaser.Math.Vector2; + flipY?: boolean; + }; - /** - * The position of this Body within the simulation. - */ - position: Phaser.Math.Vector2; + /** + * A Tween Event. + */ + type Event = string; - /** - * The position of this Body during the previous step. - */ - prev: Phaser.Math.Vector2; + type GetActiveCallback = (target: any, key: string, value: number, targetIndex: number, totalTargets: number, tween: Phaser.Tweens.Tween)=>void; + + type GetEndCallback = (target: any, key: string, value: number, targetIndex: number, totalTargets: number, tween: Phaser.Tweens.Tween)=>void; + type GetStartCallback = (target: any, key: string, value: number, targetIndex: number, totalTargets: number, tween: Phaser.Tweens.Tween)=>void; + + type NumberTweenBuilderConfig = { /** - * The position of this Body during the previous frame. + * The start number. */ - prevFrame: Phaser.Math.Vector2; - + from?: number; /** - * Whether this Body's `rotation` is affected by its angular acceleration and angular velocity. + * The end number. */ - allowRotation: boolean; - + to?: number; /** - * This body's rotation, in degrees, based on its angular acceleration and angular velocity. - * The Body's rotation controls the `angle` of its Game Object. - * It doesn't rotate the Body's boundary, which is always an axis-aligned rectangle or a circle. + * The number of milliseconds to delay before the tween will start. */ - rotation: number; - + delay?: number; /** - * The Body rotation, in degrees, during the previous step. + * The duration of the tween in milliseconds. */ - preRotation: number; - + duration?: number; /** - * The width of the Body boundary, in pixels. - * If the Body is circular, this is also the diameter. - * If you wish to change the width use the `Body.setSize` method. + * The easing equation to use for the tween. */ - readonly width: number; - + ease?: string | Function; /** - * The height of the Body boundary, in pixels. - * If the Body is circular, this is also the diameter. - * If you wish to change the height use the `Body.setSize` method. + * Optional easing parameters. */ - readonly height: number; - + easeParams?: any[]; /** - * The unscaled width of the Body, in source pixels, as set by setSize(). - * The default is the width of the Body's Game Object's texture frame. + * The number of milliseconds to hold the tween for before yoyo'ing. */ - sourceWidth: number; - + hold?: number; /** - * The unscaled height of the Body, in source pixels, as set by setSize(). - * The default is the height of the Body's Game Object's texture frame. + * The number of times to repeat the tween. */ - sourceHeight: number; - + repeat?: number; /** - * Half the Body's width, in pixels. + * The number of milliseconds to pause before a tween will repeat. */ - halfWidth: number; - + repeatDelay?: number; /** - * Half the Body's height, in pixels. + * Should the tween complete, then reverse the values incrementally to get back to the starting tween values? The reverse tweening will also take `duration` milliseconds to complete. */ - halfHeight: number; - + yoyo?: boolean; /** - * The center of the Body's boundary. - * The midpoint of its `position` (top-left corner) and its bottom-right corner. + * Used when the Tween is part of a Timeline. */ - center: Phaser.Math.Vector2; - + offset?: string | number | Function | object | any[]; /** - * The Body's velocity, in pixels per second. + * The time the tween will wait before the onComplete event is dispatched once it has completed, in ms. */ - velocity: Phaser.Math.Vector2; - + completeDelay?: string | number | Function | object | any[]; /** - * The Body's change in position (due to velocity) at the last step, in pixels. - * - * The size of this value depends on the simulation's step rate. + * The number of times the tween will repeat. (A value of 1 means the tween will play twice, as it repeated once.) The first loop starts after every property tween has completed once. */ - readonly newVelocity: Phaser.Math.Vector2; - + loop?: string | number | Function | object | any[]; /** - * The Body's absolute maximum change in position, in pixels per step. + * The time the tween will pause before starting either a yoyo or returning to the start for a repeat. */ - deltaMax: Phaser.Math.Vector2; - + loopDelay?: string | number | Function | object | any[]; /** - * The Body's change in velocity, in pixels per second squared. + * Does the tween start in a paused state (true) or playing (false)? */ - acceleration: Phaser.Math.Vector2; - + paused?: boolean; /** - * Whether this Body's velocity is affected by its `drag`. + * Use frames or milliseconds? */ - allowDrag: boolean; - + useFrames?: boolean; /** - * Absolute loss of velocity due to movement, in pixels per second squared. - * The x and y components are applied separately. - * - * When `useDamping` is true, this is 1 minus the damping factor. - * A value of 1 means the Body loses no velocity. - * A value of 0.95 means the Body loses 5% of its velocity per step. - * A value of 0.5 means the Body loses 50% of its velocity per step. - * - * Drag is applied only when `acceleration` is zero. + * Scope (this) for the callbacks. The default scope is the tween. */ - drag: Phaser.Math.Vector2 | number; - + callbackScope?: any; /** - * Whether this Body's position is affected by gravity (local or world). + * A function to call when the tween completes. */ - allowGravity: boolean; - + onComplete?: Phaser.Types.Tweens.TweenOnCompleteCallback; /** - * Acceleration due to gravity (specific to this Body), in pixels per second squared. - * Total gravity is the sum of this vector and the simulation's `gravity`. + * Additional parameters to pass to `onComplete`. */ - gravity: Phaser.Math.Vector2; - + onCompleteParams?: any[]; /** - * Rebound following a collision, relative to 1. + * Scope (this) for `onComplete`. */ - bounce: Phaser.Math.Vector2; - + onCompleteScope?: any; /** - * Rebound following a collision with the world boundary, relative to 1. - * If null, `bounce` is used instead. + * A function to call each time the tween loops. */ - worldBounce: Phaser.Math.Vector2; - + onLoop?: Phaser.Types.Tweens.TweenOnLoopCallback; /** - * The rectangle used for world boundary collisions. - * - * By default it is set to the world boundary rectangle. Or, if this Body was - * created by a Physics Group, then whatever rectangle that Group defined. - * - * You can also change it by using the `Body.setBoundsRectangle` method. + * Additional parameters to pass to `onLoop`. */ - customBoundsRectangle: Phaser.Geom.Rectangle; - + onLoopParams?: any[]; /** - * Whether the simulation emits a `worldbounds` event when this Body collides with the world boundary (and `collideWorldBounds` is also true). + * Scope (this) for `onLoop`. */ - onWorldBounds: boolean; - + onLoopScope?: any; /** - * Whether the simulation emits a `collide` event when this Body collides with another. + * A function to call each time the tween repeats. Called once per property per target. */ - onCollide: boolean; - + onRepeat?: Phaser.Types.Tweens.TweenOnRepeatCallback; /** - * Whether the simulation emits an `overlap` event when this Body overlaps with another. + * Additional parameters to pass to `onRepeat`. */ - onOverlap: boolean; - + onRepeatParams?: any[]; /** - * The Body's absolute maximum velocity, in pixels per second. - * The horizontal and vertical components are applied separately. + * Scope (this) for `onRepeat`. */ - maxVelocity: Phaser.Math.Vector2; - + onRepeatScope?: any; /** - * The maximum speed this Body is allowed to reach, in pixels per second. - * - * If not negative it limits the scalar value of speed. - * - * Any negative value means no maximum is being applied (the default). + * A function to call when the tween starts. */ - maxSpeed: number; - + onStart?: Phaser.Types.Tweens.TweenOnStartCallback; /** - * If this Body is `immovable` and in motion, `friction` is the proportion of this Body's motion received by the riding Body on each axis, relative to 1. - * The horizontal component (x) is applied only when two colliding Bodies are separated vertically. - * The vertical component (y) is applied only when two colliding Bodies are separated horizontally. - * The default value (1, 0) moves the riding Body horizontally in equal proportion to this Body and vertically not at all. + * Additional parameters to pass to `onStart`. */ - friction: Phaser.Math.Vector2; - + onStartParams?: any[]; /** - * If this Body is using `drag` for deceleration this property controls how the drag is applied. - * If set to `true` drag will use a damping effect rather than a linear approach. If you are - * creating a game where the Body moves freely at any angle (i.e. like the way the ship moves in - * the game Asteroids) then you will get a far smoother and more visually correct deceleration - * by using damping, avoiding the axis-drift that is prone with linear deceleration. - * - * If you enable this property then you should use far smaller `drag` values than with linear, as - * they are used as a multiplier on the velocity. Values such as 0.95 will give a nice slow - * deceleration, where-as smaller values, such as 0.5 will stop an object almost immediately. + * Scope (this) for `onStart`. */ - useDamping: boolean; - + onStartScope?: any; /** - * The rate of change of this Body's `rotation`, in degrees per second. + * A function to call when the tween is stopped. */ - angularVelocity: number; - + onStop?: Phaser.Types.Tweens.TweenOnStopCallback; /** - * The Body's angular acceleration (change in angular velocity), in degrees per second squared. + * Additional parameters to pass to `onStop`. */ - angularAcceleration: number; - + onStopParams?: any[]; /** - * Loss of angular velocity due to angular movement, in degrees per second. - * - * Angular drag is applied only when angular acceleration is zero. + * Scope (this) for `onStop`. */ - angularDrag: number; - + onStopScope?: any; /** - * The Body's maximum angular velocity, in degrees per second. + * A function to call each time the tween steps. Called once per property per target. */ - maxAngular: number; - + onUpdate?: Phaser.Types.Tweens.TweenOnUpdateCallback; /** - * The Body's inertia, relative to a default unit (1). - * With `bounce`, this affects the exchange of momentum (velocities) during collisions. + * Additional parameters to pass to `onUpdate`. */ - mass: number; - + onUpdateParams?: any[]; /** - * The calculated angle of this Body's velocity vector, in radians, during the last step. + * Scope (this) for `onUpdate`. */ - angle: number; - + onUpdateScope?: any; /** - * The calculated magnitude of the Body's velocity, in pixels per second, during the last step. + * A function to call each time the tween yoyos. Called once per property per target. */ - speed: number; - + onYoyo?: Phaser.Types.Tweens.TweenOnYoyoCallback; /** - * The direction of the Body's velocity, as calculated during the last step. - * If the Body is moving on both axes (diagonally), this describes motion on the vertical axis only. + * Additional parameters to pass to `onYoyo`. */ - facing: integer; - + onYoyoParams?: any[]; /** - * Whether this Body can be moved by collisions with another Body. + * Scope (this) for `onYoyo`. */ - immovable: boolean; + onYoyoScope?: any; + }; + type StaggerConfig = { /** - * Whether the Body's position and rotation are affected by its velocity, acceleration, drag, and gravity. + * The value to start the stagger from. Can be used as a way to offset the stagger while still using a range for the value. */ - moves: boolean; - + start?: number; /** - * A flag disabling the default horizontal separation of colliding bodies. - * Pass your own `collideCallback` to the collider. + * An ease to apply across the staggered values. Can either be a string, such as 'sine.inout', or a function. */ - customSeparateX: boolean; - + ease?: string | Function; /** - * A flag disabling the default vertical separation of colliding bodies. - * Pass your own `collideCallback` to the collider. + * The index to start the stagger from. Can be the strings `first`, `last` or `center`, or an integer representing the stagger position. */ - customSeparateY: boolean; - + from?: string | number; /** - * The amount of horizontal overlap (before separation), if this Body is colliding with another. + * Set the stagger to run across a grid by providing an array where element 0 is the width of the grid and element 1 is the height. Combine with the 'from' property to control direction. */ - overlapX: number; + grid?: number[]; + }; + type TimelineBuilderConfig = { /** - * The amount of vertical overlap (before separation), if this Body is colliding with another. + * An array of tween configuration objects to create and add into the new Timeline. If this doesn't exist or is empty, the Timeline will start off paused and none of the other configuration settings will be read. If it's a function, it will be called and its return value will be used as the array. */ - overlapY: number; - + tweens?: Phaser.Types.Tweens.TweenBuilderConfig[] | object[] | Function; /** - * The amount of overlap (before separation), if this Body is circular and colliding with another circular body. + * An array (or function which returns one) of default targets to which to apply the Timeline. Each individual Tween configuration can override this value. */ - overlapR: number; - + targets?: any; /** - * Whether this Body is overlapped with another and both are not moving, on at least one axis. + * If specified, each Tween in the Timeline will get an equal portion of this duration, usually in milliseconds, by default. Each individual Tween configuration can override the Tween's duration. */ - embedded: boolean; - + totalDuration?: number; /** - * Whether this Body interacts with the world boundary. + * If `totalDuration` is not specified, the default duration, usually in milliseconds, of each Tween which will be created. Each individual Tween configuration can override the Tween's duration. */ - collideWorldBounds: boolean; - + duration?: number; /** - * Whether this Body is checked for collisions and for which directions. - * You can set `checkCollision.none = true` to disable collision checks. + * The number of milliseconds to delay before the tween will start. Each individual Tween configuration can override this value. */ - checkCollision: Phaser.Types.Physics.Arcade.ArcadeBodyCollision; - + delay?: number; /** - * Whether this Body is colliding with a Body or Static Body and in which direction. - * In a collision where both bodies have zero velocity, `embedded` will be set instead. + * Optional easing parameters. Each individual Tween configuration can override this value. */ - touching: Phaser.Types.Physics.Arcade.ArcadeBodyCollision; - + easeParams?: any[]; /** - * This Body's `touching` value during the previous step. + * The easing equation to use for each tween. Each individual Tween configuration can override this value. */ - wasTouching: Phaser.Types.Physics.Arcade.ArcadeBodyCollision; - + ease?: string | Function; /** - * Whether this Body is colliding with a Static Body, a tile, or the world boundary. - * In a collision with a Static Body, if this Body has zero velocity then `embedded` will be set instead. + * The number of milliseconds to hold each tween before yoyo'ing. Each individual Tween configuration can override this value. */ - blocked: Phaser.Types.Physics.Arcade.ArcadeBodyCollision; - + hold?: number; /** - * Whether to automatically synchronize this Body's dimensions to the dimensions of its Game Object's visual bounds. + * The number of times to repeat each tween. Each individual Tween configuration can override this value. */ - syncBounds: boolean; - + repeat?: number; /** - * The Body's physics type (dynamic or static). + * The number of milliseconds to pause before each tween will repeat. Each individual Tween configuration can override this value. */ - readonly physicsType: integer; - + repeatDelay?: number; /** - * Updates the Body's `transform`, `width`, `height`, and `center` from its Game Object. - * The Body's `position` isn't changed. + * Should each tween complete, then reverse the values incrementally to get back to the starting tween values? The reverse tweening will also take `duration` milliseconds to complete. Each individual Tween configuration can override this value. */ - updateBounds(): void; - + yoyo?: boolean; /** - * Updates the Body's `center` from its `position`, `width`, and `height`. + * Horizontally flip the target of the Tween when it completes (before it yoyos, if set to do so). Only works for targets that support the `flipX` property. Each individual Tween configuration can override this value. */ - updateCenter(): void; - + flipX?: boolean; /** - * Prepares the Body for a physics step by resetting the `wasTouching`, `touching` and `blocked` states. - * - * This method is only called if the physics world is going to run a step this frame. + * Vertically flip the target of the Tween when it completes (before it yoyos, if set to do so). Only works for targets that support the `flipY` property. Each individual Tween configuration can override this value. */ - resetFlags(): void; - + flipY?: boolean; /** - * Syncs the position body position with the parent Game Object. - * - * This method is called every game frame, regardless if the world steps or not. - * @param willStep Will this Body run an update as well? - * @param delta The delta time, in seconds, elapsed since the last frame. + * If specified, the time to wait, usually in milliseconds, before the Timeline completes. */ - preUpdate(willStep: boolean, delta: number): void; - + completeDelay?: number | Function | object | any[]; /** - * Performs a single physics step and updates the body velocity, angle, speed and other properties. - * - * This method can be called multiple times per game frame, depending on the physics step rate. - * - * The results are synced back to the Game Object in `postUpdate`. - * @param delta The delta time, in seconds, elapsed since the last frame. + * How many times the Timeline should loop, or -1 to loop indefinitely. */ - update(delta: number): void; - + loop?: number | Function | object | any[]; /** - * Feeds the Body results back into the parent Game Object. - * - * This method is called every game frame, regardless if the world steps or not. + * The time, usually in milliseconds, between each loop. */ - postUpdate(): void; - + loopDelay?: number | Function | object | any[]; /** - * Sets a custom collision boundary rectangle. Use if you want to have a custom - * boundary instead of the world boundaries. - * @param bounds The new boundary rectangle. Pass `null` to use the World bounds. + * If `true`, the Timeline will start paused. */ - setBoundsRectangle(bounds?: Phaser.Geom.Rectangle): this; - + paused?: boolean; /** - * Checks for collisions between this Body and the world boundary and separates them. + * If `true`, all duration in the Timeline will be in frames instead of milliseconds. */ - checkWorldBounds(): boolean; - + useFrames?: boolean; /** - * Sets the offset of the Body's position from its Game Object's position. - * @param x The horizontal offset, in source pixels. - * @param y The vertical offset, in source pixels. Default x. + * The default scope (`this` value) to use for each callback registered by the Timeline Builder. If not specified, the Timeline itself will be used. */ - setOffset(x: number, y?: number): Phaser.Physics.Arcade.Body; - + callbackScope?: any; /** - * Sizes and positions this Body's boundary, as a rectangle. - * Modifies the Body `offset` if `center` is true (the default). - * Resets the width and height to match current frame, if no width and height provided and a frame is found. - * @param width The width of the Body in pixels. Cannot be zero. If not given, and the parent Game Object has a frame, it will use the frame width. - * @param height The height of the Body in pixels. Cannot be zero. If not given, and the parent Game Object has a frame, it will use the frame height. - * @param center Modify the Body's `offset`, placing the Body's center on its Game Object's center. Only works if the Game Object has the `getCenter` method. Default true. + * If specified, the `onStart` callback for the Timeline, called every time it starts playing. */ - setSize(width?: integer, height?: integer, center?: boolean): Phaser.Physics.Arcade.Body; - + onStart?: Phaser.Types.Tweens.TimelineOnStartCallback; /** - * Sizes and positions this Body's boundary, as a circle. - * @param radius The radius of the Body, in source pixels. - * @param offsetX The horizontal offset of the Body from its Game Object, in source pixels. - * @param offsetY The vertical offset of the Body from its Game Object, in source pixels. + * The scope (`this` value) to use for the `onStart` callback. If not specified, the `callbackScope` will be used. */ - setCircle(radius: number, offsetX?: number, offsetY?: number): Phaser.Physics.Arcade.Body; - + onStartScope?: any; /** - * Resets this Body to the given coordinates. Also positions its parent Game Object to the same coordinates. - * If the Body had any velocity or acceleration it is lost as a result of calling this. - * @param x The horizontal position to place the Game Object and Body. - * @param y The vertical position to place the Game Object and Body. + * Additional arguments to pass to the `onStart` callback. The Timeline will always be the first argument. */ - reset(x: number, y: number): void; - + onStartParams?: any[]; /** - * Sets acceleration, velocity, and speed to zero. + * If specified, the `onUpdate` callback for the Timeline, called every frame it's active, regardless of its Tweens. */ - stop(): Phaser.Physics.Arcade.Body; - + onUpdate?: Phaser.Types.Tweens.TimelineOnUpdateCallback; /** - * Copies the coordinates of this Body's edges into an object. - * @param obj An object to copy the values into. + * The scope (`this` value) to use for the `onUpdate` callback. If not specified, the `callbackScope` will be used. */ - getBounds(obj: Phaser.Types.Physics.Arcade.ArcadeBodyBounds): Phaser.Types.Physics.Arcade.ArcadeBodyBounds; - + onUpdateScope?: any; /** - * Tests if the coordinates are within this Body's boundary. - * @param x The horizontal coordinate. - * @param y The vertical coordinate. + * Additional arguments to pass to the `onUpdate` callback. The Timeline will always be the first argument. */ - hitTest(x: number, y: number): boolean; - + onUpdateParams?: any[]; /** - * Whether this Body is touching a tile or the world boundary while moving down. + * If specified, the `onLoop` callback for the Timeline, called every time it loops. */ - onFloor(): boolean; - + onLoop?: Phaser.Types.Tweens.TimelineOnLoopCallback; /** - * Whether this Body is touching a tile or the world boundary while moving up. + * The scope (`this` value) to use for the `onLoop` callback. If not specified, the `callbackScope` will be used. */ - onCeiling(): boolean; - + onLoopScope?: any; /** - * Whether this Body is touching a tile or the world boundary while moving left or right. + * Additional arguments to pass to the `onLoop` callback. The Timeline will always be the first argument. */ - onWall(): boolean; - + onLoopParams?: any[]; /** - * The absolute (non-negative) change in this Body's horizontal position from the previous step. + * If specified, the `onYoyo` callback for the Timeline, called every time it yoyos. */ - deltaAbsX(): number; - + onYoyo?: Phaser.Types.Tweens.TimelineOnYoyoCallback; /** - * The absolute (non-negative) change in this Body's vertical position from the previous step. + * The scope (`this` value) to use for the `onYoyo` callback. If not specified, the `callbackScope` will be used. */ - deltaAbsY(): number; - + onYoyoScope?: any; /** - * The change in this Body's horizontal position from the previous step. - * This value is set during the Body's update phase. - * - * As a Body can update multiple times per step this may not hold the final - * delta value for the Body. In this case, please see the `deltaXFinal` method. + * Additional arguments to pass to the `onYoyo` callback. The first argument will always be `null`, while the Timeline will always be the second argument. */ - deltaX(): number; - + onYoyoParams?: any[]; /** - * The change in this Body's vertical position from the previous step. - * This value is set during the Body's update phase. - * - * As a Body can update multiple times per step this may not hold the final - * delta value for the Body. In this case, please see the `deltaYFinal` method. + * If specified, the `onComplete` callback for the Timeline, called after it completes. */ - deltaY(): number; - + onComplete?: Phaser.Types.Tweens.TimelineOnCompleteCallback; /** - * The change in this Body's horizontal position from the previous game update. - * - * This value is set during the `postUpdate` phase and takes into account the - * `deltaMax` and final position of the Body. - * - * Because this value is not calculated until `postUpdate`, you must listen for it - * during a Scene `POST_UPDATE` or `RENDER` event, and not in `update`, as it will - * not be calculated by that point. If you _do_ use these values in `update` they - * will represent the delta from the _previous_ game frame. + * The scope (`this` value) to use for the `onComplete` callback. If not specified, the `callbackScope` will be used. */ - deltaXFinal(): number; - + onCompleteScope?: any; /** - * The change in this Body's vertical position from the previous game update. - * - * This value is set during the `postUpdate` phase and takes into account the - * `deltaMax` and final position of the Body. - * - * Because this value is not calculated until `postUpdate`, you must listen for it - * during a Scene `POST_UPDATE` or `RENDER` event, and not in `update`, as it will - * not be calculated by that point. If you _do_ use these values in `update` they - * will represent the delta from the _previous_ game frame. + * Additional arguments to pass to the `onComplete` callback. The Timeline will always be the first argument. */ - deltaYFinal(): number; + onCompleteParams?: any[]; + }; + + type TimelineOnCompleteCallback = (timeline: Phaser.Tweens.Timeline, ...param: any[])=>void; + + type TimelineOnLoopCallback = (timeline: Phaser.Tweens.Timeline, ...param: any[])=>void; + + type TimelineOnStartCallback = (timeline: Phaser.Tweens.Timeline, ...param: any[])=>void; + + type TimelineOnUpdateCallback = (timeline: Phaser.Tweens.Timeline, ...param: any[])=>void; + + type TimelineOnYoyoCallback = (timeline: Phaser.Tweens.Timeline, ...param: any[])=>void; + type TweenBuilderConfig = { /** - * The change in this Body's rotation from the previous step, in degrees. + * The object, or an array of objects, to run the tween on. */ - deltaZ(): number; - + targets: any; /** - * Disables this Body and marks it for deletion by the simulation. + * The number of milliseconds to delay before the tween will start. */ - destroy(): void; - + delay?: number | Function; /** - * Draws this Body's boundary and velocity, if enabled. - * @param graphic The Graphics object to draw on. + * The duration of the tween in milliseconds. */ - drawDebug(graphic: Phaser.GameObjects.Graphics): void; - + duration?: number; /** - * Whether this Body will be drawn to the debug display. + * The easing equation to use for the tween. */ - willDrawDebug(): boolean; - + ease?: string | Function; /** - * Sets whether this Body collides with the world boundary. - * - * Optionally also sets the World Bounce values. If the `Body.worldBounce` is null, it's set to a new Phaser.Math.Vector2 first. - * @param value `true` if this body should collide with the world bounds, otherwise `false`. Default true. - * @param bounceX If given this will be replace the `worldBounce.x` value. - * @param bounceY If given this will be replace the `worldBounce.y` value. + * Optional easing parameters. */ - setCollideWorldBounds(value?: boolean, bounceX?: number, bounceY?: number): Phaser.Physics.Arcade.Body; - + easeParams?: any[]; /** - * Sets the Body's velocity. - * @param x The horizontal velocity, in pixels per second. - * @param y The vertical velocity, in pixels per second. Default x. + * The number of milliseconds to hold the tween for before yoyo'ing. */ - setVelocity(x: number, y?: number): Phaser.Physics.Arcade.Body; - + hold?: number; /** - * Sets the Body's horizontal velocity. - * @param value The velocity, in pixels per second. + * The number of times each property tween repeats. */ - setVelocityX(value: number): Phaser.Physics.Arcade.Body; - + repeat?: number; /** - * Sets the Body's vertical velocity. - * @param value The velocity, in pixels per second. + * The number of milliseconds to pause before a repeat. */ - setVelocityY(value: number): Phaser.Physics.Arcade.Body; - + repeatDelay?: number; /** - * Sets the Body's maximum velocity. - * @param x The horizontal velocity, in pixels per second. - * @param y The vertical velocity, in pixels per second. Default x. + * Should the tween complete, then reverse the values incrementally to get back to the starting tween values? The reverse tweening will also take `duration` milliseconds to complete. */ - setMaxVelocity(x: number, y?: number): Phaser.Physics.Arcade.Body; - + yoyo?: boolean; /** - * Sets the maximum speed the Body can move. - * @param value The maximum speed value, in pixels per second. Set to a negative value to disable. + * Horizontally flip the target of the Tween when it completes (before it yoyos, if set to do so). Only works for targets that support the `flipX` property. */ - setMaxSpeed(value: number): Phaser.Physics.Arcade.Body; - + flipX?: boolean; /** - * Sets the Body's bounce. - * @param x The horizontal bounce, relative to 1. - * @param y The vertical bounce, relative to 1. + * Vertically flip the target of the Tween when it completes (before it yoyos, if set to do so). Only works for targets that support the `flipY` property. */ - setBounce(x: number, y: number): Phaser.Physics.Arcade.Body; - + flipY?: boolean; /** - * Sets the Body's horizontal bounce. - * @param value The bounce, relative to 1. + * Used when the Tween is part of a Timeline. */ - setBounceX(value: number): Phaser.Physics.Arcade.Body; - + offset?: string | number | Function | object | any[]; /** - * Sets the Body's vertical bounce. - * @param value The bounce, relative to 1. + * The time the tween will wait before the onComplete event is dispatched once it has completed, in ms. */ - setBounceY(value: number): Phaser.Physics.Arcade.Body; - + completeDelay?: string | number | Function | object | any[]; /** - * Sets the Body's acceleration. - * @param x The horizontal component, in pixels per second squared. - * @param y The vertical component, in pixels per second squared. + * The number of times the tween will repeat. (A value of 1 means the tween will play twice, as it repeated once.) The first loop starts after every property tween has completed once. */ - setAcceleration(x: number, y: number): Phaser.Physics.Arcade.Body; - + loop?: string | number | Function | object | any[]; /** - * Sets the Body's horizontal acceleration. - * @param value The acceleration, in pixels per second squared. + * The time the tween will pause before starting either a yoyo or returning to the start for a repeat. */ - setAccelerationX(value: number): Phaser.Physics.Arcade.Body; - + loopDelay?: string | number | Function | object | any[]; /** - * Sets the Body's vertical acceleration. - * @param value The acceleration, in pixels per second squared. + * Does the tween start in a paused state (true) or playing (false)? */ - setAccelerationY(value: number): Phaser.Physics.Arcade.Body; - + paused?: boolean; /** - * Enables or disables drag. - * @param value `true` to allow drag on this body, or `false` to disable it. Default true. + * The properties to tween. */ - setAllowDrag(value?: boolean): Phaser.Physics.Arcade.Body; - + props?: {[key: string]: (number|string|Phaser.Types.Tweens.GetEndCallback|Phaser.Types.Tweens.TweenPropConfig)}; /** - * Enables or disables gravity's effect on this Body. - * @param value `true` to allow gravity on this body, or `false` to disable it. Default true. + * Use frames or milliseconds? */ - setAllowGravity(value?: boolean): Phaser.Physics.Arcade.Body; - + useFrames?: boolean; /** - * Enables or disables rotation. - * @param value `true` to allow rotation on this body, or `false` to disable it. Default true. + * Scope (this) for the callbacks. The default scope is the tween. */ - setAllowRotation(value?: boolean): Phaser.Physics.Arcade.Body; - + callbackScope?: any; /** - * Sets the Body's drag. - * @param x The horizontal component, in pixels per second squared. - * @param y The vertical component, in pixels per second squared. + * A function to call when the tween completes. */ - setDrag(x: number, y: number): Phaser.Physics.Arcade.Body; - + onComplete?: Phaser.Types.Tweens.TweenOnCompleteCallback; /** - * Sets the Body's horizontal drag. - * @param value The drag, in pixels per second squared. + * Additional parameters to pass to `onComplete`. */ - setDragX(value: number): Phaser.Physics.Arcade.Body; - + onCompleteParams?: any[]; /** - * Sets the Body's vertical drag. - * @param value The drag, in pixels per second squared. + * Scope (this) for `onComplete`. */ - setDragY(value: number): Phaser.Physics.Arcade.Body; - + onCompleteScope?: any; /** - * Sets the Body's gravity. - * @param x The horizontal component, in pixels per second squared. - * @param y The vertical component, in pixels per second squared. + * A function to call each time the tween loops. */ - setGravity(x: number, y: number): Phaser.Physics.Arcade.Body; - + onLoop?: Phaser.Types.Tweens.TweenOnLoopCallback; /** - * Sets the Body's horizontal gravity. - * @param value The gravity, in pixels per second squared. + * Additional parameters to pass to `onLoop`. */ - setGravityX(value: number): Phaser.Physics.Arcade.Body; - + onLoopParams?: any[]; /** - * Sets the Body's vertical gravity. - * @param value The gravity, in pixels per second squared. + * Scope (this) for `onLoop`. */ - setGravityY(value: number): Phaser.Physics.Arcade.Body; - + onLoopScope?: any; /** - * Sets the Body's friction. - * @param x The horizontal component, relative to 1. - * @param y The vertical component, relative to 1. + * A function to call each time the tween repeats. Called once per property per target. */ - setFriction(x: number, y: number): Phaser.Physics.Arcade.Body; - + onRepeat?: Phaser.Types.Tweens.TweenOnRepeatCallback; /** - * Sets the Body's horizontal friction. - * @param value The friction value, relative to 1. + * Additional parameters to pass to `onRepeat`. */ - setFrictionX(value: number): Phaser.Physics.Arcade.Body; - + onRepeatParams?: any[]; /** - * Sets the Body's vertical friction. - * @param value The friction value, relative to 1. + * Scope (this) for `onRepeat`. */ - setFrictionY(value: number): Phaser.Physics.Arcade.Body; - + onRepeatScope?: any; /** - * Sets the Body's angular velocity. - * @param value The velocity, in degrees per second. + * A function to call when the tween starts playback, after any delays have expired. */ - setAngularVelocity(value: number): Phaser.Physics.Arcade.Body; - + onStart?: Phaser.Types.Tweens.TweenOnStartCallback; /** - * Sets the Body's angular acceleration. - * @param value The acceleration, in degrees per second squared. + * Additional parameters to pass to `onStart`. */ - setAngularAcceleration(value: number): Phaser.Physics.Arcade.Body; - + onStartParams?: any[]; /** - * Sets the Body's angular drag. - * @param value The drag, in degrees per second squared. + * Scope (this) for `onStart`. */ - setAngularDrag(value: number): Phaser.Physics.Arcade.Body; - + onStartScope?: any; /** - * Sets the Body's mass. - * @param value The mass value, relative to 1. + * A function to call when the tween is stopped. */ - setMass(value: number): Phaser.Physics.Arcade.Body; - + onStop?: Phaser.Types.Tweens.TweenOnStopCallback; /** - * Sets the Body's `immovable` property. - * @param value The value to assign to `immovable`. Default true. + * Additional parameters to pass to `onStop`. */ - setImmovable(value?: boolean): Phaser.Physics.Arcade.Body; - + onStopParams?: any[]; /** - * Sets the Body's `enable` property. - * @param value The value to assign to `enable`. Default true. + * Scope (this) for `onStop`. */ - setEnable(value?: boolean): Phaser.Physics.Arcade.Body; - + onStopScope?: any; /** - * The Body's horizontal position (left edge). + * A function to call each time the tween steps. Called once per property per target. */ - x: number; - + onUpdate?: Phaser.Types.Tweens.TweenOnUpdateCallback; /** - * The Body's vertical position (top edge). + * Additional parameters to pass to `onUpdate`. */ - y: number; - + onUpdateParams?: any[]; /** - * The left edge of the Body's boundary. Identical to x. + * Scope (this) for `onUpdate`. */ - readonly left: number; - + onUpdateScope?: any; /** - * The right edge of the Body's boundary. + * A function to call each time the tween yoyos. Called once per property per target. */ - readonly right: number; - + onYoyo?: Phaser.Types.Tweens.TweenOnYoyoCallback; /** - * The top edge of the Body's boundary. Identical to y. + * Additional parameters to pass to `onYoyo`. */ - readonly top: number; - + onYoyoParams?: any[]; /** - * The bottom edge of this Body's boundary. + * Scope (this) for `onYoyo`. */ - readonly bottom: number; - - } - - /** - * An Arcade Physics Collider will automatically check for collision, or overlaps, between two objects - * every step. If a collision, or overlap, occurs it will invoke the given callbacks. - */ - class Collider { + onYoyoScope?: any; /** - * - * @param world The Arcade physics World that will manage the collisions. - * @param overlapOnly Whether to check for collisions or overlap. - * @param object1 The first object to check for collision. - * @param object2 The second object to check for collision. - * @param collideCallback The callback to invoke when the two objects collide. - * @param processCallback The callback to invoke when the two objects collide. Must return a boolean. - * @param callbackContext The scope in which to call the callbacks. + * A function to call when the tween becomes active within the Tween Manager. */ - constructor(world: Phaser.Physics.Arcade.World, overlapOnly: boolean, object1: Phaser.Types.Physics.Arcade.ArcadeColliderType, object2: Phaser.Types.Physics.Arcade.ArcadeColliderType, collideCallback: ArcadePhysicsCallback, processCallback: ArcadePhysicsCallback, callbackContext: any); - + onActive?: Phaser.Types.Tweens.TweenOnActiveCallback; /** - * The world in which the bodies will collide. + * Additional parameters to pass to `onActive`. */ - world: Phaser.Physics.Arcade.World; - + onActiveParams?: any[]; /** - * The name of the collider (unused by Phaser). + * Scope (this) for `onActive`. */ - name: string; + onActiveScope?: any; + }; + type TweenDataConfig = { /** - * Whether the collider is active. + * The target to tween. */ - active: boolean; - + target: any; /** - * Whether to check for collisions or overlaps. + * The target index within the Tween targets array. */ - overlapOnly: boolean; - + index: number; /** - * The first object to check for collision. + * The property of the target being tweened. */ - object1: Phaser.Types.Physics.Arcade.ArcadeColliderType; - + key: string; /** - * The second object to check for collision. + * If not null, is invoked _immediately_ as soon as the TweenData is running, and is set on the target property. */ - object2: Phaser.Types.Physics.Arcade.ArcadeColliderType; - + getActiveValue: Phaser.Types.Tweens.GetActiveCallback; /** - * The callback to invoke when the two objects collide. + * The returned value sets what the property will be at the END of the Tween. */ - collideCallback: ArcadePhysicsCallback; - + getEndValue: Phaser.Types.Tweens.GetEndCallback; /** - * If a processCallback exists it must return true or collision checking will be skipped. + * The returned value sets what the property will be at the START of the Tween. */ - processCallback: ArcadePhysicsCallback; - + getStartValue: Phaser.Types.Tweens.GetStartCallback; /** - * The context the collideCallback and processCallback will run in. + * The ease function this tween uses. */ - callbackContext: object; - + ease: Function; /** - * A name for the Collider. - * - * Phaser does not use this value, it's for your own reference. - * @param name The name to assign to the Collider. + * Duration of the tween in ms/frames, excludes time for yoyo or repeats. */ - setName(name: string): Phaser.Physics.Arcade.Collider; - + duration?: number; /** - * Called by World as part of its step processing, initial operation of collision checking. + * The total calculated duration of this TweenData (based on duration, repeat, delay and yoyo) */ - update(): void; - + totalDuration?: number; /** - * Removes Collider from World and disposes of its resources. + * Time in ms/frames before tween will start. */ - destroy(): void; - - } - - namespace Components { + delay?: number; /** - * Provides methods used for setting the acceleration properties of an Arcade Physics Body. + * Cause the tween to return back to its start value after hold has expired. */ - interface Acceleration { - /** - * Sets the body's horizontal and vertical acceleration. If the vertical acceleration value is not provided, the vertical acceleration is set to the same value as the horizontal acceleration. - * @param x The horizontal acceleration - * @param y The vertical acceleration Default x. - */ - setAcceleration(x: number, y?: number): this; - /** - * Sets the body's horizontal acceleration. - * @param value The horizontal acceleration - */ - setAccelerationX(value: number): this; - /** - * Sets the body's vertical acceleration. - * @param value The vertical acceleration - */ - setAccelerationY(value: number): this; - } - + yoyo?: boolean; /** - * Provides methods used for setting the angular acceleration properties of an Arcade Physics Body. + * Time in ms/frames the tween will pause before running the yoyo or starting a repeat. */ - interface Angular { - /** - * Sets the angular velocity of the body. - * - * In Arcade Physics, bodies cannot rotate. They are always axis-aligned. - * However, they can have angular motion, which is passed on to the Game Object bound to the body, - * causing them to visually rotate, even though the body remains axis-aligned. - * @param value The amount of angular velocity. - */ - setAngularVelocity(value: number): this; - /** - * Sets the angular acceleration of the body. - * - * In Arcade Physics, bodies cannot rotate. They are always axis-aligned. - * However, they can have angular motion, which is passed on to the Game Object bound to the body, - * causing them to visually rotate, even though the body remains axis-aligned. - * @param value The amount of angular acceleration. - */ - setAngularAcceleration(value: number): this; - /** - * Sets the angular drag of the body. Drag is applied to the current velocity, providing a form of deceleration. - * @param value The amount of drag. - */ - setAngularDrag(value: number): this; - } - + hold?: number; /** - * Provides methods used for setting the bounce properties of an Arcade Physics Body. + * Number of times to repeat the tween. The tween will always run once regardless, so a repeat value of '1' will play the tween twice. */ - interface Bounce { - /** - * Sets the bounce values of this body. - * - * Bounce is the amount of restitution, or elasticity, the body has when it collides with another object. - * A value of 1 means that it will retain its full velocity after the rebound. A value of 0 means it will not rebound at all. - * @param x The amount of horizontal bounce to apply on collision. A float, typically between 0 and 1. - * @param y The amount of vertical bounce to apply on collision. A float, typically between 0 and 1. Default x. - */ - setBounce(x: number, y?: number): this; - /** - * Sets the horizontal bounce value for this body. - * @param value The amount of horizontal bounce to apply on collision. A float, typically between 0 and 1. - */ - setBounceX(value: number): this; - /** - * Sets the vertical bounce value for this body. - * @param value The amount of vertical bounce to apply on collision. A float, typically between 0 and 1. - */ - setBounceY(value: number): this; - /** - * Sets whether this Body collides with the world boundary. - * - * Optionally also sets the World Bounce values. If the `Body.worldBounce` is null, it's set to a new Phaser.Math.Vector2 first. - * @param value `true` if this body should collide with the world bounds, otherwise `false`. Default true. - * @param bounceX If given this will be replace the `worldBounce.x` value. - * @param bounceY If given this will be replace the `worldBounce.y` value. - */ - setCollideWorldBounds(value?: boolean, bounceX?: number, bounceY?: number): this; - } - + repeat?: number; + /** + * Time in ms/frames before the repeat will start. + */ + repeatDelay?: number; /** - * Provides methods used for setting the debug properties of an Arcade Physics Body. + * Automatically call toggleFlipX when the TweenData yoyos or repeats */ - interface Debug { - /** - * Sets the debug values of this body. - * - * Bodies will only draw their debug if debug has been enabled for Arcade Physics as a whole. - * Note that there is a performance cost in drawing debug displays. It should never be used in production. - * @param showBody Set to `true` to have this body render its outline to the debug display. - * @param showVelocity Set to `true` to have this body render a velocity marker to the debug display. - * @param bodyColor The color of the body outline when rendered to the debug display. - */ - setDebug(showBody: boolean, showVelocity: boolean, bodyColor: number): this; - /** - * Sets the color of the body outline when it renders to the debug display. - * @param value The color of the body outline when rendered to the debug display. - */ - setDebugBodyColor(value: number): this; - /** - * Set to `true` to have this body render its outline to the debug display. - */ - debugShowBody: boolean; - /** - * Set to `true` to have this body render a velocity marker to the debug display. - */ - debugShowVelocity: boolean; - /** - * The color of the body outline when it renders to the debug display. - */ - debugBodyColor: number; - } - + flipX?: boolean; /** - * Provides methods used for setting the drag properties of an Arcade Physics Body. + * Automatically call toggleFlipY when the TweenData yoyos or repeats */ - interface Drag { - /** - * Sets the body's horizontal and vertical drag. If the vertical drag value is not provided, the vertical drag is set to the same value as the horizontal drag. - * - * Drag can be considered as a form of deceleration that will return the velocity of a body back to zero over time. - * It is the absolute loss of velocity due to movement, in pixels per second squared. - * The x and y components are applied separately. - * - * When `useDamping` is true, this is 1 minus the damping factor. - * A value of 1 means the Body loses no velocity. - * A value of 0.95 means the Body loses 5% of its velocity per step. - * A value of 0.5 means the Body loses 50% of its velocity per step. - * - * Drag is applied only when `acceleration` is zero. - * @param x The amount of horizontal drag to apply. - * @param y The amount of vertical drag to apply. Default x. - */ - setDrag(x: number, y?: number): this; - /** - * Sets the body's horizontal drag. - * - * Drag can be considered as a form of deceleration that will return the velocity of a body back to zero over time. - * It is the absolute loss of velocity due to movement, in pixels per second squared. - * The x and y components are applied separately. - * - * When `useDamping` is true, this is 1 minus the damping factor. - * A value of 1 means the Body loses no velocity. - * A value of 0.95 means the Body loses 5% of its velocity per step. - * A value of 0.5 means the Body loses 50% of its velocity per step. - * - * Drag is applied only when `acceleration` is zero. - * @param value The amount of horizontal drag to apply. - */ - setDragX(value: number): this; - /** - * Sets the body's vertical drag. - * - * Drag can be considered as a form of deceleration that will return the velocity of a body back to zero over time. - * It is the absolute loss of velocity due to movement, in pixels per second squared. - * The x and y components are applied separately. - * - * When `useDamping` is true, this is 1 minus the damping factor. - * A value of 1 means the Body loses no velocity. - * A value of 0.95 means the Body loses 5% of its velocity per step. - * A value of 0.5 means the Body loses 50% of its velocity per step. - * - * Drag is applied only when `acceleration` is zero. - * @param value The amount of vertical drag to apply. - */ - setDragY(value: number): this; - /** - * If this Body is using `drag` for deceleration this function controls how the drag is applied. - * If set to `true` drag will use a damping effect rather than a linear approach. If you are - * creating a game where the Body moves freely at any angle (i.e. like the way the ship moves in - * the game Asteroids) then you will get a far smoother and more visually correct deceleration - * by using damping, avoiding the axis-drift that is prone with linear deceleration. - * - * If you enable this property then you should use far smaller `drag` values than with linear, as - * they are used as a multiplier on the velocity. Values such as 0.95 will give a nice slow - * deceleration, where-as smaller values, such as 0.5 will stop an object almost immediately. - * @param value `true` to use damping for deceleration, or `false` to use linear deceleration. - */ - setDamping(value: boolean): this; - } - + flipY?: boolean; /** - * Provides methods used for setting the enable properties of an Arcade Physics Body. + * Between 0 and 1 showing completion of this TweenData. */ - interface Enable { - /** - * Enables this Game Object's Body. - * @param reset Also reset the Body and place it at (x, y). - * @param x The horizontal position to place the Game Object and Body. - * @param y The horizontal position to place the Game Object and Body. - * @param enableGameObject Also activate this Game Object. - * @param showGameObject Also show this Game Object. - */ - enableBody(reset: boolean, x: number, y: number, enableGameObject: boolean, showGameObject: boolean): this; - /** - * Stops and disables this Game Object's Body. - * @param disableGameObject Also deactivate this Game Object. Default false. - * @param hideGameObject Also hide this Game Object. Default false. - */ - disableBody(disableGameObject?: boolean, hideGameObject?: boolean): this; - /** - * Syncs the Body's position and size with its parent Game Object. - * You don't need to call this for Dynamic Bodies, as it happens automatically. - * But for Static bodies it's a useful way of modifying the position of a Static Body - * in the Physics World, based on its Game Object. - */ - refreshBody(): this; - } - + progress?: number; /** - * Sets the friction (e.g. the amount of velocity reduced over time) of the physics body when moving horizontally in the X axis. The higher than friction, the faster the body will slow down once force stops being applied to it. + * Delta counter */ - interface Friction { - /** - * Sets the friction (e.g. the amount of velocity reduced over time) of the physics body when moving. - * The higher than friction, the faster the body will slow down once force stops being applied to it. - * @param x The amount of horizontal friction to apply. - * @param y The amount of vertical friction to apply. Default x. - */ - setFriction(x: number, y?: number): this; - /** - * Sets the friction (e.g. the amount of velocity reduced over time) of the physics body when moving horizontally in the X axis. - * The higher than friction, the faster the body will slow down once force stops being applied to it. - * @param x The amount of friction to apply. - */ - setFrictionX(x: number): this; - /** - * Sets the friction (e.g. the amount of velocity reduced over time) of the physics body when moving vertically in the Y axis. - * The higher than friction, the faster the body will slow down once force stops being applied to it. - * @param x The amount of friction to apply. - */ - setFrictionY(x: number): this; - } - + elapsed?: number; /** - * Provides methods for setting the gravity properties of an Arcade Physics Game Object. - * Should be applied as a mixin and not used directly. + * How many repeats are left to run? */ - interface Gravity { - /** - * Set the X and Y values of the gravitational pull to act upon this Arcade Physics Game Object. Values can be positive or negative. Larger values result in a stronger effect. - * - * If only one value is provided, this value will be used for both the X and Y axis. - * @param x The gravitational force to be applied to the X-axis. - * @param y The gravitational force to be applied to the Y-axis. If this is not specified, the X value will be used. Default x. - */ - setGravity(x: number, y?: number): this; - /** - * Set the gravitational force to be applied to the X axis. Value can be positive or negative. Larger values result in a stronger effect. - * @param x The gravitational force to be applied to the X-axis. - */ - setGravityX(x: number): this; - /** - * Set the gravitational force to be applied to the Y axis. Value can be positive or negative. Larger values result in a stronger effect. - * @param y The gravitational force to be applied to the Y-axis. - */ - setGravityY(y: number): this; - } - + repeatCounter?: number; /** - * Provides methods used for setting the immovable properties of an Arcade Physics Body. + * The property value at the start of the ease. */ - interface Immovable { - /** - * Sets Whether this Body can be moved by collisions with another Body. - * @param value Sets if this body can be moved by collisions with another Body. Default true. - */ - setImmovable(value?: boolean): this; - } - + start?: number; /** - * Provides methods used for setting the mass properties of an Arcade Physics Body. + * The current propety value. */ - interface Mass { - /** - * Sets the mass of the physics body - * @param value New value for the mass of the body. - */ - setMass(value: number): this; - } - + current?: number; /** - * This method will search the given circular area and return an array of all physics bodies that - * overlap with it. It can return either Dynamic, Static bodies or a mixture of both. - * - * A body only has to intersect with the search area to be considered, it doesn't have to be fully - * contained within it. - * - * If Arcade Physics is set to use the RTree (which it is by default) then the search is rather fast, - * otherwise the search is O(N) for Dynamic Bodies. + * The previous property value. */ - interface OverlapCirc { - } - + previous?: number; /** - * This method will search the given rectangular area and return an array of all physics bodies that - * overlap with it. It can return either Dynamic, Static bodies or a mixture of both. - * - * A body only has to intersect with the search area to be considered, it doesn't have to be fully - * contained within it. - * - * If Arcade Physics is set to use the RTree (which it is by default) then the search for is extremely fast, - * otherwise the search is O(N) for Dynamic Bodies. + * The property value at the end of the ease. */ - interface OverlapRect { - } - + end?: number; /** - * Provides methods for setting the size of an Arcade Physics Game Object. - * Should be applied as a mixin and not used directly. + * Time duration 1. */ - interface Size { - /** - * Sets the body offset. This allows you to adjust the difference between the center of the body - * and the x and y coordinates of the parent Game Object. - * @param x The amount to offset the body from the parent Game Object along the x-axis. - * @param y The amount to offset the body from the parent Game Object along the y-axis. Defaults to the value given for the x-axis. Default x. - */ - setOffset(x: number, y?: number): this; - /** - * Sets the size of this physics body. Setting the size does not adjust the dimensions - * of the parent Game Object. - * @param width The new width of the physics body, in pixels. - * @param height The new height of the physics body, in pixels. - * @param center Should the body be re-positioned so its center aligns with the parent Game Object? Default true. - */ - setSize(width: number, height: number, center?: boolean): this; - /** - * Sets this physics body to use a circle for collision instead of a rectangle. - * @param radius The radius of the physics body, in pixels. - * @param offsetX The amount to offset the body from the parent Game Object along the x-axis. - * @param offsetY The amount to offset the body from the parent Game Object along the y-axis. - */ - setCircle(radius: number, offsetX?: number, offsetY?: number): this; - } - + t1?: number; /** - * Provides methods for modifying the velocity of an Arcade Physics body. - * - * Should be applied as a mixin and not used directly. + * Time duration 2. */ - interface Velocity { - /** - * Sets the velocity of the Body. - * @param x The horizontal velocity of the body. Positive values move the body to the right, while negative values move it to the left. - * @param y The vertical velocity of the body. Positive values move the body down, while negative values move it up. Default x. - */ - setVelocity(x: number, y?: number): this; - /** - * Sets the horizontal component of the body's velocity. - * - * Positive values move the body to the right, while negative values move it to the left. - * @param x The new horizontal velocity. - */ - setVelocityX(x: number): this; - /** - * Sets the vertical component of the body's velocity. - * - * Positive values move the body down, while negative values move it up. - * @param y The new vertical velocity of the body. - */ - setVelocityY(y: number): this; - /** - * Sets the maximum velocity of the body. - * @param x The new maximum horizontal velocity. - * @param y The new maximum vertical velocity. Default x. - */ - setMaxVelocity(x: number, y?: number): this; - } - - } + t2?: number; + /** + * LoadValue generation functions. + */ + gen?: Phaser.Types.Tweens.TweenDataGenConfig; + /** + * TWEEN_CONST.CREATED + */ + state?: number; + }; - /** - * Dynamic Body. - */ - var DYNAMIC_BODY: number; + type TweenDataGenConfig = { + /** + * Time in ms/frames before tween will start. + */ + delay: Function; + /** + * Duration of the tween in ms/frames, excludes time for yoyo or repeats. + */ + duration: Function; + /** + * Time in ms/frames the tween will pause before running the yoyo or starting a repeat. + */ + hold: Function; + /** + * Number of times to repeat the tween. The tween will always run once regardless, so a repeat value of '1' will play the tween twice. + */ + repeat: Function; + /** + * Time in ms/frames before the repeat will start. + */ + repeatDelay: Function; + }; - /** - * Static Body. - */ - var STATIC_BODY: number; + type TweenOnActiveCallback = (tween: Phaser.Tweens.Tween, target: any, ...param: any[])=>void; - /** - * Arcade Physics Group containing Dynamic Bodies. - */ - var GROUP: number; + type TweenOnCompleteCallback = (tween: Phaser.Tweens.Tween, targets: any[], ...param: any[])=>void; - /** - * A Tilemap Layer. - */ - var TILEMAPLAYER: number; + type TweenOnLoopCallback = (tween: Phaser.Tweens.Tween, targets: any[], ...param: any[])=>void; - /** - * Facing no direction (initial value). - */ - var FACING_NONE: number; + type TweenOnRepeatCallback = (tween: Phaser.Tweens.Tween, target: any, ...param: any[])=>void; - /** - * Facing up. - */ - var FACING_UP: number; + type TweenOnStartCallback = (tween: Phaser.Tweens.Tween, targets: any[], ...param: any[])=>void; - /** - * Facing down. - */ - var FACING_DOWN: number; + type TweenOnStopCallback = (tween: Phaser.Tweens.Tween, targets: any[], ...param: any[])=>void; - /** - * Facing left. - */ - var FACING_LEFT: number; + type TweenOnUpdateCallback = (tween: Phaser.Tweens.Tween, target: any, ...param: any[])=>void; - /** - * Facing right. - */ - var FACING_RIGHT: number; + type TweenOnYoyoCallback = (tween: Phaser.Tweens.Tween, target: any, ...param: any[])=>void; - namespace Events { + type TweenPropConfig = { /** - * The Arcade Physics World Collide Event. - * - * This event is dispatched by an Arcade Physics World instance if two bodies collide _and_ at least - * one of them has their [onCollide]{@link Phaser.Physics.Arcade.Body#onCollide} property set to `true`. - * - * It provides an alternative means to handling collide events rather than using the callback approach. - * - * Listen to it from a Scene using: `this.physics.world.on('collide', listener)`. - * - * Please note that 'collide' and 'overlap' are two different things in Arcade Physics. + * What the property will be at the END of the Tween. */ - const COLLIDE: any; - + value?: number | string | Phaser.Types.Tweens.GetEndCallback | Phaser.Types.Tweens.TweenPropConfig; /** - * The Arcade Physics World Overlap Event. - * - * This event is dispatched by an Arcade Physics World instance if two bodies overlap _and_ at least - * one of them has their [onOverlap]{@link Phaser.Physics.Arcade.Body#onOverlap} property set to `true`. - * - * It provides an alternative means to handling overlap events rather than using the callback approach. - * - * Listen to it from a Scene using: `this.physics.world.on('overlap', listener)`. - * - * Please note that 'collide' and 'overlap' are two different things in Arcade Physics. + * What the property will be set to immediately when this tween becomes active. */ - const OVERLAP: any; - + getActive?: Phaser.Types.Tweens.GetActiveCallback; /** - * The Arcade Physics World Pause Event. - * - * This event is dispatched by an Arcade Physics World instance when it is paused. - * - * Listen to it from a Scene using: `this.physics.world.on('pause', listener)`. + * What the property will be at the END of the Tween. */ - const PAUSE: any; - + getEnd?: Phaser.Types.Tweens.GetEndCallback; /** - * The Arcade Physics World Resume Event. - * - * This event is dispatched by an Arcade Physics World instance when it resumes from a paused state. - * - * Listen to it from a Scene using: `this.physics.world.on('resume', listener)`. + * What the property will be at the START of the Tween. */ - const RESUME: any; - + getStart?: Phaser.Types.Tweens.GetStartCallback; /** - * The Arcade Physics Tile Collide Event. - * - * This event is dispatched by an Arcade Physics World instance if a body collides with a Tile _and_ - * has its [onCollide]{@link Phaser.Physics.Arcade.Body#onCollide} property set to `true`. - * - * It provides an alternative means to handling collide events rather than using the callback approach. - * - * Listen to it from a Scene using: `this.physics.world.on('tilecollide', listener)`. - * - * Please note that 'collide' and 'overlap' are two different things in Arcade Physics. + * The ease function this tween uses. */ - const TILE_COLLIDE: any; + ease?: string | Function; + /** + * Time in ms/frames before tween will start. + */ + delay?: number; + /** + * Duration of the tween in ms/frames. + */ + duration?: number; + /** + * Determines whether the tween should return back to its start value after hold has expired. + */ + yoyo?: boolean; + /** + * Time in ms/frames the tween will pause before repeating or returning to its starting value if yoyo is set to true. + */ + hold?: number; + /** + * Number of times to repeat the tween. The tween will always run once regardless, so a repeat value of '1' will play the tween twice. + */ + repeat?: number; + /** + * Time in ms/frames before the repeat will start. + */ + repeatDelay?: number; + /** + * Should toggleFlipX be called when yoyo or repeat happens? + */ + flipX?: boolean; + /** + * Should toggleFlipY be called when yoyo or repeat happens? + */ + flipY?: boolean; + }; + + } + + } + namespace Physics { + namespace Arcade { + /** + * An Arcade Physics Image is an Image with an Arcade Physics body and related components. + * The body can be dynamic or static. + * + * The main difference between an Arcade Image and an Arcade Sprite is that you cannot animate an Arcade Image. + */ + class Image extends Phaser.GameObjects.Image implements Phaser.Physics.Arcade.Components.Acceleration, Phaser.Physics.Arcade.Components.Angular, Phaser.Physics.Arcade.Components.Bounce, Phaser.Physics.Arcade.Components.Debug, Phaser.Physics.Arcade.Components.Drag, Phaser.Physics.Arcade.Components.Enable, Phaser.Physics.Arcade.Components.Friction, Phaser.Physics.Arcade.Components.Gravity, Phaser.Physics.Arcade.Components.Immovable, Phaser.Physics.Arcade.Components.Mass, Phaser.Physics.Arcade.Components.Pushable, Phaser.Physics.Arcade.Components.Size, Phaser.Physics.Arcade.Components.Velocity, Phaser.GameObjects.Components.Alpha, Phaser.GameObjects.Components.BlendMode, Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.Flip, Phaser.GameObjects.Components.GetBounds, Phaser.GameObjects.Components.Origin, Phaser.GameObjects.Components.Pipeline, Phaser.GameObjects.Components.ScrollFactor, Phaser.GameObjects.Components.Size, Phaser.GameObjects.Components.Texture, Phaser.GameObjects.Components.Tint, Phaser.GameObjects.Components.Transform, Phaser.GameObjects.Components.Visible { /** - * The Arcade Physics Tile Overlap Event. - * - * This event is dispatched by an Arcade Physics World instance if a body overlaps with a Tile _and_ - * has its [onOverlap]{@link Phaser.Physics.Arcade.Body#onOverlap} property set to `true`. - * - * It provides an alternative means to handling overlap events rather than using the callback approach. - * - * Listen to it from a Scene using: `this.physics.world.on('tileoverlap', listener)`. * - * Please note that 'collide' and 'overlap' are two different things in Arcade Physics. + * @param scene The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. + * @param x The horizontal position of this Game Object in the world. + * @param y The vertical position of this Game Object in the world. + * @param texture The key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager. + * @param frame An optional frame from the Texture this Game Object is rendering with. */ - const TILE_OVERLAP: any; + constructor(scene: Phaser.Scene, x: number, y: number, texture: string | Phaser.Textures.Texture, frame?: string | number); /** - * The Arcade Physics World Bounds Event. - * - * This event is dispatched by an Arcade Physics World instance if a body makes contact with the world bounds _and_ - * it has its [onWorldBounds]{@link Phaser.Physics.Arcade.Body#onWorldBounds} property set to `true`. - * - * It provides an alternative means to handling collide events rather than using the callback approach. - * - * Listen to it from a Scene using: `this.physics.world.on('worldbounds', listener)`. + * This Game Object's Physics Body. */ - const WORLD_BOUNDS: any; + body: Phaser.Physics.Arcade.Body | Phaser.Physics.Arcade.StaticBody; /** - * The Arcade Physics World Step Event. - * - * This event is dispatched by an Arcade Physics World instance whenever a physics step is run. - * It is emitted _after_ the bodies and colliders have been updated. - * - * In high framerate settings this can be multiple times per game frame. + * Clears all alpha values associated with this Game Object. * - * Listen to it from a Scene using: `this.physics.world.on('worldstep', listener)`. + * Immediately sets the alpha levels back to 1 (fully opaque). */ - const WORLD_STEP: any; - - } + clearAlpha(): this; - /** - * The Arcade Physics Factory allows you to easily create Arcade Physics enabled Game Objects. - * Objects that are created by this Factory are automatically added to the physics world. - */ - class Factory { /** + * Set the Alpha level of this Game Object. The alpha controls the opacity of the Game Object as it renders. + * Alpha values are provided as a float between 0, fully transparent, and 1, fully opaque. * - * @param world The Arcade Physics World instance. + * If your game is running under WebGL you can optionally specify four different alpha values, each of which + * correspond to the four corners of the Game Object. Under Canvas only the `topLeft` value given is used. + * @param topLeft The alpha value used for the top-left of the Game Object. If this is the only value given it's applied across the whole Game Object. Default 1. + * @param topRight The alpha value used for the top-right of the Game Object. WebGL only. + * @param bottomLeft The alpha value used for the bottom-left of the Game Object. WebGL only. + * @param bottomRight The alpha value used for the bottom-right of the Game Object. WebGL only. */ - constructor(world: Phaser.Physics.Arcade.World); + setAlpha(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; /** - * A reference to the Arcade Physics World. + * The alpha value of the Game Object. + * + * This is a global value, impacting the entire Game Object, not just a region of it. */ - world: Phaser.Physics.Arcade.World; + alpha: number; /** - * A reference to the Scene this Arcade Physics instance belongs to. + * The alpha value starting from the top-left of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. */ - scene: Phaser.Scene; + alphaTopLeft: number; /** - * A reference to the Scene.Systems this Arcade Physics instance belongs to. + * The alpha value starting from the top-right of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. */ - sys: Phaser.Scenes.Systems; + alphaTopRight: number; /** - * Creates a new Arcade Physics Collider object. - * @param object1 The first object to check for collision. - * @param object2 The second object to check for collision. - * @param collideCallback The callback to invoke when the two objects collide. - * @param processCallback The callback to invoke when the two objects collide. Must return a boolean. - * @param callbackContext The scope in which to call the callbacks. + * The alpha value starting from the bottom-left of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. */ - collider(object1: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[] | Phaser.GameObjects.Group | Phaser.GameObjects.Group[], object2: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[] | Phaser.GameObjects.Group | Phaser.GameObjects.Group[], collideCallback?: ArcadePhysicsCallback, processCallback?: ArcadePhysicsCallback, callbackContext?: any): Phaser.Physics.Arcade.Collider; + alphaBottomLeft: number; /** - * Creates a new Arcade Physics Collider Overlap object. - * @param object1 The first object to check for overlap. - * @param object2 The second object to check for overlap. - * @param collideCallback The callback to invoke when the two objects collide. - * @param processCallback The callback to invoke when the two objects collide. Must return a boolean. - * @param callbackContext The scope in which to call the callbacks. + * The alpha value starting from the bottom-right of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. */ - overlap(object1: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[] | Phaser.GameObjects.Group | Phaser.GameObjects.Group[], object2: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[] | Phaser.GameObjects.Group | Phaser.GameObjects.Group[], collideCallback?: ArcadePhysicsCallback, processCallback?: ArcadePhysicsCallback, callbackContext?: any): Phaser.Physics.Arcade.Collider; + alphaBottomRight: number; /** - * Adds an Arcade Physics Body to the given Game Object. - * @param gameObject A Game Object. - * @param isStatic Create a Static body (true) or Dynamic body (false). Default false. + * Sets the Blend Mode being used by this Game Object. + * + * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) + * + * Under WebGL only the following Blend Modes are available: + * + * * ADD + * * MULTIPLY + * * SCREEN + * * ERASE + * + * Canvas has more available depending on browser support. + * + * You can also create your own custom Blend Modes in WebGL. + * + * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending + * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these + * reasons try to be careful about the construction of your Scene and the frequency of which blend modes + * are used. */ - existing(gameObject: Phaser.GameObjects.GameObject, isStatic?: boolean): Phaser.GameObjects.GameObject; + blendMode: Phaser.BlendModes | string; /** - * Creates a new Arcade Image object with a Static body. - * @param x The horizontal position of this Game Object in the world. - * @param y The vertical position of this Game Object in the world. - * @param texture The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. - * @param frame An optional frame from the Texture this Game Object is rendering with. + * Sets the Blend Mode being used by this Game Object. + * + * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) + * + * Under WebGL only the following Blend Modes are available: + * + * * ADD + * * MULTIPLY + * * SCREEN + * * ERASE (only works when rendering to a framebuffer, like a Render Texture) + * + * Canvas has more available depending on browser support. + * + * You can also create your own custom Blend Modes in WebGL. + * + * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending + * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these + * reasons try to be careful about the construction of your Scene and the frequency in which blend modes + * are used. + * @param value The BlendMode value. Either a string or a CONST. */ - staticImage(x: number, y: number, texture: string, frame?: string | integer): Phaser.Physics.Arcade.Image; + setBlendMode(value: string | Phaser.BlendModes): this; /** - * Creates a new Arcade Image object with a Dynamic body. - * @param x The horizontal position of this Game Object in the world. - * @param y The vertical position of this Game Object in the world. - * @param texture The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. - * @param frame An optional frame from the Texture this Game Object is rendering with. + * The depth of this Game Object within the Scene. + * + * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order + * of Game Objects, without actually moving their position in the display list. + * + * The default depth is zero. A Game Object with a higher depth + * value will always render in front of one with a lower value. + * + * Setting the depth will queue a depth sort event within the Scene. */ - image(x: number, y: number, texture: string, frame?: string | integer): Phaser.Physics.Arcade.Image; + depth: number; /** - * Creates a new Arcade Sprite object with a Static body. - * @param x The horizontal position of this Game Object in the world. - * @param y The vertical position of this Game Object in the world. - * @param texture The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. - * @param frame An optional frame from the Texture this Game Object is rendering with. + * The depth of this Game Object within the Scene. + * + * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order + * of Game Objects, without actually moving their position in the display list. + * + * The default depth is zero. A Game Object with a higher depth + * value will always render in front of one with a lower value. + * + * Setting the depth will queue a depth sort event within the Scene. + * @param value The depth of this Game Object. */ - staticSprite(x: number, y: number, texture: string, frame?: string | integer): Phaser.Physics.Arcade.Sprite; + setDepth(value: number): this; /** - * Creates a new Arcade Sprite object with a Dynamic body. - * @param x The horizontal position of this Game Object in the world. - * @param y The vertical position of this Game Object in the world. - * @param key The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. - * @param frame An optional frame from the Texture this Game Object is rendering with. + * The horizontally flipped state of the Game Object. + * + * A Game Object that is flipped horizontally will render inversed on the horizontal axis. + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. */ - sprite(x: number, y: number, key: string, frame?: string | integer): Phaser.Physics.Arcade.Sprite; + flipX: boolean; /** - * Creates a Static Physics Group object. - * All Game Objects created by this Group will automatically be static Arcade Physics objects. - * @param children Game Objects to add to this group; or the `config` argument. - * @param config Settings for this group. + * The vertically flipped state of the Game Object. + * + * A Game Object that is flipped vertically will render inversed on the vertical axis (i.e. upside down) + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. */ - staticGroup(children?: Phaser.GameObjects.GameObject[] | Phaser.Types.GameObjects.Group.GroupConfig | Phaser.Types.GameObjects.Group.GroupCreateConfig, config?: Phaser.Types.GameObjects.Group.GroupConfig | Phaser.Types.GameObjects.Group.GroupCreateConfig): Phaser.Physics.Arcade.StaticGroup; + flipY: boolean; /** - * Creates a Physics Group object. - * All Game Objects created by this Group will automatically be dynamic Arcade Physics objects. - * @param children Game Objects to add to this group; or the `config` argument. - * @param config Settings for this group. + * Toggles the horizontal flipped state of this Game Object. + * + * A Game Object that is flipped horizontally will render inversed on the horizontal axis. + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. */ - group(children?: Phaser.GameObjects.GameObject[] | Phaser.Types.Physics.Arcade.PhysicsGroupConfig | Phaser.Types.GameObjects.Group.GroupCreateConfig, config?: Phaser.Types.Physics.Arcade.PhysicsGroupConfig | Phaser.Types.GameObjects.Group.GroupCreateConfig): Phaser.Physics.Arcade.Group; + toggleFlipX(): this; /** - * Destroys this Factory. + * Toggles the vertical flipped state of this Game Object. */ - destroy(): void; - - } - - /** - * Calculates and returns the horizontal overlap between two arcade physics bodies and sets their properties - * accordingly, including: `touching.left`, `touching.right`, `touching.none` and `overlapX'. - * @param body1 The first Body to separate. - * @param body2 The second Body to separate. - * @param overlapOnly Is this an overlap only check, or part of separation? - * @param bias A value added to the delta values during collision checks. Increase it to prevent sprite tunneling(sprites passing through another instead of colliding). - */ - function GetOverlapX(body1: Phaser.Physics.Arcade.Body, body2: Phaser.Physics.Arcade.Body, overlapOnly: boolean, bias: number): number; - - /** - * Calculates and returns the vertical overlap between two arcade physics bodies and sets their properties - * accordingly, including: `touching.up`, `touching.down`, `touching.none` and `overlapY'. - * @param body1 The first Body to separate. - * @param body2 The second Body to separate. - * @param overlapOnly Is this an overlap only check, or part of separation? - * @param bias A value added to the delta values during collision checks. Increase it to prevent sprite tunneling(sprites passing through another instead of colliding). - */ - function GetOverlapY(body1: Phaser.Physics.Arcade.Body, body2: Phaser.Physics.Arcade.Body, overlapOnly: boolean, bias: number): number; + toggleFlipY(): this; - /** - * An Arcade Physics Group object. - * - * All Game Objects created by this Group will automatically be given dynamic Arcade Physics bodies. - * - * Its static counterpart is {@link Phaser.Physics.Arcade.StaticGroup}. - */ - class Group extends Phaser.GameObjects.Group { /** + * Sets the horizontal flipped state of this Game Object. * - * @param world The physics simulation. - * @param scene The scene this group belongs to. - * @param children Game Objects to add to this group; or the `config` argument. - * @param config Settings for this group. + * A Game Object that is flipped horizontally will render inversed on the horizontal axis. + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * @param value The flipped state. `false` for no flip, or `true` to be flipped. */ - constructor(world: Phaser.Physics.Arcade.World, scene: Phaser.Scene, children?: Phaser.GameObjects.GameObject[] | Phaser.Types.Physics.Arcade.PhysicsGroupConfig | Phaser.Types.GameObjects.Group.GroupCreateConfig, config?: Phaser.Types.Physics.Arcade.PhysicsGroupConfig | Phaser.Types.GameObjects.Group.GroupCreateConfig); + setFlipX(value: boolean): this; /** - * The physics simulation. + * Sets the vertical flipped state of this Game Object. + * @param value The flipped state. `false` for no flip, or `true` to be flipped. */ - world: Phaser.Physics.Arcade.World; + setFlipY(value: boolean): this; /** - * The class to create new Group members from. + * Sets the horizontal and vertical flipped state of this Game Object. * - * This should be either `Phaser.Physics.Arcade.Image`, `Phaser.Physics.Arcade.Sprite`, or a class extending one of those. + * A Game Object that is flipped will render inversed on the flipped axis. + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * @param x The horizontal flipped state. `false` for no flip, or `true` to be flipped. + * @param y The horizontal flipped state. `false` for no flip, or `true` to be flipped. */ - classType: Function; + setFlip(x: boolean, y: boolean): this; /** - * The physics type of the Group's members. + * Resets the horizontal and vertical flipped state of this Game Object back to their default un-flipped state. */ - physicsType: integer; + resetFlip(): this; /** - * Default physics properties applied to Game Objects added to the Group or created by the Group. Derived from the `config` argument. + * Gets the center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. */ - defaults: Phaser.Types.Physics.Arcade.PhysicsGroupDefaults; + getCenter(output?: O): O; /** - * A textual representation of this Game Object. - * Used internally by Phaser but is available for your own custom classes to populate. + * Gets the top-left corner coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - type: string; + getTopLeft(output?: O, includeParent?: boolean): O; /** - * Enables a Game Object's Body and assigns `defaults`. Called when a Group member is added or created. - * @param child The Game Object being added. + * Gets the top-center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - createCallbackHandler(child: Phaser.GameObjects.GameObject): void; + getTopCenter(output?: O, includeParent?: boolean): O; /** - * Disables a Game Object's Body. Called when a Group member is removed. - * @param child The Game Object being removed. + * Gets the top-right corner coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - removeCallbackHandler(child: Phaser.GameObjects.GameObject): void; + getTopRight(output?: O, includeParent?: boolean): O; /** - * Sets the velocity of each Group member. - * @param x The horizontal velocity. - * @param y The vertical velocity. - * @param step The velocity increment. When set, the first member receives velocity (x, y), the second (x + step, y + step), and so on. Default 0. + * Gets the left-center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - setVelocity(x: number, y: number, step?: number): Phaser.Physics.Arcade.Group; + getLeftCenter(output?: O, includeParent?: boolean): O; /** - * Sets the horizontal velocity of each Group member. - * @param value The velocity value. - * @param step The velocity increment. When set, the first member receives velocity (x), the second (x + step), and so on. Default 0. + * Gets the right-center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - setVelocityX(value: number, step?: number): Phaser.Physics.Arcade.Group; + getRightCenter(output?: O, includeParent?: boolean): O; /** - * Sets the vertical velocity of each Group member. - * @param value The velocity value. - * @param step The velocity increment. When set, the first member receives velocity (y), the second (y + step), and so on. Default 0. + * Gets the bottom-left corner coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - setVelocityY(value: number, step?: number): Phaser.Physics.Arcade.Group; - - } - - /** - * Separates two overlapping bodies on the X-axis (horizontally). - * - * Separation involves moving two overlapping bodies so they don't overlap anymore and adjusting their velocities based on their mass. This is a core part of collision detection. - * - * The bodies won't be separated if there is no horizontal overlap between them, if they are static, or if either one uses custom logic for its separation. - * @param body1 The first Body to separate. - * @param body2 The second Body to separate. - * @param overlapOnly If `true`, the bodies will only have their overlap data set and no separation will take place. - * @param bias A value to add to the delta value during overlap checking. Used to prevent sprite tunneling. - */ - function SeparateX(body1: Phaser.Physics.Arcade.Body, body2: Phaser.Physics.Arcade.Body, overlapOnly: boolean, bias: number): boolean; - - /** - * Separates two overlapping bodies on the Y-axis (vertically). - * - * Separation involves moving two overlapping bodies so they don't overlap anymore and adjusting their velocities based on their mass. This is a core part of collision detection. - * - * The bodies won't be separated if there is no vertical overlap between them, if they are static, or if either one uses custom logic for its separation. - * @param body1 The first Body to separate. - * @param body2 The second Body to separate. - * @param overlapOnly If `true`, the bodies will only have their overlap data set and no separation will take place. - * @param bias A value to add to the delta value during overlap checking. Used to prevent sprite tunneling. - */ - function SeparateY(body1: Phaser.Physics.Arcade.Body, body2: Phaser.Physics.Arcade.Body, overlapOnly: boolean, bias: number): boolean; + getBottomLeft(output?: O, includeParent?: boolean): O; - /** - * A Static Arcade Physics Body. - * - * A Static Body never moves, and isn't automatically synchronized with its parent Game Object. - * That means if you make any change to the parent's origin, position, or scale after creating or adding the body, you'll need to update the Body manually. - * - * A Static Body can collide with other Bodies, but is never moved by collisions. - * - * Its dynamic counterpart is {@link Phaser.Physics.Arcade.Body}. - */ - class StaticBody { /** - * - * @param world The Arcade Physics simulation this Static Body belongs to. - * @param gameObject The Game Object this Static Body belongs to. + * Gets the bottom-center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - constructor(world: Phaser.Physics.Arcade.World, gameObject: Phaser.GameObjects.GameObject); + getBottomCenter(output?: O, includeParent?: boolean): O; /** - * The Arcade Physics simulation this Static Body belongs to. + * Gets the bottom-right corner coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - world: Phaser.Physics.Arcade.World; + getBottomRight(output?: O, includeParent?: boolean): O; /** - * The Game Object this Static Body belongs to. + * Gets the bounds of this Game Object, regardless of origin. + * The values are stored and returned in a Rectangle, or Rectangle-like, object. + * @param output An object to store the values in. If not provided a new Rectangle will be created. */ - gameObject: Phaser.GameObjects.GameObject; + getBounds(output?: O): O; /** - * Whether the Static Body's boundary is drawn to the debug display. + * The Mask this Game Object is using during render. */ - debugShowBody: boolean; + mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask; /** - * The color of this Static Body on the debug display. + * Sets the mask that this Game Object will use to render with. + * + * The mask must have been previously created and can be either a GeometryMask or a BitmapMask. + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * + * If a mask is already set on this Game Object it will be immediately replaced. + * + * Masks are positioned in global space and are not relative to the Game Object to which they + * are applied. The reason for this is that multiple Game Objects can all share the same mask. + * + * Masks have no impact on physics or input detection. They are purely a rendering component + * that allows you to limit what is visible during the render pass. + * @param mask The mask this Game Object will use when rendering. */ - debugBodyColor: integer; + setMask(mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask): this; /** - * Whether this Static Body is updated by the physics simulation. + * Clears the mask that this Game Object was using. + * @param destroyMask Destroy the mask before clearing it? Default false. */ - enable: boolean; + clearMask(destroyMask?: boolean): this; /** - * Whether this Static Body's boundary is circular (`true`) or rectangular (`false`). + * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, + * including this one. + * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * + * To create the mask you need to pass in a reference to a renderable Game Object. + * A renderable Game Object is one that uses a texture to render with, such as an + * Image, Sprite, Render Texture or BitmapText. + * + * If you do not provide a renderable object, and this Game Object has a texture, + * it will use itself as the object. This means you can call this method to create + * a Bitmap Mask from any renderable Game Object. + * @param renderable A renderable Game Object that uses a texture, such as a Sprite. */ - isCircle: boolean; + createBitmapMask(renderable?: Phaser.GameObjects.GameObject): Phaser.Display.Masks.BitmapMask; /** - * If this Static Body is circular, this is the unscaled radius of the Static Body's boundary, as set by {@link #setCircle}, in source pixels. - * The true radius is equal to `halfWidth`. + * Creates and returns a Geometry Mask. This mask can be used by any Game Object, + * including this one. + * + * To create the mask you need to pass in a reference to a Graphics Game Object. + * + * If you do not provide a graphics object, and this Game Object is an instance + * of a Graphics object, then it will use itself to create the mask. + * + * This means you can call this method to create a Geometry Mask from any Graphics Game Object. + * @param graphics A Graphics Game Object. The geometry within it will be used as the mask. */ - radius: number; + createGeometryMask(graphics?: Phaser.GameObjects.Graphics): Phaser.Display.Masks.GeometryMask; /** - * The offset of this Static Body's actual position from any updated position. - * - * Unlike a dynamic Body, a Static Body does not follow its Game Object. As such, this offset is only applied when resizing the Static Body. + * The horizontal origin of this Game Object. + * The origin maps the relationship between the size and position of the Game Object. + * The default value is 0.5, meaning all Game Objects are positioned based on their center. + * Setting the value to 0 means the position now relates to the left of the Game Object. */ - offset: Phaser.Math.Vector2; + originX: number; /** - * The position of this Static Body within the simulation. + * The vertical origin of this Game Object. + * The origin maps the relationship between the size and position of the Game Object. + * The default value is 0.5, meaning all Game Objects are positioned based on their center. + * Setting the value to 0 means the position now relates to the top of the Game Object. */ - position: Phaser.Math.Vector2; + originY: number; /** - * The width of the Static Body's boundary, in pixels. - * If the Static Body is circular, this is also the Static Body's diameter. + * The horizontal display origin of this Game Object. + * The origin is a normalized value between 0 and 1. + * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. */ - width: number; + displayOriginX: number; /** - * The height of the Static Body's boundary, in pixels. - * If the Static Body is circular, this is also the Static Body's diameter. + * The vertical display origin of this Game Object. + * The origin is a normalized value between 0 and 1. + * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. */ - height: number; + displayOriginY: number; /** - * Half the Static Body's width, in pixels. - * If the Static Body is circular, this is also the Static Body's radius. + * Sets the origin of this Game Object. + * + * The values are given in the range 0 to 1. + * @param x The horizontal origin value. Default 0.5. + * @param y The vertical origin value. If not defined it will be set to the value of `x`. Default x. */ - halfWidth: number; + setOrigin(x?: number, y?: number): this; /** - * Half the Static Body's height, in pixels. - * If the Static Body is circular, this is also the Static Body's radius. + * Sets the origin of this Game Object based on the Pivot values in its Frame. */ - halfHeight: number; + setOriginFromFrame(): this; /** - * The center of the Static Body's boundary. - * This is the midpoint of its `position` (top-left corner) and its bottom-right corner. + * Sets the display origin of this Game Object. + * The difference between this and setting the origin is that you can use pixel values for setting the display origin. + * @param x The horizontal display origin value. Default 0. + * @param y The vertical display origin value. If not defined it will be set to the value of `x`. Default x. */ - center: Phaser.Math.Vector2; + setDisplayOrigin(x?: number, y?: number): this; /** - * A constant zero velocity used by the Arcade Physics simulation for calculations. + * Updates the Display Origin cached values internally stored on this Game Object. + * You don't usually call this directly, but it is exposed for edge-cases where you may. */ - readonly velocity: Phaser.Math.Vector2; + updateDisplayOrigin(): this; /** - * A constant `false` value expected by the Arcade Physics simulation. + * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. */ - readonly allowGravity: boolean; + defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; /** - * Gravitational force applied specifically to this Body. Values are in pixels per second squared. Always zero for a Static Body. + * The current WebGL pipeline of this Game Object. */ - readonly gravity: Phaser.Math.Vector2; + pipeline: Phaser.Renderer.WebGL.WebGLPipeline; /** - * Rebound, or restitution, following a collision, relative to 1. Always zero for a Static Body. + * Does this Game Object have any Post Pipelines set? */ - readonly bounce: Phaser.Math.Vector2; + hasPostPipeline: boolean; /** - * Whether the simulation emits a `worldbounds` event when this StaticBody collides with the world boundary. - * Always false for a Static Body. (Static Bodies never collide with the world boundary and never trigger a `worldbounds` event.) + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. */ - readonly onWorldBounds: boolean; + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; /** - * Whether the simulation emits a `collide` event when this StaticBody collides with another. + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. */ - onCollide: boolean; + pipelineData: object; /** - * Whether the simulation emits an `overlap` event when this StaticBody overlaps with another. + * Sets the initial WebGL Pipeline of this Game Object. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. */ - onOverlap: boolean; + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; /** - * The StaticBody's inertia, relative to a default unit (1). With `bounce`, this affects the exchange of momentum (velocities) during collisions. + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. */ - mass: number; + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; /** - * Whether this object can be moved by collisions with another body. + * Sets one, or more, Post Pipelines on this Game Object. + * + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. */ - immovable: boolean; + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; /** - * A flag disabling the default horizontal separation of colliding bodies. Pass your own `collideHandler` to the collider. + * Adds an entry to the `pipelineData` object belonging to this Game Object. + * + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. */ - customSeparateX: boolean; + setPipelineData(key: string, value?: any): this; /** - * A flag disabling the default vertical separation of colliding bodies. Pass your own `collideHandler` to the collider. + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - customSeparateY: boolean; + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; /** - * The amount of horizontal overlap (before separation), if this Body is colliding with another. + * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. */ - overlapX: number; + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; /** - * The amount of vertical overlap (before separation), if this Body is colliding with another. + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. */ - overlapY: number; + resetPostPipeline(resetData?: boolean): void; /** - * The amount of overlap (before separation), if this StaticBody is circular and colliding with another circular body. + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - overlapR: number; + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; /** - * Whether this StaticBody has ever overlapped with another while both were not moving. + * Gets the name of the WebGL Pipeline this Game Object is currently using. */ - embedded: boolean; + getPipelineName(): string; /** - * Whether this StaticBody interacts with the world boundary. - * Always false for a Static Body. (Static Bodies never collide with the world boundary.) + * The horizontal scroll factor of this Game Object. + * + * The scroll factor controls the influence of the movement of a Camera upon this Game Object. + * + * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. + * It does not change the Game Objects actual position values. + * + * A value of 1 means it will move exactly in sync with a camera. + * A value of 0 means it will not move at all, even if the camera moves. + * Other values control the degree to which the camera movement is mapped to this Game Object. + * + * Please be aware that scroll factor values other than 1 are not taken in to consideration when + * calculating physics collisions. Bodies always collide based on their world position, but changing + * the scroll factor is a visual adjustment to where the textures are rendered, which can offset + * them from physics bodies if not accounted for in your code. */ - readonly collideWorldBounds: boolean; + scrollFactorX: number; /** - * Whether this StaticBody is checked for collisions and for which directions. You can set `checkCollision.none = false` to disable collision checks. + * The vertical scroll factor of this Game Object. + * + * The scroll factor controls the influence of the movement of a Camera upon this Game Object. + * + * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. + * It does not change the Game Objects actual position values. + * + * A value of 1 means it will move exactly in sync with a camera. + * A value of 0 means it will not move at all, even if the camera moves. + * Other values control the degree to which the camera movement is mapped to this Game Object. + * + * Please be aware that scroll factor values other than 1 are not taken in to consideration when + * calculating physics collisions. Bodies always collide based on their world position, but changing + * the scroll factor is a visual adjustment to where the textures are rendered, which can offset + * them from physics bodies if not accounted for in your code. */ - checkCollision: Phaser.Types.Physics.Arcade.ArcadeBodyCollision; + scrollFactorY: number; /** - * Whether this StaticBody has ever collided with another body and in which direction. + * Sets the scroll factor of this Game Object. + * + * The scroll factor controls the influence of the movement of a Camera upon this Game Object. + * + * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. + * It does not change the Game Objects actual position values. + * + * A value of 1 means it will move exactly in sync with a camera. + * A value of 0 means it will not move at all, even if the camera moves. + * Other values control the degree to which the camera movement is mapped to this Game Object. + * + * Please be aware that scroll factor values other than 1 are not taken in to consideration when + * calculating physics collisions. Bodies always collide based on their world position, but changing + * the scroll factor is a visual adjustment to where the textures are rendered, which can offset + * them from physics bodies if not accounted for in your code. + * @param x The horizontal scroll factor of this Game Object. + * @param y The vertical scroll factor of this Game Object. If not set it will use the `x` value. Default x. */ - touching: Phaser.Types.Physics.Arcade.ArcadeBodyCollision; + setScrollFactor(x: number, y?: number): this; /** - * Whether this StaticBody was colliding with another body during the last step or any previous step, and in which direction. + * The native (un-scaled) width of this Game Object. + * + * Changing this value will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or use + * the `displayWidth` property. */ - wasTouching: Phaser.Types.Physics.Arcade.ArcadeBodyCollision; + width: number; /** - * Whether this StaticBody has ever collided with a tile or the world boundary. + * The native (un-scaled) height of this Game Object. + * + * Changing this value will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or use + * the `displayHeight` property. */ - blocked: Phaser.Types.Physics.Arcade.ArcadeBodyCollision; + height: number; /** - * The StaticBody's physics type (static by default). + * The displayed width of this Game Object. + * + * This value takes into account the scale factor. + * + * Setting this value will adjust the Game Object's scale property. */ - physicsType: integer; + displayWidth: number; /** - * Changes the Game Object this Body is bound to. - * First it removes its reference from the old Game Object, then sets the new one. - * You can optionally update the position and dimensions of this Body to reflect that of the new Game Object. - * @param gameObject The new Game Object that will own this Body. - * @param update Reposition and resize this Body to match the new Game Object? Default true. + * The displayed height of this Game Object. + * + * This value takes into account the scale factor. + * + * Setting this value will adjust the Game Object's scale property. */ - setGameObject(gameObject: Phaser.GameObjects.GameObject, update?: boolean): Phaser.Physics.Arcade.StaticBody; + displayHeight: number; /** - * Syncs the Body's position and size with its parent Game Object. + * Sets the size of this Game Object to be that of the given Frame. + * + * This will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or call the + * `setDisplaySize` method, which is the same thing as changing the scale but allows you + * to do so by giving pixel values. + * + * If you have enabled this Game Object for input, changing the size will _not_ change the + * size of the hit area. To do this you should adjust the `input.hitArea` object directly. + * @param frame The frame to base the size of this Game Object on. */ - updateFromGameObject(): Phaser.Physics.Arcade.StaticBody; + setSizeToFrame(frame: Phaser.Textures.Frame): this; /** - * Sets the offset of the body. - * @param x The horizontal offset of the Body from the Game Object's center. - * @param y The vertical offset of the Body from the Game Object's center. + * Sets the internal size of this Game Object, as used for frame or physics body creation. + * + * This will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or call the + * `setDisplaySize` method, which is the same thing as changing the scale but allows you + * to do so by giving pixel values. + * + * If you have enabled this Game Object for input, changing the size will _not_ change the + * size of the hit area. To do this you should adjust the `input.hitArea` object directly. + * @param width The width of this Game Object. + * @param height The height of this Game Object. */ - setOffset(x: number, y: number): Phaser.Physics.Arcade.StaticBody; + setSize(width: number, height: number): this; /** - * Sets the size of the body. - * Resets the width and height to match current frame, if no width and height provided and a frame is found. - * @param width The width of the Body in pixels. Cannot be zero. If not given, and the parent Game Object has a frame, it will use the frame width. - * @param height The height of the Body in pixels. Cannot be zero. If not given, and the parent Game Object has a frame, it will use the frame height. - * @param center Modify the Body's `offset`, placing the Body's center on its Game Object's center. Only works if the Game Object has the `getCenter` method. Default true. + * Sets the display size of this Game Object. + * + * Calling this will adjust the scale. + * @param width The width of this Game Object. + * @param height The height of this Game Object. */ - setSize(width?: integer, height?: integer, center?: boolean): Phaser.Physics.Arcade.StaticBody; + setDisplaySize(width: number, height: number): this; /** - * Sets this Static Body to have a circular body and sets its sizes and position. - * @param radius The radius of the StaticBody, in pixels. - * @param offsetX The horizontal offset of the StaticBody from its Game Object, in pixels. - * @param offsetY The vertical offset of the StaticBody from its Game Object, in pixels. + * The Texture this Game Object is using to render with. */ - setCircle(radius: number, offsetX?: number, offsetY?: number): Phaser.Physics.Arcade.StaticBody; + texture: Phaser.Textures.Texture | Phaser.Textures.CanvasTexture; /** - * Updates the StaticBody's `center` from its `position` and dimensions. + * The Texture Frame this Game Object is using to render with. */ - updateCenter(): void; + frame: Phaser.Textures.Frame; /** - * Resets this Body to the given coordinates. Also positions its parent Game Object to the same coordinates. - * @param x The x coordinate to reset the body to. If not given will use the parent Game Object's coordinate. - * @param y The y coordinate to reset the body to. If not given will use the parent Game Object's coordinate. + * A boolean flag indicating if this Game Object is being cropped or not. + * You can toggle this at any time after `setCrop` has been called, to turn cropping on or off. + * Equally, calling `setCrop` with no arguments will reset the crop and disable it. */ - reset(x?: number, y?: number): void; + isCropped: boolean; /** - * NOOP function. A Static Body cannot be stopped. + * Applies a crop to a texture based Game Object, such as a Sprite or Image. + * + * The crop is a rectangle that limits the area of the texture frame that is visible during rendering. + * + * Cropping a Game Object does not change its size, dimensions, physics body or hit area, it just + * changes what is shown when rendered. + * + * The crop coordinates are relative to the texture frame, not the Game Object, meaning 0 x 0 is the top-left. + * + * Therefore, if you had a Game Object that had an 800x600 sized texture, and you wanted to show only the left + * half of it, you could call `setCrop(0, 0, 400, 600)`. + * + * It is also scaled to match the Game Object scale automatically. Therefore a crop rect of 100x50 would crop + * an area of 200x100 when applied to a Game Object that had a scale factor of 2. + * + * You can either pass in numeric values directly, or you can provide a single Rectangle object as the first argument. + * + * Call this method with no arguments at all to reset the crop, or toggle the property `isCropped` to `false`. + * + * You should do this if the crop rectangle becomes the same size as the frame itself, as it will allow + * the renderer to skip several internal calculations. + * @param x The x coordinate to start the crop from. Or a Phaser.Geom.Rectangle object, in which case the rest of the arguments are ignored. + * @param y The y coordinate to start the crop from. + * @param width The width of the crop rectangle in pixels. + * @param height The height of the crop rectangle in pixels. */ - stop(): Phaser.Physics.Arcade.StaticBody; + setCrop(x?: number | Phaser.Geom.Rectangle, y?: number, width?: number, height?: number): this; /** - * Returns the x and y coordinates of the top left and bottom right points of the StaticBody. - * @param obj The object which will hold the coordinates of the bounds. + * Sets the texture and frame this Game Object will use to render with. + * + * Textures are referenced by their string-based keys, as stored in the Texture Manager. + * @param key The key of the texture to be used, as stored in the Texture Manager. + * @param frame The name or index of the frame within the Texture. */ - getBounds(obj: Phaser.Types.Physics.Arcade.ArcadeBodyBounds): Phaser.Types.Physics.Arcade.ArcadeBodyBounds; + setTexture(key: string, frame?: string | number): this; /** - * Checks to see if a given x,y coordinate is colliding with this Static Body. - * @param x The x coordinate to check against this body. - * @param y The y coordinate to check against this body. + * Sets the frame this Game Object will use to render with. + * + * The Frame has to belong to the current Texture being used. + * + * It can be either a string or an index. + * + * Calling `setFrame` will modify the `width` and `height` properties of your Game Object. + * It will also change the `origin` if the Frame has a custom pivot point, as exported from packages like Texture Packer. + * @param frame The name or index of the frame within the Texture. + * @param updateSize Should this call adjust the size of the Game Object? Default true. + * @param updateOrigin Should this call adjust the origin of the Game Object? Default true. */ - hitTest(x: number, y: number): boolean; + setFrame(frame: string | number, updateSize?: boolean, updateOrigin?: boolean): this; /** - * NOOP + * The tint value being applied to the top-left vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. */ - postUpdate(): void; + tintTopLeft: number; /** - * The absolute (non-negative) change in this StaticBody's horizontal position from the previous step. Always zero. + * The tint value being applied to the top-right vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. */ - deltaAbsX(): number; + tintTopRight: number; /** - * The absolute (non-negative) change in this StaticBody's vertical position from the previous step. Always zero. + * The tint value being applied to the bottom-left vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. */ - deltaAbsY(): number; + tintBottomLeft: number; /** - * The change in this StaticBody's horizontal position from the previous step. Always zero. + * The tint value being applied to the bottom-right vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. */ - deltaX(): number; + tintBottomRight: number; /** - * The change in this StaticBody's vertical position from the previous step. Always zero. + * The tint fill mode. + * + * `false` = An additive tint (the default), where vertices colors are blended with the texture. + * `true` = A fill tint, where the vertices colors replace the texture, but respects texture alpha. */ - deltaY(): number; + tintFill: boolean; /** - * The change in this StaticBody's rotation from the previous step. Always zero. + * Clears all tint values associated with this Game Object. + * + * Immediately sets the color values back to 0xffffff and the tint type to 'additive', + * which results in no visible change to the texture. */ - deltaZ(): number; + clearTint(): this; /** - * Disables this Body and marks it for destruction during the next step. + * Sets an additive tint on this Game Object. + * + * The tint works by taking the pixel color values from the Game Objects texture, and then + * multiplying it by the color value of the tint. You can provide either one color value, + * in which case the whole Game Object will be tinted in that color. Or you can provide a color + * per corner. The colors are blended together across the extent of the Game Object. + * + * To modify the tint color once set, either call this method again with new values or use the + * `tint` property to set all colors at once. Or, use the properties `tintTopLeft`, `tintTopRight, + * `tintBottomLeft` and `tintBottomRight` to set the corner color values independently. + * + * To remove a tint call `clearTint`. + * + * To swap this from being an additive tint to a fill based tint set the property `tintFill` to `true`. + * @param topLeft The tint being applied to the top-left of the Game Object. If no other values are given this value is applied evenly, tinting the whole Game Object. Default 0xffffff. + * @param topRight The tint being applied to the top-right of the Game Object. + * @param bottomLeft The tint being applied to the bottom-left of the Game Object. + * @param bottomRight The tint being applied to the bottom-right of the Game Object. */ - destroy(): void; + setTint(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; /** - * Draws a graphical representation of the StaticBody for visual debugging purposes. - * @param graphic The Graphics object to use for the debug drawing of the StaticBody. + * Sets a fill-based tint on this Game Object. + * + * Unlike an additive tint, a fill-tint literally replaces the pixel colors from the texture + * with those in the tint. You can use this for effects such as making a player flash 'white' + * if hit by something. You can provide either one color value, in which case the whole + * Game Object will be rendered in that color. Or you can provide a color per corner. The colors + * are blended together across the extent of the Game Object. + * + * To modify the tint color once set, either call this method again with new values or use the + * `tint` property to set all colors at once. Or, use the properties `tintTopLeft`, `tintTopRight, + * `tintBottomLeft` and `tintBottomRight` to set the corner color values independently. + * + * To remove a tint call `clearTint`. + * + * To swap this from being a fill-tint to an additive tint set the property `tintFill` to `false`. + * @param topLeft The tint being applied to the top-left of the Game Object. If not other values are given this value is applied evenly, tinting the whole Game Object. Default 0xffffff. + * @param topRight The tint being applied to the top-right of the Game Object. + * @param bottomLeft The tint being applied to the bottom-left of the Game Object. + * @param bottomRight The tint being applied to the bottom-right of the Game Object. */ - drawDebug(graphic: Phaser.GameObjects.Graphics): void; + setTintFill(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; /** - * Indicates whether the StaticBody is going to be showing a debug visualization during postUpdate. + * The tint value being applied to the whole of the Game Object. + * This property is a setter-only. Use the properties `tintTopLeft` etc to read the current tint value. */ - willDrawDebug(): boolean; + tint: number; /** - * Sets the Mass of the StaticBody. Will set the Mass to 0.1 if the value passed is less than or equal to zero. - * @param value The value to set the Mass to. Values of zero or less are changed to 0.1. + * Does this Game Object have a tint applied? + * + * It checks to see if the 4 tint properties are set to the value 0xffffff + * and that the `tintFill` property is `false`. This indicates that a Game Object isn't tinted. */ - setMass(value: number): Phaser.Physics.Arcade.StaticBody; + readonly isTinted: boolean; /** - * The x coordinate of the StaticBody. + * The x position of this Game Object. */ x: number; /** - * The y coordinate of the StaticBody. + * The y position of this Game Object. */ y: number; /** - * Returns the left-most x coordinate of the area of the StaticBody. + * The z position of this Game Object. + * + * Note: The z position does not control the rendering order of 2D Game Objects. Use + * {@link Phaser.GameObjects.Components.Depth#depth} instead. */ - readonly left: number; + z: number; /** - * The right-most x coordinate of the area of the StaticBody. + * The w position of this Game Object. */ - readonly right: number; + w: number; /** - * The highest y coordinate of the area of the StaticBody. + * This is a special setter that allows you to set both the horizontal and vertical scale of this Game Object + * to the same value, at the same time. When reading this value the result returned is `(scaleX + scaleY) / 2`. + * + * Use of this property implies you wish the horizontal and vertical scales to be equal to each other. If this + * isn't the case, use the `scaleX` or `scaleY` properties instead. */ - readonly top: number; + scale: number; /** - * The lowest y coordinate of the area of the StaticBody. (y + height) + * The horizontal scale of this Game Object. */ - readonly bottom: number; + scaleX: number; - } + /** + * The vertical scale of this Game Object. + */ + scaleY: number; - /** - * An Arcade Physics Static Group object. - * - * All Game Objects created by this Group will automatically be given static Arcade Physics bodies. - * - * Its dynamic counterpart is {@link Phaser.Physics.Arcade.Group}. - */ - class StaticGroup extends Phaser.GameObjects.Group { /** + * The angle of this Game Object as expressed in degrees. * - * @param world The physics simulation. - * @param scene The scene this group belongs to. - * @param children Game Objects to add to this group; or the `config` argument. - * @param config Settings for this group. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left + * and -90 is up. + * + * If you prefer to work in radians, see the `rotation` property instead. */ - constructor(world: Phaser.Physics.Arcade.World, scene: Phaser.Scene, children?: Phaser.GameObjects.GameObject[] | Phaser.Types.GameObjects.Group.GroupConfig | Phaser.Types.GameObjects.Group.GroupCreateConfig, config?: Phaser.Types.GameObjects.Group.GroupConfig | Phaser.Types.GameObjects.Group.GroupCreateConfig); + angle: number; /** - * The physics simulation. + * The angle of this Game Object in radians. + * + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. + * + * If you prefer to work in degrees, see the `angle` property instead. */ - world: Phaser.Physics.Arcade.World; + rotation: number; /** - * The scene this group belongs to. + * Sets the position of this Game Object. + * @param x The x position of this Game Object. Default 0. + * @param y The y position of this Game Object. If not set it will use the `x` value. Default x. + * @param z The z position of this Game Object. Default 0. + * @param w The w position of this Game Object. Default 0. */ - physicsType: integer; + setPosition(x?: number, y?: number, z?: number, w?: number): this; /** - * A textual representation of this Game Object. - * Used internally by Phaser but is available for your own custom classes to populate. + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. */ - type: string; + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; /** - * Adds a static physics body to the new group member (if it lacks one) and adds it to the simulation. - * @param child The new group member. + * Sets the position of this Game Object to be a random position within the confines of + * the given area. + * + * If no area is specified a random position between 0 x 0 and the game width x height is used instead. + * + * The position does not factor in the size of this Game Object, meaning that only the origin is + * guaranteed to be within the area. + * @param x The x position of the top-left of the random area. Default 0. + * @param y The y position of the top-left of the random area. Default 0. + * @param width The width of the random area. + * @param height The height of the random area. */ - createCallbackHandler(child: Phaser.GameObjects.GameObject): void; + setRandomPosition(x?: number, y?: number, width?: number, height?: number): this; /** - * Disables the group member's physics body, removing it from the simulation. - * @param child The group member being removed. + * Sets the rotation of this Game Object. + * @param radians The rotation of this Game Object, in radians. Default 0. */ - removeCallbackHandler(child: Phaser.GameObjects.GameObject): void; + setRotation(radians?: number): this; /** - * Refreshes the group. - * @param entries The newly created group members. + * Sets the angle of this Game Object. + * @param degrees The rotation of this Game Object, in degrees. Default 0. */ - createMultipleCallbackHandler(entries: Phaser.GameObjects.GameObject[]): void; + setAngle(degrees?: number): this; /** - * Resets each Body to the position of its parent Game Object. - * Body sizes aren't changed (use {@link Phaser.Physics.Arcade.Components.Enable#refreshBody} for that). + * Sets the scale of this Game Object. + * @param x The horizontal scale of this Game Object. + * @param y The vertical scale of this Game Object. If not set it will use the `x` value. Default x. */ - refresh(): Phaser.Physics.Arcade.StaticGroup; - - } + setScale(x: number, y?: number): this; - namespace Tilemap { /** - * A function to process the collision callbacks between a single tile and an Arcade Physics enabled Game Object. - * @param tile The Tile to process. - * @param sprite The Game Object to process with the Tile. + * Sets the x position of this Game Object. + * @param value The x position of this Game Object. Default 0. */ - function ProcessTileCallbacks(tile: Phaser.Tilemaps.Tile, sprite: Phaser.GameObjects.Sprite): boolean; + setX(value?: number): this; /** - * Internal function to process the separation of a physics body from a tile. - * @param body The Body object to separate. - * @param x The x separation amount. + * Sets the y position of this Game Object. + * @param value The y position of this Game Object. Default 0. */ - function ProcessTileSeparationX(body: Phaser.Physics.Arcade.Body, x: number): void; + setY(value?: number): this; /** - * Internal function to process the separation of a physics body from a tile. - * @param body The Body object to separate. - * @param y The y separation amount. + * Sets the z position of this Game Object. + * + * Note: The z position does not control the rendering order of 2D Game Objects. Use + * {@link Phaser.GameObjects.Components.Depth#setDepth} instead. + * @param value The z position of this Game Object. Default 0. */ - function ProcessTileSeparationY(body: Phaser.Physics.Arcade.Body, y: number): void; + setZ(value?: number): this; /** - * The core separation function to separate a physics body and a tile. - * @param i The index of the tile within the map data. - * @param body The Body object to separate. - * @param tile The tile to collide against. - * @param tileWorldRect A rectangle-like object defining the dimensions of the tile. - * @param tilemapLayer The tilemapLayer to collide against. - * @param tileBias The tile bias value. Populated by the `World.TILE_BIAS` constant. - * @param isLayer Is this check coming from a TilemapLayer or an array of tiles? + * Sets the w position of this Game Object. + * @param value The w position of this Game Object. Default 0. */ - function SeparateTile(i: number, body: Phaser.Physics.Arcade.Body, tile: Phaser.Tilemaps.Tile, tileWorldRect: Phaser.Geom.Rectangle, tilemapLayer: Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer, tileBias: number, isLayer: boolean): boolean; + setW(value?: number): this; /** - * Check the body against the given tile on the X axis. - * Used internally by the SeparateTile function. - * @param body The Body object to separate. - * @param tile The tile to check. - * @param tileLeft The left position of the tile within the tile world. - * @param tileRight The right position of the tile within the tile world. - * @param tileBias The tile bias value. Populated by the `World.TILE_BIAS` constant. - * @param isLayer Is this check coming from a TilemapLayer or an array of tiles? + * Gets the local transform matrix for this Game Object. + * @param tempMatrix The matrix to populate with the values from this Game Object. */ - function TileCheckX(body: Phaser.Physics.Arcade.Body, tile: Phaser.Tilemaps.Tile, tileLeft: number, tileRight: number, tileBias: number, isLayer: boolean): number; + getLocalTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; /** - * Check the body against the given tile on the Y axis. - * Used internally by the SeparateTile function. - * @param body The Body object to separate. - * @param tile The tile to check. - * @param tileTop The top position of the tile within the tile world. - * @param tileBottom The bottom position of the tile within the tile world. - * @param tileBias The tile bias value. Populated by the `World.TILE_BIAS` constant. - * @param isLayer Is this check coming from a TilemapLayer or an array of tiles? + * Gets the world transform matrix for this Game Object, factoring in any parent Containers. + * @param tempMatrix The matrix to populate with the values from this Game Object. + * @param parentMatrix A temporary matrix to hold parent values during the calculations. */ - function TileCheckY(body: Phaser.Physics.Arcade.Body, tile: Phaser.Tilemaps.Tile, tileTop: number, tileBottom: number, tileBias: number, isLayer: boolean): number; + getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; /** - * Checks for intersection between the given tile rectangle-like object and an Arcade Physics body. - * @param tileWorldRect A rectangle object that defines the tile placement in the world. - * @param body The body to check for intersection against. + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. */ - function TileIntersectsBody(tileWorldRect: Object, body: Phaser.Physics.Arcade.Body): boolean; - - } + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; - /** - * The Arcade Physics World. - * - * The World is responsible for creating, managing, colliding and updating all of the bodies within it. - * - * An instance of the World belongs to a Phaser.Scene and is accessed via the property `physics.world`. - */ - class World extends Phaser.Events.EventEmitter { /** + * Gets the sum total rotation of all of this Game Objects parent Containers. * - * @param scene The Scene to which this World instance belongs. - * @param config An Arcade Physics Configuration object. + * The returned value is in radians and will be zero if this Game Object has no parent container. */ - constructor(scene: Phaser.Scene, config: Phaser.Types.Physics.Arcade.ArcadeWorldConfig); + getParentRotation(): number; /** - * The Scene this simulation belongs to. + * The visible state of the Game Object. + * + * An invisible Game Object will skip rendering, but will still process update logic. */ - scene: Phaser.Scene; + visible: boolean; /** - * Dynamic Bodies in this simulation. + * Sets the visibility of this Game Object. + * + * An invisible Game Object will skip rendering, but will still process update logic. + * @param value The visible state of the Game Object. */ - bodies: Phaser.Structs.Set; + setVisible(value: boolean): this; /** - * Static Bodies in this simulation. + * Sets the body's horizontal and vertical acceleration. If the vertical acceleration value is not provided, the vertical acceleration is set to the same value as the horizontal acceleration. + * @param x The horizontal acceleration + * @param y The vertical acceleration Default x. */ - staticBodies: Phaser.Structs.Set; + setAcceleration(x: number, y?: number): this; /** - * Static Bodies marked for deletion. + * Sets the body's horizontal acceleration. + * @param value The horizontal acceleration */ - pendingDestroy: Phaser.Structs.Set<(Phaser.Physics.Arcade.Body|Phaser.Physics.Arcade.StaticBody)>; + setAccelerationX(value: number): this; /** - * This simulation's collision processors. + * Sets the body's vertical acceleration. + * @param value The vertical acceleration */ - colliders: Phaser.Structs.ProcessQueue; + setAccelerationY(value: number): this; /** - * Acceleration of Bodies due to gravity, in pixels per second. + * Sets the angular velocity of the body. + * + * In Arcade Physics, bodies cannot rotate. They are always axis-aligned. + * However, they can have angular motion, which is passed on to the Game Object bound to the body, + * causing them to visually rotate, even though the body remains axis-aligned. + * @param value The amount of angular velocity. */ - gravity: Phaser.Math.Vector2; + setAngularVelocity(value: number): this; /** - * A boundary constraining Bodies. + * Sets the angular acceleration of the body. + * + * In Arcade Physics, bodies cannot rotate. They are always axis-aligned. + * However, they can have angular motion, which is passed on to the Game Object bound to the body, + * causing them to visually rotate, even though the body remains axis-aligned. + * @param value The amount of angular acceleration. */ - bounds: Phaser.Geom.Rectangle; + setAngularAcceleration(value: number): this; /** - * The boundary edges that Bodies can collide with. + * Sets the angular drag of the body. Drag is applied to the current velocity, providing a form of deceleration. + * @param value The amount of drag. */ - checkCollision: Phaser.Types.Physics.Arcade.CheckCollisionObject; + setAngularDrag(value: number): this; /** - * The number of physics steps to be taken per second. + * Sets the bounce values of this body. * - * This property is read-only. Use the `setFPS` method to modify it at run-time. + * Bounce is the amount of restitution, or elasticity, the body has when it collides with another object. + * A value of 1 means that it will retain its full velocity after the rebound. A value of 0 means it will not rebound at all. + * @param x The amount of horizontal bounce to apply on collision. A float, typically between 0 and 1. + * @param y The amount of vertical bounce to apply on collision. A float, typically between 0 and 1. Default x. */ - readonly fps: number; + setBounce(x: number, y?: number): this; /** - * The number of steps that took place in the last frame. + * Sets the horizontal bounce value for this body. + * @param value The amount of horizontal bounce to apply on collision. A float, typically between 0 and 1. */ - readonly stepsLastFrame: number; + setBounceX(value: number): this; /** - * Scaling factor applied to the frame rate. - * - * - 1.0 = normal speed - * - 2.0 = half speed - * - 0.5 = double speed + * Sets the vertical bounce value for this body. + * @param value The amount of vertical bounce to apply on collision. A float, typically between 0 and 1. */ - timeScale: number; + setBounceY(value: number): this; /** - * The maximum absolute difference of a Body's per-step velocity and its overlap with another Body that will result in separation on *each axis*. - * Larger values favor separation. - * Smaller values favor no separation. + * Sets whether this Body collides with the world boundary. + * + * Optionally also sets the World Bounce values. If the `Body.worldBounce` is null, it's set to a new Phaser.Math.Vector2 first. + * @param value `true` if this body should collide with the world bounds, otherwise `false`. Default true. + * @param bounceX If given this will be replace the `worldBounce.x` value. + * @param bounceY If given this will be replace the `worldBounce.y` value. */ - OVERLAP_BIAS: number; + setCollideWorldBounds(value?: boolean, bounceX?: number, bounceY?: number): this; /** - * The maximum absolute value of a Body's overlap with a tile that will result in separation on *each axis*. - * Larger values favor separation. - * Smaller values favor no separation. - * The optimum value may be similar to the tile size. + * Sets the debug values of this body. + * + * Bodies will only draw their debug if debug has been enabled for Arcade Physics as a whole. + * Note that there is a performance cost in drawing debug displays. It should never be used in production. + * @param showBody Set to `true` to have this body render its outline to the debug display. + * @param showVelocity Set to `true` to have this body render a velocity marker to the debug display. + * @param bodyColor The color of the body outline when rendered to the debug display. */ - TILE_BIAS: number; + setDebug(showBody: boolean, showVelocity: boolean, bodyColor: number): this; /** - * Always separate overlapping Bodies horizontally before vertically. - * False (the default) means Bodies are first separated on the axis of greater gravity, or the vertical axis if neither is greater. + * Sets the color of the body outline when it renders to the debug display. + * @param value The color of the body outline when rendered to the debug display. */ - forceX: boolean; + setDebugBodyColor(value: number): this; /** - * Whether the simulation advances with the game loop. + * Set to `true` to have this body render its outline to the debug display. */ - isPaused: boolean; + debugShowBody: boolean; /** - * Enables the debug display. + * Set to `true` to have this body render a velocity marker to the debug display. */ - drawDebug: boolean; + debugShowVelocity: boolean; /** - * The graphics object drawing the debug display. + * The color of the body outline when it renders to the debug display. */ - debugGraphic: Phaser.GameObjects.Graphics; + debugBodyColor: number; /** - * Default debug display settings for new Bodies. + * Sets the body's horizontal and vertical drag. If the vertical drag value is not provided, the vertical drag is set to the same value as the horizontal drag. + * + * Drag can be considered as a form of deceleration that will return the velocity of a body back to zero over time. + * It is the absolute loss of velocity due to movement, in pixels per second squared. + * The x and y components are applied separately. + * + * When `useDamping` is true, this is 1 minus the damping factor. + * A value of 1 means the Body loses no velocity. + * A value of 0.95 means the Body loses 5% of its velocity per step. + * A value of 0.5 means the Body loses 50% of its velocity per step. + * + * Drag is applied only when `acceleration` is zero. + * @param x The amount of horizontal drag to apply. + * @param y The amount of vertical drag to apply. Default x. */ - defaults: Phaser.Types.Physics.Arcade.ArcadeWorldDefaults; + setDrag(x: number, y?: number): this; /** - * The maximum number of items per node on the RTree. + * Sets the body's horizontal drag. * - * This is ignored if `useTree` is `false`. If you have a large number of bodies in - * your world then you may find search performance improves by increasing this value, - * to allow more items per node and less node division. + * Drag can be considered as a form of deceleration that will return the velocity of a body back to zero over time. + * It is the absolute loss of velocity due to movement, in pixels per second squared. + * The x and y components are applied separately. + * + * When `useDamping` is true, this is 1 minus the damping factor. + * A value of 1 means the Body loses no velocity. + * A value of 0.95 means the Body loses 5% of its velocity per step. + * A value of 0.5 means the Body loses 50% of its velocity per step. + * + * Drag is applied only when `acceleration` is zero. + * @param value The amount of horizontal drag to apply. */ - maxEntries: integer; + setDragX(value: number): this; /** - * Should this Arcade Physics World use an RTree for Dynamic and Static Physics bodies? - * - * An RTree is a fast way of spatially sorting of all the bodies in the world. - * However, at certain limits, the cost of clearing and inserting the bodies into the - * tree every frame becomes more expensive than the search speed gains it provides. + * Sets the body's vertical drag. * - * If you have a large number of dynamic bodies in your world then it may be best to - * disable the use of the RTree by setting this property to `false` in the physics config. + * Drag can be considered as a form of deceleration that will return the velocity of a body back to zero over time. + * It is the absolute loss of velocity due to movement, in pixels per second squared. + * The x and y components are applied separately. * - * The number it can cope with depends on browser and device, but a conservative estimate - * of around 5,000 bodies should be considered the max before disabling it. + * When `useDamping` is true, this is 1 minus the damping factor. + * A value of 1 means the Body loses no velocity. + * A value of 0.95 means the Body loses 5% of its velocity per step. + * A value of 0.5 means the Body loses 50% of its velocity per step. * - * This only applies to dynamic bodies. Static bodies are always kept in an RTree, - * because they don't have to be cleared every frame, so you benefit from the - * massive search speeds all the time. + * Drag is applied only when `acceleration` is zero. + * @param value The amount of vertical drag to apply. */ - useTree: boolean; + setDragY(value: number): this; /** - * The spatial index of Dynamic Bodies. + * If this Body is using `drag` for deceleration this function controls how the drag is applied. + * If set to `true` drag will use a damping effect rather than a linear approach. If you are + * creating a game where the Body moves freely at any angle (i.e. like the way the ship moves in + * the game Asteroids) then you will get a far smoother and more visually correct deceleration + * by using damping, avoiding the axis-drift that is prone with linear deceleration. + * + * If you enable this property then you should use far smaller `drag` values than with linear, as + * they are used as a multiplier on the velocity. Values such as 0.95 will give a nice slow + * deceleration, where-as smaller values, such as 0.5 will stop an object almost immediately. + * @param value `true` to use damping for deceleration, or `false` to use linear deceleration. */ - tree: Phaser.Structs.RTree; + setDamping(value: boolean): this; /** - * The spatial index of Static Bodies. + * Enables this Game Object's Body. + * @param reset Also reset the Body and place it at (x, y). + * @param x The horizontal position to place the Game Object and Body. + * @param y The horizontal position to place the Game Object and Body. + * @param enableGameObject Also activate this Game Object. + * @param showGameObject Also show this Game Object. */ - staticTree: Phaser.Structs.RTree; + enableBody(reset: boolean, x: number, y: number, enableGameObject: boolean, showGameObject: boolean): this; /** - * Recycled input for tree searches. + * Stops and disables this Game Object's Body. + * @param disableGameObject Also deactivate this Game Object. Default false. + * @param hideGameObject Also hide this Game Object. Default false. */ - treeMinMax: Phaser.Types.Physics.Arcade.ArcadeWorldTreeMinMax; + disableBody(disableGameObject?: boolean, hideGameObject?: boolean): this; /** - * Adds an Arcade Physics Body to a Game Object, an array of Game Objects, or the children of a Group. - * - * The difference between this and the `enableBody` method is that you can pass arrays or Groups - * to this method. - * - * You can specify if the bodies are to be Dynamic or Static. A dynamic body can move via velocity and - * acceleration. A static body remains fixed in place and as such is able to use an optimized search - * tree, making it ideal for static elements such as level objects. You can still collide and overlap - * with static bodies. - * - * Normally, rather than calling this method directly, you'd use the helper methods available in the - * Arcade Physics Factory, such as: - * - * ```javascript - * this.physics.add.image(x, y, textureKey); - * this.physics.add.sprite(x, y, textureKey); - * ``` - * - * Calling factory methods encapsulates the creation of a Game Object and the creation of its - * body at the same time. If you are creating custom classes then you can pass them to this - * method to have their bodies created. - * @param object The object, or objects, on which to create the bodies. - * @param bodyType The type of Body to create. Either `DYNAMIC_BODY` or `STATIC_BODY`. + * Syncs the Body's position and size with its parent Game Object. + * You don't need to call this for Dynamic Bodies, as it happens automatically. + * But for Static bodies it's a useful way of modifying the position of a Static Body + * in the Physics World, based on its Game Object. */ - enable(object: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[] | Phaser.GameObjects.Group | Phaser.GameObjects.Group[], bodyType?: integer): void; + refreshBody(): this; /** - * Creates an Arcade Physics Body on a single Game Object. - * - * If the Game Object already has a body, this method will simply add it back into the simulation. - * - * You can specify if the body is Dynamic or Static. A dynamic body can move via velocity and - * acceleration. A static body remains fixed in place and as such is able to use an optimized search - * tree, making it ideal for static elements such as level objects. You can still collide and overlap - * with static bodies. - * - * Normally, rather than calling this method directly, you'd use the helper methods available in the - * Arcade Physics Factory, such as: - * - * ```javascript - * this.physics.add.image(x, y, textureKey); - * this.physics.add.sprite(x, y, textureKey); - * ``` - * - * Calling factory methods encapsulates the creation of a Game Object and the creation of its - * body at the same time. If you are creating custom classes then you can pass them to this - * method to have their bodies created. - * @param object The Game Object on which to create the body. - * @param bodyType The type of Body to create. Either `DYNAMIC_BODY` or `STATIC_BODY`. + * Sets the friction of this game object's physics body. + * In Arcade Physics, friction is a special case of motion transfer from an "immovable" body to a riding body. + * @param x The amount of horizontal friction to apply, [0, 1]. + * @param y The amount of vertical friction to apply, [0, 1]. Default x. */ - enableBody(object: Phaser.GameObjects.GameObject, bodyType?: integer): Phaser.GameObjects.GameObject; + setFriction(x: number, y?: number): this; /** - * Adds an existing Arcade Physics Body or StaticBody to the simulation. - * - * The body is enabled and added to the local search trees. - * @param body The Body to be added to the simulation. + * Sets the horizontal friction of this game object's physics body. + * This can move a riding body horizontally when it collides with this one on the vertical axis. + * @param x The amount of friction to apply, [0, 1]. */ - add(body: Phaser.Physics.Arcade.Body | Phaser.Physics.Arcade.StaticBody): Phaser.Physics.Arcade.Body | Phaser.Physics.Arcade.StaticBody; + setFrictionX(x: number): this; /** - * Disables the Arcade Physics Body of a Game Object, an array of Game Objects, or the children of a Group. - * - * The difference between this and the `disableBody` method is that you can pass arrays or Groups - * to this method. - * - * The body itself is not deleted, it just has its `enable` property set to false, which - * means you can re-enable it again at any point by passing it to enable `World.enable` or `World.add`. - * @param object The object, or objects, on which to disable the bodies. + * Sets the vertical friction of this game object's physics body. + * This can move a riding body vertically when it collides with this one on the horizontal axis. + * @param y The amount of friction to apply, [0, 1]. */ - disable(object: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[] | Phaser.GameObjects.Group | Phaser.GameObjects.Group[]): void; + setFrictionY(y: number): this; /** - * Disables an existing Arcade Physics Body or StaticBody and removes it from the simulation. - * - * The body is disabled and removed from the local search trees. + * Set the X and Y values of the gravitational pull to act upon this Arcade Physics Game Object. Values can be positive or negative. Larger values result in a stronger effect. * - * The body itself is not deleted, it just has its `enable` property set to false, which - * means you can re-enable it again at any point by passing it to enable `World.enable` or `World.add`. - * @param body The Body to be disabled. + * If only one value is provided, this value will be used for both the X and Y axis. + * @param x The gravitational force to be applied to the X-axis. + * @param y The gravitational force to be applied to the Y-axis. If this is not specified, the X value will be used. Default x. */ - disableBody(body: Phaser.Physics.Arcade.Body | Phaser.Physics.Arcade.StaticBody): void; + setGravity(x: number, y?: number): this; /** - * Removes an existing Arcade Physics Body or StaticBody from the simulation. - * - * The body is disabled and removed from the local search trees. - * - * The body itself is not deleted, it just has its `enabled` property set to false, which - * means you can re-enable it again at any point by passing it to enable `enable` or `add`. - * @param body The body to be removed from the simulation. + * Set the gravitational force to be applied to the X axis. Value can be positive or negative. Larger values result in a stronger effect. + * @param x The gravitational force to be applied to the X-axis. */ - remove(body: Phaser.Physics.Arcade.Body | Phaser.Physics.Arcade.StaticBody): void; + setGravityX(x: number): this; /** - * Creates a Graphics Game Object that the world will use to render the debug display to. - * - * This is called automatically when the World is instantiated if the `debug` config property - * was set to `true`. However, you can call it at any point should you need to display the - * debug Graphic from a fixed point. - * - * You can control which objects are drawn to the Graphics object, and the colors they use, - * by setting the debug properties in the physics config. - * - * You should not typically use this in a production game. Use it to aid during debugging. + * Set the gravitational force to be applied to the Y axis. Value can be positive or negative. Larger values result in a stronger effect. + * @param y The gravitational force to be applied to the Y-axis. */ - createDebugGraphic(): Phaser.GameObjects.Graphics; + setGravityY(y: number): this; /** - * Sets the position, size and properties of the World boundary. + * Sets if this Body can be separated during collisions with other bodies. * - * The World boundary is an invisible rectangle that defines the edges of the World. - * If a Body is set to collide with the world bounds then it will automatically stop - * when it reaches any of the edges. You can optionally set which edges of the boundary - * should be checked against. - * @param x The top-left x coordinate of the boundary. - * @param y The top-left y coordinate of the boundary. - * @param width The width of the boundary. - * @param height The height of the boundary. - * @param checkLeft Should bodies check against the left edge of the boundary? - * @param checkRight Should bodies check against the right edge of the boundary? - * @param checkUp Should bodies check against the top edge of the boundary? - * @param checkDown Should bodies check against the bottom edge of the boundary? + * When a body is immovable it means it won't move at all, not even to separate it from collision + * overlap. If you just wish to prevent a body from being knocked around by other bodies, see + * the `setPushable` method instead. + * @param value Sets if this body will be separated during collisions with other bodies. Default true. */ - setBounds(x: number, y: number, width: number, height: number, checkLeft?: boolean, checkRight?: boolean, checkUp?: boolean, checkDown?: boolean): Phaser.Physics.Arcade.World; + setImmovable(value?: boolean): this; /** - * Enables or disables collisions on each edge of the World boundary. - * @param left Should bodies check against the left edge of the boundary? Default true. - * @param right Should bodies check against the right edge of the boundary? Default true. - * @param up Should bodies check against the top edge of the boundary? Default true. - * @param down Should bodies check against the bottom edge of the boundary? Default true. + * Sets the mass of the physics body + * @param value New value for the mass of the body. */ - setBoundsCollision(left?: boolean, right?: boolean, up?: boolean, down?: boolean): Phaser.Physics.Arcade.World; + setMass(value: number): this; /** - * Pauses the simulation. + * Sets if this Body can be pushed by another Body. * - * A paused simulation does not update any existing bodies, or run any Colliders. + * A body that cannot be pushed will reflect back all of the velocity it is given to the + * colliding body. If that body is also not pushable, then the separation will be split + * between them evenly. * - * However, you can still enable and disable bodies within it, or manually run collide or overlap - * checks. + * If you want your body to never move or seperate at all, see the `setImmovable` method. + * @param value Sets if this body can be pushed by collisions with another Body. Default true. */ - pause(): Phaser.Physics.Arcade.World; + setPushable(value?: boolean): this; /** - * Resumes the simulation, if paused. + * Sets the body offset. This allows you to adjust the difference between the center of the body + * and the x and y coordinates of the parent Game Object. + * @param x The amount to offset the body from the parent Game Object along the x-axis. + * @param y The amount to offset the body from the parent Game Object along the y-axis. Defaults to the value given for the x-axis. Default x. */ - resume(): Phaser.Physics.Arcade.World; + setOffset(x: number, y?: number): this; /** - * Creates a new Collider object and adds it to the simulation. - * - * A Collider is a way to automatically perform collision checks between two objects, - * calling the collide and process callbacks if they occur. - * - * Colliders are run as part of the World update, after all of the Bodies have updated. - * - * By creating a Collider you don't need then call `World.collide` in your `update` loop, - * as it will be handled for you automatically. - * @param object1 The first object to check for collision. - * @param object2 The second object to check for collision. - * @param collideCallback The callback to invoke when the two objects collide. - * @param processCallback The callback to invoke when the two objects collide. Must return a boolean. - * @param callbackContext The scope in which to call the callbacks. + * Sets the size of this physics body. Setting the size does not adjust the dimensions of the parent Game Object. + * @param width The new width of the physics body, in pixels. + * @param height The new height of the physics body, in pixels. + * @param center Should the body be re-positioned so its center aligns with the parent Game Object? Default true. */ - addCollider(object1: Phaser.Types.Physics.Arcade.ArcadeColliderType, object2: Phaser.Types.Physics.Arcade.ArcadeColliderType, collideCallback?: ArcadePhysicsCallback, processCallback?: ArcadePhysicsCallback, callbackContext?: any): Phaser.Physics.Arcade.Collider; + setBodySize(width: number, height: number, center?: boolean): this; /** - * Creates a new Overlap Collider object and adds it to the simulation. - * - * A Collider is a way to automatically perform overlap checks between two objects, - * calling the collide and process callbacks if they occur. - * - * Colliders are run as part of the World update, after all of the Bodies have updated. - * - * By creating a Collider you don't need then call `World.overlap` in your `update` loop, - * as it will be handled for you automatically. - * @param object1 The first object to check for overlap. - * @param object2 The second object to check for overlap. - * @param collideCallback The callback to invoke when the two objects overlap. - * @param processCallback The callback to invoke when the two objects overlap. Must return a boolean. - * @param callbackContext The scope in which to call the callbacks. + * Sets this physics body to use a circle for collision instead of a rectangle. + * @param radius The radius of the physics body, in pixels. + * @param offsetX The amount to offset the body from the parent Game Object along the x-axis. + * @param offsetY The amount to offset the body from the parent Game Object along the y-axis. */ - addOverlap(object1: Phaser.Types.Physics.Arcade.ArcadeColliderType, object2: Phaser.Types.Physics.Arcade.ArcadeColliderType, collideCallback?: ArcadePhysicsCallback, processCallback?: ArcadePhysicsCallback, callbackContext?: any): Phaser.Physics.Arcade.Collider; + setCircle(radius: number, offsetX?: number, offsetY?: number): this; /** - * Removes a Collider from the simulation so it is no longer processed. - * - * This method does not destroy the Collider. If you wish to add it back at a later stage you can call - * `World.colliders.add(Collider)`. - * - * If you no longer need the Collider you can call the `Collider.destroy` method instead, which will - * automatically clear all of its references and then remove it from the World. If you call destroy on - * a Collider you _don't_ need to pass it to this method too. - * @param collider The Collider to remove from the simulation. + * Sets the velocity of the Body. + * @param x The horizontal velocity of the body. Positive values move the body to the right, while negative values move it to the left. + * @param y The vertical velocity of the body. Positive values move the body down, while negative values move it up. Default x. */ - removeCollider(collider: Phaser.Physics.Arcade.Collider): Phaser.Physics.Arcade.World; + setVelocity(x: number, y?: number): this; /** - * Sets the frame rate to run the simulation at. - * - * The frame rate value is used to simulate a fixed update time step. This fixed - * time step allows for a straightforward implementation of a deterministic game state. - * - * This frame rate is independent of the frequency at which the game is rendering. The - * higher you set the fps, the more physics simulation steps will occur per game step. - * Conversely, the lower you set it, the less will take place. + * Sets the horizontal component of the body's velocity. * - * You can optionally advance the simulation directly yourself by calling the `step` method. - * @param framerate The frame rate to advance the simulation at. + * Positive values move the body to the right, while negative values move it to the left. + * @param x The new horizontal velocity. */ - setFPS(framerate: integer): this; + setVelocityX(x: number): this; /** - * Advances the simulation based on the elapsed time and fps rate. + * Sets the vertical component of the body's velocity. * - * This is called automatically by your Scene and does not need to be invoked directly. - * @param time The current timestamp as generated by the Request Animation Frame or SetTimeout. - * @param delta The delta time, in ms, elapsed since the last frame. + * Positive values move the body down, while negative values move it up. + * @param y The new vertical velocity of the body. */ - protected update(time: number, delta: number): void; + setVelocityY(y: number): this; /** - * Advances the simulation by a time increment. - * @param delta The delta time amount, in seconds, by which to advance the simulation. + * Sets the maximum velocity of the body. + * @param x The new maximum horizontal velocity. + * @param y The new maximum vertical velocity. Default x. */ - step(delta: number): void; + setMaxVelocity(x: number, y?: number): this; + + } + /** + * The Arcade Physics Plugin belongs to a Scene and sets up and manages the Scene's physics simulation. + * It also holds some useful methods for moving and rotating Arcade Physics Bodies. + * + * You can access it from within a Scene using `this.physics`. + * + * Arcade Physics uses the Projection Method of collision resolution and separation. While it's fast and suitable + * for 'arcade' style games it lacks stability when multiple objects are in close proximity or resting upon each other. + * The separation that stops two objects penetrating may create a new penetration against a different object. If you + * require a high level of stability please consider using an alternative physics system, such as Matter.js. + */ + class ArcadePhysics { /** - * Updates bodies, draws the debug display, and handles pending queue operations. + * + * @param scene The Scene that this Plugin belongs to. */ - postUpdate(): void; + constructor(scene: Phaser.Scene); /** - * Calculates a Body's velocity and updates its position. - * @param body The Body to be updated. - * @param delta The delta value to be used in the motion calculations, in seconds. + * The Scene that this Plugin belongs to. */ - updateMotion(body: Phaser.Physics.Arcade.Body, delta: number): void; + scene: Phaser.Scene; /** - * Calculates a Body's angular velocity. - * @param body The Body to compute the velocity for. - * @param delta The delta value to be used in the calculation, in seconds. + * The Scene's Systems. */ - computeAngularVelocity(body: Phaser.Physics.Arcade.Body, delta: number): void; + systems: Phaser.Scenes.Systems; /** - * Calculates a Body's per-axis velocity. - * @param body The Body to compute the velocity for. - * @param delta The delta value to be used in the calculation, in seconds. + * A configuration object. Union of the `physics.arcade.*` properties of the GameConfig and SceneConfig objects. */ - computeVelocity(body: Phaser.Physics.Arcade.Body, delta: number): void; + config: Phaser.Types.Physics.Arcade.ArcadeWorldConfig; /** - * Separates two Bodies. - * @param body1 The first Body to be separated. - * @param body2 The second Body to be separated. - * @param processCallback The process callback. - * @param callbackContext The context in which to invoke the callback. - * @param overlapOnly If this a collide or overlap check? + * The physics simulation. */ - separate(body1: Phaser.Physics.Arcade.Body, body2: Phaser.Physics.Arcade.Body, processCallback?: ArcadePhysicsCallback, callbackContext?: any, overlapOnly?: boolean): boolean; + world: Phaser.Physics.Arcade.World; /** - * Separates two Bodies, when both are circular. - * @param body1 The first Body to be separated. - * @param body2 The second Body to be separated. - * @param overlapOnly If this a collide or overlap check? - * @param bias A small value added to the calculations. + * An object holding the Arcade Physics factory methods. */ - separateCircle(body1: Phaser.Physics.Arcade.Body, body2: Phaser.Physics.Arcade.Body, overlapOnly?: boolean, bias?: number): boolean; + add: Phaser.Physics.Arcade.Factory; /** - * Checks to see if two Bodies intersect at all. - * @param body1 The first body to check. - * @param body2 The second body to check. + * Causes `World.update` to be automatically called each time the Scene + * emits and `UPDATE` event. This is the default setting, so only needs + * calling if you have specifically disabled it. */ - intersects(body1: Phaser.Physics.Arcade.Body, body2: Phaser.Physics.Arcade.Body): boolean; + enableUpdate(): void; /** - * Tests if a circular Body intersects with another Body. - * @param circle The circular body to test. - * @param body The rectangular body to test. + * Causes `World.update` to **not** be automatically called each time the Scene + * emits and `UPDATE` event. + * + * If you wish to run the World update at your own rate, or from your own + * component, then you should call this method to disable the built-in link, + * and then call `World.update(delta, time)` accordingly. + * + * Note that `World.postUpdate` is always automatically called when the Scene + * emits a `POST_UPDATE` event, regardless of this setting. */ - circleBodyIntersects(circle: Phaser.Physics.Arcade.Body, body: Phaser.Physics.Arcade.Body): boolean; + disableUpdate(): void; /** - * Tests if Game Objects overlap. + * Creates the physics configuration for the current Scene. + */ + getConfig(): Phaser.Types.Physics.Arcade.ArcadeWorldConfig; + + /** + * Tests if Game Objects overlap. See {@link Phaser.Physics.Arcade.World#overlap} * @param object1 The first object or array of objects to check. * @param object2 The second object or array of objects to check, or `undefined`. - * @param overlapCallback An optional callback function that is called if the objects overlap. - * @param processCallback An optional callback function that lets you perform additional checks against the two objects if they overlap. If this is set then `overlapCallback` will only be called if this callback returns `true`. + * @param collideCallback An optional callback function that is called if the objects collide. + * @param processCallback An optional callback function that lets you perform additional checks against the two objects if they overlap. If this is set then `collideCallback` will only be called if this callback returns `true`. * @param callbackContext The context in which to run the callbacks. */ - overlap(object1: Phaser.Types.Physics.Arcade.ArcadeColliderType, object2?: Phaser.Types.Physics.Arcade.ArcadeColliderType, overlapCallback?: ArcadePhysicsCallback, processCallback?: ArcadePhysicsCallback, callbackContext?: any): boolean; + overlap(object1: Phaser.Types.Physics.Arcade.ArcadeColliderType, object2?: Phaser.Types.Physics.Arcade.ArcadeColliderType, collideCallback?: ArcadePhysicsCallback, processCallback?: ArcadePhysicsCallback, callbackContext?: any): boolean; /** * Performs a collision check and separation between the two physics enabled objects given, which can be single @@ -63262,3858 +68299,4372 @@ declare namespace Phaser { * @param processCallback An optional callback function that lets you perform additional checks against the two objects if they collide. If this is set then `collideCallback` will only be called if this callback returns `true`. * @param callbackContext The context in which to run the callbacks. */ - overlapTiles(sprite: Phaser.GameObjects.GameObject, tiles: Phaser.Tilemaps.Tile[], collideCallback?: ArcadePhysicsCallback, processCallback?: ArcadePhysicsCallback, callbackContext?: any): boolean; + overlapTiles(sprite: Phaser.GameObjects.GameObject, tiles: Phaser.Tilemaps.Tile[], collideCallback?: ArcadePhysicsCallback, processCallback?: ArcadePhysicsCallback, callbackContext?: any): boolean; + + /** + * Pauses the simulation. + */ + pause(): Phaser.Physics.Arcade.World; + + /** + * Resumes the simulation (if paused). + */ + resume(): Phaser.Physics.Arcade.World; + + /** + * Sets the acceleration.x/y property on the game object so it will move towards the x/y coordinates at the given rate (in pixels per second squared) + * + * You must give a maximum speed value, beyond which the game object won't go any faster. + * + * Note: The game object does not continuously track the target. If the target changes location during transit the game object will not modify its course. + * Note: The game object doesn't stop moving once it reaches the destination coordinates. + * @param gameObject Any Game Object with an Arcade Physics body. + * @param x The x coordinate to accelerate towards. + * @param y The y coordinate to accelerate towards. + * @param speed The acceleration (change in speed) in pixels per second squared. Default 60. + * @param xSpeedMax The maximum x velocity the game object can reach. Default 500. + * @param ySpeedMax The maximum y velocity the game object can reach. Default 500. + */ + accelerateTo(gameObject: Phaser.GameObjects.GameObject, x: number, y: number, speed?: number, xSpeedMax?: number, ySpeedMax?: number): number; + + /** + * Sets the acceleration.x/y property on the game object so it will move towards the x/y coordinates at the given rate (in pixels per second squared) + * + * You must give a maximum speed value, beyond which the game object won't go any faster. + * + * Note: The game object does not continuously track the target. If the target changes location during transit the game object will not modify its course. + * Note: The game object doesn't stop moving once it reaches the destination coordinates. + * @param gameObject Any Game Object with an Arcade Physics body. + * @param destination The Game Object to move towards. Can be any object but must have visible x/y properties. + * @param speed The acceleration (change in speed) in pixels per second squared. Default 60. + * @param xSpeedMax The maximum x velocity the game object can reach. Default 500. + * @param ySpeedMax The maximum y velocity the game object can reach. Default 500. + */ + accelerateToObject(gameObject: Phaser.GameObjects.GameObject, destination: Phaser.GameObjects.GameObject, speed?: number, xSpeedMax?: number, ySpeedMax?: number): number; + + /** + * Finds the Body or Game Object closest to a source point or object. + * + * If a `targets` argument is passed, this method finds the closest of those. + * The targets can be Arcade Physics Game Objects, Dynamic Bodies, or Static Bodies. + * + * If no `targets` argument is passed, this method finds the closest Dynamic Body. + * + * If two or more targets are the exact same distance from the source point, only the first target + * is returned. + * @param source Any object with public `x` and `y` properties, such as a Game Object or Geometry object. + * @param targets The targets. + */ + closest(source: any, targets?: Phaser.Physics.Arcade.Body[] | Phaser.Physics.Arcade.StaticBody[] | Phaser.GameObjects.GameObject[]): Phaser.Physics.Arcade.Body | Phaser.Physics.Arcade.StaticBody | Phaser.GameObjects.GameObject; + + /** + * Finds the Body or Game Object farthest from a source point or object. + * + * If a `targets` argument is passed, this method finds the farthest of those. + * The targets can be Arcade Physics Game Objects, Dynamic Bodies, or Static Bodies. + * + * If no `targets` argument is passed, this method finds the farthest Dynamic Body. + * + * If two or more targets are the exact same distance from the source point, only the first target + * is returned. + * @param source Any object with public `x` and `y` properties, such as a Game Object or Geometry object. + * @param targets The targets. + */ + furthest(source: any, targets?: Phaser.Physics.Arcade.Body[] | Phaser.Physics.Arcade.StaticBody[] | Phaser.GameObjects.GameObject[]): Phaser.Physics.Arcade.Body | Phaser.Physics.Arcade.StaticBody | Phaser.GameObjects.GameObject; + + /** + * Move the given display object towards the x/y coordinates at a steady velocity. + * If you specify a maxTime then it will adjust the speed (over-writing what you set) so it arrives at the destination in that number of seconds. + * Timings are approximate due to the way browser timers work. Allow for a variance of +- 50ms. + * Note: The display object does not continuously track the target. If the target changes location during transit the display object will not modify its course. + * Note: The display object doesn't stop moving once it reaches the destination coordinates. + * Note: Doesn't take into account acceleration, maxVelocity or drag (if you've set drag or acceleration too high this object may not move at all) + * @param gameObject Any Game Object with an Arcade Physics body. + * @param x The x coordinate to move towards. + * @param y The y coordinate to move towards. + * @param speed The speed it will move, in pixels per second (default is 60 pixels/sec) Default 60. + * @param maxTime Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the object will arrive at destination in the given number of ms. Default 0. + */ + moveTo(gameObject: Phaser.GameObjects.GameObject, x: number, y: number, speed?: number, maxTime?: number): number; + + /** + * Move the given display object towards the destination object at a steady velocity. + * If you specify a maxTime then it will adjust the speed (overwriting what you set) so it arrives at the destination in that number of seconds. + * Timings are approximate due to the way browser timers work. Allow for a variance of +- 50ms. + * Note: The display object does not continuously track the target. If the target changes location during transit the display object will not modify its course. + * Note: The display object doesn't stop moving once it reaches the destination coordinates. + * Note: Doesn't take into account acceleration, maxVelocity or drag (if you've set drag or acceleration too high this object may not move at all) + * @param gameObject Any Game Object with an Arcade Physics body. + * @param destination Any object with public `x` and `y` properties, such as a Game Object or Geometry object. + * @param speed The speed it will move, in pixels per second (default is 60 pixels/sec) Default 60. + * @param maxTime Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the object will arrive at destination in the given number of ms. Default 0. + */ + moveToObject(gameObject: Phaser.GameObjects.GameObject, destination: object, speed?: number, maxTime?: number): number; + + /** + * Given the angle (in degrees) and speed calculate the velocity and return it as a vector, or set it to the given vector object. + * One way to use this is: velocityFromAngle(angle, 200, sprite.body.velocity) which will set the values directly to the sprite's velocity and not create a new vector object. + * @param angle The angle in degrees calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative) + * @param speed The speed it will move, in pixels per second squared. Default 60. + * @param vec2 The Vector2 in which the x and y properties will be set to the calculated velocity. + */ + velocityFromAngle(angle: number, speed?: number, vec2?: Phaser.Math.Vector2): Phaser.Math.Vector2; /** - * Internal handler for Sprite vs. Tilemap collisions. - * Please use Phaser.Physics.Arcade.World#collide instead. - * @param sprite The first object to check for collision. - * @param tilemapLayer The second object to check for collision. - * @param collideCallback An optional callback function that is called if the objects collide. - * @param processCallback An optional callback function that lets you perform additional checks against the two objects if they collide. If this is set then `collideCallback` will only be called if this callback returns `true`. - * @param callbackContext The context in which to run the callbacks. - * @param overlapOnly Whether this is a collision or overlap check. + * Given the rotation (in radians) and speed calculate the velocity and return it as a vector, or set it to the given vector object. + * One way to use this is: velocityFromRotation(rotation, 200, sprite.body.velocity) which will set the values directly to the sprite's velocity and not create a new vector object. + * @param rotation The angle in radians. + * @param speed The speed it will move, in pixels per second squared Default 60. + * @param vec2 The Vector2 in which the x and y properties will be set to the calculated velocity. */ - collideSpriteVsTilemapLayer(sprite: Phaser.GameObjects.GameObject, tilemapLayer: Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer, collideCallback?: ArcadePhysicsCallback, processCallback?: ArcadePhysicsCallback, callbackContext?: any, overlapOnly?: boolean): boolean; + velocityFromRotation(rotation: number, speed?: number, vec2?: Phaser.Math.Vector2): Phaser.Math.Vector2; /** - * Wrap an object's coordinates (or several objects' coordinates) within {@link Phaser.Physics.Arcade.World#bounds}. + * This method will search the given rectangular area and return an array of all physics bodies that + * overlap with it. It can return either Dynamic, Static bodies or a mixture of both. * - * If the object is outside any boundary edge (left, top, right, bottom), it will be moved to the same offset from the opposite edge (the interior). - * @param object A Game Object, a Group, an object with `x` and `y` coordinates, or an array of such objects. - * @param padding An amount added to each boundary edge during the operation. Default 0. - */ - wrap(object: any, padding?: number): void; - - /** - * Wrap each object's coordinates within {@link Phaser.Physics.Arcade.World#bounds}. - * @param objects An array of objects to be wrapped. - * @param padding An amount added to the boundary. Default 0. + * A body only has to intersect with the search area to be considered, it doesn't have to be fully + * contained within it. + * + * If Arcade Physics is set to use the RTree (which it is by default) then the search for is extremely fast, + * otherwise the search is O(N) for Dynamic Bodies. + * @param x The top-left x coordinate of the area to search within. + * @param y The top-left y coordinate of the area to search within. + * @param width The width of the area to search within. + * @param height The height of the area to search within. + * @param includeDynamic Should the search include Dynamic Bodies? Default true. + * @param includeStatic Should the search include Static Bodies? Default false. */ - wrapArray(objects: any[], padding?: number): void; + overlapRect(x: number, y: number, width: number, height: number, includeDynamic?: boolean, includeStatic?: boolean): Phaser.Physics.Arcade.Body[] | Phaser.Physics.Arcade.StaticBody[]; /** - * Wrap an object's coordinates within {@link Phaser.Physics.Arcade.World#bounds}. - * @param object A Game Object, a Physics Body, or any object with `x` and `y` coordinates - * @param padding An amount added to the boundary. Default 0. + * This method will search the given circular area and return an array of all physics bodies that + * overlap with it. It can return either Dynamic, Static bodies or a mixture of both. + * + * A body only has to intersect with the search area to be considered, it doesn't have to be fully + * contained within it. + * + * If Arcade Physics is set to use the RTree (which it is by default) then the search is rather fast, + * otherwise the search is O(N) for Dynamic Bodies. + * @param x The x coordinate of the center of the area to search within. + * @param y The y coordinate of the center of the area to search within. + * @param radius The radius of the area to search within. + * @param includeDynamic Should the search include Dynamic Bodies? Default true. + * @param includeStatic Should the search include Static Bodies? Default false. */ - wrapObject(object: any, padding?: number): void; + overlapCirc(x: number, y: number, radius: number, includeDynamic?: boolean, includeStatic?: boolean): Phaser.Physics.Arcade.Body[] | Phaser.Physics.Arcade.StaticBody[]; /** - * Shuts down the simulation, clearing physics data and removing listeners. + * The Scene that owns this plugin is shutting down. + * We need to kill and reset all internal properties as well as stop listening to Scene events. */ shutdown(): void; /** - * Shuts down the simulation and disconnects it from the current scene. + * The Scene that owns this plugin is being destroyed. + * We need to shutdown and then kill off all external references. */ destroy(): void; } - } - - /** - * An Impact.js compatible physics world, body and solver, for those who are used - * to the Impact way of defining and controlling physics bodies. Also works with - * the new Loader support for Weltmeister map data. - * - * World updated to run off the Phaser main loop. - * Body extended to support additional setter functions. - * - * To create the map data you'll need Weltmeister, which comes with Impact - * and can be purchased from http://impactjs.com - * - * My thanks to Dominic Szablewski for his permission to support Impact in Phaser. - */ - namespace Impact { /** - * An Impact.js compatible physics body. - * This re-creates the properties you'd get on an Entity and the math needed to update them. + * An Arcade Physics Sprite is a Sprite with an Arcade Physics body and related components. + * The body can be dynamic or static. + * + * The main difference between an Arcade Sprite and an Arcade Image is that you cannot animate an Arcade Image. + * If you do not require animation then you can safely use Arcade Images instead of Arcade Sprites. */ - class Body { + class Sprite extends Phaser.GameObjects.Sprite implements Phaser.Physics.Arcade.Components.Acceleration, Phaser.Physics.Arcade.Components.Angular, Phaser.Physics.Arcade.Components.Bounce, Phaser.Physics.Arcade.Components.Debug, Phaser.Physics.Arcade.Components.Drag, Phaser.Physics.Arcade.Components.Enable, Phaser.Physics.Arcade.Components.Friction, Phaser.Physics.Arcade.Components.Gravity, Phaser.Physics.Arcade.Components.Immovable, Phaser.Physics.Arcade.Components.Mass, Phaser.Physics.Arcade.Components.Pushable, Phaser.Physics.Arcade.Components.Size, Phaser.Physics.Arcade.Components.Velocity, Phaser.GameObjects.Components.Alpha, Phaser.GameObjects.Components.BlendMode, Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.Flip, Phaser.GameObjects.Components.GetBounds, Phaser.GameObjects.Components.Origin, Phaser.GameObjects.Components.Pipeline, Phaser.GameObjects.Components.ScrollFactor, Phaser.GameObjects.Components.Size, Phaser.GameObjects.Components.Texture, Phaser.GameObjects.Components.Tint, Phaser.GameObjects.Components.Transform, Phaser.GameObjects.Components.Visible { /** * - * @param world [description] - * @param x [description] - * @param y [description] - * @param sx [description] Default 16. - * @param sy [description] Default 16. + * @param scene The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. + * @param x The horizontal position of this Game Object in the world. + * @param y The vertical position of this Game Object in the world. + * @param texture The key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager. + * @param frame An optional frame from the Texture this Game Object is rendering with. */ - constructor(world: Phaser.Physics.Impact.World, x: number, y: number, sx?: number, sy?: number); + constructor(scene: Phaser.Scene, x: number, y: number, texture: string | Phaser.Textures.Texture, frame?: string | number); /** - * [description] + * This Game Object's Physics Body. */ - world: Phaser.Physics.Impact.World; + body: Phaser.Physics.Arcade.Body | Phaser.Physics.Arcade.StaticBody; /** - * [description] + * Clears all alpha values associated with this Game Object. + * + * Immediately sets the alpha levels back to 1 (fully opaque). */ - gameObject: Phaser.GameObjects.GameObject; + clearAlpha(): this; /** - * [description] + * Set the Alpha level of this Game Object. The alpha controls the opacity of the Game Object as it renders. + * Alpha values are provided as a float between 0, fully transparent, and 1, fully opaque. + * + * If your game is running under WebGL you can optionally specify four different alpha values, each of which + * correspond to the four corners of the Game Object. Under Canvas only the `topLeft` value given is used. + * @param topLeft The alpha value used for the top-left of the Game Object. If this is the only value given it's applied across the whole Game Object. Default 1. + * @param topRight The alpha value used for the top-right of the Game Object. WebGL only. + * @param bottomLeft The alpha value used for the bottom-left of the Game Object. WebGL only. + * @param bottomRight The alpha value used for the bottom-right of the Game Object. WebGL only. */ - enabled: boolean; + setAlpha(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; /** - * The ImpactBody, ImpactSprite or ImpactImage object that owns this Body, if any. + * The alpha value of the Game Object. + * + * This is a global value, impacting the entire Game Object, not just a region of it. */ - parent: Phaser.Physics.Impact.ImpactBody | Phaser.Physics.Impact.ImpactImage | Phaser.Physics.Impact.ImpactSprite; + alpha: number; /** - * [description] + * The alpha value starting from the top-left of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. */ - id: integer; + alphaTopLeft: number; /** - * [description] + * The alpha value starting from the top-right of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. */ - name: string; + alphaTopRight: number; /** - * [description] + * The alpha value starting from the bottom-left of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. */ - size: Phaser.Types.Math.Vector2Like; + alphaBottomLeft: number; /** - * [description] + * The alpha value starting from the bottom-right of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. */ - offset: Phaser.Types.Math.Vector2Like; + alphaBottomRight: number; /** - * [description] + * Sets the Blend Mode being used by this Game Object. + * + * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) + * + * Under WebGL only the following Blend Modes are available: + * + * * ADD + * * MULTIPLY + * * SCREEN + * * ERASE + * + * Canvas has more available depending on browser support. + * + * You can also create your own custom Blend Modes in WebGL. + * + * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending + * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these + * reasons try to be careful about the construction of your Scene and the frequency of which blend modes + * are used. */ - pos: Phaser.Types.Math.Vector2Like; + blendMode: Phaser.BlendModes | string; /** - * [description] + * Sets the Blend Mode being used by this Game Object. + * + * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) + * + * Under WebGL only the following Blend Modes are available: + * + * * ADD + * * MULTIPLY + * * SCREEN + * * ERASE (only works when rendering to a framebuffer, like a Render Texture) + * + * Canvas has more available depending on browser support. + * + * You can also create your own custom Blend Modes in WebGL. + * + * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending + * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these + * reasons try to be careful about the construction of your Scene and the frequency in which blend modes + * are used. + * @param value The BlendMode value. Either a string or a CONST. */ - last: Phaser.Types.Math.Vector2Like; + setBlendMode(value: string | Phaser.BlendModes): this; /** - * [description] + * The depth of this Game Object within the Scene. + * + * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order + * of Game Objects, without actually moving their position in the display list. + * + * The default depth is zero. A Game Object with a higher depth + * value will always render in front of one with a lower value. + * + * Setting the depth will queue a depth sort event within the Scene. */ - vel: Phaser.Types.Math.Vector2Like; + depth: number; /** - * [description] + * The depth of this Game Object within the Scene. + * + * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order + * of Game Objects, without actually moving their position in the display list. + * + * The default depth is zero. A Game Object with a higher depth + * value will always render in front of one with a lower value. + * + * Setting the depth will queue a depth sort event within the Scene. + * @param value The depth of this Game Object. */ - accel: Phaser.Types.Math.Vector2Like; + setDepth(value: number): this; /** - * [description] + * The horizontally flipped state of the Game Object. + * + * A Game Object that is flipped horizontally will render inversed on the horizontal axis. + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. */ - friction: Phaser.Types.Math.Vector2Like; + flipX: boolean; /** - * [description] + * The vertically flipped state of the Game Object. + * + * A Game Object that is flipped vertically will render inversed on the vertical axis (i.e. upside down) + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. */ - maxVel: Phaser.Types.Math.Vector2Like; + flipY: boolean; /** - * [description] + * Toggles the horizontal flipped state of this Game Object. + * + * A Game Object that is flipped horizontally will render inversed on the horizontal axis. + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. */ - standing: boolean; + toggleFlipX(): this; /** - * [description] + * Toggles the vertical flipped state of this Game Object. */ - gravityFactor: number; + toggleFlipY(): this; /** - * [description] + * Sets the horizontal flipped state of this Game Object. + * + * A Game Object that is flipped horizontally will render inversed on the horizontal axis. + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * @param value The flipped state. `false` for no flip, or `true` to be flipped. */ - bounciness: number; + setFlipX(value: boolean): this; /** - * [description] + * Sets the vertical flipped state of this Game Object. + * @param value The flipped state. `false` for no flip, or `true` to be flipped. */ - minBounceVelocity: number; + setFlipY(value: boolean): this; /** - * [description] + * Sets the horizontal and vertical flipped state of this Game Object. + * + * A Game Object that is flipped will render inversed on the flipped axis. + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * @param x The horizontal flipped state. `false` for no flip, or `true` to be flipped. + * @param y The horizontal flipped state. `false` for no flip, or `true` to be flipped. */ - accelGround: number; + setFlip(x: boolean, y: boolean): this; /** - * [description] + * Resets the horizontal and vertical flipped state of this Game Object back to their default un-flipped state. */ - accelAir: number; + resetFlip(): this; /** - * [description] + * Gets the center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. */ - jumpSpeed: number; + getCenter(output?: O): O; /** - * [description] + * Gets the top-left corner coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - type: Phaser.Physics.Impact.TYPE; + getTopLeft(output?: O, includeParent?: boolean): O; /** - * [description] + * Gets the top-center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - checkAgainst: Phaser.Physics.Impact.TYPE; + getTopCenter(output?: O, includeParent?: boolean): O; /** - * [description] + * Gets the top-right corner coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - collides: Phaser.Physics.Impact.COLLIDES; + getTopRight(output?: O, includeParent?: boolean): O; /** - * [description] + * Gets the left-center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - debugShowBody: boolean; + getLeftCenter(output?: O, includeParent?: boolean): O; /** - * [description] + * Gets the right-center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - debugShowVelocity: boolean; + getRightCenter(output?: O, includeParent?: boolean): O; /** - * [description] + * Gets the bottom-left corner coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - debugBodyColor: integer; + getBottomLeft(output?: O, includeParent?: boolean): O; /** - * [description] + * Gets the bottom-center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - updateCallback: Phaser.Types.Physics.Impact.BodyUpdateCallback; + getBottomCenter(output?: O, includeParent?: boolean): O; /** - * min 44 deg, max 136 deg + * Gets the bottom-right corner coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - slopeStanding: Object; + getBottomRight(output?: O, includeParent?: boolean): O; /** - * [description] - * @param x [description] - * @param y [description] + * Gets the bounds of this Game Object, regardless of origin. + * The values are stored and returned in a Rectangle, or Rectangle-like, object. + * @param output An object to store the values in. If not provided a new Rectangle will be created. */ - reset(x: number, y: number): void; + getBounds(output?: O): O; /** - * [description] - * @param delta The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate. + * The Mask this Game Object is using during render. */ - update(delta: number): void; + mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask; /** - * [description] - * @param graphic [description] + * Sets the mask that this Game Object will use to render with. + * + * The mask must have been previously created and can be either a GeometryMask or a BitmapMask. + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * + * If a mask is already set on this Game Object it will be immediately replaced. + * + * Masks are positioned in global space and are not relative to the Game Object to which they + * are applied. The reason for this is that multiple Game Objects can all share the same mask. + * + * Masks have no impact on physics or input detection. They are purely a rendering component + * that allows you to limit what is visible during the render pass. + * @param mask The mask this Game Object will use when rendering. */ - drawDebug(graphic: Phaser.GameObjects.Graphics): void; + setMask(mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask): this; /** - * [description] + * Clears the mask that this Game Object was using. + * @param destroyMask Destroy the mask before clearing it? Default false. */ - willDrawDebug(): boolean; + clearMask(destroyMask?: boolean): this; /** - * [description] + * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, + * including this one. + * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * + * To create the mask you need to pass in a reference to a renderable Game Object. + * A renderable Game Object is one that uses a texture to render with, such as an + * Image, Sprite, Render Texture or BitmapText. + * + * If you do not provide a renderable object, and this Game Object has a texture, + * it will use itself as the object. This means you can call this method to create + * a Bitmap Mask from any renderable Game Object. + * @param renderable A renderable Game Object that uses a texture, such as a Sprite. */ - skipHash(): boolean; + createBitmapMask(renderable?: Phaser.GameObjects.GameObject): Phaser.Display.Masks.BitmapMask; /** - * Determines whether the body collides with the `other` one or not. - * @param other [description] + * Creates and returns a Geometry Mask. This mask can be used by any Game Object, + * including this one. + * + * To create the mask you need to pass in a reference to a Graphics Game Object. + * + * If you do not provide a graphics object, and this Game Object is an instance + * of a Graphics object, then it will use itself to create the mask. + * + * This means you can call this method to create a Geometry Mask from any Graphics Game Object. + * @param graphics A Graphics Game Object. The geometry within it will be used as the mask. */ - touches(other: Phaser.Physics.Impact.Body): boolean; + createGeometryMask(graphics?: Phaser.GameObjects.Graphics): Phaser.Display.Masks.GeometryMask; /** - * Reset the size and position of the physics body. - * @param x The x coordinate to position the body. - * @param y The y coordinate to position the body. - * @param width The width of the body. - * @param height The height of the body. + * The horizontal origin of this Game Object. + * The origin maps the relationship between the size and position of the Game Object. + * The default value is 0.5, meaning all Game Objects are positioned based on their center. + * Setting the value to 0 means the position now relates to the left of the Game Object. */ - resetSize(x: number, y: number, width: number, height: number): Phaser.Physics.Impact.Body; + originX: number; /** - * Export this body object to JSON. + * The vertical origin of this Game Object. + * The origin maps the relationship between the size and position of the Game Object. + * The default value is 0.5, meaning all Game Objects are positioned based on their center. + * Setting the value to 0 means the position now relates to the top of the Game Object. */ - toJSON(): Phaser.Types.Physics.Impact.JSONImpactBody; + originY: number; /** - * [description] - * @param config [description] + * The horizontal display origin of this Game Object. + * The origin is a normalized value between 0 and 1. + * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. */ - fromJSON(config: object): void; + displayOriginX: number; /** - * Can be overridden by user code - * @param other [description] + * The vertical display origin of this Game Object. + * The origin is a normalized value between 0 and 1. + * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. */ - check(other: Phaser.Physics.Impact.Body): void; + displayOriginY: number; /** - * Can be overridden by user code - * @param other [description] - * @param axis [description] + * Sets the origin of this Game Object. + * + * The values are given in the range 0 to 1. + * @param x The horizontal origin value. Default 0.5. + * @param y The vertical origin value. If not defined it will be set to the value of `x`. Default x. */ - collideWith(other: Phaser.Physics.Impact.Body, axis: string): void; + setOrigin(x?: number, y?: number): this; /** - * Can be overridden by user code but must return a boolean. - * @param res [description] + * Sets the origin of this Game Object based on the Pivot values in its Frame. */ - handleMovementTrace(res: number): boolean; + setOriginFromFrame(): this; /** - * [description] + * Sets the display origin of this Game Object. + * The difference between this and setting the origin is that you can use pixel values for setting the display origin. + * @param x The horizontal display origin value. Default 0. + * @param y The vertical display origin value. If not defined it will be set to the value of `x`. Default x. */ - destroy(): void; - - } + setDisplayOrigin(x?: number, y?: number): this; - /** - * Collision Types - Determine if and how entities collide with each other. - * - * In ACTIVE vs. LITE or FIXED vs. ANY collisions, only the "weak" entity moves, - * while the other one stays fixed. In ACTIVE vs. ACTIVE and ACTIVE vs. PASSIVE - * collisions, both entities are moved. LITE or PASSIVE entities don't collide - * with other LITE or PASSIVE entities at all. The behavior for FIXED vs. - * FIXED collisions is undefined. - */ - enum COLLIDES { - /** - * Never collides. - */ - NEVER, - /** - * Lite collision. - */ - LITE, - /** - * Passive collision. - */ - PASSIVE, - /** - * Active collision. - */ - ACTIVE, /** - * Fixed collision. + * Updates the Display Origin cached values internally stored on this Game Object. + * You don't usually call this directly, but it is exposed for edge-cases where you may. */ - FIXED, - } + updateDisplayOrigin(): this; - /** - * [description] - */ - class CollisionMap { /** + * The initial WebGL pipeline of this Game Object. * - * @param tilesize [description] Default 32. - * @param data [description] - */ - constructor(tilesize?: integer, data?: any[]); - - /** - * [description] - */ - tilesize: integer; - - /** - * [description] + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. */ - data: any[]; + defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; /** - * [description] + * The current WebGL pipeline of this Game Object. */ - width: number; + pipeline: Phaser.Renderer.WebGL.WebGLPipeline; /** - * [description] + * Does this Game Object have any Post Pipelines set? */ - height: number; + hasPostPipeline: boolean; /** - * [description] + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. */ - lastSlope: integer; + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; /** - * [description] + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. */ - tiledef: object; + pipelineData: object; /** - * [description] - * @param x [description] - * @param y [description] - * @param vx [description] - * @param vy [description] - * @param objectWidth [description] - * @param objectHeight [description] + * Sets the initial WebGL Pipeline of this Game Object. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. */ - trace(x: number, y: number, vx: number, vy: number, objectWidth: number, objectHeight: number): boolean; + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; /** - * [description] - * @param res [description] - * @param x [description] - * @param y [description] - * @param vx [description] - * @param vy [description] - * @param width [description] - * @param height [description] - * @param rvx [description] - * @param rvy [description] - * @param step [description] + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. */ - step(res: object, x: number, y: number, vx: number, vy: number, width: number, height: number, rvx: number, rvy: number, step: number): void; + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; /** - * [description] - * @param res [description] - * @param t [description] - * @param x [description] - * @param y [description] - * @param vx [description] - * @param vy [description] - * @param width [description] - * @param height [description] - * @param tileX [description] - * @param tileY [description] + * Sets one, or more, Post Pipelines on this Game Object. + * + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. */ - checkDef(res: object, t: number, x: number, y: number, vx: number, vy: number, width: number, height: number, tileX: number, tileY: number): boolean; + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; - } - - namespace Components { /** - * The Impact Acceleration component. - * Should be applied as a mixin. + * Adds an entry to the `pipelineData` object belonging to this Game Object. + * + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. */ - interface Acceleration { - /** - * Sets the horizontal acceleration of this body. - * @param x The amount of acceleration to apply. - */ - setAccelerationX(x: number): this; - /** - * Sets the vertical acceleration of this body. - * @param y The amount of acceleration to apply. - */ - setAccelerationY(y: number): this; - /** - * Sets the horizontal and vertical acceleration of this body. - * @param x The amount of horizontal acceleration to apply. - * @param y The amount of vertical acceleration to apply. - */ - setAcceleration(x: number, y: number): this; - } + setPipelineData(key: string, value?: any): this; /** - * The Impact Body Scale component. - * Should be applied as a mixin. + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - interface BodyScale { - /** - * Sets the size of the physics body. - * @param width The width of the body in pixels. - * @param height The height of the body in pixels. Default width. - */ - setBodySize(width: number, height?: number): this; - /** - * Sets the scale of the physics body. - * @param scaleX The horizontal scale of the body. - * @param scaleY The vertical scale of the body. If not given, will use the horizontal scale value. - */ - setBodyScale(scaleX: number, scaleY?: number): this; - } + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; /** - * The Impact Body Type component. - * Should be applied as a mixin. + * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. */ - interface BodyType { - /** - * [description] - */ - getBodyType(): number; - /** - * [description] - */ - setTypeNone(): Phaser.GameObjects.GameObject; - /** - * [description] - */ - setTypeA(): Phaser.GameObjects.GameObject; - /** - * [description] - */ - setTypeB(): Phaser.GameObjects.GameObject; - } + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; /** - * The Impact Bounce component. - * Should be applied as a mixin. + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. */ - interface Bounce { - /** - * Sets the impact physics bounce, or restitution, value. - * @param value A value between 0 (no rebound) and 1 (full rebound) - */ - setBounce(value: number): Phaser.GameObjects.GameObject; - /** - * Sets the minimum velocity the body is allowed to be moving to be considered for rebound. - * @param value The minimum allowed velocity. - */ - setMinBounceVelocity(value: number): Phaser.GameObjects.GameObject; - /** - * The bounce, or restitution, value of this body. - * A value between 0 (no rebound) and 1 (full rebound) - */ - bounce: number; - } + resetPostPipeline(resetData?: boolean): void; /** - * The Impact Check Against component. - * Should be applied as a mixin. + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - interface CheckAgainst { - /** - * [description] - */ - setAvsB(): Phaser.GameObjects.GameObject; - /** - * [description] - */ - setBvsA(): Phaser.GameObjects.GameObject; - /** - * [description] - */ - setCheckAgainstNone(): Phaser.GameObjects.GameObject; - /** - * [description] - */ - setCheckAgainstA(): Phaser.GameObjects.GameObject; - /** - * [description] - */ - setCheckAgainstB(): Phaser.GameObjects.GameObject; - /** - * [description] - */ - checkAgainst: number; - } + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; /** - * The Impact Collides component. - * Should be applied as a mixin. + * Gets the name of the WebGL Pipeline this Game Object is currently using. */ - interface Collides { - /** - * [description] - * @param callback [description] - * @param scope [description] - */ - setCollideCallback(callback: CollideCallback, scope: any): Phaser.GameObjects.GameObject; - /** - * [description] - */ - setCollidesNever(): Phaser.GameObjects.GameObject; - /** - * [description] - */ - setLiteCollision(): Phaser.GameObjects.GameObject; - /** - * [description] - */ - setPassiveCollision(): Phaser.GameObjects.GameObject; - /** - * [description] - */ - setActiveCollision(): Phaser.GameObjects.GameObject; - /** - * [description] - */ - setFixedCollision(): Phaser.GameObjects.GameObject; - /** - * [description] - */ - collides: number; - } + getPipelineName(): string; /** - * The Impact Debug component. - * Should be applied as a mixin. + * The horizontal scroll factor of this Game Object. + * + * The scroll factor controls the influence of the movement of a Camera upon this Game Object. + * + * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. + * It does not change the Game Objects actual position values. + * + * A value of 1 means it will move exactly in sync with a camera. + * A value of 0 means it will not move at all, even if the camera moves. + * Other values control the degree to which the camera movement is mapped to this Game Object. + * + * Please be aware that scroll factor values other than 1 are not taken in to consideration when + * calculating physics collisions. Bodies always collide based on their world position, but changing + * the scroll factor is a visual adjustment to where the textures are rendered, which can offset + * them from physics bodies if not accounted for in your code. */ - interface Debug { - /** - * [description] - * @param showBody [description] - * @param showVelocity [description] - * @param bodyColor [description] - */ - setDebug(showBody: boolean, showVelocity: boolean, bodyColor: number): Phaser.GameObjects.GameObject; - /** - * [description] - * @param value [description] - */ - setDebugBodyColor(value: number): Phaser.GameObjects.GameObject; - /** - * [description] - */ - debugShowBody: boolean; - /** - * [description] - */ - debugShowVelocity: boolean; - /** - * [description] - */ - debugBodyColor: number; - } + scrollFactorX: number; /** - * The Impact Friction component. - * Should be applied as a mixin. - */ - interface Friction { - /** - * [description] - * @param x [description] - */ - setFrictionX(x: number): Phaser.GameObjects.GameObject; - /** - * [description] - * @param y [description] - */ - setFrictionY(y: number): Phaser.GameObjects.GameObject; - /** - * [description] - * @param x [description] - * @param y [description] - */ - setFriction(x: number, y: number): Phaser.GameObjects.GameObject; - } + * The vertical scroll factor of this Game Object. + * + * The scroll factor controls the influence of the movement of a Camera upon this Game Object. + * + * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. + * It does not change the Game Objects actual position values. + * + * A value of 1 means it will move exactly in sync with a camera. + * A value of 0 means it will not move at all, even if the camera moves. + * Other values control the degree to which the camera movement is mapped to this Game Object. + * + * Please be aware that scroll factor values other than 1 are not taken in to consideration when + * calculating physics collisions. Bodies always collide based on their world position, but changing + * the scroll factor is a visual adjustment to where the textures are rendered, which can offset + * them from physics bodies if not accounted for in your code. + */ + scrollFactorY: number; /** - * The Impact Gravity component. - * Should be applied as a mixin. + * Sets the scroll factor of this Game Object. + * + * The scroll factor controls the influence of the movement of a Camera upon this Game Object. + * + * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. + * It does not change the Game Objects actual position values. + * + * A value of 1 means it will move exactly in sync with a camera. + * A value of 0 means it will not move at all, even if the camera moves. + * Other values control the degree to which the camera movement is mapped to this Game Object. + * + * Please be aware that scroll factor values other than 1 are not taken in to consideration when + * calculating physics collisions. Bodies always collide based on their world position, but changing + * the scroll factor is a visual adjustment to where the textures are rendered, which can offset + * them from physics bodies if not accounted for in your code. + * @param x The horizontal scroll factor of this Game Object. + * @param y The vertical scroll factor of this Game Object. If not set it will use the `x` value. Default x. */ - interface Gravity { - /** - * [description] - * @param value [description] - */ - setGravity(value: number): Phaser.GameObjects.GameObject; - /** - * [description] - */ - gravity: number; - } + setScrollFactor(x: number, y?: number): this; /** - * The Impact Offset component. - * Should be applied as a mixin. + * The native (un-scaled) width of this Game Object. + * + * Changing this value will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or use + * the `displayWidth` property. */ - interface Offset { - /** - * [description] - * @param x [description] - * @param y [description] - * @param width [description] - * @param height [description] - */ - setOffset(x: number, y: number, width?: number, height?: number): Phaser.GameObjects.GameObject; - } + width: number; /** - * The Impact Set Game Object component. - * Should be applied as a mixin. + * The native (un-scaled) height of this Game Object. + * + * Changing this value will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or use + * the `displayHeight` property. */ - interface SetGameObject { - /** - * [description] - * @param gameObject [description] - * @param sync [description] Default true. - */ - setGameObject(gameObject: Phaser.GameObjects.GameObject, sync?: boolean): Phaser.GameObjects.GameObject; - /** - * [description] - */ - syncGameObject(): Phaser.GameObjects.GameObject; - } + height: number; /** - * The Impact Velocity component. - * Should be applied as a mixin. + * The displayed width of this Game Object. + * + * This value takes into account the scale factor. + * + * Setting this value will adjust the Game Object's scale property. */ - interface Velocity { - /** - * Sets the horizontal velocity of the physics body. - * @param x The horizontal velocity value. - */ - setVelocityX(x: number): this; - /** - * Sets the vertical velocity of the physics body. - * @param y The vertical velocity value. - */ - setVelocityY(y: number): this; - /** - * Sets the horizontal and vertical velocities of the physics body. - * @param x The horizontal velocity value. - * @param y The vertical velocity value. If not given, defaults to the horizontal value. Default x. - */ - setVelocity(x: number, y?: number): this; - /** - * Sets the maximum velocity this body can travel at. - * @param x The maximum allowed horizontal velocity. - * @param y The maximum allowed vertical velocity. If not given, defaults to the horizontal value. Default x. - */ - setMaxVelocity(x: number, y?: number): this; - } - - } + displayWidth: number; - namespace Events { /** - * The Impact Physics World Collide Event. + * The displayed height of this Game Object. * - * This event is dispatched by an Impact Physics World instance if two bodies collide. + * This value takes into account the scale factor. * - * Listen to it from a Scene using: `this.impact.world.on('collide', listener)`. + * Setting this value will adjust the Game Object's scale property. */ - const COLLIDE: any; + displayHeight: number; /** - * The Impact Physics World Pause Event. + * Sets the size of this Game Object to be that of the given Frame. * - * This event is dispatched by an Impact Physics World instance when it is paused. + * This will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or call the + * `setDisplaySize` method, which is the same thing as changing the scale but allows you + * to do so by giving pixel values. * - * Listen to it from a Scene using: `this.impact.world.on('pause', listener)`. + * If you have enabled this Game Object for input, changing the size will _not_ change the + * size of the hit area. To do this you should adjust the `input.hitArea` object directly. + * @param frame The frame to base the size of this Game Object on. */ - const PAUSE: any; + setSizeToFrame(frame: Phaser.Textures.Frame): this; /** - * The Impact Physics World Resume Event. + * Sets the internal size of this Game Object, as used for frame or physics body creation. * - * This event is dispatched by an Impact Physics World instance when it resumes from a paused state. + * This will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or call the + * `setDisplaySize` method, which is the same thing as changing the scale but allows you + * to do so by giving pixel values. * - * Listen to it from a Scene using: `this.impact.world.on('resume', listener)`. + * If you have enabled this Game Object for input, changing the size will _not_ change the + * size of the hit area. To do this you should adjust the `input.hitArea` object directly. + * @param width The width of this Game Object. + * @param height The height of this Game Object. */ - const RESUME: any; - - } + setSize(width: number, height: number): this; - /** - * The Impact Physics Factory allows you to easily create Impact Physics enabled Game Objects. - * Objects that are created by this Factory are automatically added to the physics world. - */ - class Factory { /** + * Sets the display size of this Game Object. * - * @param world A reference to the Impact Physics world. + * Calling this will adjust the scale. + * @param width The width of this Game Object. + * @param height The height of this Game Object. */ - constructor(world: Phaser.Physics.Impact.World); + setDisplaySize(width: number, height: number): this; /** - * A reference to the Impact Physics world. + * The Texture this Game Object is using to render with. */ - world: Phaser.Physics.Impact.World; + texture: Phaser.Textures.Texture | Phaser.Textures.CanvasTexture; /** - * A reference to the Scene.Systems this Impact Physics instance belongs to. + * The Texture Frame this Game Object is using to render with. */ - sys: Phaser.Scenes.Systems; + frame: Phaser.Textures.Frame; /** - * Creates a new ImpactBody object and adds it to the physics simulation. - * @param x The horizontal position of the body in the physics world. - * @param y The vertical position of the body in the physics world. - * @param width The width of the body. - * @param height The height of the body. + * A boolean flag indicating if this Game Object is being cropped or not. + * You can toggle this at any time after `setCrop` has been called, to turn cropping on or off. + * Equally, calling `setCrop` with no arguments will reset the crop and disable it. + */ + isCropped: boolean; + + /** + * Applies a crop to a texture based Game Object, such as a Sprite or Image. + * + * The crop is a rectangle that limits the area of the texture frame that is visible during rendering. + * + * Cropping a Game Object does not change its size, dimensions, physics body or hit area, it just + * changes what is shown when rendered. + * + * The crop coordinates are relative to the texture frame, not the Game Object, meaning 0 x 0 is the top-left. + * + * Therefore, if you had a Game Object that had an 800x600 sized texture, and you wanted to show only the left + * half of it, you could call `setCrop(0, 0, 400, 600)`. + * + * It is also scaled to match the Game Object scale automatically. Therefore a crop rect of 100x50 would crop + * an area of 200x100 when applied to a Game Object that had a scale factor of 2. + * + * You can either pass in numeric values directly, or you can provide a single Rectangle object as the first argument. + * + * Call this method with no arguments at all to reset the crop, or toggle the property `isCropped` to `false`. + * + * You should do this if the crop rectangle becomes the same size as the frame itself, as it will allow + * the renderer to skip several internal calculations. + * @param x The x coordinate to start the crop from. Or a Phaser.Geom.Rectangle object, in which case the rest of the arguments are ignored. + * @param y The y coordinate to start the crop from. + * @param width The width of the crop rectangle in pixels. + * @param height The height of the crop rectangle in pixels. */ - body(x: number, y: number, width: number, height: number): Phaser.Physics.Impact.ImpactBody; + setCrop(x?: number | Phaser.Geom.Rectangle, y?: number, width?: number, height?: number): this; /** - * Adds an Impact Physics Body to the given Game Object. - * @param gameObject The Game Object to receive the physics body. + * Sets the texture and frame this Game Object will use to render with. + * + * Textures are referenced by their string-based keys, as stored in the Texture Manager. + * @param key The key of the texture to be used, as stored in the Texture Manager. + * @param frame The name or index of the frame within the Texture. */ - existing(gameObject: Phaser.GameObjects.GameObject): Phaser.GameObjects.GameObject; + setTexture(key: string, frame?: string | number): this; /** - * Creates a new ImpactImage object and adds it to the physics world. - * @param x The horizontal position of this Game Object in the world. - * @param y The vertical position of this Game Object in the world. - * @param key The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. - * @param frame An optional frame from the Texture this Game Object is rendering with. + * Sets the frame this Game Object will use to render with. + * + * The Frame has to belong to the current Texture being used. + * + * It can be either a string or an index. + * + * Calling `setFrame` will modify the `width` and `height` properties of your Game Object. + * It will also change the `origin` if the Frame has a custom pivot point, as exported from packages like Texture Packer. + * @param frame The name or index of the frame within the Texture. + * @param updateSize Should this call adjust the size of the Game Object? Default true. + * @param updateOrigin Should this call adjust the origin of the Game Object? Default true. */ - image(x: number, y: number, key: string, frame?: string | integer): Phaser.Physics.Impact.ImpactImage; + setFrame(frame: string | number, updateSize?: boolean, updateOrigin?: boolean): this; /** - * Creates a new ImpactSprite object and adds it to the physics world. - * @param x The horizontal position of this Game Object in the world. - * @param y The vertical position of this Game Object in the world. - * @param key The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. - * @param frame An optional frame from the Texture this Game Object is rendering with. + * The tint value being applied to the top-left vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. */ - sprite(x: number, y: number, key: string, frame?: string | integer): Phaser.Physics.Impact.ImpactSprite; + tintTopLeft: number; /** - * Destroys this Factory. + * The tint value being applied to the top-right vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. */ - destroy(): void; + tintTopRight: number; - } + /** + * The tint value being applied to the bottom-left vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintBottomLeft: number; - /** - * [description] - * @param delta The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate. - * @param vel [description] - * @param accel [description] - * @param friction [description] - * @param max [description] - */ - function GetVelocity(delta: number, vel: number, accel: number, friction: number, max: number): number; + /** + * The tint value being applied to the bottom-right vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintBottomRight: number; - /** - * [description] - */ - class ImpactBody implements Phaser.Physics.Impact.Components.Acceleration, Phaser.Physics.Impact.Components.BodyScale, Phaser.Physics.Impact.Components.BodyType, Phaser.Physics.Impact.Components.Bounce, Phaser.Physics.Impact.Components.CheckAgainst, Phaser.Physics.Impact.Components.Collides, Phaser.Physics.Impact.Components.Debug, Phaser.Physics.Impact.Components.Friction, Phaser.Physics.Impact.Components.Gravity, Phaser.Physics.Impact.Components.Offset, Phaser.Physics.Impact.Components.SetGameObject, Phaser.Physics.Impact.Components.Velocity { /** + * The tint fill mode. * - * @param world [description] - * @param x x - The horizontal position of this physics body in the world. - * @param y y - The vertical position of this physics body in the world. - * @param width The width of the physics body in the world. - * @param height [description] + * `false` = An additive tint (the default), where vertices colors are blended with the texture. + * `true` = A fill tint, where the vertices colors replace the texture, but respects texture alpha. */ - constructor(world: Phaser.Physics.Impact.World, x: number, y: number, width: number, height: number); + tintFill: boolean; /** - * [description] + * Clears all tint values associated with this Game Object. + * + * Immediately sets the color values back to 0xffffff and the tint type to 'additive', + * which results in no visible change to the texture. */ - body: Phaser.Physics.Impact.Body; + clearTint(): this; /** - * [description] + * Sets an additive tint on this Game Object. + * + * The tint works by taking the pixel color values from the Game Objects texture, and then + * multiplying it by the color value of the tint. You can provide either one color value, + * in which case the whole Game Object will be tinted in that color. Or you can provide a color + * per corner. The colors are blended together across the extent of the Game Object. + * + * To modify the tint color once set, either call this method again with new values or use the + * `tint` property to set all colors at once. Or, use the properties `tintTopLeft`, `tintTopRight, + * `tintBottomLeft` and `tintBottomRight` to set the corner color values independently. + * + * To remove a tint call `clearTint`. + * + * To swap this from being an additive tint to a fill based tint set the property `tintFill` to `true`. + * @param topLeft The tint being applied to the top-left of the Game Object. If no other values are given this value is applied evenly, tinting the whole Game Object. Default 0xffffff. + * @param topRight The tint being applied to the top-right of the Game Object. + * @param bottomLeft The tint being applied to the bottom-left of the Game Object. + * @param bottomRight The tint being applied to the bottom-right of the Game Object. */ - size: Object; + setTint(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; /** - * [description] + * Sets a fill-based tint on this Game Object. + * + * Unlike an additive tint, a fill-tint literally replaces the pixel colors from the texture + * with those in the tint. You can use this for effects such as making a player flash 'white' + * if hit by something. You can provide either one color value, in which case the whole + * Game Object will be rendered in that color. Or you can provide a color per corner. The colors + * are blended together across the extent of the Game Object. + * + * To modify the tint color once set, either call this method again with new values or use the + * `tint` property to set all colors at once. Or, use the properties `tintTopLeft`, `tintTopRight, + * `tintBottomLeft` and `tintBottomRight` to set the corner color values independently. + * + * To remove a tint call `clearTint`. + * + * To swap this from being a fill-tint to an additive tint set the property `tintFill` to `false`. + * @param topLeft The tint being applied to the top-left of the Game Object. If not other values are given this value is applied evenly, tinting the whole Game Object. Default 0xffffff. + * @param topRight The tint being applied to the top-right of the Game Object. + * @param bottomLeft The tint being applied to the bottom-left of the Game Object. + * @param bottomRight The tint being applied to the bottom-right of the Game Object. */ - offset: Object; + setTintFill(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; /** - * [description] + * The tint value being applied to the whole of the Game Object. + * This property is a setter-only. Use the properties `tintTopLeft` etc to read the current tint value. */ - vel: Object; + tint: number; /** - * [description] + * Does this Game Object have a tint applied? + * + * It checks to see if the 4 tint properties are set to the value 0xffffff + * and that the `tintFill` property is `false`. This indicates that a Game Object isn't tinted. */ - accel: Object; + readonly isTinted: boolean; /** - * [description] + * The x position of this Game Object. */ - friction: Object; + x: number; /** - * [description] + * The y position of this Game Object. */ - maxVel: Object; + y: number; /** - * Sets the horizontal acceleration of this body. - * @param x The amount of acceleration to apply. + * The z position of this Game Object. + * + * Note: The z position does not control the rendering order of 2D Game Objects. Use + * {@link Phaser.GameObjects.Components.Depth#depth} instead. */ - setAccelerationX(x: number): this; + z: number; /** - * Sets the vertical acceleration of this body. - * @param y The amount of acceleration to apply. + * The w position of this Game Object. */ - setAccelerationY(y: number): this; + w: number; /** - * Sets the horizontal and vertical acceleration of this body. - * @param x The amount of horizontal acceleration to apply. - * @param y The amount of vertical acceleration to apply. + * This is a special setter that allows you to set both the horizontal and vertical scale of this Game Object + * to the same value, at the same time. When reading this value the result returned is `(scaleX + scaleY) / 2`. + * + * Use of this property implies you wish the horizontal and vertical scales to be equal to each other. If this + * isn't the case, use the `scaleX` or `scaleY` properties instead. */ - setAcceleration(x: number, y: number): this; + scale: number; /** - * Sets the size of the physics body. - * @param width The width of the body in pixels. - * @param height The height of the body in pixels. Default width. + * The horizontal scale of this Game Object. */ - setBodySize(width: number, height?: number): this; + scaleX: number; /** - * Sets the scale of the physics body. - * @param scaleX The horizontal scale of the body. - * @param scaleY The vertical scale of the body. If not given, will use the horizontal scale value. + * The vertical scale of this Game Object. */ - setBodyScale(scaleX: number, scaleY?: number): this; + scaleY: number; /** - * [description] + * The angle of this Game Object as expressed in degrees. + * + * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left + * and -90 is up. + * + * If you prefer to work in radians, see the `rotation` property instead. */ - getBodyType(): number; + angle: number; /** - * [description] + * The angle of this Game Object in radians. + * + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. + * + * If you prefer to work in degrees, see the `angle` property instead. */ - setTypeNone(): Phaser.GameObjects.GameObject; + rotation: number; /** - * [description] + * Sets the position of this Game Object. + * @param x The x position of this Game Object. Default 0. + * @param y The y position of this Game Object. If not set it will use the `x` value. Default x. + * @param z The z position of this Game Object. Default 0. + * @param w The w position of this Game Object. Default 0. */ - setTypeA(): Phaser.GameObjects.GameObject; + setPosition(x?: number, y?: number, z?: number, w?: number): this; /** - * [description] + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. */ - setTypeB(): Phaser.GameObjects.GameObject; + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; /** - * Sets the impact physics bounce, or restitution, value. - * @param value A value between 0 (no rebound) and 1 (full rebound) + * Sets the position of this Game Object to be a random position within the confines of + * the given area. + * + * If no area is specified a random position between 0 x 0 and the game width x height is used instead. + * + * The position does not factor in the size of this Game Object, meaning that only the origin is + * guaranteed to be within the area. + * @param x The x position of the top-left of the random area. Default 0. + * @param y The y position of the top-left of the random area. Default 0. + * @param width The width of the random area. + * @param height The height of the random area. */ - setBounce(value: number): Phaser.GameObjects.GameObject; + setRandomPosition(x?: number, y?: number, width?: number, height?: number): this; /** - * Sets the minimum velocity the body is allowed to be moving to be considered for rebound. - * @param value The minimum allowed velocity. + * Sets the rotation of this Game Object. + * @param radians The rotation of this Game Object, in radians. Default 0. */ - setMinBounceVelocity(value: number): Phaser.GameObjects.GameObject; + setRotation(radians?: number): this; /** - * The bounce, or restitution, value of this body. - * A value between 0 (no rebound) and 1 (full rebound) + * Sets the angle of this Game Object. + * @param degrees The rotation of this Game Object, in degrees. Default 0. */ - bounce: number; + setAngle(degrees?: number): this; /** - * [description] + * Sets the scale of this Game Object. + * @param x The horizontal scale of this Game Object. + * @param y The vertical scale of this Game Object. If not set it will use the `x` value. Default x. */ - setAvsB(): Phaser.GameObjects.GameObject; + setScale(x: number, y?: number): this; /** - * [description] + * Sets the x position of this Game Object. + * @param value The x position of this Game Object. Default 0. */ - setBvsA(): Phaser.GameObjects.GameObject; + setX(value?: number): this; /** - * [description] + * Sets the y position of this Game Object. + * @param value The y position of this Game Object. Default 0. */ - setCheckAgainstNone(): Phaser.GameObjects.GameObject; + setY(value?: number): this; /** - * [description] + * Sets the z position of this Game Object. + * + * Note: The z position does not control the rendering order of 2D Game Objects. Use + * {@link Phaser.GameObjects.Components.Depth#setDepth} instead. + * @param value The z position of this Game Object. Default 0. */ - setCheckAgainstA(): Phaser.GameObjects.GameObject; + setZ(value?: number): this; /** - * [description] + * Sets the w position of this Game Object. + * @param value The w position of this Game Object. Default 0. */ - setCheckAgainstB(): Phaser.GameObjects.GameObject; + setW(value?: number): this; /** - * [description] + * Gets the local transform matrix for this Game Object. + * @param tempMatrix The matrix to populate with the values from this Game Object. */ - checkAgainst: number; + getLocalTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; /** - * [description] - * @param callback [description] - * @param scope [description] + * Gets the world transform matrix for this Game Object, factoring in any parent Containers. + * @param tempMatrix The matrix to populate with the values from this Game Object. + * @param parentMatrix A temporary matrix to hold parent values during the calculations. */ - setCollideCallback(callback: CollideCallback, scope: any): Phaser.GameObjects.GameObject; + getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; /** - * [description] + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. */ - setCollidesNever(): Phaser.GameObjects.GameObject; + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; /** - * [description] + * Gets the sum total rotation of all of this Game Objects parent Containers. + * + * The returned value is in radians and will be zero if this Game Object has no parent container. */ - setLiteCollision(): Phaser.GameObjects.GameObject; + getParentRotation(): number; /** - * [description] + * The visible state of the Game Object. + * + * An invisible Game Object will skip rendering, but will still process update logic. */ - setPassiveCollision(): Phaser.GameObjects.GameObject; + visible: boolean; /** - * [description] + * Sets the visibility of this Game Object. + * + * An invisible Game Object will skip rendering, but will still process update logic. + * @param value The visible state of the Game Object. */ - setActiveCollision(): Phaser.GameObjects.GameObject; + setVisible(value: boolean): this; /** - * [description] + * Sets the body's horizontal and vertical acceleration. If the vertical acceleration value is not provided, the vertical acceleration is set to the same value as the horizontal acceleration. + * @param x The horizontal acceleration + * @param y The vertical acceleration Default x. */ - setFixedCollision(): Phaser.GameObjects.GameObject; + setAcceleration(x: number, y?: number): this; /** - * [description] + * Sets the body's horizontal acceleration. + * @param value The horizontal acceleration */ - collides: number; + setAccelerationX(value: number): this; /** - * [description] - * @param showBody [description] - * @param showVelocity [description] - * @param bodyColor [description] + * Sets the body's vertical acceleration. + * @param value The vertical acceleration */ - setDebug(showBody: boolean, showVelocity: boolean, bodyColor: number): Phaser.GameObjects.GameObject; + setAccelerationY(value: number): this; /** - * [description] - * @param value [description] + * Sets the angular velocity of the body. + * + * In Arcade Physics, bodies cannot rotate. They are always axis-aligned. + * However, they can have angular motion, which is passed on to the Game Object bound to the body, + * causing them to visually rotate, even though the body remains axis-aligned. + * @param value The amount of angular velocity. */ - setDebugBodyColor(value: number): Phaser.GameObjects.GameObject; + setAngularVelocity(value: number): this; /** - * [description] + * Sets the angular acceleration of the body. + * + * In Arcade Physics, bodies cannot rotate. They are always axis-aligned. + * However, they can have angular motion, which is passed on to the Game Object bound to the body, + * causing them to visually rotate, even though the body remains axis-aligned. + * @param value The amount of angular acceleration. */ - debugShowBody: boolean; + setAngularAcceleration(value: number): this; /** - * [description] + * Sets the angular drag of the body. Drag is applied to the current velocity, providing a form of deceleration. + * @param value The amount of drag. */ - debugShowVelocity: boolean; + setAngularDrag(value: number): this; /** - * [description] + * Sets the bounce values of this body. + * + * Bounce is the amount of restitution, or elasticity, the body has when it collides with another object. + * A value of 1 means that it will retain its full velocity after the rebound. A value of 0 means it will not rebound at all. + * @param x The amount of horizontal bounce to apply on collision. A float, typically between 0 and 1. + * @param y The amount of vertical bounce to apply on collision. A float, typically between 0 and 1. Default x. */ - debugBodyColor: number; + setBounce(x: number, y?: number): this; /** - * [description] - * @param x [description] + * Sets the horizontal bounce value for this body. + * @param value The amount of horizontal bounce to apply on collision. A float, typically between 0 and 1. */ - setFrictionX(x: number): Phaser.GameObjects.GameObject; + setBounceX(value: number): this; /** - * [description] - * @param y [description] + * Sets the vertical bounce value for this body. + * @param value The amount of vertical bounce to apply on collision. A float, typically between 0 and 1. */ - setFrictionY(y: number): Phaser.GameObjects.GameObject; + setBounceY(value: number): this; /** - * [description] - * @param x [description] - * @param y [description] + * Sets whether this Body collides with the world boundary. + * + * Optionally also sets the World Bounce values. If the `Body.worldBounce` is null, it's set to a new Phaser.Math.Vector2 first. + * @param value `true` if this body should collide with the world bounds, otherwise `false`. Default true. + * @param bounceX If given this will be replace the `worldBounce.x` value. + * @param bounceY If given this will be replace the `worldBounce.y` value. */ - setFriction(x: number, y: number): Phaser.GameObjects.GameObject; + setCollideWorldBounds(value?: boolean, bounceX?: number, bounceY?: number): this; /** - * [description] - * @param value [description] + * Sets the debug values of this body. + * + * Bodies will only draw their debug if debug has been enabled for Arcade Physics as a whole. + * Note that there is a performance cost in drawing debug displays. It should never be used in production. + * @param showBody Set to `true` to have this body render its outline to the debug display. + * @param showVelocity Set to `true` to have this body render a velocity marker to the debug display. + * @param bodyColor The color of the body outline when rendered to the debug display. */ - setGravity(value: number): Phaser.GameObjects.GameObject; + setDebug(showBody: boolean, showVelocity: boolean, bodyColor: number): this; /** - * [description] + * Sets the color of the body outline when it renders to the debug display. + * @param value The color of the body outline when rendered to the debug display. */ - gravity: number; + setDebugBodyColor(value: number): this; /** - * [description] - * @param x [description] - * @param y [description] - * @param width [description] - * @param height [description] + * Set to `true` to have this body render its outline to the debug display. */ - setOffset(x: number, y: number, width?: number, height?: number): Phaser.GameObjects.GameObject; + debugShowBody: boolean; /** - * [description] - * @param gameObject [description] - * @param sync [description] Default true. + * Set to `true` to have this body render a velocity marker to the debug display. */ - setGameObject(gameObject: Phaser.GameObjects.GameObject, sync?: boolean): Phaser.GameObjects.GameObject; + debugShowVelocity: boolean; /** - * [description] + * The color of the body outline when it renders to the debug display. */ - syncGameObject(): Phaser.GameObjects.GameObject; + debugBodyColor: number; /** - * Sets the horizontal velocity of the physics body. - * @param x The horizontal velocity value. + * Sets the body's horizontal and vertical drag. If the vertical drag value is not provided, the vertical drag is set to the same value as the horizontal drag. + * + * Drag can be considered as a form of deceleration that will return the velocity of a body back to zero over time. + * It is the absolute loss of velocity due to movement, in pixels per second squared. + * The x and y components are applied separately. + * + * When `useDamping` is true, this is 1 minus the damping factor. + * A value of 1 means the Body loses no velocity. + * A value of 0.95 means the Body loses 5% of its velocity per step. + * A value of 0.5 means the Body loses 50% of its velocity per step. + * + * Drag is applied only when `acceleration` is zero. + * @param x The amount of horizontal drag to apply. + * @param y The amount of vertical drag to apply. Default x. */ - setVelocityX(x: number): this; + setDrag(x: number, y?: number): this; /** - * Sets the vertical velocity of the physics body. - * @param y The vertical velocity value. + * Sets the body's horizontal drag. + * + * Drag can be considered as a form of deceleration that will return the velocity of a body back to zero over time. + * It is the absolute loss of velocity due to movement, in pixels per second squared. + * The x and y components are applied separately. + * + * When `useDamping` is true, this is 1 minus the damping factor. + * A value of 1 means the Body loses no velocity. + * A value of 0.95 means the Body loses 5% of its velocity per step. + * A value of 0.5 means the Body loses 50% of its velocity per step. + * + * Drag is applied only when `acceleration` is zero. + * @param value The amount of horizontal drag to apply. */ - setVelocityY(y: number): this; + setDragX(value: number): this; /** - * Sets the horizontal and vertical velocities of the physics body. - * @param x The horizontal velocity value. - * @param y The vertical velocity value. If not given, defaults to the horizontal value. Default x. + * Sets the body's vertical drag. + * + * Drag can be considered as a form of deceleration that will return the velocity of a body back to zero over time. + * It is the absolute loss of velocity due to movement, in pixels per second squared. + * The x and y components are applied separately. + * + * When `useDamping` is true, this is 1 minus the damping factor. + * A value of 1 means the Body loses no velocity. + * A value of 0.95 means the Body loses 5% of its velocity per step. + * A value of 0.5 means the Body loses 50% of its velocity per step. + * + * Drag is applied only when `acceleration` is zero. + * @param value The amount of vertical drag to apply. */ - setVelocity(x: number, y?: number): this; + setDragY(value: number): this; /** - * Sets the maximum velocity this body can travel at. - * @param x The maximum allowed horizontal velocity. - * @param y The maximum allowed vertical velocity. If not given, defaults to the horizontal value. Default x. + * If this Body is using `drag` for deceleration this function controls how the drag is applied. + * If set to `true` drag will use a damping effect rather than a linear approach. If you are + * creating a game where the Body moves freely at any angle (i.e. like the way the ship moves in + * the game Asteroids) then you will get a far smoother and more visually correct deceleration + * by using damping, avoiding the axis-drift that is prone with linear deceleration. + * + * If you enable this property then you should use far smaller `drag` values than with linear, as + * they are used as a multiplier on the velocity. Values such as 0.95 will give a nice slow + * deceleration, where-as smaller values, such as 0.5 will stop an object almost immediately. + * @param value `true` to use damping for deceleration, or `false` to use linear deceleration. */ - setMaxVelocity(x: number, y?: number): this; + setDamping(value: boolean): this; - } + /** + * Enables this Game Object's Body. + * @param reset Also reset the Body and place it at (x, y). + * @param x The horizontal position to place the Game Object and Body. + * @param y The horizontal position to place the Game Object and Body. + * @param enableGameObject Also activate this Game Object. + * @param showGameObject Also show this Game Object. + */ + enableBody(reset: boolean, x: number, y: number, enableGameObject: boolean, showGameObject: boolean): this; - /** - * An Impact Physics Image Game Object. - * - * An Image is a light-weight Game Object useful for the display of static images in your game, - * such as logos, backgrounds, scenery or other non-animated elements. Images can have input - * events and physics bodies, or be tweened, tinted or scrolled. The main difference between an - * Image and a Sprite is that you cannot animate an Image as they do not have the Animation component. - */ - class ImpactImage extends Phaser.GameObjects.Image implements Phaser.Physics.Impact.Components.Acceleration, Phaser.Physics.Impact.Components.BodyScale, Phaser.Physics.Impact.Components.BodyType, Phaser.Physics.Impact.Components.Bounce, Phaser.Physics.Impact.Components.CheckAgainst, Phaser.Physics.Impact.Components.Collides, Phaser.Physics.Impact.Components.Debug, Phaser.Physics.Impact.Components.Friction, Phaser.Physics.Impact.Components.Gravity, Phaser.Physics.Impact.Components.Offset, Phaser.Physics.Impact.Components.SetGameObject, Phaser.Physics.Impact.Components.Velocity, Phaser.GameObjects.Components.Alpha, Phaser.GameObjects.Components.BlendMode, Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.Flip, Phaser.GameObjects.Components.GetBounds, Phaser.GameObjects.Components.Origin, Phaser.GameObjects.Components.Pipeline, Phaser.GameObjects.Components.ScrollFactor, Phaser.GameObjects.Components.Size, Phaser.GameObjects.Components.Texture, Phaser.GameObjects.Components.Tint, Phaser.GameObjects.Components.Transform, Phaser.GameObjects.Components.Visible { /** - * - * @param world The physics world of the Impact physics system. - * @param x The horizontal position of this Game Object in the world. - * @param y The vertical position of this Game Object in the world. - * @param texture The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. - * @param frame An optional frame from the Texture this Game Object is rendering with. + * Stops and disables this Game Object's Body. + * @param disableGameObject Also deactivate this Game Object. Default false. + * @param hideGameObject Also hide this Game Object. Default false. */ - constructor(world: Phaser.Physics.Impact.World, x: number, y: number, texture: string, frame?: string | integer); + disableBody(disableGameObject?: boolean, hideGameObject?: boolean): this; /** - * The Physics Body linked to an ImpactImage. + * Syncs the Body's position and size with its parent Game Object. + * You don't need to call this for Dynamic Bodies, as it happens automatically. + * But for Static bodies it's a useful way of modifying the position of a Static Body + * in the Physics World, based on its Game Object. */ - body: Phaser.Physics.Impact.Body; + refreshBody(): this; /** - * The size of the physics Body. + * Sets the friction of this game object's physics body. + * In Arcade Physics, friction is a special case of motion transfer from an "immovable" body to a riding body. + * @param x The amount of horizontal friction to apply, [0, 1]. + * @param y The amount of vertical friction to apply, [0, 1]. Default x. */ - size: Object; + setFriction(x: number, y?: number): this; /** - * The X and Y offset of the Body from the left and top of the Image. + * Sets the horizontal friction of this game object's physics body. + * This can move a riding body horizontally when it collides with this one on the vertical axis. + * @param x The amount of friction to apply, [0, 1]. */ - offset: Object; + setFrictionX(x: number): this; /** - * The velocity, or rate of change the Body's position. Measured in pixels per second. + * Sets the vertical friction of this game object's physics body. + * This can move a riding body vertically when it collides with this one on the horizontal axis. + * @param y The amount of friction to apply, [0, 1]. */ - vel: Object; + setFrictionY(y: number): this; /** - * The acceleration is the rate of change of the velocity. Measured in pixels per second squared. + * Set the X and Y values of the gravitational pull to act upon this Arcade Physics Game Object. Values can be positive or negative. Larger values result in a stronger effect. + * + * If only one value is provided, this value will be used for both the X and Y axis. + * @param x The gravitational force to be applied to the X-axis. + * @param y The gravitational force to be applied to the Y-axis. If this is not specified, the X value will be used. Default x. */ - accel: Object; + setGravity(x: number, y?: number): this; /** - * Friction between colliding bodies. + * Set the gravitational force to be applied to the X axis. Value can be positive or negative. Larger values result in a stronger effect. + * @param x The gravitational force to be applied to the X-axis. */ - friction: Object; + setGravityX(x: number): this; /** - * The maximum velocity of the body. + * Set the gravitational force to be applied to the Y axis. Value can be positive or negative. Larger values result in a stronger effect. + * @param y The gravitational force to be applied to the Y-axis. */ - maxVel: Object; + setGravityY(y: number): this; /** - * Clears all alpha values associated with this Game Object. + * Sets if this Body can be separated during collisions with other bodies. * - * Immediately sets the alpha levels back to 1 (fully opaque). + * When a body is immovable it means it won't move at all, not even to separate it from collision + * overlap. If you just wish to prevent a body from being knocked around by other bodies, see + * the `setPushable` method instead. + * @param value Sets if this body will be separated during collisions with other bodies. Default true. */ - clearAlpha(): this; + setImmovable(value?: boolean): this; /** - * Set the Alpha level of this Game Object. The alpha controls the opacity of the Game Object as it renders. - * Alpha values are provided as a float between 0, fully transparent, and 1, fully opaque. - * - * If your game is running under WebGL you can optionally specify four different alpha values, each of which - * correspond to the four corners of the Game Object. Under Canvas only the `topLeft` value given is used. - * @param topLeft The alpha value used for the top-left of the Game Object. If this is the only value given it's applied across the whole Game Object. Default 1. - * @param topRight The alpha value used for the top-right of the Game Object. WebGL only. - * @param bottomLeft The alpha value used for the bottom-left of the Game Object. WebGL only. - * @param bottomRight The alpha value used for the bottom-right of the Game Object. WebGL only. + * Sets the mass of the physics body + * @param value New value for the mass of the body. */ - setAlpha(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; + setMass(value: number): this; /** - * The alpha value of the Game Object. + * Sets if this Body can be pushed by another Body. * - * This is a global value, impacting the entire Game Object, not just a region of it. + * A body that cannot be pushed will reflect back all of the velocity it is given to the + * colliding body. If that body is also not pushable, then the separation will be split + * between them evenly. + * + * If you want your body to never move or seperate at all, see the `setImmovable` method. + * @param value Sets if this body can be pushed by collisions with another Body. Default true. */ - alpha: number; + setPushable(value?: boolean): this; /** - * The alpha value starting from the top-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * Sets the body offset. This allows you to adjust the difference between the center of the body + * and the x and y coordinates of the parent Game Object. + * @param x The amount to offset the body from the parent Game Object along the x-axis. + * @param y The amount to offset the body from the parent Game Object along the y-axis. Defaults to the value given for the x-axis. Default x. */ - alphaTopLeft: number; + setOffset(x: number, y?: number): this; /** - * The alpha value starting from the top-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * Sets the size of this physics body. Setting the size does not adjust the dimensions of the parent Game Object. + * @param width The new width of the physics body, in pixels. + * @param height The new height of the physics body, in pixels. + * @param center Should the body be re-positioned so its center aligns with the parent Game Object? Default true. */ - alphaTopRight: number; + setBodySize(width: number, height: number, center?: boolean): this; /** - * The alpha value starting from the bottom-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * Sets this physics body to use a circle for collision instead of a rectangle. + * @param radius The radius of the physics body, in pixels. + * @param offsetX The amount to offset the body from the parent Game Object along the x-axis. + * @param offsetY The amount to offset the body from the parent Game Object along the y-axis. */ - alphaBottomLeft: number; + setCircle(radius: number, offsetX?: number, offsetY?: number): this; /** - * The alpha value starting from the bottom-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * Sets the velocity of the Body. + * @param x The horizontal velocity of the body. Positive values move the body to the right, while negative values move it to the left. + * @param y The vertical velocity of the body. Positive values move the body down, while negative values move it up. Default x. */ - alphaBottomRight: number; + setVelocity(x: number, y?: number): this; /** - * Sets the Blend Mode being used by this Game Object. - * - * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) - * - * Under WebGL only the following Blend Modes are available: - * - * * ADD - * * MULTIPLY - * * SCREEN - * * ERASE - * - * Canvas has more available depending on browser support. - * - * You can also create your own custom Blend Modes in WebGL. + * Sets the horizontal component of the body's velocity. * - * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending - * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these - * reasons try to be careful about the construction of your Scene and the frequency of which blend modes - * are used. + * Positive values move the body to the right, while negative values move it to the left. + * @param x The new horizontal velocity. */ - blendMode: Phaser.BlendModes | string; + setVelocityX(x: number): this; /** - * Sets the Blend Mode being used by this Game Object. - * - * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) - * - * Under WebGL only the following Blend Modes are available: - * - * * ADD - * * MULTIPLY - * * SCREEN - * * ERASE (only works when rendering to a framebuffer, like a Render Texture) - * - * Canvas has more available depending on browser support. - * - * You can also create your own custom Blend Modes in WebGL. + * Sets the vertical component of the body's velocity. * - * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending - * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these - * reasons try to be careful about the construction of your Scene and the frequency in which blend modes - * are used. - * @param value The BlendMode value. Either a string or a CONST. + * Positive values move the body down, while negative values move it up. + * @param y The new vertical velocity of the body. */ - setBlendMode(value: string | Phaser.BlendModes): this; + setVelocityY(y: number): this; /** - * The depth of this Game Object within the Scene. - * - * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order - * of Game Objects, without actually moving their position in the display list. - * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth - * value will always render in front of one with a lower value. - * - * Setting the depth will queue a depth sort event within the Scene. + * Sets the maximum velocity of the body. + * @param x The new maximum horizontal velocity. + * @param y The new maximum vertical velocity. Default x. */ - depth: number; + setMaxVelocity(x: number, y?: number): this; - /** - * The depth of this Game Object within the Scene. - * - * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order - * of Game Objects, without actually moving their position in the display list. - * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth - * value will always render in front of one with a lower value. - * - * Setting the depth will queue a depth sort event within the Scene. - * @param value The depth of this Game Object. - */ - setDepth(value: integer): this; + } + /** + * A Dynamic Arcade Body. + * + * Its static counterpart is {@link Phaser.Physics.Arcade.StaticBody}. + */ + class Body { /** - * The horizontally flipped state of the Game Object. * - * A Game Object that is flipped horizontally will render inversed on the horizontal axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * @param world The Arcade Physics simulation this Body belongs to. + * @param gameObject The Game Object this Body belongs to. */ - flipX: boolean; + constructor(world: Phaser.Physics.Arcade.World, gameObject: Phaser.GameObjects.GameObject); /** - * The vertically flipped state of the Game Object. - * - * A Game Object that is flipped vertically will render inversed on the vertical axis (i.e. upside down) - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * The Arcade Physics simulation this Body belongs to. */ - flipY: boolean; + world: Phaser.Physics.Arcade.World; /** - * Toggles the horizontal flipped state of this Game Object. - * - * A Game Object that is flipped horizontally will render inversed on the horizontal axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * The Game Object this Body belongs to. */ - toggleFlipX(): this; + gameObject: Phaser.GameObjects.GameObject; /** - * Toggles the vertical flipped state of this Game Object. + * Transformations applied to this Body. */ - toggleFlipY(): this; + transform: object; /** - * Sets the horizontal flipped state of this Game Object. - * - * A Game Object that is flipped horizontally will render inversed on the horizontal axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. - * @param value The flipped state. `false` for no flip, or `true` to be flipped. + * Whether the Body is drawn to the debug display. */ - setFlipX(value: boolean): this; + debugShowBody: boolean; /** - * Sets the vertical flipped state of this Game Object. - * @param value The flipped state. `false` for no flip, or `true` to be flipped. + * Whether the Body's velocity is drawn to the debug display. */ - setFlipY(value: boolean): this; + debugShowVelocity: boolean; /** - * Sets the horizontal and vertical flipped state of this Game Object. - * - * A Game Object that is flipped will render inversed on the flipped axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. - * @param x The horizontal flipped state. `false` for no flip, or `true` to be flipped. - * @param y The horizontal flipped state. `false` for no flip, or `true` to be flipped. + * The color of this Body on the debug display. */ - setFlip(x: boolean, y: boolean): this; + debugBodyColor: number; /** - * Resets the horizontal and vertical flipped state of this Game Object back to their default un-flipped state. + * Whether this Body is updated by the physics simulation. */ - resetFlip(): this; + enable: boolean; /** - * Gets the center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. + * Whether this Body is circular (true) or rectangular (false). */ - getCenter(output?: O): O; + isCircle: boolean; /** - * Gets the top-left corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * If this Body is circular, this is the unscaled radius of the Body, as set by setCircle(), in source pixels. + * The true radius is equal to `halfWidth`. */ - getTopLeft(output?: O, includeParent?: boolean): O; + radius: number; /** - * Gets the top-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * The offset of this Body's position from its Game Object's position, in source pixels. */ - getTopCenter(output?: O, includeParent?: boolean): O; + offset: Phaser.Math.Vector2; /** - * Gets the top-right corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * The position of this Body within the simulation. */ - getTopRight(output?: O, includeParent?: boolean): O; + position: Phaser.Math.Vector2; /** - * Gets the left-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * The position of this Body during the previous step. */ - getLeftCenter(output?: O, includeParent?: boolean): O; + prev: Phaser.Math.Vector2; /** - * Gets the right-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * The position of this Body during the previous frame. */ - getRightCenter(output?: O, includeParent?: boolean): O; + prevFrame: Phaser.Math.Vector2; /** - * Gets the bottom-left corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * Whether this Body's `rotation` is affected by its angular acceleration and angular velocity. */ - getBottomLeft(output?: O, includeParent?: boolean): O; + allowRotation: boolean; /** - * Gets the bottom-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * This body's rotation, in degrees, based on its angular acceleration and angular velocity. + * The Body's rotation controls the `angle` of its Game Object. + * It doesn't rotate the Body's own geometry, which is always an axis-aligned rectangle or a circle. */ - getBottomCenter(output?: O, includeParent?: boolean): O; + rotation: number; /** - * Gets the bottom-right corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * The Body rotation, in degrees, during the previous step. */ - getBottomRight(output?: O, includeParent?: boolean): O; + preRotation: number; /** - * Gets the bounds of this Game Object, regardless of origin. - * The values are stored and returned in a Rectangle, or Rectangle-like, object. - * @param output An object to store the values in. If not provided a new Rectangle will be created. + * The width of the Body, in pixels. + * If the Body is circular, this is also the diameter. + * If you wish to change the width use the `Body.setSize` method. */ - getBounds(output?: O): O; + readonly width: number; /** - * The Mask this Game Object is using during render. + * The height of the Body, in pixels. + * If the Body is circular, this is also the diameter. + * If you wish to change the height use the `Body.setSize` method. */ - mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask; + readonly height: number; /** - * Sets the mask that this Game Object will use to render with. - * - * The mask must have been previously created and can be either a GeometryMask or a BitmapMask. - * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. - * - * If a mask is already set on this Game Object it will be immediately replaced. - * - * Masks are positioned in global space and are not relative to the Game Object to which they - * are applied. The reason for this is that multiple Game Objects can all share the same mask. - * - * Masks have no impact on physics or input detection. They are purely a rendering component - * that allows you to limit what is visible during the render pass. - * @param mask The mask this Game Object will use when rendering. + * The unscaled width of the Body, in source pixels, as set by setSize(). + * The default is the width of the Body's Game Object's texture frame. */ - setMask(mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask): this; + sourceWidth: number; /** - * Clears the mask that this Game Object was using. - * @param destroyMask Destroy the mask before clearing it? Default false. + * The unscaled height of the Body, in source pixels, as set by setSize(). + * The default is the height of the Body's Game Object's texture frame. */ - clearMask(destroyMask?: boolean): this; + sourceHeight: number; /** - * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, - * including this one. - * - * To create the mask you need to pass in a reference to a renderable Game Object. - * A renderable Game Object is one that uses a texture to render with, such as an - * Image, Sprite, Render Texture or BitmapText. - * - * If you do not provide a renderable object, and this Game Object has a texture, - * it will use itself as the object. This means you can call this method to create - * a Bitmap Mask from any renderable Game Object. - * @param renderable A renderable Game Object that uses a texture, such as a Sprite. + * Half the Body's width, in pixels. */ - createBitmapMask(renderable?: Phaser.GameObjects.GameObject): Phaser.Display.Masks.BitmapMask; + halfWidth: number; /** - * Creates and returns a Geometry Mask. This mask can be used by any Game Object, - * including this one. - * - * To create the mask you need to pass in a reference to a Graphics Game Object. - * - * If you do not provide a graphics object, and this Game Object is an instance - * of a Graphics object, then it will use itself to create the mask. - * - * This means you can call this method to create a Geometry Mask from any Graphics Game Object. - * @param graphics A Graphics Game Object. The geometry within it will be used as the mask. + * Half the Body's height, in pixels. */ - createGeometryMask(graphics?: Phaser.GameObjects.Graphics): Phaser.Display.Masks.GeometryMask; + halfHeight: number; /** - * The horizontal origin of this Game Object. - * The origin maps the relationship between the size and position of the Game Object. - * The default value is 0.5, meaning all Game Objects are positioned based on their center. - * Setting the value to 0 means the position now relates to the left of the Game Object. + * The center of the Body. + * The midpoint of its `position` (top-left corner) and its bottom-right corner. */ - originX: number; + center: Phaser.Math.Vector2; /** - * The vertical origin of this Game Object. - * The origin maps the relationship between the size and position of the Game Object. - * The default value is 0.5, meaning all Game Objects are positioned based on their center. - * Setting the value to 0 means the position now relates to the top of the Game Object. + * The Body's velocity, in pixels per second. */ - originY: number; + velocity: Phaser.Math.Vector2; /** - * The horizontal display origin of this Game Object. - * The origin is a normalized value between 0 and 1. - * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. + * The Body's change in position (due to velocity) at the last step, in pixels. + * + * The size of this value depends on the simulation's step rate. */ - displayOriginX: number; + readonly newVelocity: Phaser.Math.Vector2; /** - * The vertical display origin of this Game Object. - * The origin is a normalized value between 0 and 1. - * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. + * The Body's absolute maximum change in position, in pixels per step. */ - displayOriginY: number; + deltaMax: Phaser.Math.Vector2; /** - * Sets the origin of this Game Object. - * - * The values are given in the range 0 to 1. - * @param x The horizontal origin value. Default 0.5. - * @param y The vertical origin value. If not defined it will be set to the value of `x`. Default x. + * The Body's change in velocity, in pixels per second squared. */ - setOrigin(x?: number, y?: number): this; + acceleration: Phaser.Math.Vector2; /** - * Sets the origin of this Game Object based on the Pivot values in its Frame. + * Whether this Body's velocity is affected by its `drag`. */ - setOriginFromFrame(): this; + allowDrag: boolean; /** - * Sets the display origin of this Game Object. - * The difference between this and setting the origin is that you can use pixel values for setting the display origin. - * @param x The horizontal display origin value. Default 0. - * @param y The vertical display origin value. If not defined it will be set to the value of `x`. Default x. + * When `useDamping` is false (the default), this is absolute loss of velocity due to movement, in pixels per second squared. + * + * When `useDamping` is true, this is a damping multiplier between 0 and 1. + * A value of 0 means the Body stops instantly. + * A value of 0.01 mean the Body loses 99% of its velocity per second. + * A value of 0.1 means the Body loses 90% of its velocity per second. + * A value of 1 means the Body loses no velocity. + * + * The x and y components are applied separately. + * + * Drag is applied only when `acceleration` is zero. */ - setDisplayOrigin(x?: number, y?: number): this; + drag: Phaser.Math.Vector2; /** - * Updates the Display Origin cached values internally stored on this Game Object. - * You don't usually call this directly, but it is exposed for edge-cases where you may. + * Whether this Body's position is affected by gravity (local or world). */ - updateDisplayOrigin(): this; + allowGravity: boolean; /** - * The initial WebGL pipeline of this Game Object. + * Acceleration due to gravity (specific to this Body), in pixels per second squared. + * Total gravity is the sum of this vector and the simulation's `gravity`. */ - defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; + gravity: Phaser.Math.Vector2; /** - * The current WebGL pipeline of this Game Object. + * Rebound following a collision, relative to 1. */ - pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + bounce: Phaser.Math.Vector2; /** - * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. + * Rebound following a collision with the world boundary, relative to 1. + * If null, `bounce` is used instead. */ - initPipeline(pipelineName?: string): boolean; + worldBounce: Phaser.Math.Vector2; /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. + * The rectangle used for world boundary collisions. + * + * By default it is set to the world boundary rectangle. Or, if this Body was + * created by a Physics Group, then whatever rectangle that Group defined. + * + * You can also change it by using the `Body.setBoundsRectangle` method. */ - setPipeline(pipelineName: string): this; + customBoundsRectangle: Phaser.Geom.Rectangle; /** - * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * Whether the simulation emits a `worldbounds` event when this Body collides with the world boundary (and `collideWorldBounds` is also true). */ - resetPipeline(): boolean; + onWorldBounds: boolean; /** - * Gets the name of the WebGL Pipeline this Game Object is currently using. + * Whether the simulation emits a `collide` event when this Body collides with another. */ - getPipelineName(): string; + onCollide: boolean; /** - * The horizontal scroll factor of this Game Object. - * - * The scroll factor controls the influence of the movement of a Camera upon this Game Object. - * - * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. - * It does not change the Game Objects actual position values. - * - * A value of 1 means it will move exactly in sync with a camera. - * A value of 0 means it will not move at all, even if the camera moves. - * Other values control the degree to which the camera movement is mapped to this Game Object. - * - * Please be aware that scroll factor values other than 1 are not taken in to consideration when - * calculating physics collisions. Bodies always collide based on their world position, but changing - * the scroll factor is a visual adjustment to where the textures are rendered, which can offset - * them from physics bodies if not accounted for in your code. + * Whether the simulation emits an `overlap` event when this Body overlaps with another. */ - scrollFactorX: number; + onOverlap: boolean; /** - * The vertical scroll factor of this Game Object. - * - * The scroll factor controls the influence of the movement of a Camera upon this Game Object. - * - * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. - * It does not change the Game Objects actual position values. - * - * A value of 1 means it will move exactly in sync with a camera. - * A value of 0 means it will not move at all, even if the camera moves. - * Other values control the degree to which the camera movement is mapped to this Game Object. - * - * Please be aware that scroll factor values other than 1 are not taken in to consideration when - * calculating physics collisions. Bodies always collide based on their world position, but changing - * the scroll factor is a visual adjustment to where the textures are rendered, which can offset - * them from physics bodies if not accounted for in your code. + * The Body's absolute maximum velocity, in pixels per second. + * The horizontal and vertical components are applied separately. */ - scrollFactorY: number; + maxVelocity: Phaser.Math.Vector2; /** - * Sets the scroll factor of this Game Object. - * - * The scroll factor controls the influence of the movement of a Camera upon this Game Object. - * - * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. - * It does not change the Game Objects actual position values. + * The maximum speed this Body is allowed to reach, in pixels per second. * - * A value of 1 means it will move exactly in sync with a camera. - * A value of 0 means it will not move at all, even if the camera moves. - * Other values control the degree to which the camera movement is mapped to this Game Object. + * If not negative it limits the scalar value of speed. * - * Please be aware that scroll factor values other than 1 are not taken in to consideration when - * calculating physics collisions. Bodies always collide based on their world position, but changing - * the scroll factor is a visual adjustment to where the textures are rendered, which can offset - * them from physics bodies if not accounted for in your code. - * @param x The horizontal scroll factor of this Game Object. - * @param y The vertical scroll factor of this Game Object. If not set it will use the `x` value. Default x. + * Any negative value means no maximum is being applied (the default). */ - setScrollFactor(x: number, y?: number): this; + maxSpeed: number; /** - * The native (un-scaled) width of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayWidth` property. + * If this Body is `immovable` and in motion, `friction` is the proportion of this Body's motion received by the riding Body on each axis, relative to 1. + * The horizontal component (x) is applied only when two colliding Bodies are separated vertically. + * The vertical component (y) is applied only when two colliding Bodies are separated horizontally. + * The default value (1, 0) moves the riding Body horizontally in equal proportion to this Body and vertically not at all. */ - width: number; + friction: Phaser.Math.Vector2; /** - * The native (un-scaled) height of this Game Object. + * If this Body is using `drag` for deceleration this property controls how the drag is applied. + * If set to `true` drag will use a damping effect rather than a linear approach. If you are + * creating a game where the Body moves freely at any angle (i.e. like the way the ship moves in + * the game Asteroids) then you will get a far smoother and more visually correct deceleration + * by using damping, avoiding the axis-drift that is prone with linear deceleration. * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayHeight` property. + * If you enable this property then you should use far smaller `drag` values than with linear, as + * they are used as a multiplier on the velocity. Values such as 0.05 will give a nice slow + * deceleration. */ - height: number; + useDamping: boolean; /** - * The displayed width of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. + * The rate of change of this Body's `rotation`, in degrees per second. */ - displayWidth: number; + angularVelocity: number; /** - * The displayed height of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. + * The Body's angular acceleration (change in angular velocity), in degrees per second squared. */ - displayHeight: number; + angularAcceleration: number; /** - * Sets the size of this Game Object to be that of the given Frame. - * - * This will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or call the - * `setDisplaySize` method, which is the same thing as changing the scale but allows you - * to do so by giving pixel values. + * Loss of angular velocity due to angular movement, in degrees per second. * - * If you have enabled this Game Object for input, changing the size will _not_ change the - * size of the hit area. To do this you should adjust the `input.hitArea` object directly. - * @param frame The frame to base the size of this Game Object on. + * Angular drag is applied only when angular acceleration is zero. */ - setSizeToFrame(frame: Phaser.Textures.Frame): this; + angularDrag: number; - /** - * Sets the internal size of this Game Object, as used for frame or physics body creation. - * - * This will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or call the - * `setDisplaySize` method, which is the same thing as changing the scale but allows you - * to do so by giving pixel values. - * - * If you have enabled this Game Object for input, changing the size will _not_ change the - * size of the hit area. To do this you should adjust the `input.hitArea` object directly. - * @param width The width of this Game Object. - * @param height The height of this Game Object. + /** + * The Body's maximum angular velocity, in degrees per second. */ - setSize(width: number, height: number): this; + maxAngular: number; /** - * Sets the display size of this Game Object. - * - * Calling this will adjust the scale. - * @param width The width of this Game Object. - * @param height The height of this Game Object. + * The Body's inertia, relative to a default unit (1). + * With `bounce`, this affects the exchange of momentum (velocities) during collisions. */ - setDisplaySize(width: number, height: number): this; + mass: number; /** - * The Texture this Game Object is using to render with. + * The calculated angle of this Body's velocity vector, in radians, during the last step. */ - texture: Phaser.Textures.Texture | Phaser.Textures.CanvasTexture; + angle: number; /** - * The Texture Frame this Game Object is using to render with. + * The calculated magnitude of the Body's velocity, in pixels per second, during the last step. */ - frame: Phaser.Textures.Frame; + speed: number; /** - * A boolean flag indicating if this Game Object is being cropped or not. - * You can toggle this at any time after `setCrop` has been called, to turn cropping on or off. - * Equally, calling `setCrop` with no arguments will reset the crop and disable it. + * The direction of the Body's velocity, as calculated during the last step. + * This is a numeric constant value (FACING_UP, FACING_DOWN, FACING_LEFT, FACING_RIGHT). + * If the Body is moving on both axes, this describes motion on the vertical axis only. */ - isCropped: boolean; + facing: number; /** - * Applies a crop to a texture based Game Object, such as a Sprite or Image. - * - * The crop is a rectangle that limits the area of the texture frame that is visible during rendering. - * - * Cropping a Game Object does not change its size, dimensions, physics body or hit area, it just - * changes what is shown when rendered. - * - * The crop coordinates are relative to the texture frame, not the Game Object, meaning 0 x 0 is the top-left. - * - * Therefore, if you had a Game Object that had an 800x600 sized texture, and you wanted to show only the left - * half of it, you could call `setCrop(0, 0, 400, 600)`. - * - * It is also scaled to match the Game Object scale automatically. Therefore a crop rect of 100x50 would crop - * an area of 200x100 when applied to a Game Object that had a scale factor of 2. + * Whether this Body can be moved by collisions with another Body. + */ + immovable: boolean; + + /** + * Sets if this Body can be pushed by another Body. * - * You can either pass in numeric values directly, or you can provide a single Rectangle object as the first argument. + * A body that cannot be pushed will reflect back all of the velocity it is given to the + * colliding body. If that body is also not pushable, then the separation will be split + * between them evenly. * - * Call this method with no arguments at all to reset the crop, or toggle the property `isCropped` to `false`. + * If you want your body to never move or seperate at all, see the `setImmovable` method. * - * You should do this if the crop rectangle becomes the same size as the frame itself, as it will allow - * the renderer to skip several internal calculations. - * @param x The x coordinate to start the crop from. Or a Phaser.Geom.Rectangle object, in which case the rest of the arguments are ignored. - * @param y The y coordinate to start the crop from. - * @param width The width of the crop rectangle in pixels. - * @param height The height of the crop rectangle in pixels. + * By default, Dynamic Bodies are always pushable. */ - setCrop(x?: number | Phaser.Geom.Rectangle, y?: number, width?: number, height?: number): this; + pushable: boolean; /** - * Sets the texture and frame this Game Object will use to render with. - * - * Textures are referenced by their string-based keys, as stored in the Texture Manager. - * @param key The key of the texture to be used, as stored in the Texture Manager. - * @param frame The name or index of the frame within the Texture. + * Whether the Body's position and rotation are affected by its velocity, acceleration, drag, and gravity. */ - setTexture(key: string, frame?: string | integer): this; + moves: boolean; /** - * Sets the frame this Game Object will use to render with. - * - * The Frame has to belong to the current Texture being used. - * - * It can be either a string or an index. - * - * Calling `setFrame` will modify the `width` and `height` properties of your Game Object. - * It will also change the `origin` if the Frame has a custom pivot point, as exported from packages like Texture Packer. - * @param frame The name or index of the frame within the Texture. - * @param updateSize Should this call adjust the size of the Game Object? Default true. - * @param updateOrigin Should this call adjust the origin of the Game Object? Default true. + * A flag disabling the default horizontal separation of colliding bodies. + * Pass your own `collideCallback` to the collider. */ - setFrame(frame: string | integer, updateSize?: boolean, updateOrigin?: boolean): this; + customSeparateX: boolean; /** - * Fill or additive? + * A flag disabling the default vertical separation of colliding bodies. + * Pass your own `collideCallback` to the collider. */ - tintFill: boolean; + customSeparateY: boolean; /** - * Clears all tint values associated with this Game Object. - * - * Immediately sets the color values back to 0xffffff and the tint type to 'additive', - * which results in no visible change to the texture. + * The amount of horizontal overlap (before separation), if this Body is colliding with another. */ - clearTint(): this; + overlapX: number; /** - * Sets an additive tint on this Game Object. - * - * The tint works by taking the pixel color values from the Game Objects texture, and then - * multiplying it by the color value of the tint. You can provide either one color value, - * in which case the whole Game Object will be tinted in that color. Or you can provide a color - * per corner. The colors are blended together across the extent of the Game Object. - * - * To modify the tint color once set, either call this method again with new values or use the - * `tint` property to set all colors at once. Or, use the properties `tintTopLeft`, `tintTopRight, - * `tintBottomLeft` and `tintBottomRight` to set the corner color values independently. - * - * To remove a tint call `clearTint`. - * - * To swap this from being an additive tint to a fill based tint set the property `tintFill` to `true`. - * @param topLeft The tint being applied to the top-left of the Game Object. If no other values are given this value is applied evenly, tinting the whole Game Object. Default 0xffffff. - * @param topRight The tint being applied to the top-right of the Game Object. - * @param bottomLeft The tint being applied to the bottom-left of the Game Object. - * @param bottomRight The tint being applied to the bottom-right of the Game Object. + * The amount of vertical overlap (before separation), if this Body is colliding with another. */ - setTint(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; + overlapY: number; /** - * Sets a fill-based tint on this Game Object. - * - * Unlike an additive tint, a fill-tint literally replaces the pixel colors from the texture - * with those in the tint. You can use this for effects such as making a player flash 'white' - * if hit by something. You can provide either one color value, in which case the whole - * Game Object will be rendered in that color. Or you can provide a color per corner. The colors - * are blended together across the extent of the Game Object. - * - * To modify the tint color once set, either call this method again with new values or use the - * `tint` property to set all colors at once. Or, use the properties `tintTopLeft`, `tintTopRight, - * `tintBottomLeft` and `tintBottomRight` to set the corner color values independently. - * - * To remove a tint call `clearTint`. - * - * To swap this from being a fill-tint to an additive tint set the property `tintFill` to `false`. - * @param topLeft The tint being applied to the top-left of the Game Object. If not other values are given this value is applied evenly, tinting the whole Game Object. Default 0xffffff. - * @param topRight The tint being applied to the top-right of the Game Object. - * @param bottomLeft The tint being applied to the bottom-left of the Game Object. - * @param bottomRight The tint being applied to the bottom-right of the Game Object. + * The amount of overlap (before separation), if this Body is circular and colliding with another circular body. */ - setTintFill(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; + overlapR: number; /** - * The tint value being applied to the top-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * Whether this Body is overlapped with another and both are not moving, on at least one axis. */ - tintTopLeft: integer; + embedded: boolean; /** - * The tint value being applied to the top-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * Whether this Body interacts with the world boundary. */ - tintTopRight: integer; + collideWorldBounds: boolean; /** - * The tint value being applied to the bottom-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * Whether this Body is checked for collisions and for which directions. + * You can set `checkCollision.none = true` to disable collision checks. */ - tintBottomLeft: integer; + checkCollision: Phaser.Types.Physics.Arcade.ArcadeBodyCollision; /** - * The tint value being applied to the bottom-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * Whether this Body is colliding with a Body or Static Body and in which direction. + * In a collision where both bodies have zero velocity, `embedded` will be set instead. */ - tintBottomRight: integer; + touching: Phaser.Types.Physics.Arcade.ArcadeBodyCollision; /** - * The tint value being applied to the whole of the Game Object. - * This property is a setter-only. Use the properties `tintTopLeft` etc to read the current tint value. + * This Body's `touching` value during the previous step. */ - tint: integer; + wasTouching: Phaser.Types.Physics.Arcade.ArcadeBodyCollision; /** - * Does this Game Object have a tint applied to it or not? + * Whether this Body is colliding with a Static Body, a tile, or the world boundary. + * In a collision with a Static Body, if this Body has zero velocity then `embedded` will be set instead. */ - readonly isTinted: boolean; + blocked: Phaser.Types.Physics.Arcade.ArcadeBodyCollision; /** - * The x position of this Game Object. + * Whether to automatically synchronize this Body's dimensions to the dimensions of its Game Object's visual bounds. */ - x: number; + syncBounds: boolean; /** - * The y position of this Game Object. + * The Body's physics type (dynamic or static). */ - y: number; + readonly physicsType: number; /** - * The z position of this Game Object. - * - * Note: The z position does not control the rendering order of 2D Game Objects. Use - * {@link Phaser.GameObjects.Components.Depth#depth} instead. + * Updates the Body's `transform`, `width`, `height`, and `center` from its Game Object. + * The Body's `position` isn't changed. */ - z: number; + updateBounds(): void; /** - * The w position of this Game Object. + * Updates the Body's `center` from its `position`, `width`, and `height`. */ - w: number; + updateCenter(): void; /** - * This is a special setter that allows you to set both the horizontal and vertical scale of this Game Object - * to the same value, at the same time. When reading this value the result returned is `(scaleX + scaleY) / 2`. + * Updates the Body's `position`, `width`, `height`, and `center` from its Game Object and `offset`. * - * Use of this property implies you wish the horizontal and vertical scales to be equal to each other. If this - * isn't the case, use the `scaleX` or `scaleY` properties instead. + * You don't need to call this for Dynamic Bodies, as it happens automatically during the physics step. + * But you could use it if you have modified the Body offset or Game Object transform and need to immediately + * read the Body's new `position` or `center`. + * + * To resynchronize the Body with its Game Object, use `reset()` instead. */ - scale: number; + updateFromGameObject(): void; /** - * The horizontal scale of this Game Object. + * Prepares the Body for a physics step by resetting the `wasTouching`, `touching` and `blocked` states. + * + * This method is only called if the physics world is going to run a step this frame. + * @param clear Set the `wasTouching` values to their defaults. Default false. */ - scaleX: number; + resetFlags(clear?: boolean): void; /** - * The vertical scale of this Game Object. + * Syncs the position body position with the parent Game Object. + * + * This method is called every game frame, regardless if the world steps or not. + * @param willStep Will this Body run an update as well? + * @param delta The delta time, in seconds, elapsed since the last frame. */ - scaleY: number; + preUpdate(willStep: boolean, delta: number): void; /** - * The angle of this Game Object as expressed in degrees. + * Performs a single physics step and updates the body velocity, angle, speed and other properties. * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * This method can be called multiple times per game frame, depending on the physics step rate. * - * If you prefer to work in radians, see the `rotation` property instead. + * The results are synced back to the Game Object in `postUpdate`. + * @param delta The delta time, in seconds, elapsed since the last frame. */ - angle: integer; + update(delta: number): void; /** - * The angle of this Game Object in radians. - * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Feeds the Body results back into the parent Game Object. * - * If you prefer to work in degrees, see the `angle` property instead. + * This method is called every game frame, regardless if the world steps or not. */ - rotation: number; + postUpdate(): void; /** - * Sets the position of this Game Object. - * @param x The x position of this Game Object. Default 0. - * @param y The y position of this Game Object. If not set it will use the `x` value. Default x. - * @param z The z position of this Game Object. Default 0. - * @param w The w position of this Game Object. Default 0. + * Sets a custom collision boundary rectangle. Use if you want to have a custom + * boundary instead of the world boundaries. + * @param bounds The new boundary rectangle. Pass `null` to use the World bounds. */ - setPosition(x?: number, y?: number, z?: number, w?: number): this; + setBoundsRectangle(bounds?: Phaser.Geom.Rectangle): this; /** - * Sets the position of this Game Object to be a random position within the confines of - * the given area. - * - * If no area is specified a random position between 0 x 0 and the game width x height is used instead. - * - * The position does not factor in the size of this Game Object, meaning that only the origin is - * guaranteed to be within the area. - * @param x The x position of the top-left of the random area. Default 0. - * @param y The y position of the top-left of the random area. Default 0. - * @param width The width of the random area. - * @param height The height of the random area. + * Checks for collisions between this Body and the world boundary and separates them. */ - setRandomPosition(x?: number, y?: number, width?: number, height?: number): this; + checkWorldBounds(): boolean; /** - * Sets the rotation of this Game Object. - * @param radians The rotation of this Game Object, in radians. Default 0. + * Sets the offset of the Body's position from its Game Object's position. + * The Body's `position` isn't changed until the next `preUpdate`. + * @param x The horizontal offset, in source pixels. + * @param y The vertical offset, in source pixels. Default x. */ - setRotation(radians?: number): this; + setOffset(x: number, y?: number): Phaser.Physics.Arcade.Body; /** - * Sets the angle of this Game Object. - * @param degrees The rotation of this Game Object, in degrees. Default 0. + * Sizes and positions this Body, as a rectangle. + * Modifies the Body `offset` if `center` is true (the default). + * Resets the width and height to match current frame, if no width and height provided and a frame is found. + * @param width The width of the Body in pixels. Cannot be zero. If not given, and the parent Game Object has a frame, it will use the frame width. + * @param height The height of the Body in pixels. Cannot be zero. If not given, and the parent Game Object has a frame, it will use the frame height. + * @param center Modify the Body's `offset`, placing the Body's center on its Game Object's center. Only works if the Game Object has the `getCenter` method. Default true. */ - setAngle(degrees?: number): this; + setSize(width?: number, height?: number, center?: boolean): Phaser.Physics.Arcade.Body; /** - * Sets the scale of this Game Object. - * @param x The horizontal scale of this Game Object. - * @param y The vertical scale of this Game Object. If not set it will use the `x` value. Default x. + * Sizes and positions this Body, as a circle. + * @param radius The radius of the Body, in source pixels. + * @param offsetX The horizontal offset of the Body from its Game Object, in source pixels. + * @param offsetY The vertical offset of the Body from its Game Object, in source pixels. */ - setScale(x: number, y?: number): this; + setCircle(radius: number, offsetX?: number, offsetY?: number): Phaser.Physics.Arcade.Body; /** - * Sets the x position of this Game Object. - * @param value The x position of this Game Object. Default 0. + * Sets this Body's parent Game Object to the given coordinates and resets this Body at the new coordinates. + * If the Body had any velocity or acceleration it is lost as a result of calling this. + * @param x The horizontal position to place the Game Object. + * @param y The vertical position to place the Game Object. */ - setX(value?: number): this; + reset(x: number, y: number): void; /** - * Sets the y position of this Game Object. - * @param value The y position of this Game Object. Default 0. + * Sets acceleration, velocity, and speed to zero. */ - setY(value?: number): this; + stop(): Phaser.Physics.Arcade.Body; /** - * Sets the z position of this Game Object. - * - * Note: The z position does not control the rendering order of 2D Game Objects. Use - * {@link Phaser.GameObjects.Components.Depth#setDepth} instead. - * @param value The z position of this Game Object. Default 0. + * Copies the coordinates of this Body's edges into an object. + * @param obj An object to copy the values into. */ - setZ(value?: number): this; + getBounds(obj: Phaser.Types.Physics.Arcade.ArcadeBodyBounds): Phaser.Types.Physics.Arcade.ArcadeBodyBounds; /** - * Sets the w position of this Game Object. - * @param value The w position of this Game Object. Default 0. + * Tests if the coordinates are within this Body. + * @param x The horizontal coordinate. + * @param y The vertical coordinate. */ - setW(value?: number): this; + hitTest(x: number, y: number): boolean; /** - * Gets the local transform matrix for this Game Object. - * @param tempMatrix The matrix to populate with the values from this Game Object. + * Whether this Body is touching a tile or the world boundary while moving down. */ - getLocalTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + onFloor(): boolean; /** - * Gets the world transform matrix for this Game Object, factoring in any parent Containers. - * @param tempMatrix The matrix to populate with the values from this Game Object. - * @param parentMatrix A temporary matrix to hold parent values during the calculations. + * Whether this Body is touching a tile or the world boundary while moving up. */ - getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + onCeiling(): boolean; /** - * Gets the sum total rotation of all of this Game Objects parent Containers. + * Whether this Body is touching a tile or the world boundary while moving left or right. + */ + onWall(): boolean; + + /** + * The absolute (non-negative) change in this Body's horizontal position from the previous step. + */ + deltaAbsX(): number; + + /** + * The absolute (non-negative) change in this Body's vertical position from the previous step. + */ + deltaAbsY(): number; + + /** + * The change in this Body's horizontal position from the previous step. + * This value is set during the Body's update phase. * - * The returned value is in radians and will be zero if this Game Object has no parent container. + * As a Body can update multiple times per step this may not hold the final + * delta value for the Body. In this case, please see the `deltaXFinal` method. */ - getParentRotation(): number; + deltaX(): number; /** - * The visible state of the Game Object. + * The change in this Body's vertical position from the previous step. + * This value is set during the Body's update phase. * - * An invisible Game Object will skip rendering, but will still process update logic. + * As a Body can update multiple times per step this may not hold the final + * delta value for the Body. In this case, please see the `deltaYFinal` method. */ - visible: boolean; + deltaY(): number; /** - * Sets the visibility of this Game Object. + * The change in this Body's horizontal position from the previous game update. * - * An invisible Game Object will skip rendering, but will still process update logic. - * @param value The visible state of the Game Object. + * This value is set during the `postUpdate` phase and takes into account the + * `deltaMax` and final position of the Body. + * + * Because this value is not calculated until `postUpdate`, you must listen for it + * during a Scene `POST_UPDATE` or `RENDER` event, and not in `update`, as it will + * not be calculated by that point. If you _do_ use these values in `update` they + * will represent the delta from the _previous_ game frame. */ - setVisible(value: boolean): this; + deltaXFinal(): number; + + /** + * The change in this Body's vertical position from the previous game update. + * + * This value is set during the `postUpdate` phase and takes into account the + * `deltaMax` and final position of the Body. + * + * Because this value is not calculated until `postUpdate`, you must listen for it + * during a Scene `POST_UPDATE` or `RENDER` event, and not in `update`, as it will + * not be calculated by that point. If you _do_ use these values in `update` they + * will represent the delta from the _previous_ game frame. + */ + deltaYFinal(): number; + + /** + * The change in this Body's rotation from the previous step, in degrees. + */ + deltaZ(): number; /** - * Sets the horizontal acceleration of this body. - * @param x The amount of acceleration to apply. + * Disables this Body and marks it for deletion by the simulation. */ - setAccelerationX(x: number): this; + destroy(): void; /** - * Sets the vertical acceleration of this body. - * @param y The amount of acceleration to apply. + * Draws this Body and its velocity, if enabled. + * @param graphic The Graphics object to draw on. */ - setAccelerationY(y: number): this; + drawDebug(graphic: Phaser.GameObjects.Graphics): void; /** - * Sets the horizontal and vertical acceleration of this body. - * @param x The amount of horizontal acceleration to apply. - * @param y The amount of vertical acceleration to apply. + * Whether this Body will be drawn to the debug display. */ - setAcceleration(x: number, y: number): this; + willDrawDebug(): boolean; /** - * Sets the size of the physics body. - * @param width The width of the body in pixels. - * @param height The height of the body in pixels. Default width. + * Sets whether this Body collides with the world boundary. + * + * Optionally also sets the World Bounce and `onWorldBounds` values. + * @param value `true` if the Body should collide with the world bounds, otherwise `false`. Default true. + * @param bounceX If given this replaces the Body's `worldBounce.x` value. + * @param bounceY If given this replaces the Body's `worldBounce.y` value. + * @param onWorldBounds If given this replaces the Body's `onWorldBounds` value. */ - setBodySize(width: number, height?: number): this; + setCollideWorldBounds(value?: boolean, bounceX?: number, bounceY?: number, onWorldBounds?: boolean): Phaser.Physics.Arcade.Body; /** - * Sets the scale of the physics body. - * @param scaleX The horizontal scale of the body. - * @param scaleY The vertical scale of the body. If not given, will use the horizontal scale value. + * Sets the Body's velocity. + * @param x The horizontal velocity, in pixels per second. + * @param y The vertical velocity, in pixels per second. Default x. */ - setBodyScale(scaleX: number, scaleY?: number): this; + setVelocity(x: number, y?: number): Phaser.Physics.Arcade.Body; /** - * [description] + * Sets the Body's horizontal velocity. + * @param value The velocity, in pixels per second. */ - getBodyType(): number; + setVelocityX(value: number): Phaser.Physics.Arcade.Body; /** - * [description] + * Sets the Body's vertical velocity. + * @param value The velocity, in pixels per second. */ - setTypeNone(): Phaser.GameObjects.GameObject; + setVelocityY(value: number): Phaser.Physics.Arcade.Body; /** - * [description] + * Sets the Body's maximum velocity. + * @param x The horizontal velocity, in pixels per second. + * @param y The vertical velocity, in pixels per second. Default x. */ - setTypeA(): Phaser.GameObjects.GameObject; + setMaxVelocity(x: number, y?: number): Phaser.Physics.Arcade.Body; /** - * [description] + * Sets the Body's maximum horizontal velocity. + * @param value The maximum horizontal velocity, in pixels per second. */ - setTypeB(): Phaser.GameObjects.GameObject; + setMaxVelocityX(value: number): Phaser.Physics.Arcade.Body; /** - * Sets the impact physics bounce, or restitution, value. - * @param value A value between 0 (no rebound) and 1 (full rebound) + * Sets the Body's maximum vertical velocity. + * @param value The maximum vertical velocity, in pixels per second. */ - setBounce(value: number): Phaser.GameObjects.GameObject; + setMaxVelocityY(value: number): Phaser.Physics.Arcade.Body; /** - * Sets the minimum velocity the body is allowed to be moving to be considered for rebound. - * @param value The minimum allowed velocity. + * Sets the maximum speed the Body can move. + * @param value The maximum speed value, in pixels per second. Set to a negative value to disable. */ - setMinBounceVelocity(value: number): Phaser.GameObjects.GameObject; + setMaxSpeed(value: number): Phaser.Physics.Arcade.Body; /** - * The bounce, or restitution, value of this body. - * A value between 0 (no rebound) and 1 (full rebound) + * Sets the Body's bounce. + * @param x The horizontal bounce, relative to 1. + * @param y The vertical bounce, relative to 1. */ - bounce: number; + setBounce(x: number, y: number): Phaser.Physics.Arcade.Body; + + /** + * Sets the Body's horizontal bounce. + * @param value The bounce, relative to 1. + */ + setBounceX(value: number): Phaser.Physics.Arcade.Body; /** - * [description] + * Sets the Body's vertical bounce. + * @param value The bounce, relative to 1. */ - setAvsB(): Phaser.GameObjects.GameObject; + setBounceY(value: number): Phaser.Physics.Arcade.Body; /** - * [description] + * Sets the Body's acceleration. + * @param x The horizontal component, in pixels per second squared. + * @param y The vertical component, in pixels per second squared. */ - setBvsA(): Phaser.GameObjects.GameObject; + setAcceleration(x: number, y: number): Phaser.Physics.Arcade.Body; /** - * [description] + * Sets the Body's horizontal acceleration. + * @param value The acceleration, in pixels per second squared. */ - setCheckAgainstNone(): Phaser.GameObjects.GameObject; + setAccelerationX(value: number): Phaser.Physics.Arcade.Body; /** - * [description] + * Sets the Body's vertical acceleration. + * @param value The acceleration, in pixels per second squared. */ - setCheckAgainstA(): Phaser.GameObjects.GameObject; + setAccelerationY(value: number): Phaser.Physics.Arcade.Body; /** - * [description] + * Enables or disables drag. + * @param value `true` to allow drag on this body, or `false` to disable it. Default true. */ - setCheckAgainstB(): Phaser.GameObjects.GameObject; + setAllowDrag(value?: boolean): Phaser.Physics.Arcade.Body; /** - * [description] + * Enables or disables gravity's effect on this Body. + * @param value `true` to allow gravity on this body, or `false` to disable it. Default true. */ - checkAgainst: number; + setAllowGravity(value?: boolean): Phaser.Physics.Arcade.Body; /** - * [description] - * @param callback [description] - * @param scope [description] + * Enables or disables rotation. + * @param value `true` to allow rotation on this body, or `false` to disable it. Default true. */ - setCollideCallback(callback: CollideCallback, scope: any): Phaser.GameObjects.GameObject; + setAllowRotation(value?: boolean): Phaser.Physics.Arcade.Body; /** - * [description] + * Sets the Body's drag. + * @param x The horizontal component, in pixels per second squared. + * @param y The vertical component, in pixels per second squared. */ - setCollidesNever(): Phaser.GameObjects.GameObject; + setDrag(x: number, y: number): Phaser.Physics.Arcade.Body; /** - * [description] + * If this Body is using `drag` for deceleration this property controls how the drag is applied. + * If set to `true` drag will use a damping effect rather than a linear approach. If you are + * creating a game where the Body moves freely at any angle (i.e. like the way the ship moves in + * the game Asteroids) then you will get a far smoother and more visually correct deceleration + * by using damping, avoiding the axis-drift that is prone with linear deceleration. + * + * If you enable this property then you should use far smaller `drag` values than with linear, as + * they are used as a multiplier on the velocity. Values such as 0.95 will give a nice slow + * deceleration, where-as smaller values, such as 0.5 will stop an object almost immediately. + * @param value `true` to use damping, or `false` to use drag. */ - setLiteCollision(): Phaser.GameObjects.GameObject; + setDamping(value: boolean): Phaser.Physics.Arcade.Body; /** - * [description] + * Sets the Body's horizontal drag. + * @param value The drag, in pixels per second squared. */ - setPassiveCollision(): Phaser.GameObjects.GameObject; + setDragX(value: number): Phaser.Physics.Arcade.Body; /** - * [description] + * Sets the Body's vertical drag. + * @param value The drag, in pixels per second squared. */ - setActiveCollision(): Phaser.GameObjects.GameObject; + setDragY(value: number): Phaser.Physics.Arcade.Body; /** - * [description] + * Sets the Body's gravity. + * @param x The horizontal component, in pixels per second squared. + * @param y The vertical component, in pixels per second squared. */ - setFixedCollision(): Phaser.GameObjects.GameObject; + setGravity(x: number, y: number): Phaser.Physics.Arcade.Body; /** - * [description] + * Sets the Body's horizontal gravity. + * @param value The gravity, in pixels per second squared. */ - collides: number; + setGravityX(value: number): Phaser.Physics.Arcade.Body; /** - * [description] - * @param showBody [description] - * @param showVelocity [description] - * @param bodyColor [description] + * Sets the Body's vertical gravity. + * @param value The gravity, in pixels per second squared. */ - setDebug(showBody: boolean, showVelocity: boolean, bodyColor: number): Phaser.GameObjects.GameObject; + setGravityY(value: number): Phaser.Physics.Arcade.Body; /** - * [description] - * @param value [description] + * Sets the Body's friction. + * @param x The horizontal component, relative to 1. + * @param y The vertical component, relative to 1. */ - setDebugBodyColor(value: number): Phaser.GameObjects.GameObject; + setFriction(x: number, y: number): Phaser.Physics.Arcade.Body; /** - * [description] + * Sets the Body's horizontal friction. + * @param value The friction value, relative to 1. */ - debugShowBody: boolean; + setFrictionX(value: number): Phaser.Physics.Arcade.Body; + + /** + * Sets the Body's vertical friction. + * @param value The friction value, relative to 1. + */ + setFrictionY(value: number): Phaser.Physics.Arcade.Body; /** - * [description] + * Sets the Body's angular velocity. + * @param value The velocity, in degrees per second. */ - debugShowVelocity: boolean; + setAngularVelocity(value: number): Phaser.Physics.Arcade.Body; /** - * [description] + * Sets the Body's angular acceleration. + * @param value The acceleration, in degrees per second squared. */ - debugBodyColor: number; + setAngularAcceleration(value: number): Phaser.Physics.Arcade.Body; /** - * [description] - * @param x [description] + * Sets the Body's angular drag. + * @param value The drag, in degrees per second squared. */ - setFrictionX(x: number): Phaser.GameObjects.GameObject; + setAngularDrag(value: number): Phaser.Physics.Arcade.Body; /** - * [description] - * @param y [description] + * Sets the Body's mass. + * @param value The mass value, relative to 1. */ - setFrictionY(y: number): Phaser.GameObjects.GameObject; + setMass(value: number): Phaser.Physics.Arcade.Body; /** - * [description] - * @param x [description] - * @param y [description] + * Sets the Body's `immovable` property. + * @param value The value to assign to `immovable`. Default true. */ - setFriction(x: number, y: number): Phaser.GameObjects.GameObject; + setImmovable(value?: boolean): Phaser.Physics.Arcade.Body; /** - * [description] - * @param value [description] + * Sets the Body's `enable` property. + * @param value The value to assign to `enable`. Default true. */ - setGravity(value: number): Phaser.GameObjects.GameObject; + setEnable(value?: boolean): Phaser.Physics.Arcade.Body; /** - * [description] + * This is an internal handler, called by the `ProcessX` function as part + * of the collision step. You should almost never call this directly. + * @param x The amount to add to the Body position. + * @param vx The amount to add to the Body velocity. + * @param left Set the blocked.left value? + * @param right Set the blocked.right value? */ - gravity: number; + processX(x: number, vx?: number, left?: boolean, right?: boolean): void; /** - * [description] - * @param x [description] - * @param y [description] - * @param width [description] - * @param height [description] + * This is an internal handler, called by the `ProcessY` function as part + * of the collision step. You should almost never call this directly. + * @param y The amount to add to the Body position. + * @param vy The amount to add to the Body velocity. + * @param up Set the blocked.up value? + * @param down Set the blocked.down value? */ - setOffset(x: number, y: number, width?: number, height?: number): Phaser.GameObjects.GameObject; + processY(y: number, vy?: number, up?: boolean, down?: boolean): void; /** - * [description] - * @param gameObject [description] - * @param sync [description] Default true. + * The Bodys horizontal position (left edge). */ - setGameObject(gameObject: Phaser.GameObjects.GameObject, sync?: boolean): Phaser.GameObjects.GameObject; + x: number; /** - * [description] + * The Bodys vertical position (top edge). */ - syncGameObject(): Phaser.GameObjects.GameObject; + y: number; /** - * Sets the horizontal velocity of the physics body. - * @param x The horizontal velocity value. + * The left edge of the Body. Identical to x. */ - setVelocityX(x: number): this; + readonly left: number; /** - * Sets the vertical velocity of the physics body. - * @param y The vertical velocity value. + * The right edge of the Body. */ - setVelocityY(y: number): this; + readonly right: number; /** - * Sets the horizontal and vertical velocities of the physics body. - * @param x The horizontal velocity value. - * @param y The vertical velocity value. If not given, defaults to the horizontal value. Default x. + * The top edge of the Body. Identical to y. */ - setVelocity(x: number, y?: number): this; + readonly top: number; /** - * Sets the maximum velocity this body can travel at. - * @param x The maximum allowed horizontal velocity. - * @param y The maximum allowed vertical velocity. If not given, defaults to the horizontal value. Default x. + * The bottom edge of this Body. */ - setMaxVelocity(x: number, y?: number): this; + readonly bottom: number; } /** - * [description] + * An Arcade Physics Collider will automatically check for collision, or overlaps, between two objects + * every step. If a collision, or overlap, occurs it will invoke the given callbacks. */ - class ImpactPhysics { + class Collider { /** * - * @param scene [description] + * @param world The Arcade physics World that will manage the collisions. + * @param overlapOnly Whether to check for collisions or overlap. + * @param object1 The first object to check for collision. + * @param object2 The second object to check for collision. + * @param collideCallback The callback to invoke when the two objects collide. + * @param processCallback The callback to invoke when the two objects collide. Must return a boolean. + * @param callbackContext The scope in which to call the callbacks. */ - constructor(scene: Phaser.Scene); + constructor(world: Phaser.Physics.Arcade.World, overlapOnly: boolean, object1: Phaser.Types.Physics.Arcade.ArcadeColliderType, object2: Phaser.Types.Physics.Arcade.ArcadeColliderType, collideCallback: ArcadePhysicsCallback, processCallback: ArcadePhysicsCallback, callbackContext: any); /** - * [description] + * The world in which the bodies will collide. */ - scene: Phaser.Scene; + world: Phaser.Physics.Arcade.World; /** - * [description] + * The name of the collider (unused by Phaser). */ - systems: Phaser.Scenes.Systems; + name: string; /** - * [description] + * Whether the collider is active. */ - config: object; + active: boolean; + + /** + * Whether to check for collisions or overlaps. + */ + overlapOnly: boolean; /** - * [description] + * The first object to check for collision. */ - world: Phaser.Physics.Impact.World; + object1: Phaser.Types.Physics.Arcade.ArcadeColliderType; /** - * [description] + * The second object to check for collision. */ - add: Phaser.Physics.Impact.Factory; + object2: Phaser.Types.Physics.Arcade.ArcadeColliderType; /** - * [description] + * The callback to invoke when the two objects collide. */ - getConfig(): object; + collideCallback: ArcadePhysicsCallback; /** - * [description] + * If a processCallback exists it must return true or collision checking will be skipped. */ - pause(): Phaser.Physics.Impact.World; + processCallback: ArcadePhysicsCallback; /** - * [description] + * The context the collideCallback and processCallback will run in. */ - resume(): Phaser.Physics.Impact.World; - - } + callbackContext: object; - /** - * An Impact Physics Sprite Game Object. - * - * A Sprite Game Object is used for the display of both static and animated images in your game. - * Sprites can have input events and physics bodies. They can also be tweened, tinted, scrolled - * and animated. - * - * The main difference between a Sprite and an Image Game Object is that you cannot animate Images. - * As such, Sprites take a fraction longer to process and have a larger API footprint due to the Animation - * Component. If you do not require animation then you can safely use Images to replace Sprites in all cases. - */ - class ImpactSprite extends Phaser.GameObjects.Sprite implements Phaser.Physics.Impact.Components.Acceleration, Phaser.Physics.Impact.Components.BodyScale, Phaser.Physics.Impact.Components.BodyType, Phaser.Physics.Impact.Components.Bounce, Phaser.Physics.Impact.Components.CheckAgainst, Phaser.Physics.Impact.Components.Collides, Phaser.Physics.Impact.Components.Debug, Phaser.Physics.Impact.Components.Friction, Phaser.Physics.Impact.Components.Gravity, Phaser.Physics.Impact.Components.Offset, Phaser.Physics.Impact.Components.SetGameObject, Phaser.Physics.Impact.Components.Velocity, Phaser.GameObjects.Components.Alpha, Phaser.GameObjects.Components.BlendMode, Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.Flip, Phaser.GameObjects.Components.GetBounds, Phaser.GameObjects.Components.Origin, Phaser.GameObjects.Components.Pipeline, Phaser.GameObjects.Components.ScrollFactor, Phaser.GameObjects.Components.Size, Phaser.GameObjects.Components.Texture, Phaser.GameObjects.Components.Tint, Phaser.GameObjects.Components.Transform, Phaser.GameObjects.Components.Visible { /** + * A name for the Collider. * - * @param world [description] - * @param x The horizontal position of this Game Object in the world. - * @param y The vertical position of this Game Object in the world. - * @param texture The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. - * @param frame An optional frame from the Texture this Game Object is rendering with. + * Phaser does not use this value, it's for your own reference. + * @param name The name to assign to the Collider. */ - constructor(world: Phaser.Physics.Impact.World, x: number, y: number, texture: string, frame?: string | integer); + setName(name: string): Phaser.Physics.Arcade.Collider; /** - * [description] + * Called by World as part of its step processing, initial operation of collision checking. */ - body: Phaser.Physics.Impact.Body; + update(): void; /** - * [description] + * Removes Collider from World and disposes of its resources. */ - size: Object; + destroy(): void; - /** - * [description] - */ - offset: Object; + } + namespace Components { /** - * [description] + * Provides methods used for setting the acceleration properties of an Arcade Physics Body. */ - vel: Object; + interface Acceleration { + /** + * Sets the body's horizontal and vertical acceleration. If the vertical acceleration value is not provided, the vertical acceleration is set to the same value as the horizontal acceleration. + * @param x The horizontal acceleration + * @param y The vertical acceleration Default x. + */ + setAcceleration(x: number, y?: number): this; + /** + * Sets the body's horizontal acceleration. + * @param value The horizontal acceleration + */ + setAccelerationX(value: number): this; + /** + * Sets the body's vertical acceleration. + * @param value The vertical acceleration + */ + setAccelerationY(value: number): this; + } /** - * [description] + * Provides methods used for setting the angular acceleration properties of an Arcade Physics Body. */ - accel: Object; + interface Angular { + /** + * Sets the angular velocity of the body. + * + * In Arcade Physics, bodies cannot rotate. They are always axis-aligned. + * However, they can have angular motion, which is passed on to the Game Object bound to the body, + * causing them to visually rotate, even though the body remains axis-aligned. + * @param value The amount of angular velocity. + */ + setAngularVelocity(value: number): this; + /** + * Sets the angular acceleration of the body. + * + * In Arcade Physics, bodies cannot rotate. They are always axis-aligned. + * However, they can have angular motion, which is passed on to the Game Object bound to the body, + * causing them to visually rotate, even though the body remains axis-aligned. + * @param value The amount of angular acceleration. + */ + setAngularAcceleration(value: number): this; + /** + * Sets the angular drag of the body. Drag is applied to the current velocity, providing a form of deceleration. + * @param value The amount of drag. + */ + setAngularDrag(value: number): this; + } /** - * [description] + * Provides methods used for setting the bounce properties of an Arcade Physics Body. */ - friction: Object; + interface Bounce { + /** + * Sets the bounce values of this body. + * + * Bounce is the amount of restitution, or elasticity, the body has when it collides with another object. + * A value of 1 means that it will retain its full velocity after the rebound. A value of 0 means it will not rebound at all. + * @param x The amount of horizontal bounce to apply on collision. A float, typically between 0 and 1. + * @param y The amount of vertical bounce to apply on collision. A float, typically between 0 and 1. Default x. + */ + setBounce(x: number, y?: number): this; + /** + * Sets the horizontal bounce value for this body. + * @param value The amount of horizontal bounce to apply on collision. A float, typically between 0 and 1. + */ + setBounceX(value: number): this; + /** + * Sets the vertical bounce value for this body. + * @param value The amount of vertical bounce to apply on collision. A float, typically between 0 and 1. + */ + setBounceY(value: number): this; + /** + * Sets whether this Body collides with the world boundary. + * + * Optionally also sets the World Bounce values. If the `Body.worldBounce` is null, it's set to a new Phaser.Math.Vector2 first. + * @param value `true` if this body should collide with the world bounds, otherwise `false`. Default true. + * @param bounceX If given this will be replace the `worldBounce.x` value. + * @param bounceY If given this will be replace the `worldBounce.y` value. + */ + setCollideWorldBounds(value?: boolean, bounceX?: number, bounceY?: number): this; + } /** - * [description] + * Provides methods used for setting the debug properties of an Arcade Physics Body. */ - maxVel: Object; + interface Debug { + /** + * Sets the debug values of this body. + * + * Bodies will only draw their debug if debug has been enabled for Arcade Physics as a whole. + * Note that there is a performance cost in drawing debug displays. It should never be used in production. + * @param showBody Set to `true` to have this body render its outline to the debug display. + * @param showVelocity Set to `true` to have this body render a velocity marker to the debug display. + * @param bodyColor The color of the body outline when rendered to the debug display. + */ + setDebug(showBody: boolean, showVelocity: boolean, bodyColor: number): this; + /** + * Sets the color of the body outline when it renders to the debug display. + * @param value The color of the body outline when rendered to the debug display. + */ + setDebugBodyColor(value: number): this; + /** + * Set to `true` to have this body render its outline to the debug display. + */ + debugShowBody: boolean; + /** + * Set to `true` to have this body render a velocity marker to the debug display. + */ + debugShowVelocity: boolean; + /** + * The color of the body outline when it renders to the debug display. + */ + debugBodyColor: number; + } /** - * Clears all alpha values associated with this Game Object. - * - * Immediately sets the alpha levels back to 1 (fully opaque). + * Provides methods used for setting the drag properties of an Arcade Physics Body. */ - clearAlpha(): this; + interface Drag { + /** + * Sets the body's horizontal and vertical drag. If the vertical drag value is not provided, the vertical drag is set to the same value as the horizontal drag. + * + * Drag can be considered as a form of deceleration that will return the velocity of a body back to zero over time. + * It is the absolute loss of velocity due to movement, in pixels per second squared. + * The x and y components are applied separately. + * + * When `useDamping` is true, this is 1 minus the damping factor. + * A value of 1 means the Body loses no velocity. + * A value of 0.95 means the Body loses 5% of its velocity per step. + * A value of 0.5 means the Body loses 50% of its velocity per step. + * + * Drag is applied only when `acceleration` is zero. + * @param x The amount of horizontal drag to apply. + * @param y The amount of vertical drag to apply. Default x. + */ + setDrag(x: number, y?: number): this; + /** + * Sets the body's horizontal drag. + * + * Drag can be considered as a form of deceleration that will return the velocity of a body back to zero over time. + * It is the absolute loss of velocity due to movement, in pixels per second squared. + * The x and y components are applied separately. + * + * When `useDamping` is true, this is 1 minus the damping factor. + * A value of 1 means the Body loses no velocity. + * A value of 0.95 means the Body loses 5% of its velocity per step. + * A value of 0.5 means the Body loses 50% of its velocity per step. + * + * Drag is applied only when `acceleration` is zero. + * @param value The amount of horizontal drag to apply. + */ + setDragX(value: number): this; + /** + * Sets the body's vertical drag. + * + * Drag can be considered as a form of deceleration that will return the velocity of a body back to zero over time. + * It is the absolute loss of velocity due to movement, in pixels per second squared. + * The x and y components are applied separately. + * + * When `useDamping` is true, this is 1 minus the damping factor. + * A value of 1 means the Body loses no velocity. + * A value of 0.95 means the Body loses 5% of its velocity per step. + * A value of 0.5 means the Body loses 50% of its velocity per step. + * + * Drag is applied only when `acceleration` is zero. + * @param value The amount of vertical drag to apply. + */ + setDragY(value: number): this; + /** + * If this Body is using `drag` for deceleration this function controls how the drag is applied. + * If set to `true` drag will use a damping effect rather than a linear approach. If you are + * creating a game where the Body moves freely at any angle (i.e. like the way the ship moves in + * the game Asteroids) then you will get a far smoother and more visually correct deceleration + * by using damping, avoiding the axis-drift that is prone with linear deceleration. + * + * If you enable this property then you should use far smaller `drag` values than with linear, as + * they are used as a multiplier on the velocity. Values such as 0.95 will give a nice slow + * deceleration, where-as smaller values, such as 0.5 will stop an object almost immediately. + * @param value `true` to use damping for deceleration, or `false` to use linear deceleration. + */ + setDamping(value: boolean): this; + } /** - * Set the Alpha level of this Game Object. The alpha controls the opacity of the Game Object as it renders. - * Alpha values are provided as a float between 0, fully transparent, and 1, fully opaque. - * - * If your game is running under WebGL you can optionally specify four different alpha values, each of which - * correspond to the four corners of the Game Object. Under Canvas only the `topLeft` value given is used. - * @param topLeft The alpha value used for the top-left of the Game Object. If this is the only value given it's applied across the whole Game Object. Default 1. - * @param topRight The alpha value used for the top-right of the Game Object. WebGL only. - * @param bottomLeft The alpha value used for the bottom-left of the Game Object. WebGL only. - * @param bottomRight The alpha value used for the bottom-right of the Game Object. WebGL only. + * Provides methods used for setting the enable properties of an Arcade Physics Body. */ - setAlpha(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; + interface Enable { + /** + * Enables this Game Object's Body. + * @param reset Also reset the Body and place it at (x, y). + * @param x The horizontal position to place the Game Object and Body. + * @param y The horizontal position to place the Game Object and Body. + * @param enableGameObject Also activate this Game Object. + * @param showGameObject Also show this Game Object. + */ + enableBody(reset: boolean, x: number, y: number, enableGameObject: boolean, showGameObject: boolean): this; + /** + * Stops and disables this Game Object's Body. + * @param disableGameObject Also deactivate this Game Object. Default false. + * @param hideGameObject Also hide this Game Object. Default false. + */ + disableBody(disableGameObject?: boolean, hideGameObject?: boolean): this; + /** + * Syncs the Body's position and size with its parent Game Object. + * You don't need to call this for Dynamic Bodies, as it happens automatically. + * But for Static bodies it's a useful way of modifying the position of a Static Body + * in the Physics World, based on its Game Object. + */ + refreshBody(): this; + } /** - * The alpha value of the Game Object. + * Methods for setting the friction of an Arcade Physics Body. * - * This is a global value, impacting the entire Game Object, not just a region of it. - */ - alpha: number; - - /** - * The alpha value starting from the top-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * In Arcade Physics, friction is a special case of motion transfer from an "immovable" body to a riding body. */ - alphaTopLeft: number; + interface Friction { + /** + * Sets the friction of this game object's physics body. + * In Arcade Physics, friction is a special case of motion transfer from an "immovable" body to a riding body. + * @param x The amount of horizontal friction to apply, [0, 1]. + * @param y The amount of vertical friction to apply, [0, 1]. Default x. + */ + setFriction(x: number, y?: number): this; + /** + * Sets the horizontal friction of this game object's physics body. + * This can move a riding body horizontally when it collides with this one on the vertical axis. + * @param x The amount of friction to apply, [0, 1]. + */ + setFrictionX(x: number): this; + /** + * Sets the vertical friction of this game object's physics body. + * This can move a riding body vertically when it collides with this one on the horizontal axis. + * @param y The amount of friction to apply, [0, 1]. + */ + setFrictionY(y: number): this; + } /** - * The alpha value starting from the top-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * Provides methods for setting the gravity properties of an Arcade Physics Game Object. + * Should be applied as a mixin and not used directly. */ - alphaTopRight: number; + interface Gravity { + /** + * Set the X and Y values of the gravitational pull to act upon this Arcade Physics Game Object. Values can be positive or negative. Larger values result in a stronger effect. + * + * If only one value is provided, this value will be used for both the X and Y axis. + * @param x The gravitational force to be applied to the X-axis. + * @param y The gravitational force to be applied to the Y-axis. If this is not specified, the X value will be used. Default x. + */ + setGravity(x: number, y?: number): this; + /** + * Set the gravitational force to be applied to the X axis. Value can be positive or negative. Larger values result in a stronger effect. + * @param x The gravitational force to be applied to the X-axis. + */ + setGravityX(x: number): this; + /** + * Set the gravitational force to be applied to the Y axis. Value can be positive or negative. Larger values result in a stronger effect. + * @param y The gravitational force to be applied to the Y-axis. + */ + setGravityY(y: number): this; + } /** - * The alpha value starting from the bottom-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * Provides methods used for setting the immovable properties of an Arcade Physics Body. */ - alphaBottomLeft: number; + interface Immovable { + /** + * Sets if this Body can be separated during collisions with other bodies. + * + * When a body is immovable it means it won't move at all, not even to separate it from collision + * overlap. If you just wish to prevent a body from being knocked around by other bodies, see + * the `setPushable` method instead. + * @param value Sets if this body will be separated during collisions with other bodies. Default true. + */ + setImmovable(value?: boolean): this; + } /** - * The alpha value starting from the bottom-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * Provides methods used for setting the mass properties of an Arcade Physics Body. */ - alphaBottomRight: number; + interface Mass { + /** + * Sets the mass of the physics body + * @param value New value for the mass of the body. + */ + setMass(value: number): this; + } /** - * Sets the Blend Mode being used by this Game Object. - * - * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) - * - * Under WebGL only the following Blend Modes are available: - * - * * ADD - * * MULTIPLY - * * SCREEN - * * ERASE - * - * Canvas has more available depending on browser support. + * This method will search the given circular area and return an array of all physics bodies that + * overlap with it. It can return either Dynamic, Static bodies or a mixture of both. * - * You can also create your own custom Blend Modes in WebGL. + * A body only has to intersect with the search area to be considered, it doesn't have to be fully + * contained within it. * - * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending - * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these - * reasons try to be careful about the construction of your Scene and the frequency of which blend modes - * are used. + * If Arcade Physics is set to use the RTree (which it is by default) then the search is rather fast, + * otherwise the search is O(N) for Dynamic Bodies. */ - blendMode: Phaser.BlendModes | string; + interface OverlapCirc { + } /** - * Sets the Blend Mode being used by this Game Object. - * - * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) - * - * Under WebGL only the following Blend Modes are available: - * - * * ADD - * * MULTIPLY - * * SCREEN - * * ERASE (only works when rendering to a framebuffer, like a Render Texture) - * - * Canvas has more available depending on browser support. + * This method will search the given rectangular area and return an array of all physics bodies that + * overlap with it. It can return either Dynamic, Static bodies or a mixture of both. * - * You can also create your own custom Blend Modes in WebGL. + * A body only has to intersect with the search area to be considered, it doesn't have to be fully + * contained within it. * - * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending - * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these - * reasons try to be careful about the construction of your Scene and the frequency in which blend modes - * are used. - * @param value The BlendMode value. Either a string or a CONST. + * If Arcade Physics is set to use the RTree (which it is by default) then the search for is extremely fast, + * otherwise the search is O(N) for Dynamic Bodies. */ - setBlendMode(value: string | Phaser.BlendModes): this; + interface OverlapRect { + } /** - * The depth of this Game Object within the Scene. - * - * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order - * of Game Objects, without actually moving their position in the display list. - * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth - * value will always render in front of one with a lower value. - * - * Setting the depth will queue a depth sort event within the Scene. + * Provides methods used for setting the pushable property of an Arcade Physics Body. */ - depth: number; + interface Pushable { + /** + * Sets if this Body can be pushed by another Body. + * + * A body that cannot be pushed will reflect back all of the velocity it is given to the + * colliding body. If that body is also not pushable, then the separation will be split + * between them evenly. + * + * If you want your body to never move or seperate at all, see the `setImmovable` method. + * @param value Sets if this body can be pushed by collisions with another Body. Default true. + */ + setPushable(value?: boolean): this; + } /** - * The depth of this Game Object within the Scene. - * - * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order - * of Game Objects, without actually moving their position in the display list. - * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth - * value will always render in front of one with a lower value. - * - * Setting the depth will queue a depth sort event within the Scene. - * @param value The depth of this Game Object. + * Provides methods for setting the size of an Arcade Physics Game Object. + * Should be applied as a mixin and not used directly. */ - setDepth(value: integer): this; + interface Size { + /** + * Sets the body offset. This allows you to adjust the difference between the center of the body + * and the x and y coordinates of the parent Game Object. + * @param x The amount to offset the body from the parent Game Object along the x-axis. + * @param y The amount to offset the body from the parent Game Object along the y-axis. Defaults to the value given for the x-axis. Default x. + */ + setOffset(x: number, y?: number): this; + /** + * **DEPRECATED**: Please use `setBodySize` instead. + * + * Sets the size of this physics body. Setting the size does not adjust the dimensions of the parent Game Object. + * @param width The new width of the physics body, in pixels. + * @param height The new height of the physics body, in pixels. + * @param center Should the body be re-positioned so its center aligns with the parent Game Object? Default true. + */ + setSize(width: number, height: number, center?: boolean): this; + /** + * Sets the size of this physics body. Setting the size does not adjust the dimensions of the parent Game Object. + * @param width The new width of the physics body, in pixels. + * @param height The new height of the physics body, in pixels. + * @param center Should the body be re-positioned so its center aligns with the parent Game Object? Default true. + */ + setBodySize(width: number, height: number, center?: boolean): this; + /** + * Sets this physics body to use a circle for collision instead of a rectangle. + * @param radius The radius of the physics body, in pixels. + * @param offsetX The amount to offset the body from the parent Game Object along the x-axis. + * @param offsetY The amount to offset the body from the parent Game Object along the y-axis. + */ + setCircle(radius: number, offsetX?: number, offsetY?: number): this; + } /** - * The horizontally flipped state of the Game Object. + * Provides methods for modifying the velocity of an Arcade Physics body. * - * A Game Object that is flipped horizontally will render inversed on the horizontal axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * Should be applied as a mixin and not used directly. */ - flipX: boolean; + interface Velocity { + /** + * Sets the velocity of the Body. + * @param x The horizontal velocity of the body. Positive values move the body to the right, while negative values move it to the left. + * @param y The vertical velocity of the body. Positive values move the body down, while negative values move it up. Default x. + */ + setVelocity(x: number, y?: number): this; + /** + * Sets the horizontal component of the body's velocity. + * + * Positive values move the body to the right, while negative values move it to the left. + * @param x The new horizontal velocity. + */ + setVelocityX(x: number): this; + /** + * Sets the vertical component of the body's velocity. + * + * Positive values move the body down, while negative values move it up. + * @param y The new vertical velocity of the body. + */ + setVelocityY(y: number): this; + /** + * Sets the maximum velocity of the body. + * @param x The new maximum horizontal velocity. + * @param y The new maximum vertical velocity. Default x. + */ + setMaxVelocity(x: number, y?: number): this; + } + + } + + /** + * Dynamic Body. + */ + var DYNAMIC_BODY: number; + + /** + * Static Body. + */ + var STATIC_BODY: number; + + /** + * Arcade Physics Group containing Dynamic Bodies. + */ + var GROUP: number; + + /** + * A Tilemap Layer. + */ + var TILEMAPLAYER: number; + + /** + * Facing no direction (initial value). + */ + var FACING_NONE: number; + /** + * Facing up. + */ + var FACING_UP: number; + + /** + * Facing down. + */ + var FACING_DOWN: number; + + /** + * Facing left. + */ + var FACING_LEFT: number; + + /** + * Facing right. + */ + var FACING_RIGHT: number; + + namespace Events { /** - * The vertically flipped state of the Game Object. + * The Arcade Physics World Collide Event. * - * A Game Object that is flipped vertically will render inversed on the vertical axis (i.e. upside down) - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * This event is dispatched by an Arcade Physics World instance if two bodies collide _and_ at least + * one of them has their [onCollide]{@link Phaser.Physics.Arcade.Body#onCollide} property set to `true`. + * + * It provides an alternative means to handling collide events rather than using the callback approach. + * + * Listen to it from a Scene using: `this.physics.world.on('collide', listener)`. + * + * Please note that 'collide' and 'overlap' are two different things in Arcade Physics. */ - flipY: boolean; + const COLLIDE: any; /** - * Toggles the horizontal flipped state of this Game Object. + * The Arcade Physics World Overlap Event. * - * A Game Object that is flipped horizontally will render inversed on the horizontal axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * This event is dispatched by an Arcade Physics World instance if two bodies overlap _and_ at least + * one of them has their [onOverlap]{@link Phaser.Physics.Arcade.Body#onOverlap} property set to `true`. + * + * It provides an alternative means to handling overlap events rather than using the callback approach. + * + * Listen to it from a Scene using: `this.physics.world.on('overlap', listener)`. + * + * Please note that 'collide' and 'overlap' are two different things in Arcade Physics. */ - toggleFlipX(): this; + const OVERLAP: any; /** - * Toggles the vertical flipped state of this Game Object. + * The Arcade Physics World Pause Event. + * + * This event is dispatched by an Arcade Physics World instance when it is paused. + * + * Listen to it from a Scene using: `this.physics.world.on('pause', listener)`. */ - toggleFlipY(): this; + const PAUSE: any; /** - * Sets the horizontal flipped state of this Game Object. + * The Arcade Physics World Resume Event. * - * A Game Object that is flipped horizontally will render inversed on the horizontal axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. - * @param value The flipped state. `false` for no flip, or `true` to be flipped. + * This event is dispatched by an Arcade Physics World instance when it resumes from a paused state. + * + * Listen to it from a Scene using: `this.physics.world.on('resume', listener)`. */ - setFlipX(value: boolean): this; + const RESUME: any; /** - * Sets the vertical flipped state of this Game Object. - * @param value The flipped state. `false` for no flip, or `true` to be flipped. + * The Arcade Physics Tile Collide Event. + * + * This event is dispatched by an Arcade Physics World instance if a body collides with a Tile _and_ + * has its [onCollide]{@link Phaser.Physics.Arcade.Body#onCollide} property set to `true`. + * + * It provides an alternative means to handling collide events rather than using the callback approach. + * + * Listen to it from a Scene using: `this.physics.world.on('tilecollide', listener)`. + * + * Please note that 'collide' and 'overlap' are two different things in Arcade Physics. */ - setFlipY(value: boolean): this; + const TILE_COLLIDE: any; /** - * Sets the horizontal and vertical flipped state of this Game Object. + * The Arcade Physics Tile Overlap Event. * - * A Game Object that is flipped will render inversed on the flipped axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. - * @param x The horizontal flipped state. `false` for no flip, or `true` to be flipped. - * @param y The horizontal flipped state. `false` for no flip, or `true` to be flipped. + * This event is dispatched by an Arcade Physics World instance if a body overlaps with a Tile _and_ + * has its [onOverlap]{@link Phaser.Physics.Arcade.Body#onOverlap} property set to `true`. + * + * It provides an alternative means to handling overlap events rather than using the callback approach. + * + * Listen to it from a Scene using: `this.physics.world.on('tileoverlap', listener)`. + * + * Please note that 'collide' and 'overlap' are two different things in Arcade Physics. */ - setFlip(x: boolean, y: boolean): this; + const TILE_OVERLAP: any; /** - * Resets the horizontal and vertical flipped state of this Game Object back to their default un-flipped state. + * The Arcade Physics World Bounds Event. + * + * This event is dispatched by an Arcade Physics World instance if a body makes contact with the world bounds _and_ + * it has its [onWorldBounds]{@link Phaser.Physics.Arcade.Body#onWorldBounds} property set to `true`. + * + * It provides an alternative means to handling collide events rather than using the callback approach. + * + * Listen to it from a Scene using: `this.physics.world.on('worldbounds', listener)`. */ - resetFlip(): this; + const WORLD_BOUNDS: any; /** - * Gets the center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. + * The Arcade Physics World Step Event. + * + * This event is dispatched by an Arcade Physics World instance whenever a physics step is run. + * It is emitted _after_ the bodies and colliders have been updated. + * + * In high framerate settings this can be multiple times per game frame. + * + * Listen to it from a Scene using: `this.physics.world.on('worldstep', listener)`. */ - getCenter(output?: O): O; + const WORLD_STEP: any; - /** - * Gets the top-left corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. - */ - getTopLeft(output?: O, includeParent?: boolean): O; + } + /** + * The Arcade Physics Factory allows you to easily create Arcade Physics enabled Game Objects. + * Objects that are created by this Factory are automatically added to the physics world. + */ + class Factory { /** - * Gets the top-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * + * @param world The Arcade Physics World instance. */ - getTopCenter(output?: O, includeParent?: boolean): O; + constructor(world: Phaser.Physics.Arcade.World); /** - * Gets the top-right corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * A reference to the Arcade Physics World. */ - getTopRight(output?: O, includeParent?: boolean): O; + world: Phaser.Physics.Arcade.World; /** - * Gets the left-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * A reference to the Scene this Arcade Physics instance belongs to. */ - getLeftCenter(output?: O, includeParent?: boolean): O; + scene: Phaser.Scene; /** - * Gets the right-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * A reference to the Scene.Systems this Arcade Physics instance belongs to. */ - getRightCenter(output?: O, includeParent?: boolean): O; + sys: Phaser.Scenes.Systems; /** - * Gets the bottom-left corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * Creates a new Arcade Physics Collider object. + * @param object1 The first object to check for collision. + * @param object2 The second object to check for collision. + * @param collideCallback The callback to invoke when the two objects collide. + * @param processCallback The callback to invoke when the two objects collide. Must return a boolean. + * @param callbackContext The scope in which to call the callbacks. */ - getBottomLeft(output?: O, includeParent?: boolean): O; + collider(object1: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[] | Phaser.GameObjects.Group | Phaser.GameObjects.Group[], object2: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[] | Phaser.GameObjects.Group | Phaser.GameObjects.Group[], collideCallback?: ArcadePhysicsCallback, processCallback?: ArcadePhysicsCallback, callbackContext?: any): Phaser.Physics.Arcade.Collider; /** - * Gets the bottom-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * Creates a new Arcade Physics Collider Overlap object. + * @param object1 The first object to check for overlap. + * @param object2 The second object to check for overlap. + * @param collideCallback The callback to invoke when the two objects collide. + * @param processCallback The callback to invoke when the two objects collide. Must return a boolean. + * @param callbackContext The scope in which to call the callbacks. */ - getBottomCenter(output?: O, includeParent?: boolean): O; + overlap(object1: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[] | Phaser.GameObjects.Group | Phaser.GameObjects.Group[], object2: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[] | Phaser.GameObjects.Group | Phaser.GameObjects.Group[], collideCallback?: ArcadePhysicsCallback, processCallback?: ArcadePhysicsCallback, callbackContext?: any): Phaser.Physics.Arcade.Collider; /** - * Gets the bottom-right corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * Adds an Arcade Physics Body to the given Game Object. + * @param gameObject A Game Object. + * @param isStatic Create a Static body (true) or Dynamic body (false). Default false. */ - getBottomRight(output?: O, includeParent?: boolean): O; + existing(gameObject: G, isStatic?: boolean): G; /** - * Gets the bounds of this Game Object, regardless of origin. - * The values are stored and returned in a Rectangle, or Rectangle-like, object. - * @param output An object to store the values in. If not provided a new Rectangle will be created. + * Creates a new Arcade Image object with a Static body. + * @param x The horizontal position of this Game Object in the world. + * @param y The vertical position of this Game Object in the world. + * @param texture The key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager. + * @param frame An optional frame from the Texture this Game Object is rendering with. */ - getBounds(output?: O): O; + staticImage(x: number, y: number, texture: string | Phaser.Textures.Texture, frame?: string | number): Phaser.Types.Physics.Arcade.ImageWithStaticBody; /** - * The Mask this Game Object is using during render. + * Creates a new Arcade Image object with a Dynamic body. + * @param x The horizontal position of this Game Object in the world. + * @param y The vertical position of this Game Object in the world. + * @param texture The key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager. + * @param frame An optional frame from the Texture this Game Object is rendering with. */ - mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask; + image(x: number, y: number, texture: string | Phaser.Textures.Texture, frame?: string | number): Phaser.Types.Physics.Arcade.ImageWithDynamicBody; /** - * Sets the mask that this Game Object will use to render with. - * - * The mask must have been previously created and can be either a GeometryMask or a BitmapMask. - * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. - * - * If a mask is already set on this Game Object it will be immediately replaced. - * - * Masks are positioned in global space and are not relative to the Game Object to which they - * are applied. The reason for this is that multiple Game Objects can all share the same mask. - * - * Masks have no impact on physics or input detection. They are purely a rendering component - * that allows you to limit what is visible during the render pass. - * @param mask The mask this Game Object will use when rendering. + * Creates a new Arcade Sprite object with a Static body. + * @param x The horizontal position of this Game Object in the world. + * @param y The vertical position of this Game Object in the world. + * @param texture The key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager. + * @param frame An optional frame from the Texture this Game Object is rendering with. */ - setMask(mask: Phaser.Display.Masks.BitmapMask | Phaser.Display.Masks.GeometryMask): this; + staticSprite(x: number, y: number, texture: string | Phaser.Textures.Texture, frame?: string | number): Phaser.Types.Physics.Arcade.SpriteWithStaticBody; /** - * Clears the mask that this Game Object was using. - * @param destroyMask Destroy the mask before clearing it? Default false. + * Creates a new Arcade Sprite object with a Dynamic body. + * @param x The horizontal position of this Game Object in the world. + * @param y The vertical position of this Game Object in the world. + * @param key The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. + * @param frame An optional frame from the Texture this Game Object is rendering with. */ - clearMask(destroyMask?: boolean): this; + sprite(x: number, y: number, key: string, frame?: string | number): Phaser.Types.Physics.Arcade.SpriteWithDynamicBody; /** - * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, - * including this one. - * - * To create the mask you need to pass in a reference to a renderable Game Object. - * A renderable Game Object is one that uses a texture to render with, such as an - * Image, Sprite, Render Texture or BitmapText. - * - * If you do not provide a renderable object, and this Game Object has a texture, - * it will use itself as the object. This means you can call this method to create - * a Bitmap Mask from any renderable Game Object. - * @param renderable A renderable Game Object that uses a texture, such as a Sprite. + * Creates a Static Physics Group object. + * All Game Objects created by this Group will automatically be static Arcade Physics objects. + * @param children Game Objects to add to this group; or the `config` argument. + * @param config Settings for this group. */ - createBitmapMask(renderable?: Phaser.GameObjects.GameObject): Phaser.Display.Masks.BitmapMask; + staticGroup(children?: Phaser.GameObjects.GameObject[] | Phaser.Types.GameObjects.Group.GroupConfig | Phaser.Types.GameObjects.Group.GroupCreateConfig, config?: Phaser.Types.GameObjects.Group.GroupConfig | Phaser.Types.GameObjects.Group.GroupCreateConfig): Phaser.Physics.Arcade.StaticGroup; /** - * Creates and returns a Geometry Mask. This mask can be used by any Game Object, - * including this one. - * - * To create the mask you need to pass in a reference to a Graphics Game Object. - * - * If you do not provide a graphics object, and this Game Object is an instance - * of a Graphics object, then it will use itself to create the mask. - * - * This means you can call this method to create a Geometry Mask from any Graphics Game Object. - * @param graphics A Graphics Game Object. The geometry within it will be used as the mask. + * Creates a Physics Group object. + * All Game Objects created by this Group will automatically be dynamic Arcade Physics objects. + * @param children Game Objects to add to this group; or the `config` argument. + * @param config Settings for this group. */ - createGeometryMask(graphics?: Phaser.GameObjects.Graphics): Phaser.Display.Masks.GeometryMask; + group(children?: Phaser.GameObjects.GameObject[] | Phaser.Types.Physics.Arcade.PhysicsGroupConfig | Phaser.Types.GameObjects.Group.GroupCreateConfig, config?: Phaser.Types.Physics.Arcade.PhysicsGroupConfig | Phaser.Types.GameObjects.Group.GroupCreateConfig): Phaser.Physics.Arcade.Group; /** - * The horizontal origin of this Game Object. - * The origin maps the relationship between the size and position of the Game Object. - * The default value is 0.5, meaning all Game Objects are positioned based on their center. - * Setting the value to 0 means the position now relates to the left of the Game Object. + * Destroys this Factory. */ - originX: number; + destroy(): void; - /** - * The vertical origin of this Game Object. - * The origin maps the relationship between the size and position of the Game Object. - * The default value is 0.5, meaning all Game Objects are positioned based on their center. - * Setting the value to 0 means the position now relates to the top of the Game Object. - */ - originY: number; + } - /** - * The horizontal display origin of this Game Object. - * The origin is a normalized value between 0 and 1. - * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. - */ - displayOriginX: number; + /** + * Calculates and returns the horizontal overlap between two arcade physics bodies and sets their properties + * accordingly, including: `touching.left`, `touching.right`, `touching.none` and `overlapX'. + * @param body1 The first Body to separate. + * @param body2 The second Body to separate. + * @param overlapOnly Is this an overlap only check, or part of separation? + * @param bias A value added to the delta values during collision checks. Increase it to prevent sprite tunneling(sprites passing through another instead of colliding). + */ + function GetOverlapX(body1: Phaser.Physics.Arcade.Body, body2: Phaser.Physics.Arcade.Body, overlapOnly: boolean, bias: number): number; - /** - * The vertical display origin of this Game Object. - * The origin is a normalized value between 0 and 1. - * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. - */ - displayOriginY: number; + /** + * Calculates and returns the vertical overlap between two arcade physics bodies and sets their properties + * accordingly, including: `touching.up`, `touching.down`, `touching.none` and `overlapY'. + * @param body1 The first Body to separate. + * @param body2 The second Body to separate. + * @param overlapOnly Is this an overlap only check, or part of separation? + * @param bias A value added to the delta values during collision checks. Increase it to prevent sprite tunneling(sprites passing through another instead of colliding). + */ + function GetOverlapY(body1: Phaser.Physics.Arcade.Body, body2: Phaser.Physics.Arcade.Body, overlapOnly: boolean, bias: number): number; + /** + * 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 {@link Phaser.Physics.Arcade.Group#defaults 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 {@link Phaser.Physics.Arcade.StaticGroup}. + */ + class Group extends Phaser.GameObjects.Group { /** - * Sets the origin of this Game Object. * - * The values are given in the range 0 to 1. - * @param x The horizontal origin value. Default 0.5. - * @param y The vertical origin value. If not defined it will be set to the value of `x`. Default x. + * @param world The physics simulation. + * @param scene The scene this group belongs to. + * @param children Game Objects to add to this group; or the `config` argument. + * @param config Settings for this group. */ - setOrigin(x?: number, y?: number): this; + constructor(world: Phaser.Physics.Arcade.World, scene: Phaser.Scene, children?: Phaser.GameObjects.GameObject[] | Phaser.Types.Physics.Arcade.PhysicsGroupConfig | Phaser.Types.GameObjects.Group.GroupCreateConfig, config?: Phaser.Types.Physics.Arcade.PhysicsGroupConfig | Phaser.Types.GameObjects.Group.GroupCreateConfig); /** - * Sets the origin of this Game Object based on the Pivot values in its Frame. + * The physics simulation. */ - setOriginFromFrame(): this; + world: Phaser.Physics.Arcade.World; /** - * Sets the display origin of this Game Object. - * The difference between this and setting the origin is that you can use pixel values for setting the display origin. - * @param x The horizontal display origin value. Default 0. - * @param y The vertical display origin value. If not defined it will be set to the value of `x`. Default x. + * 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. */ - setDisplayOrigin(x?: number, y?: number): this; + classType: Function; /** - * Updates the Display Origin cached values internally stored on this Game Object. - * You don't usually call this directly, but it is exposed for edge-cases where you may. + * The physics type of the Group's members. */ - updateDisplayOrigin(): this; + physicsType: number; /** - * The initial WebGL pipeline of this Game Object. + * 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 `{}`. */ - defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; + defaults: Phaser.Types.Physics.Arcade.PhysicsGroupDefaults; /** - * The current WebGL pipeline of this Game Object. + * A textual representation of this Game Object. + * Used internally by Phaser but is available for your own custom classes to populate. */ - pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + type: string; /** - * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. + * Enables a Game Object's Body and assigns `defaults`. Called when a Group member is added or created. + * @param child The Game Object being added. */ - initPipeline(pipelineName?: string): boolean; + createCallbackHandler(child: Phaser.GameObjects.GameObject): void; /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. + * Disables a Game Object's Body. Called when a Group member is removed. + * @param child The Game Object being removed. */ - setPipeline(pipelineName: string): this; + removeCallbackHandler(child: Phaser.GameObjects.GameObject): void; /** - * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * Sets the velocity of each Group member. + * @param x The horizontal velocity. + * @param y The vertical velocity. + * @param step The velocity increment. When set, the first member receives velocity (x, y), the second (x + step, y + step), and so on. Default 0. */ - resetPipeline(): boolean; + setVelocity(x: number, y: number, step?: number): Phaser.Physics.Arcade.Group; /** - * Gets the name of the WebGL Pipeline this Game Object is currently using. + * Sets the horizontal velocity of each Group member. + * @param value The velocity value. + * @param step The velocity increment. When set, the first member receives velocity (x), the second (x + step), and so on. Default 0. */ - getPipelineName(): string; + setVelocityX(value: number, step?: number): Phaser.Physics.Arcade.Group; /** - * The horizontal scroll factor of this Game Object. - * - * The scroll factor controls the influence of the movement of a Camera upon this Game Object. - * - * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. - * It does not change the Game Objects actual position values. - * - * A value of 1 means it will move exactly in sync with a camera. - * A value of 0 means it will not move at all, even if the camera moves. - * Other values control the degree to which the camera movement is mapped to this Game Object. - * - * Please be aware that scroll factor values other than 1 are not taken in to consideration when - * calculating physics collisions. Bodies always collide based on their world position, but changing - * the scroll factor is a visual adjustment to where the textures are rendered, which can offset - * them from physics bodies if not accounted for in your code. + * Sets the vertical velocity of each Group member. + * @param value The velocity value. + * @param step The velocity increment. When set, the first member receives velocity (y), the second (y + step), and so on. Default 0. */ - scrollFactorX: number; + setVelocityY(value: number, step?: number): Phaser.Physics.Arcade.Group; - /** - * The vertical scroll factor of this Game Object. - * - * The scroll factor controls the influence of the movement of a Camera upon this Game Object. - * - * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. - * It does not change the Game Objects actual position values. - * - * A value of 1 means it will move exactly in sync with a camera. - * A value of 0 means it will not move at all, even if the camera moves. - * Other values control the degree to which the camera movement is mapped to this Game Object. - * - * Please be aware that scroll factor values other than 1 are not taken in to consideration when - * calculating physics collisions. Bodies always collide based on their world position, but changing - * the scroll factor is a visual adjustment to where the textures are rendered, which can offset - * them from physics bodies if not accounted for in your code. - */ - scrollFactorY: number; + } - /** - * Sets the scroll factor of this Game Object. - * - * The scroll factor controls the influence of the movement of a Camera upon this Game Object. - * - * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. - * It does not change the Game Objects actual position values. - * - * A value of 1 means it will move exactly in sync with a camera. - * A value of 0 means it will not move at all, even if the camera moves. - * Other values control the degree to which the camera movement is mapped to this Game Object. - * - * Please be aware that scroll factor values other than 1 are not taken in to consideration when - * calculating physics collisions. Bodies always collide based on their world position, but changing - * the scroll factor is a visual adjustment to where the textures are rendered, which can offset - * them from physics bodies if not accounted for in your code. - * @param x The horizontal scroll factor of this Game Object. - * @param y The vertical scroll factor of this Game Object. If not set it will use the `x` value. Default x. - */ - setScrollFactor(x: number, y?: number): this; + /** + * Separates two overlapping bodies on the X-axis (horizontally). + * + * Separation involves moving two overlapping bodies so they don't overlap anymore and adjusting their velocities based on their mass. This is a core part of collision detection. + * + * The bodies won't be separated if there is no horizontal overlap between them, if they are static, or if either one uses custom logic for its separation. + * @param body1 The first Body to separate. + * @param body2 The second Body to separate. + * @param overlapOnly If `true`, the bodies will only have their overlap data set and no separation will take place. + * @param bias A value to add to the delta value during overlap checking. Used to prevent sprite tunneling. + */ + function SeparateX(body1: Phaser.Physics.Arcade.Body, body2: Phaser.Physics.Arcade.Body, overlapOnly: boolean, bias: number): boolean; - /** - * The native (un-scaled) width of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayWidth` property. - */ - width: number; + /** + * Separates two overlapping bodies on the Y-axis (vertically). + * + * Separation involves moving two overlapping bodies so they don't overlap anymore and adjusting their velocities based on their mass. This is a core part of collision detection. + * + * The bodies won't be separated if there is no vertical overlap between them, if they are static, or if either one uses custom logic for its separation. + * @param body1 The first Body to separate. + * @param body2 The second Body to separate. + * @param overlapOnly If `true`, the bodies will only have their overlap data set and no separation will take place. + * @param bias A value to add to the delta value during overlap checking. Used to prevent sprite tunneling. + */ + function SeparateY(body1: Phaser.Physics.Arcade.Body, body2: Phaser.Physics.Arcade.Body, overlapOnly: boolean, bias: number): boolean; + /** + * A Static Arcade Physics Body. + * + * A Static Body never moves, and isn't automatically synchronized with its parent Game Object. + * That means if you make any change to the parent's origin, position, or scale after creating or adding the body, you'll need to update the Static Body manually. + * + * A Static Body can collide with other Bodies, but is never moved by collisions. + * + * Its dynamic counterpart is {@link Phaser.Physics.Arcade.Body}. + */ + class StaticBody { /** - * The native (un-scaled) height of this Game Object. * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayHeight` property. + * @param world The Arcade Physics simulation this Static Body belongs to. + * @param gameObject The Game Object this Static Body belongs to. */ - height: number; + constructor(world: Phaser.Physics.Arcade.World, gameObject: Phaser.GameObjects.GameObject); /** - * The displayed width of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. + * The Arcade Physics simulation this Static Body belongs to. */ - displayWidth: number; + world: Phaser.Physics.Arcade.World; /** - * The displayed height of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. + * The Game Object this Static Body belongs to. */ - displayHeight: number; + gameObject: Phaser.GameObjects.GameObject; /** - * Sets the size of this Game Object to be that of the given Frame. - * - * This will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or call the - * `setDisplaySize` method, which is the same thing as changing the scale but allows you - * to do so by giving pixel values. - * - * If you have enabled this Game Object for input, changing the size will _not_ change the - * size of the hit area. To do this you should adjust the `input.hitArea` object directly. - * @param frame The frame to base the size of this Game Object on. + * Whether the Static Body's boundary is drawn to the debug display. */ - setSizeToFrame(frame: Phaser.Textures.Frame): this; + debugShowBody: boolean; /** - * Sets the internal size of this Game Object, as used for frame or physics body creation. - * - * This will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or call the - * `setDisplaySize` method, which is the same thing as changing the scale but allows you - * to do so by giving pixel values. - * - * If you have enabled this Game Object for input, changing the size will _not_ change the - * size of the hit area. To do this you should adjust the `input.hitArea` object directly. - * @param width The width of this Game Object. - * @param height The height of this Game Object. + * The color of this Static Body on the debug display. */ - setSize(width: number, height: number): this; + debugBodyColor: number; /** - * Sets the display size of this Game Object. - * - * Calling this will adjust the scale. - * @param width The width of this Game Object. - * @param height The height of this Game Object. + * Whether this Static Body is updated by the physics simulation. */ - setDisplaySize(width: number, height: number): this; + enable: boolean; /** - * The Texture this Game Object is using to render with. + * Whether this Static Body's boundary is circular (`true`) or rectangular (`false`). */ - texture: Phaser.Textures.Texture | Phaser.Textures.CanvasTexture; + isCircle: boolean; /** - * The Texture Frame this Game Object is using to render with. + * If this Static Body is circular, this is the radius of the boundary, as set by {@link Phaser.Physics.Arcade.StaticBody#setCircle}, in pixels. + * Equal to `halfWidth`. */ - frame: Phaser.Textures.Frame; + radius: number; /** - * A boolean flag indicating if this Game Object is being cropped or not. - * You can toggle this at any time after `setCrop` has been called, to turn cropping on or off. - * Equally, calling `setCrop` with no arguments will reset the crop and disable it. + * The offset set by {@link Phaser.Physics.Arcade.StaticBody#setCircle} or {@link Phaser.Physics.Arcade.StaticBody#setSize}. + * + * This doesn't affect the Static Body's position, because a Static Body does not follow its Game Object. */ - isCropped: boolean; + readonly offset: Phaser.Math.Vector2; /** - * Applies a crop to a texture based Game Object, such as a Sprite or Image. - * - * The crop is a rectangle that limits the area of the texture frame that is visible during rendering. - * - * Cropping a Game Object does not change its size, dimensions, physics body or hit area, it just - * changes what is shown when rendered. - * - * The crop coordinates are relative to the texture frame, not the Game Object, meaning 0 x 0 is the top-left. - * - * Therefore, if you had a Game Object that had an 800x600 sized texture, and you wanted to show only the left - * half of it, you could call `setCrop(0, 0, 400, 600)`. - * - * It is also scaled to match the Game Object scale automatically. Therefore a crop rect of 100x50 would crop - * an area of 200x100 when applied to a Game Object that had a scale factor of 2. - * - * You can either pass in numeric values directly, or you can provide a single Rectangle object as the first argument. - * - * Call this method with no arguments at all to reset the crop, or toggle the property `isCropped` to `false`. - * - * You should do this if the crop rectangle becomes the same size as the frame itself, as it will allow - * the renderer to skip several internal calculations. - * @param x The x coordinate to start the crop from. Or a Phaser.Geom.Rectangle object, in which case the rest of the arguments are ignored. - * @param y The y coordinate to start the crop from. - * @param width The width of the crop rectangle in pixels. - * @param height The height of the crop rectangle in pixels. + * The position of this Static Body within the simulation. */ - setCrop(x?: number | Phaser.Geom.Rectangle, y?: number, width?: number, height?: number): this; + position: Phaser.Math.Vector2; /** - * Sets the texture and frame this Game Object will use to render with. - * - * Textures are referenced by their string-based keys, as stored in the Texture Manager. - * @param key The key of the texture to be used, as stored in the Texture Manager. - * @param frame The name or index of the frame within the Texture. + * The width of the Static Body's boundary, in pixels. + * If the Static Body is circular, this is also the Static Body's diameter. */ - setTexture(key: string, frame?: string | integer): this; + width: number; /** - * Sets the frame this Game Object will use to render with. - * - * The Frame has to belong to the current Texture being used. - * - * It can be either a string or an index. - * - * Calling `setFrame` will modify the `width` and `height` properties of your Game Object. - * It will also change the `origin` if the Frame has a custom pivot point, as exported from packages like Texture Packer. - * @param frame The name or index of the frame within the Texture. - * @param updateSize Should this call adjust the size of the Game Object? Default true. - * @param updateOrigin Should this call adjust the origin of the Game Object? Default true. + * The height of the Static Body's boundary, in pixels. + * If the Static Body is circular, this is also the Static Body's diameter. */ - setFrame(frame: string | integer, updateSize?: boolean, updateOrigin?: boolean): this; + height: number; /** - * Fill or additive? + * Half the Static Body's width, in pixels. + * If the Static Body is circular, this is also the Static Body's radius. */ - tintFill: boolean; + halfWidth: number; /** - * Clears all tint values associated with this Game Object. - * - * Immediately sets the color values back to 0xffffff and the tint type to 'additive', - * which results in no visible change to the texture. + * Half the Static Body's height, in pixels. + * If the Static Body is circular, this is also the Static Body's radius. */ - clearTint(): this; + halfHeight: number; /** - * Sets an additive tint on this Game Object. - * - * The tint works by taking the pixel color values from the Game Objects texture, and then - * multiplying it by the color value of the tint. You can provide either one color value, - * in which case the whole Game Object will be tinted in that color. Or you can provide a color - * per corner. The colors are blended together across the extent of the Game Object. - * - * To modify the tint color once set, either call this method again with new values or use the - * `tint` property to set all colors at once. Or, use the properties `tintTopLeft`, `tintTopRight, - * `tintBottomLeft` and `tintBottomRight` to set the corner color values independently. - * - * To remove a tint call `clearTint`. - * - * To swap this from being an additive tint to a fill based tint set the property `tintFill` to `true`. - * @param topLeft The tint being applied to the top-left of the Game Object. If no other values are given this value is applied evenly, tinting the whole Game Object. Default 0xffffff. - * @param topRight The tint being applied to the top-right of the Game Object. - * @param bottomLeft The tint being applied to the bottom-left of the Game Object. - * @param bottomRight The tint being applied to the bottom-right of the Game Object. + * The center of the Static Body's boundary. + * This is the midpoint of its `position` (top-left corner) and its bottom-right corner. */ - setTint(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; + center: Phaser.Math.Vector2; /** - * Sets a fill-based tint on this Game Object. - * - * Unlike an additive tint, a fill-tint literally replaces the pixel colors from the texture - * with those in the tint. You can use this for effects such as making a player flash 'white' - * if hit by something. You can provide either one color value, in which case the whole - * Game Object will be rendered in that color. Or you can provide a color per corner. The colors - * are blended together across the extent of the Game Object. - * - * To modify the tint color once set, either call this method again with new values or use the - * `tint` property to set all colors at once. Or, use the properties `tintTopLeft`, `tintTopRight, - * `tintBottomLeft` and `tintBottomRight` to set the corner color values independently. - * - * To remove a tint call `clearTint`. - * - * To swap this from being a fill-tint to an additive tint set the property `tintFill` to `false`. - * @param topLeft The tint being applied to the top-left of the Game Object. If not other values are given this value is applied evenly, tinting the whole Game Object. Default 0xffffff. - * @param topRight The tint being applied to the top-right of the Game Object. - * @param bottomLeft The tint being applied to the bottom-left of the Game Object. - * @param bottomRight The tint being applied to the bottom-right of the Game Object. + * A constant zero velocity used by the Arcade Physics simulation for calculations. */ - setTintFill(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; + readonly velocity: Phaser.Math.Vector2; /** - * The tint value being applied to the top-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * A constant `false` value expected by the Arcade Physics simulation. */ - tintTopLeft: integer; + readonly allowGravity: boolean; /** - * The tint value being applied to the top-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * Gravitational force applied specifically to this Body. Values are in pixels per second squared. Always zero for a Static Body. */ - tintTopRight: integer; + readonly gravity: Phaser.Math.Vector2; /** - * The tint value being applied to the bottom-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * Rebound, or restitution, following a collision, relative to 1. Always zero for a Static Body. */ - tintBottomLeft: integer; + readonly bounce: Phaser.Math.Vector2; /** - * The tint value being applied to the bottom-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * Whether the simulation emits a `worldbounds` event when this StaticBody collides with the world boundary. + * Always false for a Static Body. (Static Bodies never collide with the world boundary and never trigger a `worldbounds` event.) */ - tintBottomRight: integer; + readonly onWorldBounds: boolean; /** - * The tint value being applied to the whole of the Game Object. - * This property is a setter-only. Use the properties `tintTopLeft` etc to read the current tint value. + * Whether the simulation emits a `collide` event when this StaticBody collides with another. */ - tint: integer; + onCollide: boolean; /** - * Does this Game Object have a tint applied to it or not? + * Whether the simulation emits an `overlap` event when this StaticBody overlaps with another. */ - readonly isTinted: boolean; + onOverlap: boolean; /** - * The x position of this Game Object. + * The StaticBody's inertia, relative to a default unit (1). With `bounce`, this affects the exchange of momentum (velocities) during collisions. */ - x: number; + mass: number; /** - * The y position of this Game Object. + * Whether this object can be moved by collisions with another body. */ - y: number; + immovable: boolean; /** - * The z position of this Game Object. + * Sets if this Body can be pushed by another Body. * - * Note: The z position does not control the rendering order of 2D Game Objects. Use - * {@link Phaser.GameObjects.Components.Depth#depth} instead. + * A body that cannot be pushed will reflect back all of the velocity it is given to the + * colliding body. If that body is also not pushable, then the separation will be split + * between them evenly. + * + * If you want your body to never move or seperate at all, see the `setImmovable` method. + * + * By default, Static Bodies are not pushable. */ - z: number; + pushable: boolean; /** - * The w position of this Game Object. + * A flag disabling the default horizontal separation of colliding bodies. Pass your own `collideHandler` to the collider. */ - w: number; + customSeparateX: boolean; /** - * This is a special setter that allows you to set both the horizontal and vertical scale of this Game Object - * to the same value, at the same time. When reading this value the result returned is `(scaleX + scaleY) / 2`. - * - * Use of this property implies you wish the horizontal and vertical scales to be equal to each other. If this - * isn't the case, use the `scaleX` or `scaleY` properties instead. + * A flag disabling the default vertical separation of colliding bodies. Pass your own `collideHandler` to the collider. */ - scale: number; + customSeparateY: boolean; /** - * The horizontal scale of this Game Object. + * The amount of horizontal overlap (before separation), if this Body is colliding with another. */ - scaleX: number; + overlapX: number; /** - * The vertical scale of this Game Object. + * The amount of vertical overlap (before separation), if this Body is colliding with another. */ - scaleY: number; + overlapY: number; /** - * The angle of this Game Object as expressed in degrees. - * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. - * - * If you prefer to work in radians, see the `rotation` property instead. + * The amount of overlap (before separation), if this StaticBody is circular and colliding with another circular body. */ - angle: integer; + overlapR: number; /** - * The angle of this Game Object in radians. - * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. - * - * If you prefer to work in degrees, see the `angle` property instead. + * Whether this StaticBody has ever overlapped with another while both were not moving. */ - rotation: number; + embedded: boolean; /** - * Sets the position of this Game Object. - * @param x The x position of this Game Object. Default 0. - * @param y The y position of this Game Object. If not set it will use the `x` value. Default x. - * @param z The z position of this Game Object. Default 0. - * @param w The w position of this Game Object. Default 0. + * Whether this StaticBody interacts with the world boundary. + * Always false for a Static Body. (Static Bodies never collide with the world boundary.) */ - setPosition(x?: number, y?: number, z?: number, w?: number): this; + readonly collideWorldBounds: boolean; /** - * Sets the position of this Game Object to be a random position within the confines of - * the given area. - * - * If no area is specified a random position between 0 x 0 and the game width x height is used instead. - * - * The position does not factor in the size of this Game Object, meaning that only the origin is - * guaranteed to be within the area. - * @param x The x position of the top-left of the random area. Default 0. - * @param y The y position of the top-left of the random area. Default 0. - * @param width The width of the random area. - * @param height The height of the random area. + * Whether this StaticBody is checked for collisions and for which directions. You can set `checkCollision.none = false` to disable collision checks. */ - setRandomPosition(x?: number, y?: number, width?: number, height?: number): this; + checkCollision: Phaser.Types.Physics.Arcade.ArcadeBodyCollision; /** - * Sets the rotation of this Game Object. - * @param radians The rotation of this Game Object, in radians. Default 0. + * This property is kept for compatibility with Dynamic Bodies. + * Avoid using it. */ - setRotation(radians?: number): this; + touching: Phaser.Types.Physics.Arcade.ArcadeBodyCollision; /** - * Sets the angle of this Game Object. - * @param degrees The rotation of this Game Object, in degrees. Default 0. + * This property is kept for compatibility with Dynamic Bodies. + * Avoid using it. + * The values are always false for a Static Body. */ - setAngle(degrees?: number): this; + wasTouching: Phaser.Types.Physics.Arcade.ArcadeBodyCollision; /** - * Sets the scale of this Game Object. - * @param x The horizontal scale of this Game Object. - * @param y The vertical scale of this Game Object. If not set it will use the `x` value. Default x. + * This property is kept for compatibility with Dynamic Bodies. + * Avoid using it. */ - setScale(x: number, y?: number): this; + blocked: Phaser.Types.Physics.Arcade.ArcadeBodyCollision; /** - * Sets the x position of this Game Object. - * @param value The x position of this Game Object. Default 0. + * The StaticBody's physics type (static by default). */ - setX(value?: number): this; + physicsType: number; /** - * Sets the y position of this Game Object. - * @param value The y position of this Game Object. Default 0. + * Changes the Game Object this Body is bound to. + * First it removes its reference from the old Game Object, then sets the new one. + * You can optionally update the position and dimensions of this Body to reflect that of the new Game Object. + * @param gameObject The new Game Object that will own this Body. + * @param update Reposition and resize this Body to match the new Game Object? Default true. */ - setY(value?: number): this; + setGameObject(gameObject: Phaser.GameObjects.GameObject, update?: boolean): Phaser.Physics.Arcade.StaticBody; /** - * Sets the z position of this Game Object. - * - * Note: The z position does not control the rendering order of 2D Game Objects. Use - * {@link Phaser.GameObjects.Components.Depth#setDepth} instead. - * @param value The z position of this Game Object. Default 0. + * Syncs the Static Body's position and size with its parent Game Object. */ - setZ(value?: number): this; + updateFromGameObject(): Phaser.Physics.Arcade.StaticBody; /** - * Sets the w position of this Game Object. - * @param value The w position of this Game Object. Default 0. + * Positions the Static Body at an offset from its Game Object. + * @param x The horizontal offset of the Static Body from the Game Object's `x`. + * @param y The vertical offset of the Static Body from the Game Object's `y`. */ - setW(value?: number): this; + setOffset(x: number, y: number): Phaser.Physics.Arcade.StaticBody; /** - * Gets the local transform matrix for this Game Object. - * @param tempMatrix The matrix to populate with the values from this Game Object. + * Sets the size of the Static Body. + * When `center` is true, also repositions it. + * Resets the width and height to match current frame, if no width and height provided and a frame is found. + * @param width The width of the Static Body in pixels. Cannot be zero. If not given, and the parent Game Object has a frame, it will use the frame width. + * @param height The height of the Static Body in pixels. Cannot be zero. If not given, and the parent Game Object has a frame, it will use the frame height. + * @param center Place the Static Body's center on its Game Object's center. Only works if the Game Object has the `getCenter` method. Default true. */ - getLocalTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + setSize(width?: number, height?: number, center?: boolean): Phaser.Physics.Arcade.StaticBody; /** - * Gets the world transform matrix for this Game Object, factoring in any parent Containers. - * @param tempMatrix The matrix to populate with the values from this Game Object. - * @param parentMatrix A temporary matrix to hold parent values during the calculations. + * Sets this Static Body to have a circular body and sets its size and position. + * @param radius The radius of the StaticBody, in pixels. + * @param offsetX The horizontal offset of the StaticBody from its Game Object, in pixels. + * @param offsetY The vertical offset of the StaticBody from its Game Object, in pixels. */ - getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + setCircle(radius: number, offsetX?: number, offsetY?: number): Phaser.Physics.Arcade.StaticBody; /** - * Gets the sum total rotation of all of this Game Objects parent Containers. - * - * The returned value is in radians and will be zero if this Game Object has no parent container. + * Updates the StaticBody's `center` from its `position` and dimensions. */ - getParentRotation(): number; + updateCenter(): void; /** - * The visible state of the Game Object. - * - * An invisible Game Object will skip rendering, but will still process update logic. + * Resets this Body to the given coordinates. Also positions its parent Game Object to the same coordinates. + * @param x The x coordinate to reset the body to. If not given will use the parent Game Object's coordinate. + * @param y The y coordinate to reset the body to. If not given will use the parent Game Object's coordinate. */ - visible: boolean; + reset(x?: number, y?: number): void; /** - * Sets the visibility of this Game Object. - * - * An invisible Game Object will skip rendering, but will still process update logic. - * @param value The visible state of the Game Object. + * NOOP function. A Static Body cannot be stopped. */ - setVisible(value: boolean): this; + stop(): Phaser.Physics.Arcade.StaticBody; /** - * Sets the horizontal acceleration of this body. - * @param x The amount of acceleration to apply. + * Returns the x and y coordinates of the top left and bottom right points of the StaticBody. + * @param obj The object which will hold the coordinates of the bounds. */ - setAccelerationX(x: number): this; + getBounds(obj: Phaser.Types.Physics.Arcade.ArcadeBodyBounds): Phaser.Types.Physics.Arcade.ArcadeBodyBounds; /** - * Sets the vertical acceleration of this body. - * @param y The amount of acceleration to apply. + * Checks to see if a given x,y coordinate is colliding with this Static Body. + * @param x The x coordinate to check against this body. + * @param y The y coordinate to check against this body. */ - setAccelerationY(y: number): this; + hitTest(x: number, y: number): boolean; /** - * Sets the horizontal and vertical acceleration of this body. - * @param x The amount of horizontal acceleration to apply. - * @param y The amount of vertical acceleration to apply. + * NOOP */ - setAcceleration(x: number, y: number): this; + postUpdate(): void; /** - * Sets the size of the physics body. - * @param width The width of the body in pixels. - * @param height The height of the body in pixels. Default width. + * The absolute (non-negative) change in this StaticBody's horizontal position from the previous step. Always zero. */ - setBodySize(width: number, height?: number): this; + deltaAbsX(): number; /** - * Sets the scale of the physics body. - * @param scaleX The horizontal scale of the body. - * @param scaleY The vertical scale of the body. If not given, will use the horizontal scale value. + * The absolute (non-negative) change in this StaticBody's vertical position from the previous step. Always zero. */ - setBodyScale(scaleX: number, scaleY?: number): this; + deltaAbsY(): number; /** - * [description] + * The change in this StaticBody's horizontal position from the previous step. Always zero. */ - getBodyType(): number; + deltaX(): number; /** - * [description] + * The change in this StaticBody's vertical position from the previous step. Always zero. */ - setTypeNone(): Phaser.GameObjects.GameObject; + deltaY(): number; /** - * [description] + * The change in this StaticBody's rotation from the previous step. Always zero. */ - setTypeA(): Phaser.GameObjects.GameObject; + deltaZ(): number; /** - * [description] + * Disables this Body and marks it for destruction during the next step. */ - setTypeB(): Phaser.GameObjects.GameObject; + destroy(): void; /** - * Sets the impact physics bounce, or restitution, value. - * @param value A value between 0 (no rebound) and 1 (full rebound) + * Draws a graphical representation of the StaticBody for visual debugging purposes. + * @param graphic The Graphics object to use for the debug drawing of the StaticBody. */ - setBounce(value: number): Phaser.GameObjects.GameObject; + drawDebug(graphic: Phaser.GameObjects.Graphics): void; /** - * Sets the minimum velocity the body is allowed to be moving to be considered for rebound. - * @param value The minimum allowed velocity. + * Indicates whether the StaticBody is going to be showing a debug visualization during postUpdate. */ - setMinBounceVelocity(value: number): Phaser.GameObjects.GameObject; + willDrawDebug(): boolean; /** - * The bounce, or restitution, value of this body. - * A value between 0 (no rebound) and 1 (full rebound) + * Sets the Mass of the StaticBody. Will set the Mass to 0.1 if the value passed is less than or equal to zero. + * @param value The value to set the Mass to. Values of zero or less are changed to 0.1. */ - bounce: number; + setMass(value: number): Phaser.Physics.Arcade.StaticBody; /** - * [description] + * The x coordinate of the StaticBody. */ - setAvsB(): Phaser.GameObjects.GameObject; + x: number; /** - * [description] + * The y coordinate of the StaticBody. */ - setBvsA(): Phaser.GameObjects.GameObject; + y: number; /** - * [description] + * Returns the left-most x coordinate of the area of the StaticBody. */ - setCheckAgainstNone(): Phaser.GameObjects.GameObject; + readonly left: number; /** - * [description] + * The right-most x coordinate of the area of the StaticBody. */ - setCheckAgainstA(): Phaser.GameObjects.GameObject; + readonly right: number; /** - * [description] + * The highest y coordinate of the area of the StaticBody. */ - setCheckAgainstB(): Phaser.GameObjects.GameObject; + readonly top: number; /** - * [description] + * The lowest y coordinate of the area of the StaticBody. (y + height) */ - checkAgainst: number; + readonly bottom: number; + } + + /** + * An Arcade Physics Static Group object. + * + * All Game Objects created by or added to this Group will automatically be given static Arcade Physics bodies, if they have no body. + * + * Its dynamic counterpart is {@link Phaser.Physics.Arcade.Group}. + */ + class StaticGroup extends Phaser.GameObjects.Group { /** - * [description] - * @param callback [description] - * @param scope [description] + * + * @param world The physics simulation. + * @param scene The scene this group belongs to. + * @param children Game Objects to add to this group; or the `config` argument. + * @param config Settings for this group. */ - setCollideCallback(callback: CollideCallback, scope: any): Phaser.GameObjects.GameObject; + constructor(world: Phaser.Physics.Arcade.World, scene: Phaser.Scene, children?: Phaser.GameObjects.GameObject[] | Phaser.Types.GameObjects.Group.GroupConfig | Phaser.Types.GameObjects.Group.GroupCreateConfig, config?: Phaser.Types.GameObjects.Group.GroupConfig | Phaser.Types.GameObjects.Group.GroupCreateConfig); /** - * [description] + * The physics simulation. */ - setCollidesNever(): Phaser.GameObjects.GameObject; + world: Phaser.Physics.Arcade.World; /** - * [description] + * The scene this group belongs to. */ - setLiteCollision(): Phaser.GameObjects.GameObject; + physicsType: number; /** - * [description] + * A textual representation of this Game Object. + * Used internally by Phaser but is available for your own custom classes to populate. */ - setPassiveCollision(): Phaser.GameObjects.GameObject; + type: string; /** - * [description] + * Adds a static physics body to the new group member (if it lacks one) and adds it to the simulation. + * @param child The new group member. */ - setActiveCollision(): Phaser.GameObjects.GameObject; + createCallbackHandler(child: Phaser.GameObjects.GameObject): void; /** - * [description] + * Disables the group member's physics body, removing it from the simulation. + * @param child The group member being removed. */ - setFixedCollision(): Phaser.GameObjects.GameObject; + removeCallbackHandler(child: Phaser.GameObjects.GameObject): void; /** - * [description] + * Refreshes the group. + * @param entries The newly created group members. */ - collides: number; + createMultipleCallbackHandler(entries: Phaser.GameObjects.GameObject[]): void; /** - * [description] - * @param showBody [description] - * @param showVelocity [description] - * @param bodyColor [description] + * Resets each Body to the position of its parent Game Object. + * Body sizes aren't changed (use {@link Phaser.Physics.Arcade.Components.Enable#refreshBody} for that). */ - setDebug(showBody: boolean, showVelocity: boolean, bodyColor: number): Phaser.GameObjects.GameObject; + refresh(): Phaser.Physics.Arcade.StaticGroup; + + } + namespace Tilemap { /** - * [description] - * @param value [description] + * A function to process the collision callbacks between a single tile and an Arcade Physics enabled Game Object. + * @param tile The Tile to process. + * @param sprite The Game Object to process with the Tile. */ - setDebugBodyColor(value: number): Phaser.GameObjects.GameObject; + function ProcessTileCallbacks(tile: Phaser.Tilemaps.Tile, sprite: Phaser.GameObjects.Sprite): boolean; /** - * [description] + * Internal function to process the separation of a physics body from a tile. + * @param body The Body object to separate. + * @param x The x separation amount. */ - debugShowBody: boolean; + function ProcessTileSeparationX(body: Phaser.Physics.Arcade.Body, x: number): void; /** - * [description] + * Internal function to process the separation of a physics body from a tile. + * @param body The Body object to separate. + * @param y The y separation amount. */ - debugShowVelocity: boolean; + function ProcessTileSeparationY(body: Phaser.Physics.Arcade.Body, y: number): void; /** - * [description] + * The core separation function to separate a physics body and a tile. + * @param i The index of the tile within the map data. + * @param body The Body object to separate. + * @param tile The tile to collide against. + * @param tileWorldRect A rectangle-like object defining the dimensions of the tile. + * @param tilemapLayer The tilemapLayer to collide against. + * @param tileBias The tile bias value. Populated by the `World.TILE_BIAS` constant. + * @param isLayer Is this check coming from a TilemapLayer or an array of tiles? */ - debugBodyColor: number; + function SeparateTile(i: number, body: Phaser.Physics.Arcade.Body, tile: Phaser.Tilemaps.Tile, tileWorldRect: Phaser.Geom.Rectangle, tilemapLayer: Phaser.Tilemaps.TilemapLayer, tileBias: number, isLayer: boolean): boolean; /** - * [description] - * @param x [description] + * Check the body against the given tile on the X axis. + * Used internally by the SeparateTile function. + * @param body The Body object to separate. + * @param tile The tile to check. + * @param tileLeft The left position of the tile within the tile world. + * @param tileRight The right position of the tile within the tile world. + * @param tileBias The tile bias value. Populated by the `World.TILE_BIAS` constant. + * @param isLayer Is this check coming from a TilemapLayer or an array of tiles? */ - setFrictionX(x: number): Phaser.GameObjects.GameObject; + function TileCheckX(body: Phaser.Physics.Arcade.Body, tile: Phaser.Tilemaps.Tile, tileLeft: number, tileRight: number, tileBias: number, isLayer: boolean): number; /** - * [description] - * @param y [description] + * Check the body against the given tile on the Y axis. + * Used internally by the SeparateTile function. + * @param body The Body object to separate. + * @param tile The tile to check. + * @param tileTop The top position of the tile within the tile world. + * @param tileBottom The bottom position of the tile within the tile world. + * @param tileBias The tile bias value. Populated by the `World.TILE_BIAS` constant. + * @param isLayer Is this check coming from a TilemapLayer or an array of tiles? */ - setFrictionY(y: number): Phaser.GameObjects.GameObject; + function TileCheckY(body: Phaser.Physics.Arcade.Body, tile: Phaser.Tilemaps.Tile, tileTop: number, tileBottom: number, tileBias: number, isLayer: boolean): number; /** - * [description] - * @param x [description] - * @param y [description] + * Checks for intersection between the given tile rectangle-like object and an Arcade Physics body. + * @param tileWorldRect A rectangle object that defines the tile placement in the world. + * @param body The body to check for intersection against. */ - setFriction(x: number, y: number): Phaser.GameObjects.GameObject; + function TileIntersectsBody(tileWorldRect: Object, body: Phaser.Physics.Arcade.Body): boolean; + + } + /** + * The Arcade Physics World. + * + * The World is responsible for creating, managing, colliding and updating all of the bodies within it. + * + * An instance of the World belongs to a Phaser.Scene and is accessed via the property `physics.world`. + */ + class World extends Phaser.Events.EventEmitter { /** - * [description] - * @param value [description] + * + * @param scene The Scene to which this World instance belongs. + * @param config An Arcade Physics Configuration object. */ - setGravity(value: number): Phaser.GameObjects.GameObject; + constructor(scene: Phaser.Scene, config: Phaser.Types.Physics.Arcade.ArcadeWorldConfig); /** - * [description] + * The Scene this simulation belongs to. */ - gravity: number; + scene: Phaser.Scene; /** - * [description] - * @param x [description] - * @param y [description] - * @param width [description] - * @param height [description] + * Dynamic Bodies in this simulation. */ - setOffset(x: number, y: number, width?: number, height?: number): Phaser.GameObjects.GameObject; + bodies: Phaser.Structs.Set; /** - * [description] - * @param gameObject [description] - * @param sync [description] Default true. + * Static Bodies in this simulation. */ - setGameObject(gameObject: Phaser.GameObjects.GameObject, sync?: boolean): Phaser.GameObjects.GameObject; + staticBodies: Phaser.Structs.Set; /** - * [description] + * Static Bodies marked for deletion. */ - syncGameObject(): Phaser.GameObjects.GameObject; + pendingDestroy: Phaser.Structs.Set<(Phaser.Physics.Arcade.Body|Phaser.Physics.Arcade.StaticBody)>; /** - * Sets the horizontal velocity of the physics body. - * @param x The horizontal velocity value. + * This simulation's collision processors. */ - setVelocityX(x: number): this; + colliders: Phaser.Structs.ProcessQueue; /** - * Sets the vertical velocity of the physics body. - * @param y The vertical velocity value. + * Acceleration of Bodies due to gravity, in pixels per second. */ - setVelocityY(y: number): this; + gravity: Phaser.Math.Vector2; /** - * Sets the horizontal and vertical velocities of the physics body. - * @param x The horizontal velocity value. - * @param y The vertical velocity value. If not given, defaults to the horizontal value. Default x. + * A boundary constraining Bodies. */ - setVelocity(x: number, y?: number): this; + bounds: Phaser.Geom.Rectangle; /** - * Sets the maximum velocity this body can travel at. - * @param x The maximum allowed horizontal velocity. - * @param y The maximum allowed vertical velocity. If not given, defaults to the horizontal value. Default x. + * The boundary edges that Bodies can collide with. */ - setMaxVelocity(x: number, y?: number): this; + checkCollision: Phaser.Types.Physics.Arcade.CheckCollisionObject; - } + /** + * The number of physics steps to be taken per second. + * + * This property is read-only. Use the `setFPS` method to modify it at run-time. + */ + readonly fps: number; - /** - * [description] - * @param world [description] - * @param left [description] - * @param right [description] - * @param weak [description] - */ - function SeparateX(world: Phaser.Physics.Impact.World, left: Phaser.Physics.Impact.Body, right: Phaser.Physics.Impact.Body, weak?: Phaser.Physics.Impact.Body): void; + /** + * Should Physics use a fixed update time-step (true) or sync to the render fps (false)?. + * False value of this property disables fps and timeScale properties. + */ + fixedStep: boolean; - /** - * [description] - * @param world [description] - * @param top [description] - * @param bottom [description] - * @param weak [description] - */ - function SeparateY(world: Phaser.Physics.Impact.World, top: Phaser.Physics.Impact.Body, bottom: Phaser.Physics.Impact.Body, weak?: Phaser.Physics.Impact.Body): void; + /** + * The number of steps that took place in the last frame. + */ + readonly stepsLastFrame: number; - /** - * Impact Physics Solver - * @param world The Impact simulation to run the solver in. - * @param bodyA The first body in the collision. - * @param bodyB The second body in the collision. - */ - function Solver(world: Phaser.Physics.Impact.World, bodyA: Phaser.Physics.Impact.Body, bodyB: Phaser.Physics.Impact.Body): void; + /** + * Scaling factor applied to the frame rate. + * + * - 1.0 = normal speed + * - 2.0 = half speed + * - 0.5 = double speed + */ + timeScale: number; - /** - * Collision Types - Determine if and how entities collide with each other. - * - * In ACTIVE vs. LITE or FIXED vs. ANY collisions, only the "weak" entity moves, - * while the other one stays fixed. In ACTIVE vs. ACTIVE and ACTIVE vs. PASSIVE - * collisions, both entities are moved. LITE or PASSIVE entities don't collide - * with other LITE or PASSIVE entities at all. The behavior for FIXED vs. - * FIXED collisions is undefined. - */ - enum TYPE { /** - * Collides with nothing. + * The maximum absolute difference of a Body's per-step velocity and its overlap with another Body that will result in separation on *each axis*. + * Larger values favor separation. + * Smaller values favor no separation. */ - NONE, + OVERLAP_BIAS: number; + /** - * Type A. Collides with Type B. + * The maximum absolute value of a Body's overlap with a tile that will result in separation on *each axis*. + * Larger values favor separation. + * Smaller values favor no separation. + * The optimum value may be similar to the tile size. */ - A, + TILE_BIAS: number; + /** - * Type B. Collides with Type A. + * Always separate overlapping Bodies horizontally before vertically. + * False (the default) means Bodies are first separated on the axis of greater gravity, or the vertical axis if neither is greater. */ - B, + forceX: boolean; + /** - * Collides with both types A and B. + * Whether the simulation advances with the game loop. */ - BOTH, - } + isPaused: boolean; - /** - * Set up the trace-result - * var res = { - * collision: {x: false, y: false, slope: false}, - * pos: {x: x, y: y}, - * tile: {x: 0, y: 0} - * }; - * @param body [description] - * @param res [description] - */ - function UpdateMotion(body: Phaser.Physics.Impact.Body, res: object): void; + /** + * Enables the debug display. + */ + drawDebug: boolean; - /** - * [description] - */ - class World extends Phaser.Events.EventEmitter { /** - * - * @param scene The Scene to which this Impact World instance belongs. - * @param config [description] + * The graphics object drawing the debug display. */ - constructor(scene: Phaser.Scene, config: Phaser.Types.Physics.Impact.WorldConfig); + debugGraphic: Phaser.GameObjects.Graphics; /** - * [description] + * Default debug display settings for new Bodies. */ - scene: Phaser.Scene; + defaults: Phaser.Types.Physics.Arcade.ArcadeWorldDefaults; /** - * [description] + * The maximum number of items per node on the RTree. + * + * This is ignored if `useTree` is `false`. If you have a large number of bodies in + * your world then you may find search performance improves by increasing this value, + * to allow more items per node and less node division. */ - bodies: Phaser.Structs.Set; + maxEntries: number; /** - * [description] + * Should this Arcade Physics World use an RTree for Dynamic bodies? + * + * An RTree is a fast way of spatially sorting of all the bodies in the world. + * However, at certain limits, the cost of clearing and inserting the bodies into the + * tree every frame becomes more expensive than the search speed gains it provides. + * + * If you have a large number of dynamic bodies in your world then it may be best to + * disable the use of the RTree by setting this property to `false` in the physics config. + * + * The number it can cope with depends on browser and device, but a conservative estimate + * of around 5,000 bodies should be considered the max before disabling it. + * + * This only applies to dynamic bodies. Static bodies are always kept in an RTree, + * because they don't have to be cleared every frame, so you benefit from the + * massive search speeds all the time. */ - gravity: number; + useTree: boolean; /** - * Spatial hash cell dimensions + * The spatial index of Dynamic Bodies. */ - cellSize: integer; + tree: Phaser.Structs.RTree; /** - * [description] + * The spatial index of Static Bodies. */ - collisionMap: Phaser.Physics.Impact.CollisionMap; + staticTree: Phaser.Structs.RTree; /** - * [description] + * Recycled input for tree searches. */ - timeScale: number; + treeMinMax: Phaser.Types.Physics.Arcade.ArcadeWorldTreeMinMax; /** - * Impacts maximum time step is 20 fps. + * Adds an Arcade Physics Body to a Game Object, an array of Game Objects, or the children of a Group. + * + * The difference between this and the `enableBody` method is that you can pass arrays or Groups + * to this method. + * + * You can specify if the bodies are to be Dynamic or Static. A dynamic body can move via velocity and + * acceleration. A static body remains fixed in place and as such is able to use an optimized search + * tree, making it ideal for static elements such as level objects. You can still collide and overlap + * with static bodies. + * + * Normally, rather than calling this method directly, you'd use the helper methods available in the + * Arcade Physics Factory, such as: + * + * ```javascript + * this.physics.add.image(x, y, textureKey); + * this.physics.add.sprite(x, y, textureKey); + * ``` + * + * Calling factory methods encapsulates the creation of a Game Object and the creation of its + * body at the same time. If you are creating custom classes then you can pass them to this + * method to have their bodies created. + * @param object The object, or objects, on which to create the bodies. + * @param bodyType The type of Body to create. Either `DYNAMIC_BODY` or `STATIC_BODY`. */ - maxStep: number; + enable(object: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[] | Phaser.GameObjects.Group | Phaser.GameObjects.Group[], bodyType?: number): void; /** - * [description] + * Creates an Arcade Physics Body on a single Game Object. + * + * If the Game Object already has a body, this method will simply add it back into the simulation. + * + * You can specify if the body is Dynamic or Static. A dynamic body can move via velocity and + * acceleration. A static body remains fixed in place and as such is able to use an optimized search + * tree, making it ideal for static elements such as level objects. You can still collide and overlap + * with static bodies. + * + * Normally, rather than calling this method directly, you'd use the helper methods available in the + * Arcade Physics Factory, such as: + * + * ```javascript + * this.physics.add.image(x, y, textureKey); + * this.physics.add.sprite(x, y, textureKey); + * ``` + * + * Calling factory methods encapsulates the creation of a Game Object and the creation of its + * body at the same time. If you are creating custom classes then you can pass them to this + * method to have their bodies created. + * @param object The Game Object on which to create the body. + * @param bodyType The type of Body to create. Either `DYNAMIC_BODY` or `STATIC_BODY`. */ - enabled: boolean; + enableBody(object: Phaser.GameObjects.GameObject, bodyType?: number): Phaser.GameObjects.GameObject; /** - * [description] + * Adds an existing Arcade Physics Body or StaticBody to the simulation. + * + * The body is enabled and added to the local search trees. + * @param body The Body to be added to the simulation. */ - drawDebug: boolean; + add(body: Phaser.Physics.Arcade.Body | Phaser.Physics.Arcade.StaticBody): Phaser.Physics.Arcade.Body | Phaser.Physics.Arcade.StaticBody; /** - * [description] + * Disables the Arcade Physics Body of a Game Object, an array of Game Objects, or the children of a Group. + * + * The difference between this and the `disableBody` method is that you can pass arrays or Groups + * to this method. + * + * The body itself is not deleted, it just has its `enable` property set to false, which + * means you can re-enable it again at any point by passing it to enable `World.enable` or `World.add`. + * @param object The object, or objects, on which to disable the bodies. */ - debugGraphic: Phaser.GameObjects.Graphics; + disable(object: Phaser.GameObjects.GameObject | Phaser.GameObjects.GameObject[] | Phaser.GameObjects.Group | Phaser.GameObjects.Group[]): void; /** - * [description] + * Disables an existing Arcade Physics Body or StaticBody and removes it from the simulation. + * + * The body is disabled and removed from the local search trees. + * + * The body itself is not deleted, it just has its `enable` property set to false, which + * means you can re-enable it again at any point by passing it to enable `World.enable` or `World.add`. + * @param body The Body to be disabled. */ - defaults: Phaser.Types.Physics.Impact.WorldDefaults; + disableBody(body: Phaser.Physics.Arcade.Body | Phaser.Physics.Arcade.StaticBody): void; /** - * An object containing the 4 wall bodies that bound the physics world. + * Removes an existing Arcade Physics Body or StaticBody from the simulation. + * + * The body is disabled and removed from the local search trees. + * + * The body itself is not deleted, it just has its `enabled` property set to false, which + * means you can re-enable it again at any point by passing it to enable `enable` or `add`. + * @param body The body to be removed from the simulation. */ - walls: Phaser.Types.Physics.Impact.WorldWalls; + remove(body: Phaser.Physics.Arcade.Body | Phaser.Physics.Arcade.StaticBody): void; /** - * [description] + * Creates a Graphics Game Object that the world will use to render the debug display to. + * + * This is called automatically when the World is instantiated if the `debug` config property + * was set to `true`. However, you can call it at any point should you need to display the + * debug Graphic from a fixed point. + * + * You can control which objects are drawn to the Graphics object, and the colors they use, + * by setting the debug properties in the physics config. + * + * You should not typically use this in a production game. Use it to aid during debugging. */ - delta: number; + createDebugGraphic(): Phaser.GameObjects.Graphics; /** - * Sets the collision map for the world either from a Weltmeister JSON level in the cache or from - * a 2D array. If loading from a Weltmeister level, the map must have a layer called "collision". - * @param key Either a string key that corresponds to a Weltmeister level - * in the cache, or a 2D array of collision IDs. - * @param tileSize The size of a tile. This is optional if loading from a Weltmeister - * level in the cache. + * Sets the position, size and properties of the World boundary. + * + * The World boundary is an invisible rectangle that defines the edges of the World. + * If a Body is set to collide with the world bounds then it will automatically stop + * when it reaches any of the edges. You can optionally set which edges of the boundary + * should be checked against. + * @param x The top-left x coordinate of the boundary. + * @param y The top-left y coordinate of the boundary. + * @param width The width of the boundary. + * @param height The height of the boundary. + * @param checkLeft Should bodies check against the left edge of the boundary? + * @param checkRight Should bodies check against the right edge of the boundary? + * @param checkUp Should bodies check against the top edge of the boundary? + * @param checkDown Should bodies check against the bottom edge of the boundary? */ - setCollisionMap(key: string | integer[][], tileSize: integer): Phaser.Physics.Impact.CollisionMap; + setBounds(x: number, y: number, width: number, height: number, checkLeft?: boolean, checkRight?: boolean, checkUp?: boolean, checkDown?: boolean): Phaser.Physics.Arcade.World; /** - * Sets the collision map for the world from a tilemap layer. Only tiles that are marked as - * colliding will be used. You can specify the mapping from tiles to slope IDs in a couple of - * ways. The easiest is to use Tiled and the slopeTileProperty option. Alternatively, you can - * manually create a slopeMap that stores the mapping between tile indices and slope IDs. - * @param tilemapLayer The tilemap layer to use. - * @param options Options for controlling the mapping from tiles to slope IDs. + * Enables or disables collisions on each edge of the World boundary. + * @param left Should bodies check against the left edge of the boundary? Default true. + * @param right Should bodies check against the right edge of the boundary? Default true. + * @param up Should bodies check against the top edge of the boundary? Default true. + * @param down Should bodies check against the bottom edge of the boundary? Default true. */ - setCollisionMapFromTilemapLayer(tilemapLayer: Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer, options?: Phaser.Types.Physics.Impact.CollisionOptions): Phaser.Physics.Impact.CollisionMap; + setBoundsCollision(left?: boolean, right?: boolean, up?: boolean, down?: boolean): Phaser.Physics.Arcade.World; /** - * Sets the bounds of the Physics world to match the given world pixel dimensions. - * You can optionally set which 'walls' to create: left, right, top or bottom. - * If none of the walls are given it will default to use the walls settings it had previously. - * I.e. if you previously told it to not have the left or right walls, and you then adjust the world size - * the newly created bounds will also not have the left and right walls. - * Explicitly state them in the parameters to override this. - * @param x The x coordinate of the top-left corner of the bounds. - * @param y The y coordinate of the top-left corner of the bounds. - * @param width The width of the bounds. - * @param height The height of the bounds. - * @param thickness [description] Default 64. - * @param left If true will create the left bounds wall. Default true. - * @param right If true will create the right bounds wall. Default true. - * @param top If true will create the top bounds wall. Default true. - * @param bottom If true will create the bottom bounds wall. Default true. + * Pauses the simulation. + * + * A paused simulation does not update any existing bodies, or run any Colliders. + * + * However, you can still enable and disable bodies within it, or manually run collide or overlap + * checks. */ - setBounds(x?: number, y?: number, width?: number, height?: number, thickness?: number, left?: boolean, right?: boolean, top?: boolean, bottom?: boolean): Phaser.Physics.Impact.World; + pause(): Phaser.Physics.Arcade.World; /** - * position = 'left', 'right', 'top' or 'bottom' - * @param add [description] - * @param position [description] - * @param x [description] - * @param y [description] - * @param width [description] - * @param height [description] + * Resumes the simulation, if paused. */ - updateWall(add: boolean, position: string, x: number, y: number, width: number, height: number): void; + resume(): Phaser.Physics.Arcade.World; /** - * Creates a Graphics Game Object used for debug display and enables the world for debug drawing. + * Creates a new Collider object and adds it to the simulation. + * + * A Collider is a way to automatically perform collision checks between two objects, + * calling the collide and process callbacks if they occur. + * + * Colliders are run as part of the World update, after all of the Bodies have updated. + * + * By creating a Collider you don't need then call `World.collide` in your `update` loop, + * as it will be handled for you automatically. + * @param object1 The first object to check for collision. + * @param object2 The second object to check for collision. + * @param collideCallback The callback to invoke when the two objects collide. + * @param processCallback The callback to invoke when the two objects collide. Must return a boolean. + * @param callbackContext The scope in which to call the callbacks. */ - createDebugGraphic(): Phaser.GameObjects.Graphics; + addCollider(object1: Phaser.Types.Physics.Arcade.ArcadeColliderType, object2: Phaser.Types.Physics.Arcade.ArcadeColliderType, collideCallback?: ArcadePhysicsCallback, processCallback?: ArcadePhysicsCallback, callbackContext?: any): Phaser.Physics.Arcade.Collider; /** - * [description] + * Creates a new Overlap Collider object and adds it to the simulation. + * + * A Collider is a way to automatically perform overlap checks between two objects, + * calling the collide and process callbacks if they occur. + * + * Colliders are run as part of the World update, after all of the Bodies have updated. + * + * By creating a Collider you don't need then call `World.overlap` in your `update` loop, + * as it will be handled for you automatically. + * @param object1 The first object to check for overlap. + * @param object2 The second object to check for overlap. + * @param collideCallback The callback to invoke when the two objects overlap. + * @param processCallback The callback to invoke when the two objects overlap. Must return a boolean. + * @param callbackContext The scope in which to call the callbacks. */ - getNextID(): integer; + addOverlap(object1: Phaser.Types.Physics.Arcade.ArcadeColliderType, object2: Phaser.Types.Physics.Arcade.ArcadeColliderType, collideCallback?: ArcadePhysicsCallback, processCallback?: ArcadePhysicsCallback, callbackContext?: any): Phaser.Physics.Arcade.Collider; /** - * [description] - * @param x [description] - * @param y [description] - * @param sizeX [description] - * @param sizeY [description] + * Removes a Collider from the simulation so it is no longer processed. + * + * This method does not destroy the Collider. If you wish to add it back at a later stage you can call + * `World.colliders.add(Collider)`. + * + * If you no longer need the Collider you can call the `Collider.destroy` method instead, which will + * automatically clear all of its references and then remove it from the World. If you call destroy on + * a Collider you _don't_ need to pass it to this method too. + * @param collider The Collider to remove from the simulation. */ - create(x: number, y: number, sizeX: number, sizeY: number): Phaser.Physics.Impact.Body; + removeCollider(collider: Phaser.Physics.Arcade.Collider): Phaser.Physics.Arcade.World; /** - * [description] - * @param object The Body to remove from this World. + * Sets the frame rate to run the simulation at. + * + * The frame rate value is used to simulate a fixed update time step. This fixed + * time step allows for a straightforward implementation of a deterministic game state. + * + * This frame rate is independent of the frequency at which the game is rendering. The + * higher you set the fps, the more physics simulation steps will occur per game step. + * Conversely, the lower you set it, the less will take place. + * + * You can optionally advance the simulation directly yourself by calling the `step` method. + * @param framerate The frame rate to advance the simulation at. */ - remove(object: Phaser.Physics.Impact.Body): void; + setFPS(framerate: number): this; /** - * [description] + * Advances the simulation based on the elapsed time and fps rate. + * + * This is called automatically by your Scene and does not need to be invoked directly. + * @param time The current timestamp as generated by the Request Animation Frame or SetTimeout. + * @param delta The delta time, in ms, elapsed since the last frame. */ - pause(): Phaser.Physics.Impact.World; + update(time: number, delta: number): void; /** - * [description] + * Advances the simulation by a time increment. + * @param delta The delta time amount, in seconds, by which to advance the simulation. */ - resume(): Phaser.Physics.Impact.World; + step(delta: number): void; /** - * [description] - * @param time The current time. Either a High Resolution Timer value if it comes from Request Animation Frame, or Date.now if using SetTimeout. - * @param delta The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate. + * Updates bodies, draws the debug display, and handles pending queue operations. */ - update(time: number, delta: number): void; + postUpdate(): void; /** - * Check the body against the spatial hash. - * @param body [description] - * @param hash [description] - * @param size [description] + * Calculates a Body's velocity and updates its position. + * @param body The Body to be updated. + * @param delta The delta value to be used in the motion calculations, in seconds. */ - checkHash(body: Phaser.Physics.Impact.Body, hash: object, size: number): void; + updateMotion(body: Phaser.Physics.Arcade.Body, delta: number): void; /** - * [description] - * @param bodyA [description] - * @param bodyB [description] + * Calculates a Body's angular velocity. + * @param body The Body to compute the velocity for. + * @param delta The delta value to be used in the calculation, in seconds. */ - checkBodies(bodyA: Phaser.Physics.Impact.Body, bodyB: Phaser.Physics.Impact.Body): void; + computeAngularVelocity(body: Phaser.Physics.Arcade.Body, delta: number): void; /** - * [description] - * @param bodies An Array of Impact Bodies to set the collides value on. + * Calculates a Body's per-axis velocity. + * @param body The Body to compute the velocity for. + * @param delta The delta value to be used in the calculation, in seconds. */ - setCollidesNever(bodies: Phaser.Physics.Impact.Body[]): Phaser.Physics.Impact.World; + computeVelocity(body: Phaser.Physics.Arcade.Body, delta: number): void; /** - * [description] - * @param bodies An Array of Impact Bodies to set the collides value on. + * Separates two Bodies. + * @param body1 The first Body to be separated. + * @param body2 The second Body to be separated. + * @param processCallback The process callback. + * @param callbackContext The context in which to invoke the callback. + * @param overlapOnly If this a collide or overlap check? + * @param intersects Assert that the bodies intersect and should not be tested before separation. */ - setLite(bodies: Phaser.Physics.Impact.Body[]): Phaser.Physics.Impact.World; + separate(body1: Phaser.Physics.Arcade.Body, body2: Phaser.Physics.Arcade.Body, processCallback?: ArcadePhysicsCallback, callbackContext?: any, overlapOnly?: boolean, intersects?: boolean): boolean; /** - * [description] - * @param bodies An Array of Impact Bodies to set the collides value on. + * Separates two Bodies, when both are circular. + * @param body1 The first Body to be separated. + * @param body2 The second Body to be separated. + * @param overlapOnly If this a collide or overlap check? + * @param bias A small value added to the calculations. */ - setPassive(bodies: Phaser.Physics.Impact.Body[]): Phaser.Physics.Impact.World; + separateCircle(body1: Phaser.Physics.Arcade.Body, body2: Phaser.Physics.Arcade.Body, overlapOnly?: boolean, bias?: number): boolean; /** - * [description] - * @param bodies An Array of Impact Bodies to set the collides value on. + * Checks to see if two Bodies intersect at all. + * @param body1 The first body to check. + * @param body2 The second body to check. */ - setActive(bodies: Phaser.Physics.Impact.Body[]): Phaser.Physics.Impact.World; + intersects(body1: Phaser.Physics.Arcade.Body, body2: Phaser.Physics.Arcade.Body): boolean; /** - * [description] - * @param bodies An Array of Impact Bodies to set the collides value on. + * Tests if a circular Body intersects with another Body. + * @param circle The circular body to test. + * @param body The rectangular body to test. */ - setFixed(bodies: Phaser.Physics.Impact.Body[]): Phaser.Physics.Impact.World; + circleBodyIntersects(circle: Phaser.Physics.Arcade.Body, body: Phaser.Physics.Arcade.Body): boolean; /** - * [description] - * @param bodies An Array of Impact Bodies to set the type value on. + * Tests if Game Objects overlap. + * + * See details in {@link Phaser.Physics.Arcade.World#collide}. + * @param object1 The first object or array of objects to check. + * @param object2 The second object or array of objects to check, or `undefined`. + * @param overlapCallback An optional callback function that is called if the objects overlap. + * @param processCallback An optional callback function that lets you perform additional checks against the two objects if they overlap. If this is set then `overlapCallback` will only be called if this callback returns `true`. + * @param callbackContext The context in which to run the callbacks. */ - setTypeNone(bodies: Phaser.Physics.Impact.Body[]): Phaser.Physics.Impact.World; + overlap(object1: Phaser.Types.Physics.Arcade.ArcadeColliderType, object2?: Phaser.Types.Physics.Arcade.ArcadeColliderType, overlapCallback?: ArcadePhysicsCallback, processCallback?: ArcadePhysicsCallback, callbackContext?: any): boolean; /** - * [description] - * @param bodies An Array of Impact Bodies to set the type value on. + * Performs a collision check and separation between the two physics enabled objects given, which can be single + * Game Objects, arrays of Game Objects, Physics Groups, arrays of Physics Groups or normal Groups. + * + * If you don't require separation then use {@link Phaser.Physics.Arcade.World#overlap} instead. + * + * If two Groups or arrays are passed, each member of one will be tested against each member of the other. + * + * If **only** one Group is passed (as `object1`), each member of the Group will be collided against the other members. + * + * If **only** one Array is passed, the array is iterated and every element in it is tested against the others. + * + * Two callbacks can be provided; they receive the colliding game objects as arguments. + * If an overlap is detected, the `processCallback` is called first. It can cancel the collision by returning false. + * Next the objects are separated and `collideCallback` is invoked. + * + * Arcade Physics uses the Projection Method of collision resolution and separation. While it's fast and suitable + * for 'arcade' style games it lacks stability when multiple objects are in close proximity or resting upon each other. + * The separation that stops two objects penetrating may create a new penetration against a different object. If you + * require a high level of stability please consider using an alternative physics system, such as Matter.js. + * @param object1 The first object or array of objects to check. + * @param object2 The second object or array of objects to check, or `undefined`. + * @param collideCallback An optional callback function that is called if the objects collide. + * @param processCallback An optional callback function that lets you perform additional checks against the two objects if they collide. If this is set then `collideCallback` will only be called if this callback returns `true`. + * @param callbackContext The context in which to run the callbacks. */ - setTypeA(bodies: Phaser.Physics.Impact.Body[]): Phaser.Physics.Impact.World; + collide(object1: Phaser.Types.Physics.Arcade.ArcadeColliderType, object2?: Phaser.Types.Physics.Arcade.ArcadeColliderType, collideCallback?: ArcadePhysicsCallback, processCallback?: ArcadePhysicsCallback, callbackContext?: any): boolean; /** - * [description] - * @param bodies An Array of Impact Bodies to set the type value on. + * This advanced method is specifically for testing for collision between a single Sprite and an array of Tile objects. + * + * You should generally use the `collide` method instead, with a Sprite vs. a Tilemap Layer, as that will perform + * tile filtering and culling for you, as well as handle the interesting face collision automatically. + * + * This method is offered for those who would like to check for collision with specific Tiles in a layer, without + * having to set any collision attributes on the tiles in question. This allows you to perform quick dynamic collisions + * on small sets of Tiles. As such, no culling or checks are made to the array of Tiles given to this method, + * you should filter them before passing them to this method. + * + * Important: Use of this method skips the `interesting faces` system that Tilemap Layers use. This means if you have + * say a row or column of tiles, and you jump into, or walk over them, it's possible to get stuck on the edges of the + * tiles as the interesting face calculations are skipped. However, for quick-fire small collision set tests on + * dynamic maps, this method can prove very useful. + * @param sprite The first object to check for collision. + * @param tiles An array of Tiles to check for collision against. + * @param collideCallback An optional callback function that is called if the objects collide. + * @param processCallback An optional callback function that lets you perform additional checks against the two objects if they collide. If this is set then `collideCallback` will only be called if this callback returns `true`. + * @param callbackContext The context in which to run the callbacks. */ - setTypeB(bodies: Phaser.Physics.Impact.Body[]): Phaser.Physics.Impact.World; + collideTiles(sprite: Phaser.GameObjects.GameObject, tiles: Phaser.Tilemaps.Tile[], collideCallback?: ArcadePhysicsCallback, processCallback?: ArcadePhysicsCallback, callbackContext?: any): boolean; /** - * [description] - * @param bodies An Array of Impact Bodies to set the type value on. + * This advanced method is specifically for testing for overlaps between a single Sprite and an array of Tile objects. + * + * You should generally use the `overlap` method instead, with a Sprite vs. a Tilemap Layer, as that will perform + * tile filtering and culling for you, as well as handle the interesting face collision automatically. + * + * This method is offered for those who would like to check for overlaps with specific Tiles in a layer, without + * having to set any collision attributes on the tiles in question. This allows you to perform quick dynamic overlap + * tests on small sets of Tiles. As such, no culling or checks are made to the array of Tiles given to this method, + * you should filter them before passing them to this method. + * @param sprite The first object to check for collision. + * @param tiles An array of Tiles to check for collision against. + * @param collideCallback An optional callback function that is called if the objects overlap. + * @param processCallback An optional callback function that lets you perform additional checks against the two objects if they collide. If this is set then `collideCallback` will only be called if this callback returns `true`. + * @param callbackContext The context in which to run the callbacks. */ - setAvsB(bodies: Phaser.Physics.Impact.Body[]): Phaser.Physics.Impact.World; + overlapTiles(sprite: Phaser.GameObjects.GameObject, tiles: Phaser.Tilemaps.Tile[], collideCallback?: ArcadePhysicsCallback, processCallback?: ArcadePhysicsCallback, callbackContext?: any): boolean; /** - * [description] - * @param bodies An Array of Impact Bodies to set the type value on. + * Internal handler for Sprite vs. Tilemap collisions. + * Please use Phaser.Physics.Arcade.World#collide instead. + * @param sprite The first object to check for collision. + * @param tilemapLayer The second object to check for collision. + * @param collideCallback An optional callback function that is called if the objects collide. + * @param processCallback An optional callback function that lets you perform additional checks against the two objects if they collide. If this is set then `collideCallback` will only be called if this callback returns `true`. + * @param callbackContext The context in which to run the callbacks. + * @param overlapOnly Whether this is a collision or overlap check. */ - setBvsA(bodies: Phaser.Physics.Impact.Body[]): Phaser.Physics.Impact.World; + collideSpriteVsTilemapLayer(sprite: Phaser.GameObjects.GameObject, tilemapLayer: Phaser.Tilemaps.TilemapLayer, collideCallback?: ArcadePhysicsCallback, processCallback?: ArcadePhysicsCallback, callbackContext?: any, overlapOnly?: boolean): boolean; /** - * [description] - * @param bodies An Array of Impact Bodies to set the type value on. + * Wrap an object's coordinates (or several objects' coordinates) within {@link Phaser.Physics.Arcade.World#bounds}. + * + * If the object is outside any boundary edge (left, top, right, bottom), it will be moved to the same offset from the opposite edge (the interior). + * @param object A Game Object, a Group, an object with `x` and `y` coordinates, or an array of such objects. + * @param padding An amount added to each boundary edge during the operation. Default 0. */ - setCheckAgainstNone(bodies: Phaser.Physics.Impact.Body[]): Phaser.Physics.Impact.World; + wrap(object: any, padding?: number): void; /** - * [description] - * @param bodies An Array of Impact Bodies to set the type value on. + * Wrap each object's coordinates within {@link Phaser.Physics.Arcade.World#bounds}. + * @param objects An array of objects to be wrapped. + * @param padding An amount added to the boundary. Default 0. */ - setCheckAgainstA(bodies: Phaser.Physics.Impact.Body[]): Phaser.Physics.Impact.World; + wrapArray(objects: any[], padding?: number): void; /** - * [description] - * @param bodies An Array of Impact Bodies to set the type value on. + * Wrap an object's coordinates within {@link Phaser.Physics.Arcade.World#bounds}. + * @param object A Game Object, a Physics Body, or any object with `x` and `y` coordinates + * @param padding An amount added to the boundary. Default 0. */ - setCheckAgainstB(bodies: Phaser.Physics.Impact.Body[]): Phaser.Physics.Impact.World; + wrapObject(object: any, padding?: number): void; /** - * [description] + * Shuts down the simulation, clearing physics data and removing listeners. */ shutdown(): void; /** - * [description] + * Shuts down the simulation and disconnects it from the current scene. */ destroy(): void; @@ -68199,7 +73750,7 @@ declare namespace Phaser { * @param rowGap The distance between each row. Default 0. * @param options An optional Body configuration object that is used to set initial Body properties on creation. */ - imageStack(key: string, frame: string | integer, x: number, y: number, columns: number, rows: number, columnGap?: number, rowGap?: number, options?: Phaser.Types.Physics.Matter.MatterBodyConfig): MatterJS.CompositeType; + imageStack(key: string, frame: string | number, x: number, y: number, columns: number, rows: number, columnGap?: number, rowGap?: number, options?: Phaser.Types.Physics.Matter.MatterBodyConfig): MatterJS.CompositeType; /** * Create a new composite containing bodies created in the callback in a grid arrangement. @@ -68415,7 +73966,7 @@ declare namespace Phaser { * @param frame An optional frame from the Texture this Game Object is rendering with. Set to `null` to skip this value. * @param options An optional Body configuration object that is used to set initial Body properties on creation. */ - image(x: number, y: number, key: string, frame?: string | integer, options?: Phaser.Types.Physics.Matter.MatterBodyConfig): Phaser.Physics.Matter.Image; + image(x: number, y: number, key: string, frame?: string | number, options?: Phaser.Types.Physics.Matter.MatterBodyConfig): Phaser.Physics.Matter.Image; /** * Creates a wrapper around a Tile that provides access to a corresponding Matter body. A tile can only @@ -68449,7 +74000,7 @@ declare namespace Phaser { * @param frame An optional frame from the Texture this Game Object is rendering with. Set to `null` to skip this value. * @param options An optional Body configuration object that is used to set initial Body properties on creation. */ - sprite(x: number, y: number, key: string, frame?: string | integer, options?: Phaser.Types.Physics.Matter.MatterBodyConfig): Phaser.Physics.Matter.Sprite; + sprite(x: number, y: number, key: string, frame?: string | number, options?: Phaser.Types.Physics.Matter.MatterBodyConfig): Phaser.Physics.Matter.Sprite; /** * Takes an existing Game Object and injects all of the Matter Components into it. @@ -68463,7 +74014,7 @@ declare namespace Phaser { * @param options A Matter Body configuration object, or an instance of a Matter Body. * @param addToWorld Add this Matter Body to the World? Default true. */ - gameObject(gameObject: Phaser.GameObjects.GameObject, options?: Phaser.Types.Physics.Matter.MatterBodyConfig | MatterJS.Body, addToWorld?: boolean): Phaser.GameObjects.GameObject; + gameObject(gameObject: Phaser.GameObjects.GameObject, options?: Phaser.Types.Physics.Matter.MatterBodyConfig | MatterJS.Body, addToWorld?: boolean): Phaser.Physics.Matter.Image | Phaser.Physics.Matter.Sprite | Phaser.GameObjects.GameObject; /** * Destroys this Factory. @@ -68499,11 +74050,11 @@ declare namespace Phaser { * @param world A reference to the Matter.World instance that this body belongs to. * @param x The horizontal position of this Game Object in the world. * @param y The vertical position of this Game Object in the world. - * @param texture The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. + * @param texture The key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager. * @param frame An optional frame from the Texture this Game Object is rendering with. * @param options An optional Body configuration object that is used to set initial Body properties on creation. */ - constructor(world: Phaser.Physics.Matter.World, x: number, y: number, texture: string, frame?: string | integer, options?: Phaser.Types.Physics.Matter.MatterBodyConfig); + constructor(world: Phaser.Physics.Matter.World, x: number, y: number, texture: string | Phaser.Textures.Texture, frame?: string | number, options?: Phaser.Types.Physics.Matter.MatterBodyConfig); /** * A reference to the Matter.World instance that this body belongs to. @@ -68614,7 +74165,7 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. @@ -68627,13 +74178,13 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. * @param value The depth of this Game Object. */ - setDepth(value: integer): this; + setDepth(value: number): this; /** * The horizontally flipped state of the Game Object. @@ -68809,6 +74360,8 @@ declare namespace Phaser { * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, * including this one. * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * * To create the mask you need to pass in a reference to a renderable Game Object. * A renderable Game Object is one that uses a texture to render with, such as an * Image, Sprite, Render Texture or BitmapText. @@ -68894,6 +74447,8 @@ declare namespace Phaser { /** * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. */ defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; @@ -68902,23 +74457,109 @@ declare namespace Phaser { */ pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + /** + * Does this Game Object have any Post Pipelines set? + */ + hasPostPipeline: boolean; + + /** + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. + */ + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; + + /** + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. + */ + pipelineData: object; + /** * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + */ + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; + + /** + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; + + /** + * Sets one, or more, Post Pipelines on this Game Object. + * + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; + + /** + * Adds an entry to the `pipelineData` object belonging to this Game Object. + * + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. */ - initPipeline(pipelineName?: string): boolean; + setPipelineData(key: string, value?: any): this; /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - setPipeline(pipelineName: string): this; + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; /** * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; + + /** + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPostPipeline(resetData?: boolean): void; + + /** + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - resetPipeline(): boolean; + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; /** * Gets the name of the WebGL Pipeline this Game Object is currently using. @@ -69111,7 +74752,7 @@ declare namespace Phaser { * @param key The key of the texture to be used, as stored in the Texture Manager. * @param frame The name or index of the frame within the Texture. */ - setTexture(key: string, frame?: string | integer): this; + setTexture(key: string, frame?: string | number): this; /** * Sets the frame this Game Object will use to render with. @@ -69126,10 +74767,41 @@ declare namespace Phaser { * @param updateSize Should this call adjust the size of the Game Object? Default true. * @param updateOrigin Should this call adjust the origin of the Game Object? Default true. */ - setFrame(frame: string | integer, updateSize?: boolean, updateOrigin?: boolean): this; + setFrame(frame: string | number, updateSize?: boolean, updateOrigin?: boolean): this; + + /** + * The tint value being applied to the top-left vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintTopLeft: number; + + /** + * The tint value being applied to the top-right vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintTopRight: number; + + /** + * The tint value being applied to the bottom-left vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintBottomLeft: number; + + /** + * The tint value being applied to the bottom-right vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintBottomRight: number; /** - * Fill or additive? + * The tint fill mode. + * + * `false` = An additive tint (the default), where vertices colors are blended with the texture. + * `true` = A fill tint, where the vertices colors replace the texture, but respects texture alpha. */ tintFill: boolean; @@ -69161,7 +74833,7 @@ declare namespace Phaser { * @param bottomLeft The tint being applied to the bottom-left of the Game Object. * @param bottomRight The tint being applied to the bottom-right of the Game Object. */ - setTint(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; + setTint(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; /** * Sets a fill-based tint on this Game Object. @@ -69184,40 +74856,19 @@ declare namespace Phaser { * @param bottomLeft The tint being applied to the bottom-left of the Game Object. * @param bottomRight The tint being applied to the bottom-right of the Game Object. */ - setTintFill(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; - - /** - * The tint value being applied to the top-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintTopLeft: integer; - - /** - * The tint value being applied to the top-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintTopRight: integer; - - /** - * The tint value being applied to the bottom-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintBottomLeft: integer; - - /** - * The tint value being applied to the bottom-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintBottomRight: integer; + setTintFill(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; /** * The tint value being applied to the whole of the Game Object. * This property is a setter-only. Use the properties `tintTopLeft` etc to read the current tint value. */ - tint: integer; + tint: number; /** - * Does this Game Object have a tint applied to it or not? + * Does this Game Object have a tint applied? + * + * It checks to see if the 4 tint properties are set to the value 0xffffff + * and that the `tintFill` property is `false`. This indicates that a Game Object isn't tinted. */ readonly isTinted: boolean; @@ -69271,13 +74922,13 @@ declare namespace Phaser { * * If you prefer to work in radians, see the `rotation` property instead. */ - angle: integer; + angle: number; /** * The angle of this Game Object in radians. * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. * * If you prefer to work in degrees, see the `angle` property instead. */ @@ -69292,6 +74943,12 @@ declare namespace Phaser { */ setPosition(x?: number, y?: number, z?: number, w?: number): this; + /** + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; + /** * Sets the position of this Game Object to be a random position within the confines of * the given area. @@ -69366,6 +75023,22 @@ declare namespace Phaser { */ getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. + */ + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + /** * Gets the sum total rotation of all of this Game Objects parent Containers. * @@ -70291,7 +75964,7 @@ declare namespace Phaser { * @param y The vertical position to align the body to. * @param align One of the `Phaser.Display.Align` constants, such as `Phaser.Display.Align.TOP_LEFT`. */ - alignBody(body: Phaser.Types.Physics.Matter.MatterBody, x: number, y: number, align: integer): this; + alignBody(body: Phaser.Types.Physics.Matter.MatterBody, x: number, y: number, align: number): this; } @@ -70312,11 +75985,11 @@ declare namespace Phaser { * @param world A reference to the Matter.World instance that this body belongs to. * @param x The horizontal position of this Game Object in the world. * @param y The vertical position of this Game Object in the world. - * @param texture The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. + * @param texture The key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager. * @param frame An optional frame from the Texture this Game Object is rendering with. * @param options An optional Body configuration object that is used to set initial Body properties on creation. */ - constructor(world: Phaser.Physics.Matter.World, x: number, y: number, texture: string, frame?: string | integer, options?: Phaser.Types.Physics.Matter.MatterBodyConfig); + constructor(world: Phaser.Physics.Matter.World, x: number, y: number, texture: string | Phaser.Textures.Texture, frame?: string | number, options?: Phaser.Types.Physics.Matter.MatterBodyConfig); /** * A reference to the Matter.World instance that this body belongs to. @@ -70427,7 +76100,7 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. @@ -70440,13 +76113,13 @@ declare namespace Phaser { * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order * of Game Objects, without actually moving their position in the display list. * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth + * The default depth is zero. A Game Object with a higher depth * value will always render in front of one with a lower value. * * Setting the depth will queue a depth sort event within the Scene. * @param value The depth of this Game Object. */ - setDepth(value: integer): this; + setDepth(value: number): this; /** * The horizontally flipped state of the Game Object. @@ -70622,6 +76295,8 @@ declare namespace Phaser { * Creates and returns a Bitmap Mask. This mask can be used by any Game Object, * including this one. * + * Note: Bitmap Masks only work on WebGL. Geometry Masks work on both WebGL and Canvas. + * * To create the mask you need to pass in a reference to a renderable Game Object. * A renderable Game Object is one that uses a texture to render with, such as an * Image, Sprite, Render Texture or BitmapText. @@ -70707,6 +76382,8 @@ declare namespace Phaser { /** * The initial WebGL pipeline of this Game Object. + * + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. */ defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; @@ -70715,23 +76392,109 @@ declare namespace Phaser { */ pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + /** + * Does this Game Object have any Post Pipelines set? + */ + hasPostPipeline: boolean; + + /** + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. + * + * The pipelines are processed in the order in which they appear in this array. + * + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. + */ + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; + + /** + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. + */ + pipelineData: object; + /** * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + */ + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; + + /** + * Sets the main WebGL Pipeline of this Game Object. + * + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; + + /** + * Sets one, or more, Post Pipelines on this Game Object. + * + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. + */ + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; + + /** + * Adds an entry to the `pipelineData` object belonging to this Game Object. + * + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. */ - initPipeline(pipelineName?: string): boolean; + setPipelineData(key: string, value?: any): this; /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - setPipeline(pipelineName: string): this; + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; /** * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; + + /** + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. + */ + resetPostPipeline(resetData?: boolean): void; + + /** + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. + * + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - resetPipeline(): boolean; + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; /** * Gets the name of the WebGL Pipeline this Game Object is currently using. @@ -70924,7 +76687,7 @@ declare namespace Phaser { * @param key The key of the texture to be used, as stored in the Texture Manager. * @param frame The name or index of the frame within the Texture. */ - setTexture(key: string, frame?: string | integer): this; + setTexture(key: string, frame?: string | number): this; /** * Sets the frame this Game Object will use to render with. @@ -70939,10 +76702,41 @@ declare namespace Phaser { * @param updateSize Should this call adjust the size of the Game Object? Default true. * @param updateOrigin Should this call adjust the origin of the Game Object? Default true. */ - setFrame(frame: string | integer, updateSize?: boolean, updateOrigin?: boolean): this; + setFrame(frame: string | number, updateSize?: boolean, updateOrigin?: boolean): this; + + /** + * The tint value being applied to the top-left vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintTopLeft: number; + + /** + * The tint value being applied to the top-right vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintTopRight: number; + + /** + * The tint value being applied to the bottom-left vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintBottomLeft: number; + + /** + * The tint value being applied to the bottom-right vertice of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. + * The value should be set as a hex number, i.e. 0xff0000 for red, or 0xff00ff for purple. + */ + tintBottomRight: number; /** - * Fill or additive? + * The tint fill mode. + * + * `false` = An additive tint (the default), where vertices colors are blended with the texture. + * `true` = A fill tint, where the vertices colors replace the texture, but respects texture alpha. */ tintFill: boolean; @@ -70974,7 +76768,7 @@ declare namespace Phaser { * @param bottomLeft The tint being applied to the bottom-left of the Game Object. * @param bottomRight The tint being applied to the bottom-right of the Game Object. */ - setTint(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; + setTint(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; /** * Sets a fill-based tint on this Game Object. @@ -70997,40 +76791,19 @@ declare namespace Phaser { * @param bottomLeft The tint being applied to the bottom-left of the Game Object. * @param bottomRight The tint being applied to the bottom-right of the Game Object. */ - setTintFill(topLeft?: integer, topRight?: integer, bottomLeft?: integer, bottomRight?: integer): this; - - /** - * The tint value being applied to the top-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintTopLeft: integer; - - /** - * The tint value being applied to the top-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintTopRight: integer; - - /** - * The tint value being applied to the bottom-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintBottomLeft: integer; - - /** - * The tint value being applied to the bottom-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. - */ - tintBottomRight: integer; + setTintFill(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; /** * The tint value being applied to the whole of the Game Object. * This property is a setter-only. Use the properties `tintTopLeft` etc to read the current tint value. */ - tint: integer; + tint: number; /** - * Does this Game Object have a tint applied to it or not? + * Does this Game Object have a tint applied? + * + * It checks to see if the 4 tint properties are set to the value 0xffffff + * and that the `tintFill` property is `false`. This indicates that a Game Object isn't tinted. */ readonly isTinted: boolean; @@ -71084,13 +76857,13 @@ declare namespace Phaser { * * If you prefer to work in radians, see the `rotation` property instead. */ - angle: integer; + angle: number; /** * The angle of this Game Object in radians. * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. * * If you prefer to work in degrees, see the `angle` property instead. */ @@ -71105,6 +76878,12 @@ declare namespace Phaser { */ setPosition(x?: number, y?: number, z?: number, w?: number): this; + /** + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; + /** * Sets the position of this Game Object to be a random position within the confines of * the given area. @@ -71179,6 +76958,22 @@ declare namespace Phaser { */ getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. + * + * The returned Vector2 contains the translated point in its properties. + * + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. + */ + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + /** * Gets the sum total rotation of all of this Game Objects parent Containers. * @@ -71537,7 +77332,7 @@ declare namespace Phaser { * Note: not all Tiled collision shapes are supported. See * Phaser.Physics.Matter.TileBody#setFromTileCollision for more information. */ - class TileBody implements Phaser.Physics.Matter.Components.Bounce, Phaser.Physics.Matter.Components.Collision, Phaser.Physics.Matter.Components.Friction, Phaser.Physics.Matter.Components.Gravity, Phaser.Physics.Matter.Components.Mass, Phaser.Physics.Matter.Components.Sensor, Phaser.Physics.Matter.Components.Sleep, Phaser.Physics.Matter.Components.Static { + class TileBody extends Phaser.Events.EventEmitter implements Phaser.Physics.Matter.Components.Bounce, Phaser.Physics.Matter.Components.Collision, Phaser.Physics.Matter.Components.Friction, Phaser.Physics.Matter.Components.Gravity, Phaser.Physics.Matter.Components.Mass, Phaser.Physics.Matter.Components.Sensor, Phaser.Physics.Matter.Components.Sleep, Phaser.Physics.Matter.Components.Static { /** * * @param world The Matter world instance this body belongs to. @@ -72260,7 +78055,7 @@ declare namespace Phaser { * @param tilemapLayer An array of tiles. * @param options Options to be passed to the MatterTileBody constructor. {@see Phaser.Physics.Matter.TileBody} */ - convertTilemapLayer(tilemapLayer: Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer, options?: object): this; + convertTilemapLayer(tilemapLayer: Phaser.Tilemaps.TilemapLayer, options?: object): this; /** * Adds `MatterTileBody` instances for the given tiles. This adds bodies regardless of whether the @@ -72591,47 +78386,38 @@ declare namespace Phaser { } - type DefaultPlugins = { + /** + * The Default Plugins. + */ + namespace DefaultPlugins { /** * These are the Global Managers that are created by the Phaser.Game instance. + * They are referenced from Scene.Systems so that plugins can use them. */ - Global: any[]; + var Global: any[]; + /** * These are the core plugins that are installed into every Scene.Systems instance, no matter what. + * They are optionally exposed in the Scene as well (see the InjectionMap for details) + * + * They are created in the order in which they appear in this array and EventEmitter is always first. */ - CoreScene: any[]; + var CoreScene: any[]; + /** * These plugins are created in Scene.Systems in addition to the CoreScenePlugins. + * + * You can elect not to have these plugins by either creating a DefaultPlugins object as part + * of the Game Config, by creating a Plugins object as part of a Scene Config, or by modifying this array + * and building your own bundle. + * + * They are optionally exposed in the Scene as well (see the InjectionMap for details) + * + * They are always created in the order in which they appear in the array. */ - DefaultScene: any[]; - }; - - /** - * These are the Global Managers that are created by the Phaser.Game instance. - * They are referenced from Scene.Systems so that plugins can use them. - */ - var Global: any[]; + var DefaultScene: any[]; - /** - * These are the core plugins that are installed into every Scene.Systems instance, no matter what. - * They are optionally exposed in the Scene as well (see the InjectionMap for details) - * - * They are created in the order in which they appear in this array and EventEmitter is always first. - */ - var CoreScene: any[]; - - /** - * These plugins are created in Scene.Systems in addition to the CoreScenePlugins. - * - * You can elect not to have these plugins by either creating a DefaultPlugins object as part - * of the Game Config, by creating a Plugins object as part of a Scene Config, or by modifying this array - * and building your own bundle. - * - * They are optionally exposed in the Scene as well (see the InjectionMap for details) - * - * They are always created in the order in which they appear in the array. - */ - var DefaultScene: any[]; + } namespace PluginCache { /** @@ -72849,7 +78635,7 @@ declare namespace Phaser { * Gets an index of a global plugin based on the given key. * @param key The unique plugin key. */ - protected getIndex(key: string): integer; + protected getIndex(key: string): number; /** * Gets a global plugin based on the given key. @@ -72887,7 +78673,7 @@ declare namespace Phaser { * If the plugin is not already running, nothing will happen. * @param key The key of the plugin to stop. */ - stop(key: string): Phaser.Plugins.PluginManager; + stop(key: string): this; /** * Gets a global plugin from the Plugin Manager based on the given key and returns it. @@ -73233,15 +79019,23 @@ declare namespace Phaser { namespace Renderer { namespace Canvas { /** - * The Canvas Renderer is responsible for managing 2D canvas rendering contexts, including the one used by the Game's canvas. It tracks the internal state of a given context and can renderer textured Game Objects to it, taking into account alpha, blending, and scaling. + * The Canvas Renderer is responsible for managing 2D canvas rendering contexts, + * including the one used by the Games canvas. It tracks the internal state of a + * given context and can renderer textured Game Objects to it, taking into + * account alpha, blending, and scaling. */ - class CanvasRenderer { + class CanvasRenderer extends Phaser.Events.EventEmitter { /** * * @param game The Phaser Game instance that owns this renderer. */ constructor(game: Phaser.Game); + /** + * The local configuration settings of the CanvasRenderer. + */ + config: object; + /** * The Phaser Game instance that owns this renderer. */ @@ -73250,7 +79044,7 @@ declare namespace Phaser { /** * A constant which allows the renderer to be easily identified as a Canvas Renderer. */ - type: integer; + type: number; /** * The total number of Game Objects which were rendered in a frame. @@ -73260,17 +79054,12 @@ declare namespace Phaser { /** * The width of the canvas being rendered to. */ - width: integer; + width: number; /** * The height of the canvas being rendered to. */ - height: integer; - - /** - * The local configuration settings of the CanvasRenderer. - */ - config: object; + height: number; /** * The canvas element which the Game uses. @@ -73306,6 +79095,11 @@ declare namespace Phaser { */ snapshotState: Phaser.Types.Renderer.Snapshot.SnapshotState; + /** + * Has this renderer fully booted yet? + */ + isBooted: boolean; + /** * Prepares the game canvas for rendering. */ @@ -73315,10 +79109,8 @@ declare namespace Phaser { * The event handler that manages the `resize` event dispatched by the Scale Manager. * @param gameSize The default Game Size object. This is the un-modified game dimensions. * @param baseSize The base Size object. The game dimensions multiplied by the resolution. The canvas width / height values match this. - * @param displaySize The display Size object. The size of the canvas style width / height attributes. - * @param resolution The Scale Manager resolution setting. */ - onResize(gameSize: Phaser.Structs.Size, baseSize: Phaser.Structs.Size, displaySize: Phaser.Structs.Size, resolution?: number): void; + onResize(gameSize: Phaser.Structs.Size, baseSize: Phaser.Structs.Size): void; /** * Resize the main game canvas. @@ -73356,13 +79148,19 @@ declare namespace Phaser { preRender(): void; /** - * Renders the Scene to the given Camera. + * The core render step for a Scene Camera. + * + * Iterates through the given array of Game Objects and renders them with the given Camera. + * + * This is called by the `CameraManager.render` method. The Camera Manager instance belongs to a Scene, and is invoked + * by the Scene Systems.render method. + * + * This method is not called if `Camera.visible` is `false`, or `Camera.alpha` is zero. * @param scene The Scene to render. - * @param children The Game Objects within the Scene to be rendered. - * @param interpolationPercentage The interpolation percentage to apply. Currently unused. + * @param children An array of filtered Game Objects that can be rendered by the given Camera. * @param camera The Scene Camera to render with. */ - render(scene: Phaser.Scene, children: Phaser.GameObjects.DisplayList, interpolationPercentage: number, camera: Phaser.Cameras.Scene2D.Camera): void; + render(scene: Phaser.Scene, children: Phaser.GameObjects.GameObject[], camera: Phaser.Cameras.Scene2D.Camera): void; /** * Restores the game context's global settings and takes a snapshot if one is scheduled. @@ -73388,725 +79186,1948 @@ declare namespace Phaser { * @param type The format of the image to create, usually `image/png` or `image/jpeg`. Default 'image/png'. * @param encoderOptions The image quality, between 0 and 1. Used for image formats with lossy compression, such as `image/jpeg`. Default 0.92. */ - snapshotCanvas(canvas: HTMLCanvasElement, callback: Phaser.Types.Renderer.Snapshot.SnapshotCallback, getPixel?: boolean, x?: integer, y?: integer, width?: integer, height?: integer, type?: string, encoderOptions?: number): this; + snapshotCanvas(canvas: HTMLCanvasElement, callback: Phaser.Types.Renderer.Snapshot.SnapshotCallback, getPixel?: boolean, x?: number, y?: number, width?: number, height?: number, type?: string, encoderOptions?: number): this; + + /** + * Schedules a snapshot of the entire game viewport to be taken after the current frame is rendered. + * + * To capture a specific area see the `snapshotArea` method. To capture a specific pixel, see `snapshotPixel`. + * + * Only one snapshot can be active _per frame_. If you have already called `snapshotPixel`, for example, then + * calling this method will override it. + * + * Snapshots work by creating an Image object from the canvas data, this is a blocking process, which gets + * more expensive the larger the canvas size gets, so please be careful how you employ this in your game. + * @param callback The Function to invoke after the snapshot image is created. + * @param type The format of the image to create, usually `image/png` or `image/jpeg`. Default 'image/png'. + * @param encoderOptions The image quality, between 0 and 1. Used for image formats with lossy compression, such as `image/jpeg`. Default 0.92. + */ + snapshot(callback: Phaser.Types.Renderer.Snapshot.SnapshotCallback, type?: string, encoderOptions?: number): this; + + /** + * Schedules a snapshot of the given area of the game viewport to be taken after the current frame is rendered. + * + * To capture the whole game viewport see the `snapshot` method. To capture a specific pixel, see `snapshotPixel`. + * + * Only one snapshot can be active _per frame_. If you have already called `snapshotPixel`, for example, then + * calling this method will override it. + * + * Snapshots work by creating an Image object from the canvas data, this is a blocking process, which gets + * more expensive the larger the canvas size gets, so please be careful how you employ this in your game. + * @param x The x coordinate to grab from. + * @param y The y coordinate to grab from. + * @param width The width of the area to grab. + * @param height The height of the area to grab. + * @param callback The Function to invoke after the snapshot image is created. + * @param type The format of the image to create, usually `image/png` or `image/jpeg`. Default 'image/png'. + * @param encoderOptions The image quality, between 0 and 1. Used for image formats with lossy compression, such as `image/jpeg`. Default 0.92. + */ + snapshotArea(x: number, y: number, width: number, height: number, callback: Phaser.Types.Renderer.Snapshot.SnapshotCallback, type?: string, encoderOptions?: number): this; + + /** + * Schedules a snapshot of the given pixel from the game viewport to be taken after the current frame is rendered. + * + * To capture the whole game viewport see the `snapshot` method. To capture a specific area, see `snapshotArea`. + * + * Only one snapshot can be active _per frame_. If you have already called `snapshotArea`, for example, then + * calling this method will override it. + * + * Unlike the other two snapshot methods, this one will return a `Color` object containing the color data for + * the requested pixel. It doesn't need to create an internal Canvas or Image object, so is a lot faster to execute, + * using less memory. + * @param x The x coordinate of the pixel to get. + * @param y The y coordinate of the pixel to get. + * @param callback The Function to invoke after the snapshot pixel data is extracted. + */ + snapshotPixel(x: number, y: number, callback: Phaser.Types.Renderer.Snapshot.SnapshotCallback): this; + + /** + * Takes a Sprite Game Object, or any object that extends it, and draws it to the current context. + * @param sprite The texture based Game Object to draw. + * @param frame The frame to draw, doesn't have to be that owned by the Game Object. + * @param camera The Camera to use for the rendering transform. + * @param parentTransformMatrix The transform matrix of the parent container, if set. + */ + batchSprite(sprite: Phaser.GameObjects.GameObject, frame: Phaser.Textures.Frame, camera: Phaser.Cameras.Scene2D.Camera, parentTransformMatrix?: Phaser.GameObjects.Components.TransformMatrix): void; + + /** + * Destroys all object references in the Canvas Renderer. + */ + destroy(): void; + + } + + /** + * Returns an array which maps the default blend modes to supported Canvas blend modes. + * + * If the browser doesn't support a blend mode, it will default to the normal `source-over` blend mode. + */ + function GetBlendModes(): any[]; + + /** + * Takes a reference to the Canvas Renderer, a Canvas Rendering Context, a Game Object, a Camera and a parent matrix + * and then performs the following steps: + * + * 1. Checks the alpha of the source combined with the Camera alpha. If 0 or less it aborts. + * 2. Takes the Camera and Game Object matrix and multiplies them, combined with the parent matrix if given. + * 3. Sets the blend mode of the context to be that used by the Game Object. + * 4. Sets the alpha value of the context to be that used by the Game Object combined with the Camera. + * 5. Saves the context state. + * 6. Sets the final matrix values into the context via setTransform. + * 7. If Renderer.antialias, or the frame.source.scaleMode is set, then imageSmoothingEnabled is set. + * + * This function is only meant to be used internally. Most of the Canvas Renderer classes use it. + * @param renderer A reference to the current active Canvas renderer. + * @param ctx The canvas context to set the transform on. + * @param src The Game Object being rendered. Can be any type that extends the base class. + * @param camera The Camera that is rendering the Game Object. + * @param parentMatrix A parent transform matrix to apply to the Game Object before rendering. + */ + function SetTransform(renderer: Phaser.Renderer.Canvas.CanvasRenderer, ctx: CanvasRenderingContext2D, src: Phaser.GameObjects.GameObject, camera: Phaser.Cameras.Scene2D.Camera, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): boolean; + + } + + namespace Events { + /** + * The Post-Render Event. + * + * This event is dispatched by the Renderer when all rendering, for all cameras in all Scenes, + * has completed, but before any pending snap shots have been taken. + */ + const POST_RENDER: any; + + /** + * The Pre-Render Event. + * + * This event is dispatched by the Phaser Renderer. This happens right at the start of the render + * process, after the context has been cleared, the scissors enabled (WebGL only) and everything has been + * reset ready for the render. + */ + const PRE_RENDER: any; + + /** + * The Render Event. + * + * This event is dispatched by the Phaser Renderer for every camera in every Scene. + * + * It is dispatched before any of the children in the Scene have been rendered. + */ + const RENDER: any; + + /** + * The Renderer Resize Event. + * + * This event is dispatched by the Phaser Renderer when it is resized, usually as a result + * of the Scale Manager resizing. + */ + const RESIZE: any; + + } + + namespace Snapshot { + /** + * Takes a snapshot of an area from the current frame displayed by a canvas. + * + * This is then copied to an Image object. When this loads, the results are sent + * to the callback provided in the Snapshot Configuration object. + * @param sourceCanvas The canvas to take a snapshot of. + * @param config The snapshot configuration object. + */ + function Canvas(sourceCanvas: HTMLCanvasElement, config: Phaser.Types.Renderer.Snapshot.SnapshotState): void; + + /** + * Takes a snapshot of an area from the current frame displayed by a WebGL canvas. + * + * This is then copied to an Image object. When this loads, the results are sent + * to the callback provided in the Snapshot Configuration object. + * @param sourceCanvas The canvas to take a snapshot of. + * @param config The snapshot configuration object. + */ + function WebGL(sourceCanvas: HTMLCanvasElement, config: Phaser.Types.Renderer.Snapshot.SnapshotState): void; + + } + + namespace WebGL { + /** + * 8-bit twos complement signed integer. + */ + var BYTE: Phaser.Types.Renderer.WebGL.WebGLConst; + + /** + * 8-bit twos complement unsigned integer. + */ + var UNSIGNED_BYTE: Phaser.Types.Renderer.WebGL.WebGLConst; + + /** + * 16-bit twos complement signed integer. + */ + var SHORT: Phaser.Types.Renderer.WebGL.WebGLConst; + + /** + * 16-bit twos complement unsigned integer. + */ + var UNSIGNED_SHORT: Phaser.Types.Renderer.WebGL.WebGLConst; + + /** + * 32-bit twos complement signed integer. + */ + var INT: Phaser.Types.Renderer.WebGL.WebGLConst; + + /** + * 32-bit twos complement unsigned integer. + */ + var UNSIGNED_INT: Phaser.Types.Renderer.WebGL.WebGLConst; + + /** + * 32-bit IEEE floating point number. + */ + var FLOAT: Phaser.Types.Renderer.WebGL.WebGLConst; + + /** + * The Pipeline Manager is responsible for the creation, activation, running and destruction + * of WebGL Pipelines and Post FX Pipelines in Phaser 3. + * + * The `WebGLRenderer` owns a single instance of the Pipeline Manager, which you can access + * via the `WebGLRenderer.pipelines` property. + * + * By default, there are 8 pipelines installed into the Pipeline Manager when Phaser boots: + * + * 1. The Multi Pipeline. Responsible for all multi-texture rendering, i.e. Sprites and Tilemaps. + * 2. The Graphics Pipeline. Responsible for rendering Graphics and Shape objects. + * 3. The Rope Pipeline. Responsible for rendering the Rope Game Object. + * 4. The Light Pipeline. Responsible for rendering the Light Game Object. + * 5. The Point Light Pipeline. Responsible for rendering the Point Light Game Object. + * 6. The Single Pipeline. Responsible for rendering Game Objects that explicitly require one bound texture. + * 7. The Bitmap Mask Pipeline. Responsible for Bitmap Mask rendering. + * 8. The Utility Pipeline. Responsible for providing lots of handy texture manipulation functions. + * + * You can add your own custom pipeline via the `PipelineManager.add` method. Pipelines are + * identified by unique string-based keys. + */ + class PipelineManager { + /** + * + * @param renderer A reference to the WebGL Renderer that owns this Pipeline Manager. + */ + constructor(renderer: Phaser.Renderer.WebGL.WebGLRenderer); + + /** + * A reference to the Game instance. + */ + game: Phaser.Game; + + /** + * A reference to the WebGL Renderer instance. + */ + renderer: Phaser.Renderer.WebGL.WebGLRenderer; + + /** + * This map stores all pipeline classes available in this manager. + * + * The Utility Class must always come first. + */ + classes: Phaser.Structs.Map; + + /** + * This map stores all Post FX Pipeline classes available in this manager. + */ + postPipelineClasses: Phaser.Structs.Map; + + /** + * This map stores all pipeline instances in this manager. + * + * This is populated with the default pipelines in the `boot` method. + */ + pipelines: Phaser.Structs.Map; + + /** + * Current pipeline in use by the WebGLRenderer. + */ + current: Phaser.Renderer.WebGL.WebGLPipeline; + + /** + * The previous WebGLPipeline that was in use. + * + * This is set when `clearPipeline` is called and restored in `rebindPipeline` if none is given. + */ + previous: Phaser.Renderer.WebGL.WebGLPipeline; + + /** + * A constant-style reference to the Multi Pipeline Instance. + * + * This is the default Phaser 3 pipeline and is used by the WebGL Renderer to manage + * camera effects and more. This property is set during the `boot` method. + */ + MULTI_PIPELINE: Phaser.Renderer.WebGL.Pipelines.MultiPipeline; + + /** + * A constant-style reference to the Bitmap Mask Pipeline Instance. + * + * This is the default Phaser 3 mask pipeline and is used Game Objects using + * a Bitmap Mask. This property is set during the `boot` method. + */ + BITMAPMASK_PIPELINE: Phaser.Renderer.WebGL.Pipelines.BitmapMaskPipeline; + + /** + * A constant-style reference to the Utility Pipeline Instance. + */ + UTILITY_PIPELINE: Phaser.Renderer.WebGL.Pipelines.UtilityPipeline; + + /** + * A reference to the Full Frame 1 Render Target that belongs to the + * Utility Pipeline. This property is set during the `boot` method. + * + * This Render Target is the full size of the renderer. + * + * You can use this directly in Post FX Pipelines for multi-target effects. + * However, be aware that these targets are shared between all post fx pipelines. + */ + fullFrame1: Phaser.Renderer.WebGL.RenderTarget; + + /** + * A reference to the Full Frame 2 Render Target that belongs to the + * Utility Pipeline. This property is set during the `boot` method. + * + * This Render Target is the full size of the renderer. + * + * You can use this directly in Post FX Pipelines for multi-target effects. + * However, be aware that these targets are shared between all post fx pipelines. + */ + fullFrame2: Phaser.Renderer.WebGL.RenderTarget; + + /** + * A reference to the Half Frame 1 Render Target that belongs to the + * Utility Pipeline. This property is set during the `boot` method. + * + * This Render Target is half the size of the renderer. + * + * You can use this directly in Post FX Pipelines for multi-target effects. + * However, be aware that these targets are shared between all post fx pipelines. + */ + halfFrame1: Phaser.Renderer.WebGL.RenderTarget; + + /** + * A reference to the Half Frame 2 Render Target that belongs to the + * Utility Pipeline. This property is set during the `boot` method. + * + * This Render Target is half the size of the renderer. + * + * You can use this directly in Post FX Pipelines for multi-target effects. + * However, be aware that these targets are shared between all post fx pipelines. + */ + halfFrame2: Phaser.Renderer.WebGL.RenderTarget; + + /** + * Internal boot handler, called by the WebGLRenderer durings its boot process. + * + * Adds all of the default pipelines, based on the game config, and then calls + * the `boot` method on each one of them. + * + * Finally, the default pipeline is set. + * @param pipelineConfig The pipeline configuration object as set in the Game Config. + */ + boot(pipelineConfig?: Phaser.Types.Core.PipelineConfig): void; + + /** + * Adds a pipeline instance to this Pipeline Manager. + * + * The name of the instance must be unique within this manager. + * + * Make sure to pass an instance to this method, not a base class. + * + * For example, you should pass it like this: + * + * ```javascript + * this.add('yourName', new CustomPipeline());` + * ``` + * + * and **not** like this: + * + * ```javascript + * this.add('yourName', CustomPipeline);` + * ``` + * + * To add a **Post Pipeline**, see `addPostPipeline` instead. + * @param name A unique string-based key for the pipeline within the manager. + * @param pipeline A pipeline _instance_ which must extend `WebGLPipeline`. + */ + add(name: string, pipeline: Phaser.Renderer.WebGL.WebGLPipeline): Phaser.Renderer.WebGL.WebGLPipeline; + + /** + * Adds a Post Pipeline to this Pipeline Manager. + * + * Make sure to pass a base class to this method, not an instance. + * + * For example, you should pass it like this: + * + * ```javascript + * this.addPostPipeline('yourName', CustomPipeline);` + * ``` + * + * and **not** like this: + * + * ```javascript + * this.addPostPipeline('yourName', new CustomPipeline());` + * ``` + * + * To add a regular pipeline, see the `add` method instead. + * @param name A unique string-based key for the pipeline within the manager. + * @param pipeline A pipeline class which must extend `PostFXPipeline`. + */ + addPostPipeline(name: string, pipeline: Function): this; + + /** + * Flushes the current pipeline, if one is bound. + */ + flush(): void; + + /** + * Checks if a pipeline is present in this Pipeline Manager. + * @param pipeline Either the string-based name of the pipeline to get, or a pipeline instance to look-up. + */ + has(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; + + /** + * Returns the pipeline instance based on the given name, or instance. + * + * If no instance, or matching name, exists in this manager, it returns `undefined`. + * @param pipeline Either the string-based name of the pipeline to get, or a pipeline instance to look-up. + */ + get(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): Phaser.Renderer.WebGL.WebGLPipeline; + + /** + * Returns a _new instance_ of the post pipeline based on the given name, or class. + * + * If no instance, or matching name, exists in this manager, it returns `undefined`. + * @param pipeline Either the string-based name of the pipeline to get, or a pipeline instance, or class to look-up. + * @param gameObject If this post pipeline is being installed into a Game Object or Camera, this is a reference to it. + */ + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline, gameObject?: Phaser.GameObjects.GameObject): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; + + /** + * Removes a pipeline instance based on the given name. + * + * If no pipeline matches the name, this method does nothing. + * + * Note that the pipeline will not be flushed or destroyed, it's simply removed from + * this manager. + * @param name The name of the pipeline to be removed. + * @param removeClass Remove the pipeline class as well as the instance? Default true. + * @param removePostPipelineClass Remove the post pipeline class as well as the instance? Default true. + */ + remove(name: string, removeClass?: boolean, removePostPipelineClass?: boolean): void; + + /** + * Sets the current pipeline to be used by the `WebGLRenderer`. + * + * This method accepts a pipeline instance as its parameter, not the name. + * + * If the pipeline isn't already the current one it will call `WebGLPipeline.bind` and then `onBind`. + * + * You cannot set Post FX Pipelines using this method. To use a Post FX Pipeline, you should + * apply it to either a Camera, Container or other supporting Game Object. + * @param pipeline The pipeline instance to be set as current. + * @param gameObject The Game Object that invoked this pipeline, if any. + * @param currentShader The shader to set as being current. + */ + set(pipeline: Phaser.Renderer.WebGL.WebGLPipeline, gameObject?: Phaser.GameObjects.GameObject, currentShader?: Phaser.Renderer.WebGL.WebGLShader): Phaser.Renderer.WebGL.WebGLPipeline; + + /** + * This method is called by the `WebGLPipeline.batchQuad` method, right before a quad + * belonging to a Game Object is about to be added to the batch. It causes a batch + * flush, then calls the `preBatch` method on the post-fx pipelines belonging to the + * Game Object. + * @param gameObject The Game Object about to be batched. + */ + preBatch(gameObject: Phaser.GameObjects.GameObject): void; + + /** + * This method is called by the `WebGLPipeline.batchQuad` method, right after a quad + * belonging to a Game Object has been added to the batch. It causes a batch + * flush, then calls the `postBatch` method on the post-fx pipelines belonging to the + * Game Object. + * @param gameObject The Game Object that was just added to the batch. + */ + postBatch(gameObject: Phaser.GameObjects.GameObject): void; + + /** + * Called at the start of the `WebGLRenderer.preRenderCamera` method. + * + * If the Camera has post pipelines set, it will flush the batch and then call the + * `preBatch` method on the post-fx pipelines belonging to the Camera. + * @param camera The Camera about to be rendered. + */ + preBatchCamera(camera: Phaser.Cameras.Scene2D.Camera): void; + + /** + * Called at the end of the `WebGLRenderer.postRenderCamera` method. + * + * If the Camera has post pipelines set, it will flush the batch and then call the + * `postBatch` method on the post-fx pipelines belonging to the Camera. + * @param camera The Camera that was just rendered. + */ + postBatchCamera(camera: Phaser.Cameras.Scene2D.Camera): void; + + /** + * Checks to see if the given pipeline is already the active pipeline, both within this + * Pipeline Manager and also has the same shader set in the Renderer. + * @param pipeline The pipeline instance to be checked. + * @param currentShader The shader to set as being current. + */ + isCurrent(pipeline: Phaser.Renderer.WebGL.WebGLPipeline, currentShader?: Phaser.Renderer.WebGL.WebGLShader): boolean; + + /** + * Copy the `source` Render Target to the `target` Render Target. + * + * You can optionally set the brightness factor of the copy. + * + * The difference between this method and `drawFrame` is that this method + * uses a faster copy shader, where only the brightness can be modified. + * If you need color level manipulation, see `drawFrame` instead. + * + * The copy itself is handled by the Utility Pipeline. + * @param source The source Render Target. + * @param target The target Render Target. + * @param brightness The brightness value applied to the frame copy. Default 1. + * @param clear Clear the target before copying? Default true. + * @param clearAlpha Clear the alpha channel when running `gl.clear` on the target? Default true. + */ + copyFrame(source: Phaser.Renderer.WebGL.RenderTarget, target?: Phaser.Renderer.WebGL.RenderTarget, brightness?: number, clear?: boolean, clearAlpha?: boolean): this; + + /** + * Pops the framebuffer from the renderers FBO stack and sets that as the active target, + * then draws the `source` Render Target to it. It then resets the renderer textures. + * + * This should be done when you need to draw the _final_ results of a pipeline to the game + * canvas, or the next framebuffer in line on the FBO stack. You should only call this once + * in the `onDraw` handler and it should be the final thing called. Be careful not to call + * this if you need to actually use the pipeline shader, instead of the copy shader. In + * those cases, use the `bindAndDraw` method. + * @param source The Render Target to draw from. + */ + copyToGame(source: Phaser.Renderer.WebGL.RenderTarget): void; + + /** + * Copy the `source` Render Target to the `target` Render Target, using the + * given Color Matrix. + * + * The difference between this method and `copyFrame` is that this method + * uses a color matrix shader, where you have full control over the luminance + * values used during the copy. If you don't need this, you can use the faster + * `copyFrame` method instead. + * + * The copy itself is handled by the Utility Pipeline. + * @param source The source Render Target. + * @param target The target Render Target. + * @param clearAlpha Clear the alpha channel when running `gl.clear` on the target? Default true. + * @param colorMatrix The Color Matrix to use when performing the draw. + */ + drawFrame(source: Phaser.Renderer.WebGL.RenderTarget, target?: Phaser.Renderer.WebGL.RenderTarget, clearAlpha?: boolean, colorMatrix?: Phaser.Display.ColorMatrix): this; + + /** + * Draws the `source1` and `source2` Render Targets to the `target` Render Target + * using a linear blend effect, which is controlled by the `strength` parameter. + * + * The draw itself is handled by the Utility Pipeline. + * @param source1 The first source Render Target. + * @param source2 The second source Render Target. + * @param target The target Render Target. + * @param strength The strength of the blend. Default 1. + * @param clearAlpha Clear the alpha channel when running `gl.clear` on the target? Default true. + */ + blendFrames(source1: Phaser.Renderer.WebGL.RenderTarget, source2: Phaser.Renderer.WebGL.RenderTarget, target?: Phaser.Renderer.WebGL.RenderTarget, strength?: number, clearAlpha?: boolean): this; + + /** + * Draws the `source1` and `source2` Render Targets to the `target` Render Target + * using an additive blend effect, which is controlled by the `strength` parameter. + * + * The draw itself is handled by the Utility Pipeline. + * @param source1 The first source Render Target. + * @param source2 The second source Render Target. + * @param target The target Render Target. + * @param strength The strength of the blend. Default 1. + * @param clearAlpha Clear the alpha channel when running `gl.clear` on the target? Default true. + */ + blendFramesAdditive(source1: Phaser.Renderer.WebGL.RenderTarget, source2: Phaser.Renderer.WebGL.RenderTarget, target?: Phaser.Renderer.WebGL.RenderTarget, strength?: number, clearAlpha?: boolean): this; + + /** + * Clears the given Render Target. + * @param target The Render Target to clear. + * @param clearAlpha Clear the alpha channel when running `gl.clear` on the target? Default true. + */ + clearFrame(target: Phaser.Renderer.WebGL.RenderTarget, clearAlpha?: boolean): this; + + /** + * Copy the `source` Render Target to the `target` Render Target. + * + * The difference with this copy is that no resizing takes place. If the `source` + * Render Target is larger than the `target` then only a portion the same size as + * the `target` dimensions is copied across. + * + * You can optionally set the brightness factor of the copy. + * @param source The source Render Target. + * @param target The target Render Target. + * @param brightness The brightness value applied to the frame copy. Default 1. + * @param clear Clear the target before copying? Default true. + * @param clearAlpha Clear the alpha channel when running `gl.clear` on the target? Default true. + * @param eraseMode Erase source from target using ERASE Blend Mode? Default false. + */ + blitFrame(source: Phaser.Renderer.WebGL.RenderTarget, target: Phaser.Renderer.WebGL.RenderTarget, brightness?: number, clear?: boolean, clearAlpha?: boolean, eraseMode?: boolean): this; + + /** + * Binds the `source` Render Target and then copies a section of it to the `target` Render Target. + * + * This method is extremely fast because it uses `gl.copyTexSubImage2D` and doesn't + * require the use of any shaders. Remember the coordinates are given in standard WebGL format, + * where x and y specify the lower-left corner of the section, not the top-left. Also, the + * copy entirely replaces the contents of the target texture, no 'merging' or 'blending' takes + * place. + * @param source The source Render Target. + * @param target The target Render Target. + * @param x The x coordinate of the lower left corner where to start copying. + * @param y The y coordinate of the lower left corner where to start copying. + * @param width The width of the texture. + * @param height The height of the texture. + * @param clear Clear the target before copying? Default true. + * @param clearAlpha Clear the alpha channel when running `gl.clear` on the target? Default true. + */ + copyFrameRect(source: Phaser.Renderer.WebGL.RenderTarget, target: Phaser.Renderer.WebGL.RenderTarget, x: number, y: number, width: number, height: number, clear?: boolean, clearAlpha?: boolean): this; + + /** + * Returns `true` if the current pipeline is forced to use texture unit zero. + */ + forceZero(): boolean; + + /** + * Sets the Multi Pipeline to be the currently bound pipeline. + * + * This is the default Phaser 3 rendering pipeline. + */ + setMulti(): Phaser.Renderer.WebGL.Pipelines.MultiPipeline; /** - * Schedules a snapshot of the entire game viewport to be taken after the current frame is rendered. + * Sets the Utility Pipeline to be the currently bound pipeline. + * @param currentShader The shader to set as being current. + */ + setUtility(currentShader?: Phaser.Renderer.WebGL.WebGLShader): Phaser.Renderer.WebGL.Pipelines.UtilityPipeline; + + /** + * Use this to reset the gl context to the state that Phaser requires to continue rendering. * - * To capture a specific area see the `snapshotArea` method. To capture a specific pixel, see `snapshotPixel`. + * Calling this will: * - * Only one snapshot can be active _per frame_. If you have already called `snapshotPixel`, for example, then - * calling this method will override it. + * * Disable `DEPTH_TEST`, `CULL_FACE` and `STENCIL_TEST`. + * * Clear the depth buffer and stencil buffers. + * * Reset the viewport size. + * * Reset the blend mode. + * * Bind a blank texture as the active texture on texture unit zero. + * * Rebinds the given pipeline instance. * - * Snapshots work by creating an Image object from the canvas data, this is a blocking process, which gets - * more expensive the larger the canvas size gets, so please be careful how you employ this in your game. - * @param callback The Function to invoke after the snapshot image is created. - * @param type The format of the image to create, usually `image/png` or `image/jpeg`. Default 'image/png'. - * @param encoderOptions The image quality, between 0 and 1. Used for image formats with lossy compression, such as `image/jpeg`. Default 0.92. + * You should call this if you have previously called `clear`, and then wish to return + * rendering control to Phaser again. + * @param pipeline The pipeline instance to be rebound. If not given, the previous pipeline will be bound. */ - snapshot(callback: Phaser.Types.Renderer.Snapshot.SnapshotCallback, type?: string, encoderOptions?: number): this; + rebind(pipeline?: Phaser.Renderer.WebGL.WebGLPipeline): void; /** - * Schedules a snapshot of the given area of the game viewport to be taken after the current frame is rendered. - * - * To capture the whole game viewport see the `snapshot` method. To capture a specific pixel, see `snapshotPixel`. + * Flushes the current pipeline being used and then clears it, along with the + * the current shader program and vertex buffer from the `WebGLRenderer`. * - * Only one snapshot can be active _per frame_. If you have already called `snapshotPixel`, for example, then - * calling this method will override it. + * Then resets the blend mode to NORMAL. * - * Snapshots work by creating an Image object from the canvas data, this is a blocking process, which gets - * more expensive the larger the canvas size gets, so please be careful how you employ this in your game. - * @param x The x coordinate to grab from. - * @param y The y coordinate to grab from. - * @param width The width of the area to grab. - * @param height The height of the area to grab. - * @param callback The Function to invoke after the snapshot image is created. - * @param type The format of the image to create, usually `image/png` or `image/jpeg`. Default 'image/png'. - * @param encoderOptions The image quality, between 0 and 1. Used for image formats with lossy compression, such as `image/jpeg`. Default 0.92. + * Call this before jumping to your own gl context handler, and then call `rebind` when + * you wish to return control to Phaser again. */ - snapshotArea(x: integer, y: integer, width: integer, height: integer, callback: Phaser.Types.Renderer.Snapshot.SnapshotCallback, type?: string, encoderOptions?: number): this; + clear(): void; /** - * Schedules a snapshot of the given pixel from the game viewport to be taken after the current frame is rendered. + * Destroy the Pipeline Manager, cleaning up all related resources and references. + */ + destroy(): void; + + } + + namespace Pipelines { + /** + * The Bitmap Mask Pipeline handles all of the bitmap mask rendering in WebGL for applying + * alpha masks to Game Objects. It works by sampling two texture on the fragment shader and + * using the fragments alpha to clip the region. * - * To capture the whole game viewport see the `snapshot` method. To capture a specific area, see `snapshotArea`. + * The fragment shader it uses can be found in `shaders/src/BitmapMask.frag`. + * The vertex shader it uses can be found in `shaders/src/BitmapMask.vert`. * - * Only one snapshot can be active _per frame_. If you have already called `snapshotArea`, for example, then - * calling this method will override it. + * The default shader attributes for this pipeline are: * - * Unlike the other two snapshot methods, this one will return a `Color` object containing the color data for - * the requested pixel. It doesn't need to create an internal Canvas or Image object, so is a lot faster to execute, - * using less memory. - * @param x The x coordinate of the pixel to get. - * @param y The y coordinate of the pixel to get. - * @param callback The Function to invoke after the snapshot pixel data is extracted. + * `inPosition` (vec2, offset 0) + * + * The default shader uniforms for this pipeline are: + * + * `uResolution` (vec2) + * `uMainSampler` (sampler2D) + * `uMaskSampler` (sampler2D) + * `uInvertMaskAlpha` (bool) */ - snapshotPixel(x: integer, y: integer, callback: Phaser.Types.Renderer.Snapshot.SnapshotCallback): this; + class BitmapMaskPipeline extends Phaser.Renderer.WebGL.WebGLPipeline { + /** + * + * @param config The configuration options for this pipeline. + */ + constructor(config: Phaser.Types.Renderer.WebGL.WebGLPipelineConfig); + + /** + * Binds necessary resources and renders the mask to a separated framebuffer. + * The framebuffer for the masked object is also bound for further use. + * @param mask GameObject used as mask. + * @param maskedObject GameObject masked by the mask GameObject. + * @param camera The camera rendering the current mask. + */ + beginMask(mask: Phaser.GameObjects.GameObject, maskedObject: Phaser.GameObjects.GameObject, camera: Phaser.Cameras.Scene2D.Camera): void; + + /** + * The masked game objects framebuffer is unbound and its texture + * is bound together with the mask texture and the mask shader and + * a draw call with a single quad is processed. Here is where the + * masking effect is applied. + * @param mask GameObject used as a mask. + */ + endMask(mask: Phaser.GameObjects.GameObject): void; + + } /** - * Takes a Sprite Game Object, or any object that extends it, and draws it to the current context. - * @param sprite The texture based Game Object to draw. - * @param frame The frame to draw, doesn't have to be that owned by the Game Object. - * @param camera The Camera to use for the rendering transform. - * @param parentTransformMatrix The transform matrix of the parent container, if set. + * The Bitmap Mask Pipeline. */ - batchSprite(sprite: Phaser.GameObjects.GameObject, frame: Phaser.Textures.Frame, camera: Phaser.Cameras.Scene2D.Camera, parentTransformMatrix?: Phaser.GameObjects.Components.TransformMatrix): void; + const BITMAPMASK_PIPELINE: string; /** - * Destroys all object references in the Canvas Renderer. + * The Light 2D Pipeline. */ - destroy(): void; + const LIGHT_PIPELINE: string; - } - - /** - * Returns an array which maps the default blend modes to supported Canvas blend modes. - * - * If the browser doesn't support a blend mode, it will default to the normal `source-over` blend mode. - */ - function GetBlendModes(): any[]; + /** + * The Point Light Pipeline. + */ + const POINTLIGHT_PIPELINE: string; - /** - * Takes a reference to the Canvas Renderer, a Canvas Rendering Context, a Game Object, a Camera and a parent matrix - * and then performs the following steps: - * - * 1. Checks the alpha of the source combined with the Camera alpha. If 0 or less it aborts. - * 2. Takes the Camera and Game Object matrix and multiplies them, combined with the parent matrix if given. - * 3. Sets the blend mode of the context to be that used by the Game Object. - * 4. Sets the alpha value of the context to be that used by the Game Object combined with the Camera. - * 5. Saves the context state. - * 6. Sets the final matrix values into the context via setTransform. - * 7. If Renderer.antialias, or the frame.source.scaleMode is set, then imageSmoothingEnabled is set. - * - * This function is only meant to be used internally. Most of the Canvas Renderer classes use it. - * @param renderer A reference to the current active Canvas renderer. - * @param ctx The canvas context to set the transform on. - * @param src The Game Object being rendered. Can be any type that extends the base class. - * @param camera The Camera that is rendering the Game Object. - * @param parentMatrix A parent transform matrix to apply to the Game Object before rendering. - */ - function SetTransform(renderer: Phaser.Renderer.Canvas.CanvasRenderer, ctx: CanvasRenderingContext2D, src: Phaser.GameObjects.GameObject, camera: Phaser.Cameras.Scene2D.Camera, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): boolean; + /** + * The Single Texture Pipeline. + */ + const SINGLE_PIPELINE: string; - } + /** + * The Multi Texture Pipeline. + */ + const MULTI_PIPELINE: string; - namespace Snapshot { - /** - * Takes a snapshot of an area from the current frame displayed by a canvas. - * - * This is then copied to an Image object. When this loads, the results are sent - * to the callback provided in the Snapshot Configuration object. - * @param sourceCanvas The canvas to take a snapshot of. - * @param config The snapshot configuration object. - */ - function Canvas(sourceCanvas: HTMLCanvasElement, config: Phaser.Types.Renderer.Snapshot.SnapshotState): void; + /** + * The Rope Pipeline. + */ + const ROPE_PIPELINE: string; - /** - * Takes a snapshot of an area from the current frame displayed by a WebGL canvas. - * - * This is then copied to an Image object. When this loads, the results are sent - * to the callback provided in the Snapshot Configuration object. - * @param sourceCanvas The canvas to take a snapshot of. - * @param config The snapshot configuration object. - */ - function WebGL(sourceCanvas: HTMLCanvasElement, config: Phaser.Types.Renderer.Snapshot.SnapshotState): void; + /** + * The Graphics and Shapes Pipeline. + */ + const GRAPHICS_PIPELINE: string; - } + /** + * The Post FX Pipeline. + */ + const POSTFX_PIPELINE: string; - namespace WebGL { - namespace Pipelines { /** - * BitmapMaskPipeline handles all bitmap masking rendering in WebGL. It works by using - * sampling two texture on the fragment shader and using the fragment's alpha to clip the region. - * The config properties are: - * - game: Current game instance. - * - renderer: Current WebGL renderer. - * - topology: This indicates how the primitives are rendered. The default value is GL_TRIANGLES. - * Here is the full list of rendering primitives (https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Constants). - * - vertShader: Source for vertex shader as a string. - * - fragShader: Source for fragment shader as a string. - * - vertexCapacity: The amount of vertices that shall be allocated - * - vertexSize: The size of a single vertex in bytes. + * The Utility Pipeline. */ - class BitmapMaskPipeline extends Phaser.Renderer.WebGL.WebGLPipeline { - /** - * - * @param config Used for overriding shader an pipeline properties if extending this pipeline. - */ - constructor(config: object); + const UTILITY_PIPELINE: string; + namespace Events { /** - * Float32 view of the array buffer containing the pipeline's vertices. + * The WebGLPipeline After Flush Event. + * + * This event is dispatched by a WebGLPipeline right after it has issued a drawArrays command + * and cleared its vertex count. */ - vertexViewF32: Float32Array; + const AFTER_FLUSH: any; /** - * Size of the batch. + * The WebGLPipeline Before Flush Event. + * + * This event is dispatched by a WebGLPipeline right before it is about to + * flush and issue a bufferData and drawArrays command. */ - maxQuads: number; + const BEFORE_FLUSH: any; /** - * Dirty flag to check if resolution properties need to be updated on the - * masking shader. + * The WebGLPipeline Bind Event. + * + * This event is dispatched by a WebGLPipeline when it is bound by the Pipeline Manager. */ - resolutionDirty: boolean; + const BIND: any; /** - * Called every time the pipeline needs to be used. - * It binds all necessary resources. + * The WebGLPipeline Boot Event. + * + * This event is dispatched by a WebGLPipeline when it has completed its `boot` phase. */ - onBind(): this; + const BOOT: any; /** - * [description] - * @param width [description] - * @param height [description] - * @param resolution [description] + * The WebGLPipeline Destroy Event. + * + * This event is dispatched by a WebGLPipeline when it is starting its destroy process. */ - resize(width: number, height: number, resolution: number): this; + const DESTROY: any; /** - * Binds necessary resources and renders the mask to a separated framebuffer. - * The framebuffer for the masked object is also bound for further use. - * @param mask GameObject used as mask. - * @param maskedObject GameObject masked by the mask GameObject. - * @param camera [description] + * The WebGLPipeline ReBind Event. + * + * This event is dispatched by a WebGLPipeline when it is re-bound by the Pipeline Manager. */ - beginMask(mask: Phaser.GameObjects.GameObject, maskedObject: Phaser.GameObjects.GameObject, camera: Phaser.Cameras.Scene2D.Camera): void; + const REBIND: any; /** - * The masked game objects framebuffer is unbound and its texture - * is bound together with the mask texture and the mask shader and - * a draw call with a single quad is processed. Here is where the - * masking effect is applied. - * @param mask GameObject used as a mask. + * The WebGLPipeline Resize Event. + * + * This event is dispatched by a WebGLPipeline when it is resized, usually as a result + * of the Renderer resizing. */ - endMask(mask: Phaser.GameObjects.GameObject): void; + const RESIZE: any; } /** - * Implements a model view projection matrices. - * Pipelines can implement this for doing 2D and 3D rendering. + * The Graphics Pipeline is the rendering pipeline used by Phaser in WebGL when drawing + * primitive geometry objects, such as the Graphics Game Object, or the Shape Game Objects + * such as Arc, Line, Rectangle and Star. It handles the preperation and batching of related vertices. + * + * Prior to Phaser v3.50 the functions of this pipeline were merged with the `TextureTintPipeline`. + * + * The fragment shader it uses can be found in `shaders/src/Graphics.frag`. + * The vertex shader it uses can be found in `shaders/src/Graphics.vert`. + * + * The default shader attributes for this pipeline are: + * + * `inPosition` (vec2) + * `inColor` (vec4, normalized) + * + * The default shader uniforms for this pipeline are: + * + * `uProjectionMatrix` (mat4) */ - interface ModelViewProjection { + class GraphicsPipeline extends Phaser.Renderer.WebGL.WebGLPipeline { + /** + * + * @param config The configuration options for this pipeline. + */ + constructor(config: Phaser.Types.Renderer.WebGL.WebGLPipelineConfig); + + /** + * A temporary Transform Matrix, re-used internally during batching by the + * Shape Game Objects. + */ + calcMatrix: Phaser.GameObjects.Components.TransformMatrix; + /** - * Dirty flag for checking if model matrix needs to be updated on GPU. + * Pushes a filled rectangle into the vertex batch. + * + * Rectangle factors in the given transform matrices before adding to the batch. + * @param x Horizontal top left coordinate of the rectangle. + * @param y Vertical top left coordinate of the rectangle. + * @param width Width of the rectangle. + * @param height Height of the rectangle. + * @param currentMatrix The current transform. + * @param parentMatrix The parent transform. */ - modelMatrixDirty: boolean; + batchFillRect(x: number, y: number, width: number, height: number, currentMatrix: Phaser.GameObjects.Components.TransformMatrix, parentMatrix: Phaser.GameObjects.Components.TransformMatrix): void; + /** - * Dirty flag for checking if view matrix needs to be updated on GPU. + * Pushes a filled triangle into the vertex batch. + * + * Triangle factors in the given transform matrices before adding to the batch. + * @param x0 Point 0 x coordinate. + * @param y0 Point 0 y coordinate. + * @param x1 Point 1 x coordinate. + * @param y1 Point 1 y coordinate. + * @param x2 Point 2 x coordinate. + * @param y2 Point 2 y coordinate. + * @param currentMatrix The current transform. + * @param parentMatrix The parent transform. */ - viewMatrixDirty: boolean; + batchFillTriangle(x0: number, y0: number, x1: number, y1: number, x2: number, y2: number, currentMatrix: Phaser.GameObjects.Components.TransformMatrix, parentMatrix: Phaser.GameObjects.Components.TransformMatrix): void; + /** - * Dirty flag for checking if projection matrix needs to be updated on GPU. + * Pushes a stroked triangle into the vertex batch. + * + * Triangle factors in the given transform matrices before adding to the batch. + * + * The triangle is created from 3 lines and drawn using the `batchStrokePath` method. + * @param x0 Point 0 x coordinate. + * @param y0 Point 0 y coordinate. + * @param x1 Point 1 x coordinate. + * @param y1 Point 1 y coordinate. + * @param x2 Point 2 x coordinate. + * @param y2 Point 2 y coordinate. + * @param lineWidth The width of the line in pixels. + * @param currentMatrix The current transform. + * @param parentMatrix The parent transform. */ - projectionMatrixDirty: boolean; + batchStrokeTriangle(x0: number, y0: number, x1: number, y1: number, x2: number, y2: number, lineWidth: number, currentMatrix: Phaser.GameObjects.Components.TransformMatrix, parentMatrix: Phaser.GameObjects.Components.TransformMatrix): void; + /** - * Model matrix + * Adds the given path to the vertex batch for rendering. + * + * It works by taking the array of path data and then passing it through Earcut, which + * creates a list of polygons. Each polygon is then added to the batch. + * + * The path is always automatically closed because it's filled. + * @param path Collection of points that represent the path. + * @param currentMatrix The current transform. + * @param parentMatrix The parent transform. */ - modelMatrix: Float32Array; + batchFillPath(path: Phaser.Types.Math.Vector2Like[], currentMatrix: Phaser.GameObjects.Components.TransformMatrix, parentMatrix: Phaser.GameObjects.Components.TransformMatrix): void; + /** - * View matrix + * Adds the given path to the vertex batch for rendering. + * + * It works by taking the array of path data and calling `batchLine` for each section + * of the path. + * + * The path is optionally closed at the end. + * @param path Collection of points that represent the path. + * @param lineWidth The width of the line segments in pixels. + * @param pathOpen Indicates if the path should be closed or left open. + * @param currentMatrix The current transform. + * @param parentMatrix The parent transform. */ - viewMatrix: Float32Array; + batchStrokePath(path: Phaser.Types.Math.Vector2Like[], lineWidth: number, pathOpen: boolean, currentMatrix: Phaser.GameObjects.Components.TransformMatrix, parentMatrix: Phaser.GameObjects.Components.TransformMatrix): void; + /** - * Projection matrix + * Creates a line out of 4 quads and adds it to the vertex batch based on the given line values. + * @param ax x coordinate of the start of the line. + * @param ay y coordinate of the start of the line. + * @param bx x coordinate of the end of the line. + * @param by y coordinate of the end of the line. + * @param aLineWidth Width of the start of the line. + * @param bLineWidth Width of the end of the line. + * @param index If this line is part of a multi-line draw, the index of the line in the draw. + * @param closePath Does this line close a multi-line path? + * @param currentMatrix The current transform. + * @param parentMatrix The parent transform. */ - projectionMatrix: Float32Array; + batchLine(ax: number, ay: number, bx: number, by: number, aLineWidth: number, bLineWidth: number, index: number, closePath: boolean, currentMatrix: Phaser.GameObjects.Components.TransformMatrix, parentMatrix: Phaser.GameObjects.Components.TransformMatrix): void; + /** - * Initializes MVP matrices with an identity matrix + * Adds a single vertex to the current vertex buffer and increments the + * `vertexCount` property by 1. + * + * This method is called directly by `batchTri` and `batchQuad`. + * + * It does not perform any batch limit checking itself, so if you need to call + * this method directly, do so in the same way that `batchQuad` does, for example. + * @param x The vertex x position. + * @param y The vertex y position. + * @param tint The tint color value. */ - mvpInit(): void; + batchVert(x: number, y: number, tint: number): void; + /** - * If dirty flags are set then the matrices are uploaded to the GPU. + * Destroys all shader instances, removes all object references and nulls all external references. */ - mvpUpdate(): void; + destroy(): this; + + } + + /** + * The Light Pipeline is an extension of the Multi Pipeline and uses a custom shader + * designed to handle forward diffused rendering of 2D lights in a Scene. + * + * The shader works in tandem with Light Game Objects, and optionally texture normal maps, + * to provide an ambient illumination effect. + * + * If you wish to provide your own shader, you can use the `%LIGHT_COUNT%` declaration in the source, + * and it will be automatically replaced at run-time with the total number of configured lights. + * + * The maximum number of lights can be set in the Render Config `maxLights` property and defaults to 10. + * + * Prior to Phaser v3.50 this pipeline was called the `ForwardDiffuseLightPipeline`. + * + * The fragment shader it uses can be found in `shaders/src/Light.frag`. + * The vertex shader it uses can be found in `shaders/src/Multi.vert`. + * + * The default shader attributes for this pipeline are: + * + * `inPosition` (vec2, offset 0) + * `inTexCoord` (vec2, offset 8) + * `inTexId` (float, offset 16) + * `inTintEffect` (float, offset 20) + * `inTint` (vec4, offset 24, normalized) + * + * The default shader uniforms for this pipeline are those from the Multi Pipeline, plus: + * + * `uMainSampler` (sampler2D) + * `uNormSampler` (sampler2D) + * `uCamera` (vec4) + * `uResolution` (vec2) + * `uAmbientLightColor` (vec3) + * `uInverseRotationMatrix` (mat3) + * `uLights` (Light struct) + */ + class LightPipeline extends Phaser.Renderer.WebGL.Pipelines.MultiPipeline { /** - * Loads an identity matrix to the model matrix + * + * @param config The configuration options for this pipeline. */ - modelIdentity(): void; + constructor(config: Phaser.Types.Renderer.WebGL.WebGLPipelineConfig); + /** - * Scale model matrix - * @param x The x component. - * @param y The y component. - * @param z The z component. + * Stores a default normal map, which is an object with a `glTexture` property that + * maps to a 1x1 texture of the color #7f7fff created in the `boot` method. */ - modelScale(x: number, y: number, z: number): this; + defaultNormalMap: object; + /** - * Translate model matrix - * @param x The x component. - * @param y The y component. - * @param z The z component. + * Called when the Game has fully booted and the Renderer has finished setting up. + * + * By this stage all Game level systems are now in place and you can perform any final + * tasks that the pipeline may need that relied on game systems such as the Texture Manager. */ - modelTranslate(x: number, y: number, z: number): this; + boot(): void; + /** - * Rotates the model matrix in the X axis. - * @param radians The amount to rotate by. + * Rotates the normal map vectors inversely by the given angle. + * Only works in 2D space. + * @param rotation The angle of rotation in radians. */ - modelRotateX(radians: number): this; + setNormalMapRotation(rotation: number): void; + /** - * Rotates the model matrix in the Y axis. - * @param radians The amount to rotate by. + * Returns the normal map WebGLTexture from the given Game Object. + * If the Game Object doesn't have one, it returns the default normal map from this pipeline instead. + * @param gameObject The Game Object to get the normal map from. */ - modelRotateY(radians: number): this; + getNormalMap(gameObject?: Phaser.GameObjects.GameObject): WebGLTexture; + + } + + /** + * The Multi Pipeline is the core 2D texture rendering pipeline used by Phaser in WebGL. + * Virtually all Game Objects use this pipeline by default, including Sprites, Graphics + * and Tilemaps. It handles the batching of quads and tris, as well as methods for + * drawing and batching geometry data. + * + * Prior to Phaser v3.50 this pipeline was called the `TextureTintPipeline`. + * + * In previous versions of Phaser only one single texture unit was supported at any one time. + * The Multi Pipeline is an evolution of the old Texture Tint Pipeline, updated to support + * multi-textures for increased performance. + * + * The fragment shader it uses can be found in `shaders/src/Multi.frag`. + * The vertex shader it uses can be found in `shaders/src/Multi.vert`. + * + * The default shader attributes for this pipeline are: + * + * `inPosition` (vec2, offset 0) + * `inTexCoord` (vec2, offset 8) + * `inTexId` (float, offset 16) + * `inTintEffect` (float, offset 20) + * `inTint` (vec4, offset 24, normalized) + * + * The default shader uniforms for this pipeline are: + * + * `uProjectionMatrix` (mat4) + * `uMainSampler` (sampler2D array) + * + * If you wish to create a custom pipeline extending from this one, you can use two string + * declarations in your fragment shader source: `%count%` and `%forloop%`, where `count` is + * used to set the number of `sampler2Ds` available, and `forloop` is a block of GLSL code + * that will get the currently bound texture unit. + * + * This pipeline will automatically inject that code for you, should those values exist + * in your shader source. If you wish to handle this yourself, you can also use the + * function `Utils.parseFragmentShaderMaxTextures`. + * + * If you wish to create a pipeline that works from a single texture, or that doesn't have + * internal texture iteration, please see the `SinglePipeline` instead. + */ + class MultiPipeline extends Phaser.Renderer.WebGL.WebGLPipeline { /** - * Rotates the model matrix in the Z axis. - * @param radians The amount to rotate by. + * + * @param config The configuration options for this pipeline. */ - modelRotateZ(radians: number): this; + constructor(config: Phaser.Types.Renderer.WebGL.WebGLPipelineConfig); + /** - * Loads identity matrix into the view matrix + * Called every time the pipeline is bound by the renderer. + * Sets the shader program, vertex buffer and other resources. + * Should only be called when changing pipeline. */ - viewIdentity(): this; + bind(): this; + /** - * Scales view matrix - * @param x The x component. - * @param y The y component. - * @param z The z component. + * Takes a Sprite Game Object, or any object that extends it, and adds it to the batch. + * @param gameObject The texture based Game Object to add to the batch. + * @param camera The Camera to use for the rendering transform. + * @param parentTransformMatrix The transform matrix of the parent container, if set. */ - viewScale(x: number, y: number, z: number): this; + batchSprite(gameObject: Phaser.GameObjects.Image | Phaser.GameObjects.Sprite, camera: Phaser.Cameras.Scene2D.Camera, parentTransformMatrix?: Phaser.GameObjects.Components.TransformMatrix): void; + /** - * Translates view matrix - * @param x The x component. - * @param y The y component. - * @param z The z component. + * Generic function for batching a textured quad using argument values instead of a Game Object. + * @param gameObject Source GameObject. + * @param texture Raw WebGLTexture associated with the quad. + * @param textureWidth Real texture width. + * @param textureHeight Real texture height. + * @param srcX X coordinate of the quad. + * @param srcY Y coordinate of the quad. + * @param srcWidth Width of the quad. + * @param srcHeight Height of the quad. + * @param scaleX X component of scale. + * @param scaleY Y component of scale. + * @param rotation Rotation of the quad. + * @param flipX Indicates if the quad is horizontally flipped. + * @param flipY Indicates if the quad is vertically flipped. + * @param scrollFactorX By which factor is the quad affected by the camera horizontal scroll. + * @param scrollFactorY By which factor is the quad effected by the camera vertical scroll. + * @param displayOriginX Horizontal origin in pixels. + * @param displayOriginY Vertical origin in pixels. + * @param frameX X coordinate of the texture frame. + * @param frameY Y coordinate of the texture frame. + * @param frameWidth Width of the texture frame. + * @param frameHeight Height of the texture frame. + * @param tintTL Tint for top left. + * @param tintTR Tint for top right. + * @param tintBL Tint for bottom left. + * @param tintBR Tint for bottom right. + * @param tintEffect The tint effect. + * @param uOffset Horizontal offset on texture coordinate. + * @param vOffset Vertical offset on texture coordinate. + * @param camera Current used camera. + * @param parentTransformMatrix Parent container. + * @param skipFlip Skip the renderTexture check. Default false. + * @param textureUnit Use the currently bound texture unit? */ - viewTranslate(x: number, y: number, z: number): this; + batchTexture(gameObject: Phaser.GameObjects.GameObject, texture: WebGLTexture, textureWidth: number, textureHeight: number, srcX: number, srcY: number, srcWidth: number, srcHeight: number, scaleX: number, scaleY: number, rotation: number, flipX: boolean, flipY: boolean, scrollFactorX: number, scrollFactorY: number, displayOriginX: number, displayOriginY: number, frameX: number, frameY: number, frameWidth: number, frameHeight: number, tintTL: number, tintTR: number, tintBL: number, tintBR: number, tintEffect: number, uOffset: number, vOffset: number, camera: Phaser.Cameras.Scene2D.Camera, parentTransformMatrix: Phaser.GameObjects.Components.TransformMatrix, skipFlip?: boolean, textureUnit?: number): void; + /** - * Rotates view matrix in the X axis. - * @param radians The amount to rotate by. + * Adds a Texture Frame into the batch for rendering. + * @param frame The Texture Frame to be rendered. + * @param x The horizontal position to render the texture at. + * @param y The vertical position to render the texture at. + * @param tint The tint color. + * @param alpha The alpha value. + * @param transformMatrix The Transform Matrix to use for the texture. + * @param parentTransformMatrix A parent Transform Matrix. */ - viewRotateX(radians: number): this; + batchTextureFrame(frame: Phaser.Textures.Frame, x: number, y: number, tint: number, alpha: number, transformMatrix: Phaser.GameObjects.Components.TransformMatrix, parentTransformMatrix?: Phaser.GameObjects.Components.TransformMatrix): void; + + } + + /** + * The Point Light Pipeline handles rendering the Point Light Game Objects in WebGL. + * + * The fragment shader it uses can be found in `shaders/src/PointLight.frag`. + * The vertex shader it uses can be found in `shaders/src/PointLight.vert`. + * + * The default shader attributes for this pipeline are: + * + * `inPosition` (vec2) + * `inLightPosition` (vec2) + * `inLightRadius` (float) + * `inLightAttenuation` (float) + * `inLightColor` (vec4) + * + * The default shader uniforms for this pipeline are: + * + * `uProjectionMatrix` (mat4) + * `uResolution` (vec2) + * `uCameraZoom` (sampler2D) + */ + class PointLightPipeline extends Phaser.Renderer.WebGL.WebGLPipeline { /** - * Rotates view matrix in the Y axis. - * @param radians The amount to rotate by. + * + * @param config The configuration options for this pipeline. */ - viewRotateY(radians: number): this; + constructor(config: Phaser.Types.Renderer.WebGL.WebGLPipelineConfig); + /** - * Rotates view matrix in the Z axis. - * @param radians The amount to rotate by. + * Adds a Point Light Game Object to the batch, flushing if required. + * @param light The Point Light Game Object. + * @param camera The camera rendering the Point Light. + * @param x0 The top-left x position. + * @param y0 The top-left y position. + * @param x1 The bottom-left x position. + * @param y1 The bottom-left y position. + * @param x2 The bottom-right x position. + * @param y2 The bottom-right y position. + * @param x3 The top-right x position. + * @param y3 The top-right y position. + * @param lightX The horizontal center of the light. + * @param lightY The vertical center of the light. */ - viewRotateZ(radians: number): this; + batchPointLight(light: Phaser.GameObjects.PointLight, camera: Phaser.Cameras.Scene2D.Camera, x0: number, y0: number, x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, lightX: number, lightY: number): void; + + /** + * Adds a single Point Light vertex to the current vertex buffer and increments the + * `vertexCount` property by 1. + * + * This method is called directly by `batchPointLight`. + * @param x The vertex x position. + * @param y The vertex y position. + * @param lightX The horizontal center of the light. + * @param lightY The vertical center of the light. + * @param radius The radius of the light. + * @param attenuation The attenuation of the light. + * @param r The red color channel of the light. + * @param g The green color channel of the light. + * @param b The blue color channel of the light. + * @param a The alpha color channel of the light. + */ + batchLightVert(x: number, y: number, lightX: number, lightY: number, radius: number, attenuation: number, r: number, g: number, b: number, a: number): void; + + } + + /** + * The Post FX Pipeline is a special kind of pipeline specifically for handling post + * processing effects. Where-as a standard Pipeline allows you to control the process + * of rendering Game Objects by configuring the shaders and attributes used to draw them, + * a Post FX Pipeline is designed to allow you to apply processing _after_ the Game Object/s + * have been rendered. Typical examples of post processing effects are bloom filters, + * blurs, light effects and color manipulation. + * + * The pipeline works by creating a tiny vertex buffer with just one single hard-coded quad + * in it. Game Objects can have a Post Pipeline set on them. Those objects are then rendered + * using their standard pipeline, but are redirected to the Render Targets owned by the + * post pipeline, which can then apply their own shaders and effects, before passing them + * back to the main renderer. + * + * Please see the Phaser 3 examples for further details on this extensive subject. + * + * The default fragment shader it uses can be found in `shaders/src/PostFX.frag`. + * The default vertex shader it uses can be found in `shaders/src/Quad.vert`. + * + * The default shader attributes for this pipeline are: + * + * `inPosition` (vec2, offset 0) + * `inTexCoord` (vec2, offset 8) + * + * The vertices array layout is: + * + * -1, 1 B----C 1, 1 + * 0, 1 | /| 1, 1 + * | / | + * | / | + * |/ | + * -1, -1 A----D 1, -1 + * 0, 0 1, 0 + * + * A = -1, -1 (pos) and 0, 0 (uv) + * B = -1, 1 (pos) and 0, 1 (uv) + * C = 1, 1 (pos) and 1, 1 (uv) + * D = 1, -1 (pos) and 1, 0 (uv) + * + * First tri: A, B, C + * Second tri: A, C, D + * + * Array index: + * + * 0 = Tri 1 - Vert A - x pos + * 1 = Tri 1 - Vert A - y pos + * 2 = Tri 1 - Vert A - uv u + * 3 = Tri 1 - Vert A - uv v + * + * 4 = Tri 1 - Vert B - x pos + * 5 = Tri 1 - Vert B - y pos + * 6 = Tri 1 - Vert B - uv u + * 7 = Tri 1 - Vert B - uv v + * + * 8 = Tri 1 - Vert C - x pos + * 9 = Tri 1 - Vert C - y pos + * 10 = Tri 1 - Vert C - uv u + * 11 = Tri 1 - Vert C - uv v + * + * 12 = Tri 2 - Vert A - x pos + * 13 = Tri 2 - Vert A - y pos + * 14 = Tri 2 - Vert A - uv u + * 15 = Tri 2 - Vert A - uv v + * + * 16 = Tri 2 - Vert C - x pos + * 17 = Tri 2 - Vert C - y pos + * 18 = Tri 2 - Vert C - uv u + * 19 = Tri 2 - Vert C - uv v + * + * 20 = Tri 2 - Vert D - x pos + * 21 = Tri 2 - Vert D - y pos + * 22 = Tri 2 - Vert D - uv u + * 23 = Tri 2 - Vert D - uv v + */ + class PostFXPipeline extends Phaser.Renderer.WebGL.WebGLPipeline { /** - * Loads a 2D view matrix (3x2 matrix) into a 4x4 view matrix - * @param matrix2D The Matrix2D. + * + * @param config The configuration options for this pipeline. */ - viewLoad2D(matrix2D: Float32Array): this; + constructor(config: Phaser.Types.Renderer.WebGL.WebGLPipelineConfig); + /** - * Copies a 4x4 matrix into the view matrix - * @param matrix The Matrix2D. + * If this post-pipeline belongs to a Game Object or Camera, this contains a reference to it. */ - viewLoad(matrix: Float32Array): this; + gameObject: Phaser.GameObjects.GameObject; + /** - * Loads identity matrix into the projection matrix. + * A Color Matrix instance belonging to this pipeline. + * + * Used during calls to the `drawFrame` method. */ - projIdentity(): this; + colorMatrix: Phaser.Display.ColorMatrix; + /** - * Sets up an orthographic projection matrix - * @param left The left value. - * @param right The right value. - * @param bottom The bottom value. - * @param top The top value. - * @param near The near value. - * @param far The far value. + * A reference to the Full Frame 1 Render Target that belongs to the + * Utility Pipeline. This property is set during the `boot` method. + * + * This Render Target is the full size of the renderer. + * + * You can use this directly in Post FX Pipelines for multi-target effects. + * However, be aware that these targets are shared between all post fx pipelines. */ - projOrtho(left: number, right: number, bottom: number, top: number, near: number, far: number): this; + fullFrame1: Phaser.Renderer.WebGL.RenderTarget; + /** - * Sets up a perspective projection matrix - * @param fovY The fov value. - * @param aspectRatio The aspectRatio value. - * @param near The near value. - * @param far The far value. + * A reference to the Full Frame 2 Render Target that belongs to the + * Utility Pipeline. This property is set during the `boot` method. + * + * This Render Target is the full size of the renderer. + * + * You can use this directly in Post FX Pipelines for multi-target effects. + * However, be aware that these targets are shared between all post fx pipelines. */ - projPersp(fovY: number, aspectRatio: number, near: number, far: number): this; - } + fullFrame2: Phaser.Renderer.WebGL.RenderTarget; - /** - * ForwardDiffuseLightPipeline implements a forward rendering approach for 2D lights. - * This pipeline extends TextureTintPipeline so it implements all it's rendering functions - * and batching system. - */ - class ForwardDiffuseLightPipeline extends Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline { /** + * A reference to the Half Frame 1 Render Target that belongs to the + * Utility Pipeline. This property is set during the `boot` method. + * + * This Render Target is half the size of the renderer. * - * @param config The configuration of the pipeline, same as the {@link Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline}. The fragment shader will be replaced with the lighting shader. - */ - constructor(config: object); - - /** - * This function sets all the needed resources for each camera pass. - * @param scene The Scene being rendered. - * @param camera The Scene Camera being rendered with. - */ - onRender(scene: Phaser.Scene, camera: Phaser.Cameras.Scene2D.Camera): this; - - /** - * Generic function for batching a textured quad - * @param gameObject Source GameObject - * @param texture Raw WebGLTexture associated with the quad - * @param textureWidth Real texture width - * @param textureHeight Real texture height - * @param srcX X coordinate of the quad - * @param srcY Y coordinate of the quad - * @param srcWidth Width of the quad - * @param srcHeight Height of the quad - * @param scaleX X component of scale - * @param scaleY Y component of scale - * @param rotation Rotation of the quad - * @param flipX Indicates if the quad is horizontally flipped - * @param flipY Indicates if the quad is vertically flipped - * @param scrollFactorX By which factor is the quad affected by the camera horizontal scroll - * @param scrollFactorY By which factor is the quad effected by the camera vertical scroll - * @param displayOriginX Horizontal origin in pixels - * @param displayOriginY Vertical origin in pixels - * @param frameX X coordinate of the texture frame - * @param frameY Y coordinate of the texture frame - * @param frameWidth Width of the texture frame - * @param frameHeight Height of the texture frame - * @param tintTL Tint for top left - * @param tintTR Tint for top right - * @param tintBL Tint for bottom left - * @param tintBR Tint for bottom right - * @param tintEffect The tint effect (0 for additive, 1 for replacement) - * @param uOffset Horizontal offset on texture coordinate - * @param vOffset Vertical offset on texture coordinate - * @param camera Current used camera - * @param parentTransformMatrix Parent container - */ - batchTexture(gameObject: Phaser.GameObjects.GameObject, texture: WebGLTexture, textureWidth: integer, textureHeight: integer, srcX: number, srcY: number, srcWidth: number, srcHeight: number, scaleX: number, scaleY: number, rotation: number, flipX: boolean, flipY: boolean, scrollFactorX: number, scrollFactorY: number, displayOriginX: number, displayOriginY: number, frameX: number, frameY: number, frameWidth: number, frameHeight: number, tintTL: integer, tintTR: integer, tintBL: integer, tintBR: integer, tintEffect: number, uOffset: number, vOffset: number, camera: Phaser.Cameras.Scene2D.Camera, parentTransformMatrix: Phaser.GameObjects.Components.TransformMatrix): void; - - /** - * Sets the Game Objects normal map as the active texture. - * @param gameObject The Game Object to update. - */ - setNormalMap(gameObject: Phaser.GameObjects.GameObject): void; + * You can use this directly in Post FX Pipelines for multi-target effects. + * However, be aware that these targets are shared between all post fx pipelines. + */ + halfFrame1: Phaser.Renderer.WebGL.RenderTarget; /** - * Rotates the normal map vectors inversely by the given angle. - * Only works in 2D space. - * @param rotation The angle of rotation in radians. + * A reference to the Half Frame 2 Render Target that belongs to the + * Utility Pipeline. This property is set during the `boot` method. + * + * This Render Target is half the size of the renderer. + * + * You can use this directly in Post FX Pipelines for multi-target effects. + * However, be aware that these targets are shared between all post fx pipelines. */ - setNormalMapRotation(rotation: number): void; + halfFrame2: Phaser.Renderer.WebGL.RenderTarget; /** - * Takes a Sprite Game Object, or any object that extends it, which has a normal texture and adds it to the batch. - * @param sprite The texture-based Game Object to add to the batch. - * @param camera The Camera to use for the rendering transform. - * @param parentTransformMatrix The transform matrix of the parent container, if set. + * Copy the `source` Render Target to the `target` Render Target. + * + * You can optionally set the brightness factor of the copy. + * + * The difference between this method and `drawFrame` is that this method + * uses a faster copy shader, where only the brightness can be modified. + * If you need color level manipulation, see `drawFrame` instead. + * @param source The source Render Target. + * @param target The target Render Target. + * @param brightness The brightness value applied to the frame copy. Default 1. + * @param clear Clear the target before copying? Default true. + * @param clearAlpha Clear the alpha channel when running `gl.clear` on the target? Default true. */ - batchSprite(sprite: Phaser.GameObjects.Sprite, camera: Phaser.Cameras.Scene2D.Camera, parentTransformMatrix: Phaser.GameObjects.Components.TransformMatrix): void; + copyFrame(source: Phaser.Renderer.WebGL.RenderTarget, target?: Phaser.Renderer.WebGL.RenderTarget, brightness?: number, clear?: boolean, clearAlpha?: boolean): void; - } + /** + * Pops the framebuffer from the renderers FBO stack and sets that as the active target, + * then draws the `source` Render Target to it. It then resets the renderer textures. + * + * This should be done when you need to draw the _final_ results of a pipeline to the game + * canvas, or the next framebuffer in line on the FBO stack. You should only call this once + * in the `onDraw` handler and it should be the final thing called. Be careful not to call + * this if you need to actually use the pipeline shader, instead of the copy shader. In + * those cases, use the `bindAndDraw` method. + * @param source The Render Target to draw from. + */ + copyToGame(source: Phaser.Renderer.WebGL.RenderTarget): void; - /** - * TextureTintPipeline implements the rendering infrastructure - * for displaying textured objects - * The config properties are: - * - game: Current game instance. - * - renderer: Current WebGL renderer. - * - topology: This indicates how the primitives are rendered. The default value is GL_TRIANGLES. - * Here is the full list of rendering primitives (https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Constants). - * - vertShader: Source for vertex shader as a string. - * - fragShader: Source for fragment shader as a string. - * - vertexCapacity: The amount of vertices that shall be allocated - * - vertexSize: The size of a single vertex in bytes. - */ - class TextureTintPipeline extends Phaser.Renderer.WebGL.WebGLPipeline { /** + * Copy the `source` Render Target to the `target` Render Target, using the + * given Color Matrix. * - * @param config The configuration options for this Texture Tint Pipeline, as described above. + * The difference between this method and `copyFrame` is that this method + * uses a color matrix shader, where you have full control over the luminance + * values used during the copy. If you don't need this, you can use the faster + * `copyFrame` method instead. + * @param source The source Render Target. + * @param target The target Render Target. + * @param clearAlpha Clear the alpha channel when running `gl.clear` on the target? Default true. */ - constructor(config: object); + drawFrame(source: Phaser.Renderer.WebGL.RenderTarget, target?: Phaser.Renderer.WebGL.RenderTarget, clearAlpha?: boolean): void; /** - * Float32 view of the array buffer containing the pipeline's vertices. + * Draws the `source1` and `source2` Render Targets to the `target` Render Target + * using a linear blend effect, which is controlled by the `strength` parameter. + * @param source1 The first source Render Target. + * @param source2 The second source Render Target. + * @param target The target Render Target. + * @param strength The strength of the blend. Default 1. + * @param clearAlpha Clear the alpha channel when running `gl.clear` on the target? Default true. */ - vertexViewF32: Float32Array; + blendFrames(source1: Phaser.Renderer.WebGL.RenderTarget, source2: Phaser.Renderer.WebGL.RenderTarget, target?: Phaser.Renderer.WebGL.RenderTarget, strength?: number, clearAlpha?: boolean): void; /** - * Uint32 view of the array buffer containing the pipeline's vertices. + * Draws the `source1` and `source2` Render Targets to the `target` Render Target + * using an additive blend effect, which is controlled by the `strength` parameter. + * @param source1 The first source Render Target. + * @param source2 The second source Render Target. + * @param target The target Render Target. + * @param strength The strength of the blend. Default 1. + * @param clearAlpha Clear the alpha channel when running `gl.clear` on the target? Default true. */ - vertexViewU32: Uint32Array; + blendFramesAdditive(source1: Phaser.Renderer.WebGL.RenderTarget, source2: Phaser.Renderer.WebGL.RenderTarget, target?: Phaser.Renderer.WebGL.RenderTarget, strength?: number, clearAlpha?: boolean): void; /** - * Size of the batch. + * Clears the given Render Target. + * @param target The Render Target to clear. + * @param clearAlpha Clear the alpha channel when running `gl.clear` on the target? Default true. */ - maxQuads: integer; + clearFrame(target: Phaser.Renderer.WebGL.RenderTarget, clearAlpha?: boolean): void; /** - * Collection of batch information + * Copy the `source` Render Target to the `target` Render Target. + * + * The difference with this copy is that no resizing takes place. If the `source` + * Render Target is larger than the `target` then only a portion the same size as + * the `target` dimensions is copied across. + * + * You can optionally set the brightness factor of the copy. + * @param source The source Render Target. + * @param target The target Render Target. + * @param brightness The brightness value applied to the frame copy. Default 1. + * @param clear Clear the target before copying? Default true. + * @param clearAlpha Clear the alpha channel when running `gl.clear` on the target? Default true. + * @param eraseMode Erase source from target using ERASE Blend Mode? Default false. */ - batches: any[]; + blitFrame(source: Phaser.Renderer.WebGL.RenderTarget, target: Phaser.Renderer.WebGL.RenderTarget, brightness?: number, clear?: boolean, clearAlpha?: boolean, eraseMode?: boolean): void; /** - * Called every time the pipeline needs to be used. - * It binds all necessary resources. + * Binds the `source` Render Target and then copies a section of it to the `target` Render Target. + * + * This method is extremely fast because it uses `gl.copyTexSubImage2D` and doesn't + * require the use of any shaders. Remember the coordinates are given in standard WebGL format, + * where x and y specify the lower-left corner of the section, not the top-left. Also, the + * copy entirely replaces the contents of the target texture, no 'merging' or 'blending' takes + * place. + * @param source The source Render Target. + * @param target The target Render Target. + * @param x The x coordinate of the lower left corner where to start copying. + * @param y The y coordinate of the lower left corner where to start copying. + * @param width The width of the texture. + * @param height The height of the texture. + * @param clear Clear the target before copying? Default true. + * @param clearAlpha Clear the alpha channel when running `gl.clear` on the target? Default true. + */ + copyFrameRect(source: Phaser.Renderer.WebGL.RenderTarget, target: Phaser.Renderer.WebGL.RenderTarget, x: number, y: number, width: number, height: number, clear?: boolean, clearAlpha?: boolean): void; + + /** + * Binds this pipeline and draws the `source` Render Target to the `target` Render Target. + * + * If no `target` is specified, it will pop the framebuffer from the Renderers FBO stack + * and use that instead, which should be done when you need to draw the final results of + * this pipeline to the game canvas. + * + * You can optionally set the shader to be used for the draw here, if this is a multi-shader + * pipeline. By default `currentShader` will be used. If you need to set a shader but not + * a target, just pass `null` as the `target` parameter. + * @param source The Render Target to draw from. + * @param target The Render Target to draw to. If not set, it will pop the fbo from the stack. + * @param clear Clear the target before copying? Only used if `target` parameter is set. Default true. + * @param clearAlpha Clear the alpha channel when running `gl.clear` on the target? Default true. + * @param currentShader The shader to use during the draw. */ - onBind(): this; + bindAndDraw(source: Phaser.Renderer.WebGL.RenderTarget, target?: Phaser.Renderer.WebGL.RenderTarget, clear?: boolean, clearAlpha?: boolean, currentShader?: Phaser.Renderer.WebGL.WebGLShader): void; + } + + /** + * The Rope Pipeline is a variation of the Multi Pipeline that uses a `TRIANGLE_STRIP` for + * its topology, instead of TRIANGLES. This is primarily used by the Rope Game Object, + * or anything that extends it. + * + * Prior to Phaser v3.50 this pipeline was called the `TextureTintStripPipeline`. + * + * The fragment shader it uses can be found in `shaders/src/Multi.frag`. + * The vertex shader it uses can be found in `shaders/src/Multi.vert`. + * + * The default shader attributes for this pipeline are: + * + * `inPosition` (vec2, offset 0) + * `inTexCoord` (vec2, offset 8) + * `inTexId` (float, offset 16) + * `inTintEffect` (float, offset 20) + * `inTint` (vec4, offset 24, normalized) + * + * The default shader uniforms for this pipeline are: + * + * `uProjectionMatrix` (mat4) + * `uMainSampler` (sampler2D array) + * + * The pipeline is structurally identical to the Multi Pipeline and should be treated as such. + */ + class RopePipeline extends Phaser.Renderer.WebGL.Pipelines.MultiPipeline { /** - * Resizes this pipeline and updates the projection. - * @param width The new width. - * @param height The new height. - * @param resolution The resolution. + * + * @param config The configuration options for this pipeline. */ - resize(width: number, height: number, resolution: number): this; + constructor(config: Phaser.Types.Renderer.WebGL.WebGLPipelineConfig); + } + + /** + * The Single Pipeline is a special version of the Multi Pipeline that only ever + * uses one texture, bound to texture unit zero. Although not as efficient as the + * Multi Pipeline, it provides an easier way to create custom pipelines that only require + * a single bound texture. + * + * Prior to Phaser v3.50 this pipeline didn't exist, but could be compared to the old `TextureTintPipeline`. + * + * The fragment shader it uses can be found in `shaders/src/Single.frag`. + * The vertex shader it uses can be found in `shaders/src/Single.vert`. + * + * The default shader attributes for this pipeline are: + * + * `inPosition` (vec2, offset 0) + * `inTexCoord` (vec2, offset 8) + * `inTexId` (float, offset 16) - this value is always zero in the Single Pipeline + * `inTintEffect` (float, offset 20) + * `inTint` (vec4, offset 24, normalized) + * + * The default shader uniforms for this pipeline are: + * + * `uProjectionMatrix` (mat4) + * `uMainSampler` (sampler2D) + */ + class SinglePipeline extends Phaser.Renderer.WebGL.Pipelines.MultiPipeline { /** - * Assigns a texture to the current batch. If a different texture is already set it creates a new batch object. - * @param texture WebGLTexture that will be assigned to the current batch. If not given uses blankTexture. - * @param unit Texture unit to which the texture needs to be bound. Default 0. + * + * @param config The configuration options for this pipeline. */ - setTexture2D(texture?: WebGLTexture, unit?: integer): Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline; + constructor(config: Phaser.Types.Renderer.WebGL.WebGLPipelineConfig); + + } + /** + * The Utility Pipeline is a special-use pipeline that belongs to the Pipeline Manager. + * + * It provides 4 shaders and handy associated methods: + * + * 1) Copy Shader. A fast texture to texture copy shader with optional brightness setting. + * 2) Additive Blend Mode Shader. Blends two textures using an additive blend mode. + * 3) Linear Blend Mode Shader. Blends two textures using a linear blend mode. + * 4) Color Matrix Copy Shader. Draws a texture to a target using a Color Matrix. + * + * You do not extend this pipeline, but instead get a reference to it from the Pipeline + * Manager via the `setUtility` method. You can also access methods such as `copyFrame` + * directly from the Pipeline Manager. + * + * This pipeline provides methods for manipulating framebuffer backed textures, such as + * copying or blending one texture to another, copying a portion of a texture, additively + * blending two textures, flipping textures and more. + * + * The default shader attributes for this pipeline are: + * + * `inPosition` (vec2, offset 0) + * `inTexCoord` (vec2, offset 8) + * + * This pipeline has a hard-coded batch size of 1 and a hard coded set of vertices. + */ + class UtilityPipeline extends Phaser.Renderer.WebGL.WebGLPipeline { /** - * Checks if the current batch has the same texture and texture unit, or if we need to create a new batch. - * @param texture WebGLTexture that will be assigned to the current batch. If not given uses blankTexture. - * @param unit Texture unit to which the texture needs to be bound. + * + * @param config The configuration options for this pipeline. */ - requireTextureBatch(texture: WebGLTexture, unit: integer): boolean; + constructor(config: Phaser.Types.Renderer.WebGL.WebGLPipelineConfig); /** - * Creates a new batch object and pushes it to a batch array. - * The batch object contains information relevant to the current - * vertex batch like the offset in the vertex buffer, vertex count and - * the textures used by that batch. - * @param texture Optional WebGLTexture that will be assigned to the created batch. - * @param unit Texture unit to which the texture needs to be bound. + * A default Color Matrix, used by the Color Matrix Shader when one + * isn't provided. */ - pushBatch(texture: WebGLTexture, unit: integer): void; + colorMatrix: Phaser.Display.ColorMatrix; /** - * Uploads the vertex data and emits a draw call for the current batch of vertices. + * A reference to the Copy Shader belonging to this Utility Pipeline. + * + * This property is set during the `boot` method. */ - flush(): this; + copyShader: Phaser.Renderer.WebGL.WebGLShader; /** - * Takes a Sprite Game Object, or any object that extends it, and adds it to the batch. - * @param sprite The texture based Game Object to add to the batch. - * @param camera The Camera to use for the rendering transform. - * @param parentTransformMatrix The transform matrix of the parent container, if set. + * A reference to the Additive Blend Shader belonging to this Utility Pipeline. + * + * This property is set during the `boot` method. */ - batchSprite(sprite: Phaser.GameObjects.Image | Phaser.GameObjects.Sprite, camera: Phaser.Cameras.Scene2D.Camera, parentTransformMatrix?: Phaser.GameObjects.Components.TransformMatrix): void; + addShader: Phaser.Renderer.WebGL.WebGLShader; /** - * Adds the vertices data into the batch and flushes if full. + * A reference to the Linear Blend Shader belonging to this Utility Pipeline. * - * Assumes 6 vertices in the following arrangement: + * This property is set during the `boot` method. + */ + linearShader: Phaser.Renderer.WebGL.WebGLShader; + + /** + * A reference to the Color Matrix Shader belonging to this Utility Pipeline. * - * ``` - * 0----3 - * |\ B| - * | \ | - * | \ | - * | A \| - * | \ - * 1----2 - * ``` + * This property is set during the `boot` method. + */ + colorMatrixShader: Phaser.Renderer.WebGL.WebGLShader; + + /** + * A reference to the Full Frame 1 Render Target. * - * Where tx0/ty0 = 0, tx1/ty1 = 1, tx2/ty2 = 2 and tx3/ty3 = 3 - * @param x0 The top-left x position. - * @param y0 The top-left y position. - * @param x1 The bottom-left x position. - * @param y1 The bottom-left y position. - * @param x2 The bottom-right x position. - * @param y2 The bottom-right y position. - * @param x3 The top-right x position. - * @param y3 The top-right y position. - * @param u0 UV u0 value. - * @param v0 UV v0 value. - * @param u1 UV u1 value. - * @param v1 UV v1 value. - * @param tintTL The top-left tint color value. - * @param tintTR The top-right tint color value. - * @param tintBL The bottom-left tint color value. - * @param tintBR The bottom-right tint color value. - * @param tintEffect The tint effect for the shader to use. - * @param texture WebGLTexture that will be assigned to the current batch if a flush occurs. - * @param unit Texture unit to which the texture needs to be bound. Default 0. - */ - batchQuad(x0: number, y0: number, x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, u0: number, v0: number, u1: number, v1: number, tintTL: number, tintTR: number, tintBL: number, tintBR: number, tintEffect: number | boolean, texture?: WebGLTexture, unit?: integer): boolean; - - /** - * Adds the vertices data into the batch and flushes if full. + * This property is set during the `boot` method. * - * Assumes 3 vertices in the following arrangement: + * This Render Target is the full size of the renderer. * - * ``` - * 0 - * |\ - * | \ - * | \ - * | \ - * | \ - * 1-----2 - * ``` - * @param x1 The bottom-left x position. - * @param y1 The bottom-left y position. - * @param x2 The bottom-right x position. - * @param y2 The bottom-right y position. - * @param x3 The top-right x position. - * @param y3 The top-right y position. - * @param u0 UV u0 value. - * @param v0 UV v0 value. - * @param u1 UV u1 value. - * @param v1 UV v1 value. - * @param tintTL The top-left tint color value. - * @param tintTR The top-right tint color value. - * @param tintBL The bottom-left tint color value. - * @param tintEffect The tint effect for the shader to use. - * @param texture WebGLTexture that will be assigned to the current batch if a flush occurs. - * @param unit Texture unit to which the texture needs to be bound. Default 0. + * You can use this directly in Post FX Pipelines for multi-target effects. + * However, be aware that these targets are shared between all post fx pipelines. */ - batchTri(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, u0: number, v0: number, u1: number, v1: number, tintTL: number, tintTR: number, tintBL: number, tintEffect: number | boolean, texture?: WebGLTexture, unit?: integer): boolean; + fullFrame1: Phaser.Renderer.WebGL.RenderTarget; /** - * Generic function for batching a textured quad using argument values instead of a Game Object. - * @param gameObject Source GameObject. - * @param texture Raw WebGLTexture associated with the quad. - * @param textureWidth Real texture width. - * @param textureHeight Real texture height. - * @param srcX X coordinate of the quad. - * @param srcY Y coordinate of the quad. - * @param srcWidth Width of the quad. - * @param srcHeight Height of the quad. - * @param scaleX X component of scale. - * @param scaleY Y component of scale. - * @param rotation Rotation of the quad. - * @param flipX Indicates if the quad is horizontally flipped. - * @param flipY Indicates if the quad is vertically flipped. - * @param scrollFactorX By which factor is the quad affected by the camera horizontal scroll. - * @param scrollFactorY By which factor is the quad effected by the camera vertical scroll. - * @param displayOriginX Horizontal origin in pixels. - * @param displayOriginY Vertical origin in pixels. - * @param frameX X coordinate of the texture frame. - * @param frameY Y coordinate of the texture frame. - * @param frameWidth Width of the texture frame. - * @param frameHeight Height of the texture frame. - * @param tintTL Tint for top left. - * @param tintTR Tint for top right. - * @param tintBL Tint for bottom left. - * @param tintBR Tint for bottom right. - * @param tintEffect The tint effect. - * @param uOffset Horizontal offset on texture coordinate. - * @param vOffset Vertical offset on texture coordinate. - * @param camera Current used camera. - * @param parentTransformMatrix Parent container. - * @param skipFlip Skip the renderTexture check. Default false. + * A reference to the Full Frame 2 Render Target. + * + * This property is set during the `boot` method. + * + * This Render Target is the full size of the renderer. + * + * You can use this directly in Post FX Pipelines for multi-target effects. + * However, be aware that these targets are shared between all post fx pipelines. + */ + fullFrame2: Phaser.Renderer.WebGL.RenderTarget; + + /** + * A reference to the Half Frame 1 Render Target. + * + * This property is set during the `boot` method. + * + * This Render Target is half the size of the renderer. + * + * You can use this directly in Post FX Pipelines for multi-target effects. + * However, be aware that these targets are shared between all post fx pipelines. */ - batchTexture(gameObject: Phaser.GameObjects.GameObject, texture: WebGLTexture, textureWidth: integer, textureHeight: integer, srcX: number, srcY: number, srcWidth: number, srcHeight: number, scaleX: number, scaleY: number, rotation: number, flipX: boolean, flipY: boolean, scrollFactorX: number, scrollFactorY: number, displayOriginX: number, displayOriginY: number, frameX: number, frameY: number, frameWidth: number, frameHeight: number, tintTL: integer, tintTR: integer, tintBL: integer, tintBR: integer, tintEffect: number, uOffset: number, vOffset: number, camera: Phaser.Cameras.Scene2D.Camera, parentTransformMatrix: Phaser.GameObjects.Components.TransformMatrix, skipFlip?: boolean): void; + halfFrame1: Phaser.Renderer.WebGL.RenderTarget; /** - * Adds a Texture Frame into the batch for rendering. - * @param frame The Texture Frame to be rendered. - * @param x The horizontal position to render the texture at. - * @param y The vertical position to render the texture at. - * @param tint The tint color. - * @param alpha The alpha value. - * @param transformMatrix The Transform Matrix to use for the texture. - * @param parentTransformMatrix A parent Transform Matrix. + * A reference to the Half Frame 2 Render Target. + * + * This property is set during the `boot` method. + * + * This Render Target is half the size of the renderer. + * + * You can use this directly in Post FX Pipelines for multi-target effects. + * However, be aware that these targets are shared between all post fx pipelines. */ - batchTextureFrame(frame: Phaser.Textures.Frame, x: number, y: number, tint: number, alpha: number, transformMatrix: Phaser.GameObjects.Components.TransformMatrix, parentTransformMatrix?: Phaser.GameObjects.Components.TransformMatrix): void; + halfFrame2: Phaser.Renderer.WebGL.RenderTarget; /** - * Pushes a filled rectangle into the vertex batch. - * Rectangle has no transform values and isn't transformed into the local space. - * Used for directly batching untransformed rectangles, such as Camera background colors. - * @param x Horizontal top left coordinate of the rectangle. - * @param y Vertical top left coordinate of the rectangle. - * @param width Width of the rectangle. - * @param height Height of the rectangle. - * @param color Color of the rectangle to draw. - * @param alpha Alpha value of the rectangle to draw. + * Copy the `source` Render Target to the `target` Render Target. + * + * You can optionally set the brightness factor of the copy. + * + * The difference between this method and `drawFrame` is that this method + * uses a faster copy shader, where only the brightness can be modified. + * If you need color level manipulation, see `drawFrame` instead. + * @param source The source Render Target. + * @param target The target Render Target. + * @param brightness The brightness value applied to the frame copy. Default 1. + * @param clear Clear the target before copying? Default true. + * @param clearAlpha Clear the alpha channel when running `gl.clear` on the target? Default true. */ - drawFillRect(x: number, y: number, width: number, height: number, color: number, alpha: number): void; + copyFrame(source: Phaser.Renderer.WebGL.RenderTarget, target?: Phaser.Renderer.WebGL.RenderTarget, brightness?: number, clear?: boolean, clearAlpha?: boolean): void; /** - * Pushes a filled rectangle into the vertex batch. - * Rectangle factors in the given transform matrices before adding to the batch. - * @param x Horizontal top left coordinate of the rectangle. - * @param y Vertical top left coordinate of the rectangle. - * @param width Width of the rectangle. - * @param height Height of the rectangle. - * @param currentMatrix The current transform. - * @param parentMatrix The parent transform. + * Copy the `source` Render Target to the `target` Render Target. + * + * The difference with this copy is that no resizing takes place. If the `source` + * Render Target is larger than the `target` then only a portion the same size as + * the `target` dimensions is copied across. + * + * You can optionally set the brightness factor of the copy. + * @param source The source Render Target. + * @param target The target Render Target. + * @param brightness The brightness value applied to the frame copy. Default 1. + * @param clear Clear the target before copying? Default true. + * @param clearAlpha Clear the alpha channel when running `gl.clear` on the target? Default true. + * @param eraseMode Erase source from target using ERASE Blend Mode? Default false. */ - batchFillRect(x: number, y: number, width: number, height: number, currentMatrix: Phaser.GameObjects.Components.TransformMatrix, parentMatrix: Phaser.GameObjects.Components.TransformMatrix): void; + blitFrame(source: Phaser.Renderer.WebGL.RenderTarget, target: Phaser.Renderer.WebGL.RenderTarget, brightness?: number, clear?: boolean, clearAlpha?: boolean, eraseMode?: boolean): void; /** - * Pushes a filled triangle into the vertex batch. - * Triangle factors in the given transform matrices before adding to the batch. - * @param x0 Point 0 x coordinate. - * @param y0 Point 0 y coordinate. - * @param x1 Point 1 x coordinate. - * @param y1 Point 1 y coordinate. - * @param x2 Point 2 x coordinate. - * @param y2 Point 2 y coordinate. - * @param currentMatrix The current transform. - * @param parentMatrix The parent transform. + * Binds the `source` Render Target and then copies a section of it to the `target` Render Target. + * + * This method is extremely fast because it uses `gl.copyTexSubImage2D` and doesn't + * require the use of any shaders. Remember the coordinates are given in standard WebGL format, + * where x and y specify the lower-left corner of the section, not the top-left. Also, the + * copy entirely replaces the contents of the target texture, no 'merging' or 'blending' takes + * place. + * @param source The source Render Target. + * @param target The target Render Target. + * @param x The x coordinate of the lower left corner where to start copying. + * @param y The y coordinate of the lower left corner where to start copying. + * @param width The width of the texture. + * @param height The height of the texture. + * @param clear Clear the target before copying? Default true. + * @param clearAlpha Clear the alpha channel when running `gl.clear` on the target? Default true. + */ + copyFrameRect(source: Phaser.Renderer.WebGL.RenderTarget, target: Phaser.Renderer.WebGL.RenderTarget, x: number, y: number, width: number, height: number, clear?: boolean, clearAlpha?: boolean): void; + + /** + * Pops the framebuffer from the renderers FBO stack and sets that as the active target, + * then draws the `source` Render Target to it. It then resets the renderer textures. + * + * This should be done when you need to draw the _final_ results of a pipeline to the game + * canvas, or the next framebuffer in line on the FBO stack. You should only call this once + * in the `onDraw` handler and it should be the final thing called. Be careful not to call + * this if you need to actually use the pipeline shader, instead of the copy shader. In + * those cases, use the `bindAndDraw` method. + * @param source The Render Target to draw from. */ - batchFillTriangle(x0: number, y0: number, x1: number, y1: number, x2: number, y2: number, currentMatrix: Phaser.GameObjects.Components.TransformMatrix, parentMatrix: Phaser.GameObjects.Components.TransformMatrix): void; + copyToGame(source: Phaser.Renderer.WebGL.RenderTarget): void; /** - * Pushes a stroked triangle into the vertex batch. - * Triangle factors in the given transform matrices before adding to the batch. - * The triangle is created from 3 lines and drawn using the `batchStrokePath` method. - * @param x0 Point 0 x coordinate. - * @param y0 Point 0 y coordinate. - * @param x1 Point 1 x coordinate. - * @param y1 Point 1 y coordinate. - * @param x2 Point 2 x coordinate. - * @param y2 Point 2 y coordinate. - * @param lineWidth The width of the line in pixels. - * @param currentMatrix The current transform. - * @param parentMatrix The parent transform. + * Copy the `source` Render Target to the `target` Render Target, using the + * given Color Matrix. + * + * The difference between this method and `copyFrame` is that this method + * uses a color matrix shader, where you have full control over the luminance + * values used during the copy. If you don't need this, you can use the faster + * `copyFrame` method instead. + * @param source The source Render Target. + * @param target The target Render Target. + * @param clearAlpha Clear the alpha channel when running `gl.clear` on the target? Default true. + * @param colorMatrix The Color Matrix to use when performing the draw. */ - batchStrokeTriangle(x0: number, y0: number, x1: number, y1: number, x2: number, y2: number, lineWidth: number, currentMatrix: Phaser.GameObjects.Components.TransformMatrix, parentMatrix: Phaser.GameObjects.Components.TransformMatrix): void; + drawFrame(source: Phaser.Renderer.WebGL.RenderTarget, target?: Phaser.Renderer.WebGL.RenderTarget, clearAlpha?: boolean, colorMatrix?: Phaser.Display.ColorMatrix): void; /** - * Adds the given path to the vertex batch for rendering. + * Draws the `source1` and `source2` Render Targets to the `target` Render Target + * using a linear blend effect, which is controlled by the `strength` parameter. + * @param source1 The first source Render Target. + * @param source2 The second source Render Target. + * @param target The target Render Target. + * @param strength The strength of the blend. Default 1. + * @param clearAlpha Clear the alpha channel when running `gl.clear` on the target? Default true. + * @param blendShader The shader to use during the blend copy. + */ + blendFrames(source1: Phaser.Renderer.WebGL.RenderTarget, source2: Phaser.Renderer.WebGL.RenderTarget, target?: Phaser.Renderer.WebGL.RenderTarget, strength?: number, clearAlpha?: boolean, blendShader?: Phaser.Renderer.WebGL.WebGLShader): void; + + /** + * Draws the `source1` and `source2` Render Targets to the `target` Render Target + * using an additive blend effect, which is controlled by the `strength` parameter. + * @param source1 The first source Render Target. + * @param source2 The second source Render Target. + * @param target The target Render Target. + * @param strength The strength of the blend. Default 1. + * @param clearAlpha Clear the alpha channel when running `gl.clear` on the target? Default true. + */ + blendFramesAdditive(source1: Phaser.Renderer.WebGL.RenderTarget, source2: Phaser.Renderer.WebGL.RenderTarget, target?: Phaser.Renderer.WebGL.RenderTarget, strength?: number, clearAlpha?: boolean): void; + + /** + * Clears the given Render Target. + * @param target The Render Target to clear. + * @param clearAlpha Clear the alpha channel when running `gl.clear` on the target? Default true. + */ + clearFrame(target: Phaser.Renderer.WebGL.RenderTarget, clearAlpha?: boolean): void; + + /** + * Set the UV values for the 6 vertices that make up the quad used by the shaders + * in the Utility Pipeline. * - * It works by taking the array of path data and then passing it through Earcut, which - * creates a list of polygons. Each polygon is then added to the batch. + * Be sure to call `resetUVs` once you have finished manipulating the UV coordinates. + * @param uA The u value of vertex A. + * @param vA The v value of vertex A. + * @param uB The u value of vertex B. + * @param vB The v value of vertex B. + * @param uC The u value of vertex C. + * @param vC The v value of vertex C. + * @param uD The u value of vertex D. + * @param vD The v value of vertex D. + */ + setUVs(uA: number, vA: number, uB: number, vB: number, uC: number, vC: number, uD: number, vD: number): void; + + /** + * Sets the vertex UV coordinates of the quad used by the shaders in the Utility Pipeline + * so that they correctly adjust the texture coordinates for a blit frame effect. * - * The path is always automatically closed because it's filled. - * @param path Collection of points that represent the path. - * @param currentMatrix The current transform. - * @param parentMatrix The parent transform. + * Be sure to call `resetUVs` once you have finished manipulating the UV coordinates. + * @param source The source Render Target. + * @param target The target Render Target. */ - batchFillPath(path: any[], currentMatrix: Phaser.GameObjects.Components.TransformMatrix, parentMatrix: Phaser.GameObjects.Components.TransformMatrix): void; + setTargetUVs(source: Phaser.Renderer.WebGL.RenderTarget, target: Phaser.Renderer.WebGL.RenderTarget): void; /** - * Adds the given path to the vertex batch for rendering. + * Horizontally flips the UV coordinates of the quad used by the shaders in this + * Utility Pipeline. * - * It works by taking the array of path data and calling `batchLine` for each section - * of the path. + * Be sure to call `resetUVs` once you have finished manipulating the UV coordinates. + */ + flipX(): void; + + /** + * Vertically flips the UV coordinates of the quad used by the shaders in this + * Utility Pipeline. * - * The path is optionally closed at the end. - * @param path Collection of points that represent the path. - * @param lineWidth The width of the line segments in pixels. - * @param pathOpen Indicates if the path should be closed or left open. - * @param currentMatrix The current transform. - * @param parentMatrix The parent transform. + * Be sure to call `resetUVs` once you have finished manipulating the UV coordinates. */ - batchStrokePath(path: any[], lineWidth: number, pathOpen: boolean, currentMatrix: Phaser.GameObjects.Components.TransformMatrix, parentMatrix: Phaser.GameObjects.Components.TransformMatrix): void; + flipY(): void; /** - * Creates a quad and adds it to the vertex batch based on the given line values. - * @param ax X coordinate to the start of the line - * @param ay Y coordinate to the start of the line - * @param bx X coordinate to the end of the line - * @param by Y coordinate to the end of the line - * @param aLineWidth Width of the start of the line - * @param bLineWidth Width of the end of the line - * @param currentMatrix Parent matrix, generally used by containers + * Resets the quad vertice UV values to their default settings. + * + * The quad is used by all shaders of the Utility Pipeline. */ - batchLine(ax: number, ay: number, bx: number, by: number, aLineWidth: number, bLineWidth: number, currentMatrix: Float32Array): void; + resetUVs(): void; } } + /** + * A Render Target encapsulates a WebGL framebuffer and the WebGL Texture that displays it. + * + * Instances of this class are typically created by, and belong to WebGL Pipelines, however + * other Game Objects and classes can take advantage of Render Targets as well. + */ + class RenderTarget { + /** + * + * @param renderer A reference to the WebGLRenderer. + * @param width The width of this Render Target. + * @param height The height of this Render Target. + * @param scale A value between 0 and 1. Controls the size of this Render Target in relation to the Renderer. Default 1. + * @param minFilter The minFilter mode of the texture when created. 0 is `LINEAR`, 1 is `NEAREST`. Default 0. + * @param autoClear Automatically clear this framebuffer when bound? Default true. + * @param autoResize Automatically resize this Render Target if the WebGL Renderer resizes? Default false. + */ + constructor(renderer: Phaser.Renderer.WebGL.WebGLRenderer, width: number, height: number, scale?: number, minFilter?: number, autoClear?: boolean, autoResize?: boolean); + + /** + * A reference to the WebGLRenderer instance. + */ + renderer: Phaser.Renderer.WebGL.WebGLRenderer; + + /** + * The WebGLFramebuffer of this Render Target. + * + * This is created in the `RenderTarget.resize` method. + */ + framebuffer: WebGLFramebuffer; + + /** + * The WebGLTexture of this Render Target. + * + * This is created in the `RenderTarget.resize` method. + */ + texture: WebGLTexture; + + /** + * The width of the texture. + */ + readonly width: number; + + /** + * The height of the texture. + */ + readonly height: number; + + /** + * A value between 0 and 1. Controls the size of this Render Target in relation to the Renderer. + * + * A value of 1 matches it. 0.5 makes the Render Target half the size of the renderer, etc. + */ + scale: number; + + /** + * The minFilter mode of the texture. 0 is `LINEAR`, 1 is `NEAREST`. + */ + minFilter: number; + + /** + * Controls if this Render Target is automatically cleared (via `gl.COLOR_BUFFER_BIT`) + * during the `RenderTarget.bind` method. + * + * If you need more control over how, or if, the target is cleared, you can disable + * this via the config on creation, or even toggle it directly at runtime. + */ + autoClear: boolean; + + /** + * Does this Render Target automatically resize when the WebGL Renderer does? + * + * Modify this property via the `setAutoResize` method. + */ + readonly autoResize: boolean; + + /** + * Sets if this Render Target should automatically resize when the WebGL Renderer + * emits a resize event. + * @param autoResize Automatically resize this Render Target when the WebGL Renderer resizes? + */ + setAutoResize(autoResize: boolean): this; + + /** + * Resizes this Render Target. + * + * Deletes both the frame buffer and texture, if they exist and then re-creates + * them using the new sizes. + * + * This method is called automatically by the pipeline during its resize handler. + * @param width The new width of this Render Target. + * @param height The new height of this Render Target. + */ + resize(width: number, height: number): this; + + /** + * Pushes this Render Target as the current frame buffer of the renderer. + * + * If `autoClear` is set, then clears the texture. + * + * If `adjustViewport` is `true` then it will flush the renderer and then adjust the GL viewport. + * @param adjustViewport Adjust the GL viewport by calling `RenderTarget.adjustViewport` ? Default false. + * @param width Optional new width of this Render Target. + * @param height Optional new height of this Render Target. + */ + bind(adjustViewport?: boolean, width?: number, height?: number): void; + + /** + * Adjusts the GL viewport to match the width and height of this Render Target. + * + * Also disables `SCISSOR_TEST`. + */ + adjustViewport(): void; + + /** + * Clears this Render Target. + */ + clear(): void; + + /** + * Unbinds this Render Target and optionally flushes the WebGL Renderer first. + */ + unbind: any; + + /** + * Removes all external references from this class and deletes the + * WebGL framebuffer and texture instances. + * + * Does not remove this Render Target from the parent pipeline. + */ + destroy: any; + + } + namespace Utils { /** * Packs four floats on a range from 0.0 to 1.0 into a single Uint32 @@ -74127,7 +81148,7 @@ declare namespace Phaser { /** * Packs a Uint24, representing RGB components, with a Float32, representing - * the alpha component, with a range between 0.0 and 1.0 and return a + * the alpha component, with a range between 0.0 and 1.0 and return a * swizzled Uint32 * @param rgb Uint24 representing RGB components * @param a Float32 representing Alpha component @@ -74141,345 +81162,945 @@ declare namespace Phaser { function getFloatsFromUintRGB(rgb: number): any[]; /** - * Counts how many attributes of 32 bits a vertex has - * @param attributes Array of attributes - * @param glContext WebGLContext used for check types + * Check to see how many texture units the GPU supports, based on the given config value. + * Then tests this against the maximum number of iterations GLSL can support. + * @param gl The WebGLContext used to create the shaders. + * @param maxTextures The Game Config maxTextures value. + */ + function checkShaderMax(gl: WebGLRenderingContext, maxTextures: number): number; + + /** + * Checks the given Fragment Shader Source for `%count%` and `%forloop%` declarations and + * replaces those with GLSL code for setting `texture = texture2D(uMainSampler[i], outTexCoord)`. + * @param fragmentShaderSource The Fragment Shader source code to operate on. + * @param maxTextures The number of maxTextures value. */ - function getComponentCount(attributes: any[], glContext: WebGLRenderingContext): number; + function parseFragmentShaderMaxTextures(fragmentShaderSource: string, maxTextures: number): string; } /** - * WebGLPipeline is a class that describes the way elements will be renderered - * in WebGL, specially focused on batching vertices (batching is not provided). - * Pipelines are mostly used for describing 2D rendering passes but it's - * flexible enough to be used for any type of rendering including 3D. - * Internally WebGLPipeline will handle things like compiling shaders, - * creating vertex buffers, assigning primitive topology and binding - * vertex attributes. + * The `WebGLPipeline` is a base class used by all of the core Phaser pipelines. + * + * It describes the way elements will be rendered in WebGL. Internally, it handles + * compiling the shaders, creating vertex buffers, assigning primitive topology and + * binding vertex attributes, all based on the given configuration data. + * + * The pipeline is configured by passing in a `WebGLPipelineConfig` object. Please + * see the documentation for this type to fully understand the configuration options + * available to you. * - * The config properties are: - * - game: Current game instance. - * - renderer: Current WebGL renderer. - * - gl: Current WebGL context. - * - topology: This indicates how the primitives are rendered. The default value is GL_TRIANGLES. - * Here is the full list of rendering primitives (https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Constants). - * - vertShader: Source for vertex shader as a string. - * - fragShader: Source for fragment shader as a string. - * - vertexCapacity: The amount of vertices that shall be allocated - * - vertexSize: The size of a single vertex in bytes. - * - vertices: An optional buffer of vertices - * - attributes: An array describing the vertex attributes + * Usually, you would not extend from this class directly, but would instead extend + * from one of the core pipelines, such as the Multi Pipeline. * - * The vertex attributes properties are: - * - name : String - Name of the attribute in the vertex shader - * - size : integer - How many components describe the attribute. For ex: vec3 = size of 3, float = size of 1 - * - type : GLenum - WebGL type (gl.BYTE, gl.SHORT, gl.UNSIGNED_BYTE, gl.UNSIGNED_SHORT, gl.FLOAT) - * - normalized : boolean - Is the attribute normalized - * - offset : integer - The offset in bytes to the current attribute in the vertex. Equivalent to offsetof(vertex, attrib) in C - * Here you can find more information of how to describe an attribute: - * - https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/vertexAttribPointer + * The pipeline flow per render-step is as follows: + * + * 1) onPreRender - called once at the start of the render step + * 2) onRender - call for each Scene Camera that needs to render (so can be multiple times per render step) + * 3) Internal flow: + * 3a) bind (only called if a Game Object is using this pipeline and it's not currently active) + * 3b) onBind (called for every Game Object that uses this pipeline) + * 3c) flush (can be called by a Game Object, internal method or from outside by changing pipeline) + * 4) onPostRender - called once at the end of the render step */ - class WebGLPipeline { + class WebGLPipeline extends Phaser.Events.EventEmitter { /** * - * @param config The configuration object for this WebGL Pipeline, as described above. + * @param config The configuration object for this WebGL Pipeline. */ - constructor(config: object); + constructor(config: Phaser.Types.Renderer.WebGL.WebGLPipelineConfig); /** - * Name of the Pipeline. Used for identifying + * Name of the pipeline. Used for identification and setting from Game Objects. */ name: string; /** - * The Game which owns this WebGL Pipeline. + * The Phaser Game instance to which this pipeline is bound. */ game: Phaser.Game; /** - * The canvas which this WebGL Pipeline renders to. + * The WebGL Renderer instance to which this pipeline is bound. */ - view: HTMLCanvasElement; + renderer: Phaser.Renderer.WebGL.WebGLRenderer; /** - * Used to store the current game resolution + * A reference to the WebGL Pipeline Manager. + * + * This is initially undefined and only set when this pipeline is added + * to the manager. + */ + manager: Phaser.Renderer.WebGL.PipelineManager; + + /** + * The WebGL context this WebGL Pipeline uses. + */ + gl: WebGLRenderingContext; + + /** + * The canvas which this WebGL Pipeline renders to. */ - resolution: number; + view: HTMLCanvasElement; /** - * Width of the current viewport + * Width of the current viewport. */ width: number; /** - * Height of the current viewport + * Height of the current viewport. */ height: number; /** - * The WebGL context this WebGL Pipeline uses. + * The current number of vertices that have been added to the pipeline batch. */ - gl: WebGLRenderingContext; + vertexCount: number; /** - * How many vertices have been fed to the current pipeline. + * The total number of vertices that this pipeline batch can hold before it will flush. + * + * This defaults to `renderer batchSize * 6`, where `batchSize` is defined in the Renderer Game Config. */ - vertexCount: number; + vertexCapacity: number; /** - * The limit of vertices that the pipeline can hold + * Raw byte buffer of vertices. + * + * Either set via the config object `vertices` property, or generates a new Array Buffer of + * size `vertexCapacity * vertexSize`. */ - vertexCapacity: integer; + readonly vertexData: ArrayBuffer; /** - * The WebGL Renderer which owns this WebGL Pipeline. + * The WebGLBuffer that holds the vertex data. + * + * Created from the `vertexData` ArrayBuffer. If `vertices` are set in the config, a `STATIC_DRAW` buffer + * is created. If not, a `DYNAMIC_DRAW` buffer is created. */ - renderer: Phaser.Renderer.WebGL.WebGLRenderer; + readonly vertexBuffer: WebGLBuffer; /** - * Raw byte buffer of vertices. + * The primitive topology which the pipeline will use to submit draw calls. + * + * Defaults to GL_TRIANGLES if not otherwise set in the config. */ - vertexData: ArrayBuffer; + topology: GLenum; /** - * The handle to a WebGL vertex buffer object. + * Uint8 view to the `vertexData` ArrayBuffer. Used for uploading vertex buffer resources to the GPU. */ - vertexBuffer: WebGLBuffer; + bytes: Uint8Array; /** - * The handle to a WebGL program + * Float32 view of the array buffer containing the pipeline's vertices. */ - program: WebGLProgram; + vertexViewF32: Float32Array; /** - * Array of objects that describe the vertex attributes + * Uint32 view of the array buffer containing the pipeline's vertices. */ - attributes: object; + vertexViewU32: Uint32Array; /** - * The size in bytes of the vertex + * Indicates if the current pipeline is active, or not. + * + * Toggle this property to enable or disable a pipeline from rendering anything. */ - vertexSize: integer; + active: boolean; /** - * The primitive topology which the pipeline will use to submit draw calls + * Holds the most recently assigned texture unit. + * + * Treat this value as read-only. */ - topology: integer; + currentUnit: number; /** - * Uint8 view to the vertex raw buffer. Used for uploading vertex buffer resources - * to the GPU. + * Some pipelines require the forced use of texture zero (like the light pipeline). + * + * This property should be set when that is the case. */ - bytes: Uint8Array; + forceZero: boolean; /** - * This will store the amount of components of 32 bit length + * Indicates if this pipeline has booted or not. + * + * A pipeline boots only when the Game instance itself, and all associated systems, is + * fully ready. */ - vertexComponentCount: integer; + readonly hasBooted: boolean; /** - * Indicates if the current pipeline is flushing the contents to the GPU. - * When the variable is set the flush function will be locked. + * Indicates if this is a Post FX Pipeline, or not. */ - flushLocked: boolean; + readonly isPostFX: boolean; /** - * Indicates if the current pipeline is active or not for this frame only. - * Reset in the onRender method. + * An array of RenderTarget instances that belong to this pipeline. */ - active: boolean; + renderTargets: Phaser.Renderer.WebGL.RenderTarget[]; + + /** + * A reference to the currently bound Render Target instance from the `WebGLPipeline.renderTargets` array. + */ + currentRenderTarget: Phaser.Renderer.WebGL.RenderTarget; + + /** + * An array of all the WebGLShader instances that belong to this pipeline. + * + * Shaders manage their own attributes and uniforms, but share the same vertex data buffer, + * which belongs to this pipeline. + * + * Shaders are set in a call to the `setShadersFromConfig` method, which happens automatically, + * but can also be called at any point in your game. See the method documentation for details. + */ + shaders: Phaser.Renderer.WebGL.WebGLShader[]; + + /** + * A reference to the currently bound WebGLShader instance from the `WebGLPipeline.shaders` array. + * + * For lots of pipelines, this is the only shader, so it is a quick way to reference it without + * an array look-up. + */ + currentShader: Phaser.Renderer.WebGL.WebGLShader; + + /** + * The Projection matrix, used by shaders as 'uProjectionMatrix' uniform. + */ + projectionMatrix: Phaser.Math.Matrix4; + + /** + * The cached width of the Projection matrix. + */ + projectionWidth: number; + + /** + * The cached height of the Projection matrix. + */ + projectionHeight: number; + + /** + * The configuration object that was used to create this pipeline. + * + * Treat this object as 'read only', because changing it post-creation will not + * impact this pipeline in any way. However, it is used internally for cloning + * and post-boot set-up. + */ + config: Phaser.Types.Renderer.WebGL.WebGLPipelineConfig; /** * Called when the Game has fully booted and the Renderer has finished setting up. * - * By this stage all Game level systems are now in place and you can perform any final - * tasks that the pipeline may need that relied on game systems such as the Texture Manager. + * By this stage all Game level systems are now in place. You can perform any final tasks that the + * pipeline may need, that relies on game systems such as the Texture Manager being ready. */ boot(): void; /** - * Adds a description of vertex attribute to the pipeline - * @param name Name of the vertex attribute - * @param size Vertex component size - * @param type Type of the attribute - * @param normalized Is the value normalized to a range - * @param offset Byte offset to the beginning of the first element in the vertex + * This method is called once when this pipeline has finished being set-up + * at the end of the boot process. By the time this method is called, all + * of the shaders are ready and configured. + */ + onBoot(): void; + + /** + * This method is called once when this pipeline has finished being set-up + * at the end of the boot process. By the time this method is called, all + * of the shaders are ready and configured. It's also called if the renderer + * changes size. + * @param width The new width of this WebGL Pipeline. + * @param height The new height of this WebGL Pipeline. + */ + onResize(width: number, height: number): void; + + /** + * Sets the currently active shader within this pipeline. + * @param shader The shader to set as being current. + * @param setAttributes Should the vertex attribute pointers be set? Default false. */ - addAttribute(name: string, size: integer, type: integer, normalized: boolean, offset: integer): this; + setShader(shader: Phaser.Renderer.WebGL.WebGLShader, setAttributes?: boolean): this; + + /** + * Searches all shaders in this pipeline for one matching the given name, then returns it. + * @param name The index of the shader to set. + */ + getShaderByName(name: string): Phaser.Renderer.WebGL.WebGLShader; + + /** + * Destroys all shaders currently set in the `WebGLPipeline.shaders` array and then parses the given + * `config` object, extracting the shaders from it, creating `WebGLShader` instances and finally + * setting them into the `shaders` array of this pipeline. + * + * This is a destructive process. Be very careful when you call it, should you need to. + * @param config The configuration object for this WebGL Pipeline. + */ + setShadersFromConfig(config: Phaser.Types.Renderer.WebGL.WebGLPipelineConfig): this; + + /** + * Custom pipelines can use this method in order to perform any required pre-batch tasks + * for the given Game Object. It must return the texture unit the Game Object was assigned. + * @param gameObject The Game Object being rendered or added to the batch. + * @param frame Optional frame to use. Can override that of the Game Object. + */ + setGameObject(gameObject: Phaser.GameObjects.GameObject, frame?: Phaser.Textures.Frame): number; /** * Check if the current batch of vertices is full. + * + * You can optionally provide an `amount` parameter. If given, it will check if the batch + * needs to flush _if_ the `amount` is added to it. This allows you to test if you should + * flush before populating the batch. + * @param amount Will the batch need to flush if this many vertices are added to it? Default 0. + */ + shouldFlush(amount?: number): boolean; + + /** + * Resizes the properties used to describe the viewport. + * + * This method is called automatically by the renderer during its resize handler. + * @param width The new width of this WebGL Pipeline. + * @param height The new height of this WebGL Pipeline. */ - shouldFlush(): boolean; + resize(width: number, height: number): this; /** - * Resizes the properties used to describe the viewport + * Adjusts this pipelines ortho Projection Matrix to use the given dimensions + * and resets the `uProjectionMatrix` uniform on all bound shaders. + * + * This method is called automatically by the renderer during its resize handler. * @param width The new width of this WebGL Pipeline. * @param height The new height of this WebGL Pipeline. - * @param resolution The resolution this WebGL Pipeline should be resized to. */ - resize(width: number, height: number, resolution: number): this; + setProjectionMatrix(width: number, height: number): this; + + /** + * Adjusts this pipelines ortho Projection Matrix to match that of the global + * WebGL Renderer Projection Matrix. + * + * This method is called automatically by the Pipeline Manager when this + * pipeline is set. + */ + updateProjectionMatrix(): void; + + /** + * This method is called every time the Pipeline Manager makes this pipeline the currently active one. + * + * It binds the resources and shader needed for this pipeline, including setting the vertex buffer + * and attribute pointers. + * @param currentShader The shader to set as being current. + */ + bind(currentShader?: Phaser.Renderer.WebGL.WebGLShader): this; + + /** + * This method is called every time the Pipeline Manager rebinds this pipeline. + * + * It resets all shaders this pipeline uses, setting their attributes again. + */ + rebind(): this; + + /** + * Binds the vertex buffer to be the active ARRAY_BUFFER on the WebGL context. + * + * It first checks to see if it's already set as the active buffer and only + * binds itself if not. + */ + setVertexBuffer(): boolean; + + /** + * This method is called as a result of the `WebGLPipeline.batchQuad` method, right before a quad + * belonging to a Game Object is about to be added to the batch. When this is called, the + * renderer has just performed a flush. It will bind the current render target, if any are set + * and finally call the `onPreBatch` hook. + * @param gameObject The Game Object or Camera that invoked this pipeline, if any. + */ + preBatch(gameObject?: Phaser.GameObjects.GameObject | Phaser.Cameras.Scene2D.Camera): this; + + /** + * This method is called as a result of the `WebGLPipeline.batchQuad` method, right after a quad + * belonging to a Game Object has been added to the batch. When this is called, the + * renderer has just performed a flush. + * + * It calls the `onDraw` hook followed by the `onPostBatch` hook, which can be used to perform + * additional Post FX Pipeline processing. + * @param gameObject The Game Object or Camera that invoked this pipeline, if any. + */ + postBatch(gameObject?: Phaser.GameObjects.GameObject | Phaser.Cameras.Scene2D.Camera): this; + + /** + * This method is only used by Post FX Pipelines and those that extend from them. + * + * This method is called every time the `postBatch` method is called and is passed a + * reference to the current render target. + * + * At the very least a Post FX Pipeline should call `this.bindAndDraw(renderTarget)`, + * however, you can do as much additional processing as you like in this method if + * you override it from within your own pipelines. + * @param renderTarget The Render Target. + */ + onDraw(renderTarget: Phaser.Renderer.WebGL.RenderTarget): void; + + /** + * This method is called every time the Pipeline Manager deactivates this pipeline, swapping from + * it to another one. This happens after a call to `flush` and before the new pipeline is bound. + */ + unbind(): void; + + /** + * Uploads the vertex data and emits a draw call for the current batch of vertices. + * @param isPostFlush Was this flush invoked as part of a post-process, or not? Default false. + */ + flush(isPostFlush?: boolean): this; + + /** + * By default this is an empty method hook that you can override and use in your own custom pipelines. + * + * This method is called every time the Pipeline Manager makes this the active pipeline. It is called + * at the end of the `WebGLPipeline.bind` method, after the current shader has been set. The current + * shader is passed to this hook. + * + * For example, if a display list has 3 Sprites in it that all use the same pipeline, this hook will + * only be called for the first one, as the 2nd and 3rd Sprites do not cause the pipeline to be changed. + * + * If you need to listen for that event instead, use the `onBind` hook. + * @param currentShader The shader that was set as current. + */ + onActive(currentShader: Phaser.Renderer.WebGL.WebGLShader): void; + + /** + * By default this is an empty method hook that you can override and use in your own custom pipelines. + * + * This method is called every time a **Game Object** asks the Pipeline Manager to use this pipeline, + * even if the pipeline is already active. + * + * Unlike the `onActive` method, which is only called when the Pipeline Manager makes this pipeline + * active, this hook is called for every Game Object that requests use of this pipeline, allowing you to + * perform per-object set-up, such as loading shader uniform data. + * @param gameObject The Game Object that invoked this pipeline, if any. + */ + onBind(gameObject?: Phaser.GameObjects.GameObject): void; /** - * Binds the pipeline resources, including programs, vertex buffers and binds attributes + * By default this is an empty method hook that you can override and use in your own custom pipelines. + * + * This method is called when the Pipeline Manager needs to rebind this pipeline. This happens after a + * pipeline has been cleared, usually when passing control over to a 3rd party WebGL library, like Spine, + * and then returing to Phaser again. + */ + onRebind(): void; + + /** + * By default this is an empty method hook that you can override and use in your own custom pipelines. + * + * This method is called every time the `batchQuad` or `batchTri` methods are called. If this was + * as a result of a Game Object, then the Game Object reference is passed to this hook too. + * + * This hook is called _after_ the quad (or tri) has been added to the batch, so you can safely + * call 'flush' from within this. + * + * Note that Game Objects may call `batchQuad` or `batchTri` multiple times for a single draw, + * for example the Graphics Game Object. + * @param gameObject The Game Object that invoked this pipeline, if any. */ - bind(): this; + onBatch(gameObject?: Phaser.GameObjects.GameObject): void; /** - * Set whenever this WebGL Pipeline is bound to a WebGL Renderer. + * By default this is an empty method hook that you can override and use in your own custom pipelines. * - * This method is called every time the WebGL Pipeline is attempted to be bound, even if it already is the current pipeline. + * This method is called immediately before a **Game Object** is about to add itself to the batch. + * @param gameObject The Game Object that invoked this pipeline, if any. + */ + onPreBatch(gameObject?: Phaser.GameObjects.GameObject): void; + + /** + * By default this is an empty method hook that you can override and use in your own custom pipelines. + * + * This method is called immediately after a **Game Object** has been added to the batch. + * @param gameObject The Game Object that invoked this pipeline, if any. */ - onBind(): this; + onPostBatch(gameObject?: Phaser.GameObjects.GameObject): void; /** - * Called before each frame is rendered, but after the canvas has been cleared. + * By default this is an empty method hook that you can override and use in your own custom pipelines. + * + * This method is called once per frame, right before anything has been rendered, but after the canvas + * has been cleared. If this pipeline has a render target, it will also have been cleared by this point. */ - onPreRender(): this; + onPreRender(): void; /** - * Called before a Scene's Camera is rendered. + * By default this is an empty method hook that you can override and use in your own custom pipelines. + * + * This method is called _once per frame_, by every Camera in a Scene that wants to render. + * + * It is called at the start of the rendering process, before anything has been drawn to the Camera. * @param scene The Scene being rendered. * @param camera The Scene Camera being rendered with. */ - onRender(scene: Phaser.Scene, camera: Phaser.Cameras.Scene2D.Camera): this; + onRender(scene: Phaser.Scene, camera: Phaser.Cameras.Scene2D.Camera): void; + + /** + * By default this is an empty method hook that you can override and use in your own custom pipelines. + * + * This method is called _once per frame_, after all rendering has happened and snapshots have been taken. + * + * It is called at the very end of the rendering process, once all Cameras, for all Scenes, have + * been rendered. + */ + onPostRender(): void; /** - * Called after each frame has been completely rendered and snapshots have been taken. + * By default this is an empty method hook that you can override and use in your own custom pipelines. + * + * This method is called every time this pipeline is asked to flush its batch. + * + * It is called immediately before the `gl.bufferData` and `gl.drawArrays` calls are made, so you can + * perform any final pre-render modifications. To apply changes post-render, see `onAfterFlush`. + * @param isPostFlush Was this flush invoked as part of a post-process, or not? Default false. */ - onPostRender(): this; + onBeforeFlush(isPostFlush?: boolean): void; /** - * Uploads the vertex data and emits a draw call - * for the current batch of vertices. + * By default this is an empty method hook that you can override and use in your own custom pipelines. + * + * This method is called immediately after this pipeline has finished flushing its batch. + * + * It is called after the `gl.drawArrays` call. + * + * You can perform additional post-render effects, but be careful not to call `flush` + * on this pipeline from within this method, or you'll cause an infinite loop. + * + * To apply changes pre-render, see `onBeforeFlush`. + * @param isPostFlush Was this flush invoked as part of a post-process, or not? Default false. */ - flush(): this; + onAfterFlush(isPostFlush?: boolean): void; /** - * Removes all object references in this WebGL Pipeline and removes its program from the WebGL context. + * Adds a single vertex to the current vertex buffer and increments the + * `vertexCount` property by 1. + * + * This method is called directly by `batchTri` and `batchQuad`. + * + * It does not perform any batch limit checking itself, so if you need to call + * this method directly, do so in the same way that `batchQuad` does, for example. + * @param x The vertex x position. + * @param y The vertex y position. + * @param u UV u value. + * @param v UV v value. + * @param unit Texture unit to which the texture needs to be bound. + * @param tintEffect The tint effect for the shader to use. + * @param tint The tint color value. */ - destroy(): this; + batchVert(x: number, y: number, u: number, v: number, unit: number, tintEffect: number | boolean, tint: number): void; + + /** + * Adds the vertices data into the batch and flushes if full. + * + * Assumes 6 vertices in the following arrangement: + * + * ``` + * 0----3 + * |\ B| + * | \ | + * | \ | + * | A \| + * | \ + * 1----2 + * ``` + * + * Where tx0/ty0 = 0, tx1/ty1 = 1, tx2/ty2 = 2 and tx3/ty3 = 3 + * @param gameObject The Game Object, if any, drawing this quad. + * @param x0 The top-left x position. + * @param y0 The top-left y position. + * @param x1 The bottom-left x position. + * @param y1 The bottom-left y position. + * @param x2 The bottom-right x position. + * @param y2 The bottom-right y position. + * @param x3 The top-right x position. + * @param y3 The top-right y position. + * @param u0 UV u0 value. + * @param v0 UV v0 value. + * @param u1 UV u1 value. + * @param v1 UV v1 value. + * @param tintTL The top-left tint color value. + * @param tintTR The top-right tint color value. + * @param tintBL The bottom-left tint color value. + * @param tintBR The bottom-right tint color value. + * @param tintEffect The tint effect for the shader to use. + * @param texture WebGLTexture that will be assigned to the current batch if a flush occurs. + * @param unit Texture unit to which the texture needs to be bound. Default 0. + */ + batchQuad(gameObject: Phaser.GameObjects.GameObject | null, x0: number, y0: number, x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, u0: number, v0: number, u1: number, v1: number, tintTL: number, tintTR: number, tintBL: number, tintBR: number, tintEffect: number | boolean, texture?: WebGLTexture, unit?: number): boolean; + + /** + * Adds the vertices data into the batch and flushes if full. + * + * Assumes 3 vertices in the following arrangement: + * + * ``` + * 0 + * |\ + * | \ + * | \ + * | \ + * | \ + * 1-----2 + * ``` + * @param gameObject The Game Object, if any, drawing this quad. + * @param x1 The bottom-left x position. + * @param y1 The bottom-left y position. + * @param x2 The bottom-right x position. + * @param y2 The bottom-right y position. + * @param x3 The top-right x position. + * @param y3 The top-right y position. + * @param u0 UV u0 value. + * @param v0 UV v0 value. + * @param u1 UV u1 value. + * @param v1 UV v1 value. + * @param tintTL The top-left tint color value. + * @param tintTR The top-right tint color value. + * @param tintBL The bottom-left tint color value. + * @param tintEffect The tint effect for the shader to use. + * @param texture WebGLTexture that will be assigned to the current batch if a flush occurs. + * @param unit Texture unit to which the texture needs to be bound. Default 0. + */ + batchTri(gameObject: Phaser.GameObjects.GameObject | null, x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, u0: number, v0: number, u1: number, v1: number, tintTL: number, tintTR: number, tintBL: number, tintEffect: number | boolean, texture?: WebGLTexture, unit?: number): boolean; + + /** + * Pushes a filled rectangle into the vertex batch. + * + * The dimensions are run through `Math.floor` before the quad is generated. + * + * Rectangle has no transform values and isn't transformed into the local space. + * + * Used for directly batching untransformed rectangles, such as Camera background colors. + * @param x Horizontal top left coordinate of the rectangle. + * @param y Vertical top left coordinate of the rectangle. + * @param width Width of the rectangle. + * @param height Height of the rectangle. + * @param color Color of the rectangle to draw. + * @param alpha Alpha value of the rectangle to draw. + * @param texture WebGLTexture that will be assigned to the current batch if a flush occurs. + * @param flipUV Flip the vertical UV coordinates of the texture before rendering? Default true. + */ + drawFillRect(x: number, y: number, width: number, height: number, color: number, alpha: number, texture?: WebGLTexture, flipUV?: boolean): void; + + /** + * Sets the texture to be bound to the next available texture unit and returns + * the unit id. + * @param texture WebGLTexture that will be assigned to the current batch. If not given uses `whiteTexture`. + */ + setTexture2D(texture?: WebGLTexture): number; + + /** + * Activates the given WebGL Texture and binds it to the requested texture slot. + * @param target The WebGLTexture to activate and bind. + * @param unit The WebGL texture ID to activate. Defaults to `gl.TEXTURE0`. Default 0. + */ + bindTexture(target?: WebGLTexture, unit?: number): this; + + /** + * Activates the given Render Target texture and binds it to the + * requested WebGL texture slot. + * @param target The Render Target to activate and bind. + * @param unit The WebGL texture ID to activate. Defaults to `gl.TEXTURE0`. Default 0. + */ + bindRenderTarget(target?: Phaser.Renderer.WebGL.RenderTarget, unit?: number): this; + + /** + * Sets the current duration into a 1f uniform value based on the given name. + * + * This can be used for mapping time uniform values, such as `iTime`. + * @param name The name of the uniform to set. + */ + setTime(name: string): this; /** - * Set a uniform value of the current pipeline program. - * @param name The name of the uniform to look-up and modify. + * Sets a 1f uniform value based on the given name on the currently set shader. + * + * The current shader is bound, before the uniform is set, making it active within the + * WebGLRenderer. This means you can safely call this method from a location such as + * a Scene `create` or `update` method. However, when working within a Shader file + * directly, use the `WebGLShader` method equivalent instead, to avoid the program + * being set. + * @param name The name of the uniform to set. * @param x The new value of the `float` uniform. + * @param shader The shader to set the value on. If not given, the `currentShader` is used. */ - setFloat1(name: string, x: number): this; + set1f(name: string, x: number, shader?: Phaser.Renderer.WebGL.WebGLShader): this; /** - * Set a uniform value of the current pipeline program. - * @param name The name of the uniform to look-up and modify. + * Sets a 2f uniform value based on the given name on the currently set shader. + * + * The current shader is bound, before the uniform is set, making it active within the + * WebGLRenderer. This means you can safely call this method from a location such as + * a Scene `create` or `update` method. However, when working within a Shader file + * directly, use the `WebGLShader` method equivalent instead, to avoid the program + * being set. + * @param name The name of the uniform to set. * @param x The new X component of the `vec2` uniform. * @param y The new Y component of the `vec2` uniform. + * @param shader The shader to set the value on. If not given, the `currentShader` is used. */ - setFloat2(name: string, x: number, y: number): this; + set2f(name: string, x: number, y: number, shader?: Phaser.Renderer.WebGL.WebGLShader): this; /** - * Set a uniform value of the current pipeline program. - * @param name The name of the uniform to look-up and modify. + * Sets a 3f uniform value based on the given name on the currently set shader. + * + * The current shader is bound, before the uniform is set, making it active within the + * WebGLRenderer. This means you can safely call this method from a location such as + * a Scene `create` or `update` method. However, when working within a Shader file + * directly, use the `WebGLShader` method equivalent instead, to avoid the program + * being set. + * @param name The name of the uniform to set. * @param x The new X component of the `vec3` uniform. * @param y The new Y component of the `vec3` uniform. * @param z The new Z component of the `vec3` uniform. + * @param shader The shader to set the value on. If not given, the `currentShader` is used. */ - setFloat3(name: string, x: number, y: number, z: number): this; + set3f(name: string, x: number, y: number, z: number, shader?: Phaser.Renderer.WebGL.WebGLShader): this; /** - * Set a uniform value of the current pipeline program. - * @param name The name of the uniform to look-up and modify. + * Sets a 4f uniform value based on the given name on the currently set shader. + * + * The current shader is bound, before the uniform is set, making it active within the + * WebGLRenderer. This means you can safely call this method from a location such as + * a Scene `create` or `update` method. However, when working within a Shader file + * directly, use the `WebGLShader` method equivalent instead, to avoid the program + * being set. + * @param name The name of the uniform to set. * @param x X component of the uniform * @param y Y component of the uniform * @param z Z component of the uniform * @param w W component of the uniform + * @param shader The shader to set the value on. If not given, the `currentShader` is used. + */ + set4f(name: string, x: number, y: number, z: number, w: number, shader?: Phaser.Renderer.WebGL.WebGLShader): this; + + /** + * Sets a 1fv uniform value based on the given name on the currently set shader. + * + * The current shader is bound, before the uniform is set, making it active within the + * WebGLRenderer. This means you can safely call this method from a location such as + * a Scene `create` or `update` method. However, when working within a Shader file + * directly, use the `WebGLShader` method equivalent instead, to avoid the program + * being set. + * @param name The name of the uniform to set. + * @param arr The new value to be used for the uniform variable. + * @param shader The shader to set the value on. If not given, the `currentShader` is used. + */ + set1fv(name: string, arr: number[] | Float32Array, shader?: Phaser.Renderer.WebGL.WebGLShader): this; + + /** + * Sets a 2fv uniform value based on the given name on the currently set shader. + * + * The current shader is bound, before the uniform is set, making it active within the + * WebGLRenderer. This means you can safely call this method from a location such as + * a Scene `create` or `update` method. However, when working within a Shader file + * directly, use the `WebGLShader` method equivalent instead, to avoid the program + * being set. + * @param name The name of the uniform to set. + * @param arr The new value to be used for the uniform variable. + * @param shader The shader to set the value on. If not given, the `currentShader` is used. + */ + set2fv(name: string, arr: number[] | Float32Array, shader?: Phaser.Renderer.WebGL.WebGLShader): this; + + /** + * Sets a 3fv uniform value based on the given name on the currently set shader. + * + * The current shader is bound, before the uniform is set, making it active within the + * WebGLRenderer. This means you can safely call this method from a location such as + * a Scene `create` or `update` method. However, when working within a Shader file + * directly, use the `WebGLShader` method equivalent instead, to avoid the program + * being set. + * @param name The name of the uniform to set. + * @param arr The new value to be used for the uniform variable. + * @param shader The shader to set the value on. If not given, the `currentShader` is used. + */ + set3fv(name: string, arr: number[] | Float32Array, shader?: Phaser.Renderer.WebGL.WebGLShader): this; + + /** + * Sets a 4fv uniform value based on the given name on the currently set shader. + * + * The current shader is bound, before the uniform is set, making it active within the + * WebGLRenderer. This means you can safely call this method from a location such as + * a Scene `create` or `update` method. However, when working within a Shader file + * directly, use the `WebGLShader` method equivalent instead, to avoid the program + * being set. + * @param name The name of the uniform to set. + * @param arr The new value to be used for the uniform variable. + * @param shader The shader to set the value on. If not given, the `currentShader` is used. */ - setFloat4(name: string, x: number, y: number, z: number, w: number): this; + set4fv(name: string, arr: number[] | Float32Array, shader?: Phaser.Renderer.WebGL.WebGLShader): this; /** - * Set a uniform value of the current pipeline program. - * @param name The name of the uniform to look-up and modify. + * Sets a 1iv uniform value based on the given name on the currently set shader. + * + * The current shader is bound, before the uniform is set, making it active within the + * WebGLRenderer. This means you can safely call this method from a location such as + * a Scene `create` or `update` method. However, when working within a Shader file + * directly, use the `WebGLShader` method equivalent instead, to avoid the program + * being set. + * @param name The name of the uniform to set. * @param arr The new value to be used for the uniform variable. + * @param shader The shader to set the value on. If not given, the `currentShader` is used. */ - setFloat1v(name: string, arr: Float32Array): this; + set1iv(name: string, arr: number[] | Float32Array, shader?: Phaser.Renderer.WebGL.WebGLShader): this; /** - * Set a uniform value of the current pipeline program. - * @param name The name of the uniform to look-up and modify. + * Sets a 2iv uniform value based on the given name on the currently set shader. + * + * The current shader is bound, before the uniform is set, making it active within the + * WebGLRenderer. This means you can safely call this method from a location such as + * a Scene `create` or `update` method. However, when working within a Shader file + * directly, use the `WebGLShader` method equivalent instead, to avoid the program + * being set. + * @param name The name of the uniform to set. * @param arr The new value to be used for the uniform variable. + * @param shader The shader to set the value on. If not given, the `currentShader` is used. */ - setFloat2v(name: string, arr: Float32Array): this; + set2iv(name: string, arr: number[] | Float32Array, shader?: Phaser.Renderer.WebGL.WebGLShader): this; /** - * Set a uniform value of the current pipeline program. - * @param name The name of the uniform to look-up and modify. + * Sets a 3iv uniform value based on the given name on the currently set shader. + * + * The current shader is bound, before the uniform is set, making it active within the + * WebGLRenderer. This means you can safely call this method from a location such as + * a Scene `create` or `update` method. However, when working within a Shader file + * directly, use the `WebGLShader` method equivalent instead, to avoid the program + * being set. + * @param name The name of the uniform to set. * @param arr The new value to be used for the uniform variable. + * @param shader The shader to set the value on. If not given, the `currentShader` is used. */ - setFloat3v(name: string, arr: Float32Array): this; + set3iv(name: string, arr: number[] | Float32Array, shader?: Phaser.Renderer.WebGL.WebGLShader): this; /** - * Set a uniform value of the current pipeline program. - * @param name The name of the uniform to look-up and modify. + * Sets a 4iv uniform value based on the given name on the currently set shader. + * + * The current shader is bound, before the uniform is set, making it active within the + * WebGLRenderer. This means you can safely call this method from a location such as + * a Scene `create` or `update` method. However, when working within a Shader file + * directly, use the `WebGLShader` method equivalent instead, to avoid the program + * being set. + * @param name The name of the uniform to set. * @param arr The new value to be used for the uniform variable. + * @param shader The shader to set the value on. If not given, the `currentShader` is used. */ - setFloat4v(name: string, arr: Float32Array): this; + set4iv(name: string, arr: number[] | Float32Array, shader?: Phaser.Renderer.WebGL.WebGLShader): this; /** - * Set a uniform value of the current pipeline program. - * @param name The name of the uniform to look-up and modify. + * Sets a 1i uniform value based on the given name on the currently set shader. + * + * The current shader is bound, before the uniform is set, making it active within the + * WebGLRenderer. This means you can safely call this method from a location such as + * a Scene `create` or `update` method. However, when working within a Shader file + * directly, use the `WebGLShader` method equivalent instead, to avoid the program + * being set. + * @param name The name of the uniform to set. * @param x The new value of the `int` uniform. + * @param shader The shader to set the value on. If not given, the `currentShader` is used. */ - setInt1(name: string, x: integer): this; + set1i(name: string, x: number, shader?: Phaser.Renderer.WebGL.WebGLShader): this; /** - * Set a uniform value of the current pipeline program. - * @param name The name of the uniform to look-up and modify. + * Sets a 2i uniform value based on the given name on the currently set shader. + * + * The current shader is bound, before the uniform is set, making it active within the + * WebGLRenderer. This means you can safely call this method from a location such as + * a Scene `create` or `update` method. However, when working within a Shader file + * directly, use the `WebGLShader` method equivalent instead, to avoid the program + * being set. + * @param name The name of the uniform to set. * @param x The new X component of the `ivec2` uniform. * @param y The new Y component of the `ivec2` uniform. + * @param shader The shader to set the value on. If not given, the `currentShader` is used. */ - setInt2(name: string, x: integer, y: integer): this; + set2i(name: string, x: number, y: number, shader?: Phaser.Renderer.WebGL.WebGLShader): this; /** - * Set a uniform value of the current pipeline program. - * @param name The name of the uniform to look-up and modify. + * Sets a 3i uniform value based on the given name on the currently set shader. + * + * The current shader is bound, before the uniform is set, making it active within the + * WebGLRenderer. This means you can safely call this method from a location such as + * a Scene `create` or `update` method. However, when working within a Shader file + * directly, use the `WebGLShader` method equivalent instead, to avoid the program + * being set. + * @param name The name of the uniform to set. * @param x The new X component of the `ivec3` uniform. * @param y The new Y component of the `ivec3` uniform. * @param z The new Z component of the `ivec3` uniform. + * @param shader The shader to set the value on. If not given, the `currentShader` is used. */ - setInt3(name: string, x: integer, y: integer, z: integer): this; + set3i(name: string, x: number, y: number, z: number, shader?: Phaser.Renderer.WebGL.WebGLShader): this; /** - * Set a uniform value of the current pipeline program. - * @param name The name of the uniform to look-up and modify. - * @param x X component of the uniform - * @param y Y component of the uniform - * @param z Z component of the uniform - * @param w W component of the uniform + * Sets a 4i uniform value based on the given name on the currently set shader. + * + * The current shader is bound, before the uniform is set, making it active within the + * WebGLRenderer. This means you can safely call this method from a location such as + * a Scene `create` or `update` method. However, when working within a Shader file + * directly, use the `WebGLShader` method equivalent instead, to avoid the program + * being set. + * @param name The name of the uniform to set. + * @param x X component of the uniform. + * @param y Y component of the uniform. + * @param z Z component of the uniform. + * @param w W component of the uniform. + * @param shader The shader to set the value on. If not given, the `currentShader` is used. */ - setInt4(name: string, x: integer, y: integer, z: integer, w: integer): this; + set4i(name: string, x: number, y: number, z: number, w: number, shader?: Phaser.Renderer.WebGL.WebGLShader): this; /** - * Set a uniform value of the current pipeline program. - * @param name The name of the uniform to look-up and modify. + * Sets a matrix 2fv uniform value based on the given name on the currently set shader. + * + * The current shader is bound, before the uniform is set, making it active within the + * WebGLRenderer. This means you can safely call this method from a location such as + * a Scene `create` or `update` method. However, when working within a Shader file + * directly, use the `WebGLShader` method equivalent instead, to avoid the program + * being set. + * @param name The name of the uniform to set. * @param transpose Whether to transpose the matrix. Should be `false`. * @param matrix The new values for the `mat2` uniform. + * @param shader The shader to set the value on. If not given, the `currentShader` is used. */ - setMatrix2(name: string, transpose: boolean, matrix: Float32Array): this; + setMatrix2fv(name: string, transpose: boolean, matrix: number[] | Float32Array, shader?: Phaser.Renderer.WebGL.WebGLShader): this; /** - * Set a uniform value of the current pipeline program. - * @param name The name of the uniform to look-up and modify. + * Sets a matrix 3fv uniform value based on the given name on the currently set shader. + * + * The current shader is bound, before the uniform is set, making it active within the + * WebGLRenderer. This means you can safely call this method from a location such as + * a Scene `create` or `update` method. However, when working within a Shader file + * directly, use the `WebGLShader` method equivalent instead, to avoid the program + * being set. + * @param name The name of the uniform to set. * @param transpose Whether to transpose the matrix. Should be `false`. * @param matrix The new values for the `mat3` uniform. + * @param shader The shader to set the value on. If not given, the `currentShader` is used. */ - setMatrix3(name: string, transpose: boolean, matrix: Float32Array): this; + setMatrix3fv(name: string, transpose: boolean, matrix: Float32Array, shader?: Phaser.Renderer.WebGL.WebGLShader): this; /** - * Set a uniform value of the current pipeline program. - * @param name The name of the uniform to look-up and modify. + * Sets a matrix 4fv uniform value based on the given name on the currently set shader. + * + * The current shader is bound, before the uniform is set, making it active within the + * WebGLRenderer. This means you can safely call this method from a location such as + * a Scene `create` or `update` method. However, when working within a Shader file + * directly, use the `WebGLShader` method equivalent instead, to avoid the program + * being set. + * @param name The name of the uniform to set. * @param transpose Should the matrix be transpose * @param matrix Matrix data + * @param shader The shader to set the value on. If not given, the `currentShader` is used. */ - setMatrix4(name: string, transpose: boolean, matrix: Float32Array): this; + setMatrix4fv(name: string, transpose: boolean, matrix: Float32Array, shader?: Phaser.Renderer.WebGL.WebGLShader): this; + + /** + * Destroys all shader instances, removes all object references and nulls all external references. + */ + destroy(): this; } @@ -74492,7 +82113,7 @@ declare namespace Phaser { * unexpected behavior. It's recommended that WebGL interaction is done through * WebGLRenderer and/or WebGLPipeline. */ - class WebGLRenderer { + class WebGLRenderer extends Phaser.Events.EventEmitter { /** * * @param game The Game instance which owns this WebGL Renderer. @@ -74512,19 +82133,32 @@ declare namespace Phaser { /** * A constant which allows the renderer to be easily identified as a WebGL Renderer. */ - type: integer; + type: number; + + /** + * An instance of the Pipeline Manager class, that handles all WebGL Pipelines. + * + * Use this to manage all of your interactions with pipelines, such as adding, getting, + * setting and rendering them. + * + * The Pipeline Manager class is created in the `init` method and then populated + * with pipelines during the `boot` method. + * + * Prior to Phaser v3.50.0 this was just a plain JavaScript object, not a class. + */ + pipelines: Phaser.Renderer.WebGL.PipelineManager; /** * The width of the canvas being rendered to. * This is populated in the onResize event handler. */ - width: integer; + width: number; /** * The height of the canvas being rendered to. * This is populated in the onResize event handler. */ - height: integer; + height: number; /** * The canvas which this WebGL Renderer draws to. @@ -74538,21 +82172,11 @@ declare namespace Phaser { */ blendModes: any[]; - /** - * Keeps track of any WebGLTexture created with the current WebGLRenderingContext - */ - nativeTextures: any[]; - /** * This property is set to `true` if the WebGL context of the renderer is lost. */ contextLost: boolean; - /** - * This object will store all pipelines created through addPipeline - */ - pipelines: object; - /** * Details about the currently scheduled snapshot. * @@ -74561,44 +82185,65 @@ declare namespace Phaser { snapshotState: Phaser.Types.Renderer.Snapshot.SnapshotState; /** - * Cached value for the last texture unit that was used + * Cached value for the last texture unit that was used. */ - currentActiveTextureUnit: integer; + currentActiveTexture: number; /** - * An array of the last texture handles that were bound to the WebGLRenderingContext + * Contains the current starting active texture unit. + * This value is constantly updated and should be treated as read-only by your code. */ - currentTextures: any[]; + startActiveTexture: number; /** - * Current framebuffer in use + * The maximum number of textures the GPU can handle. The minimum under the WebGL1 spec is 8. + * This is set via the Game Config `maxTextures` property and should never be changed after boot. */ - currentFramebuffer: WebGLFramebuffer; + maxTextures: number; /** - * Current WebGLPipeline in use + * An array of the available WebGL texture units, used to populate the uSampler uniforms. + * + * This array is populated during the init phase and should never be changed after boot. */ - currentPipeline: Phaser.Renderer.WebGL.WebGLPipeline; + textureIndexes: any[]; /** - * Current WebGLProgram in use + * An array of default temporary WebGL Textures. + * + * This array is populated during the init phase and should never be changed after boot. */ - currentProgram: WebGLProgram; + tempTextures: any[]; + + /** + * The currently bound texture at texture unit zero, if any. + */ + textureZero: WebGLTexture; + + /** + * The currently bound normal map texture at texture unit one, if any. + */ + normalTexture: WebGLTexture; + + /** + * The currently bound framebuffer in use. + */ + currentFramebuffer: WebGLFramebuffer; /** - * Current WebGLBuffer (Vertex buffer) in use + * A stack into which the frame buffer objects are pushed and popped. */ - currentVertexBuffer: WebGLBuffer; + fboStack: WebGLFramebuffer[]; /** - * Current WebGLBuffer (Index buffer) in use + * Current WebGLProgram in use. */ - currentIndexBuffer: WebGLBuffer; + currentProgram: WebGLProgram; /** * Current blend mode in use */ - currentBlendMode: integer; + currentBlendMode: number; /** * Indicates if the the scissor state is enabled in WebGLRenderingContext @@ -74633,24 +82278,37 @@ declare namespace Phaser { gl: WebGLRenderingContext; /** - * Array of strings that indicate which WebGL extensions are supported by the browser + * Array of strings that indicate which WebGL extensions are supported by the browser. + * This is populated in the `boot` method. + */ + supportedExtensions: string[]; + + /** + * If the browser supports the `ANGLE_instanced_arrays` extension, this property will hold + * a reference to the glExtension for it. */ - supportedExtensions: object; + instancedArraysExtension: ANGLE_instanced_arrays; /** - * Extensions loaded into the current context + * If the browser supports the `OES_vertex_array_object` extension, this property will hold + * a reference to the glExtension for it. + */ + vaoExtension: OES_vertex_array_object; + + /** + * The WebGL Extensions loaded into the current context. */ extensions: object; /** - * Stores the current WebGL component formats for further use + * Stores the current WebGL component formats for further use. */ glFormats: any[]; /** * Stores the supported WebGL texture compression formats. */ - compression: any[]; + compression: object; /** * Cached drawing buffer height to reduce gl calls. @@ -74664,14 +82322,15 @@ declare namespace Phaser { readonly blankTexture: WebGLTexture; /** - * A default Camera used in calls when no other camera has been provided. + * A pure white 4x4 texture, as used by the Graphics system where needed. + * This is set in the `boot` method. */ - defaultCamera: Phaser.Cameras.Scene2D.BaseCamera; + readonly whiteTexture: WebGLTexture; /** * The total number of masks currently stacked. */ - maskCount: integer; + maskCount: number; /** * The mask stack. @@ -74712,6 +82371,11 @@ declare namespace Phaser { */ nextTypeMatch: boolean; + /** + * Is the Game Object being currently rendered the final one in the list? + */ + finalType: boolean; + /** * The mipmap magFilter to be used when creating textures. * @@ -74734,6 +82398,38 @@ declare namespace Phaser { */ mipmapFilter: GLenum; + /** + * The number of times the renderer had to flush this frame, due to running out of texture units. + */ + textureFlush: number; + + /** + * Has this renderer fully booted yet? + */ + isBooted: boolean; + + /** + * A Render Target you can use to capture the current state of the Renderer. + * + * A Render Target encapsulates a framebuffer and texture for the WebGL Renderer. + */ + renderTarget: Phaser.Renderer.WebGL.RenderTarget; + + /** + * The global game Projection matrix, used by shaders as 'uProjectionMatrix' uniform. + */ + projectionMatrix: Phaser.Math.Matrix4; + + /** + * The cached width of the Projection matrix. + */ + projectionWidth: number; + + /** + * The cached height of the Projection matrix. + */ + projectionHeight: number; + /** * Creates a new WebGLRenderingContext and initializes all internal state. * @param config The configuration object for the renderer. @@ -74743,61 +82439,70 @@ declare namespace Phaser { /** * The event handler that manages the `resize` event dispatched by the Scale Manager. * @param gameSize The default Game Size object. This is the un-modified game dimensions. - * @param baseSize The base Size object. The game dimensions multiplied by the resolution. The canvas width / height values match this. - * @param displaySize The display Size object. The size of the canvas style width / height attributes. - * @param resolution The Scale Manager resolution setting. + * @param baseSize The base Size object. The game dimensions. The canvas width / height values match this. */ - onResize(gameSize: Phaser.Structs.Size, baseSize: Phaser.Structs.Size, displaySize: Phaser.Structs.Size, resolution?: number): void; + onResize(gameSize: Phaser.Structs.Size, baseSize: Phaser.Structs.Size): void; /** - * Resizes the drawing buffer to match that required by the Scale Manager. - * @param width The new width of the renderer. - * @param height The new height of the renderer. - * @param resolution The new resolution of the renderer. + * Binds the WebGL Renderers Render Target, so all drawn content is now redirected to it. + * + * Make sure to call `endCapture` when you are finished. + * @param width Optional new width of the Render Target. + * @param height Optional new height of the Render Target. */ - resize(width?: number, height?: number, resolution?: number): this; + beginCapture(width?: number, height?: number): void; /** - * Checks if a WebGL extension is supported - * @param extensionName Name of the WebGL extension + * Unbinds the WebGL Renderers Render Target and returns it, stopping any further content being drawn to it. + * + * If the viewport or scissors were modified during the capture, you should reset them by calling + * `resetViewport` and `resetScissor` accordingly. */ - hasExtension(extensionName: string): boolean; + endCapture(): Phaser.Renderer.WebGL.RenderTarget; /** - * Loads a WebGL extension - * @param extensionName The name of the extension to load. + * Resizes the drawing buffer to match that required by the Scale Manager. + * @param width The new width of the renderer. + * @param height The new height of the renderer. */ - getExtension(extensionName: string): object; + resize(width?: number, height?: number): this; /** - * Flushes the current pipeline if the pipeline is bound + * Gets the aspect ratio of the WebGLRenderer dimensions. */ - flush(): void; + getAspectRatio(): number; + + /** + * Sets the Projection Matrix of this renderer to the given dimensions. + * @param width The new width of the Projection Matrix. + * @param height The new height of the Projection Matrix. + */ + setProjectionMatrix(width: number, height: number): this; /** - * Checks if a pipeline is present in the current WebGLRenderer - * @param pipelineName The name of the pipeline. + * Resets the Projection Matrix back to this renderers width and height. + * + * This is called during `endCapture`, should the matrix have been changed + * as a result of the capture process. */ - hasPipeline(pipelineName: string): boolean; + resetProjectionMatrix(): void; /** - * Returns the pipeline by name if the pipeline exists - * @param pipelineName The name of the pipeline. + * Checks if a WebGL extension is supported + * @param extensionName Name of the WebGL extension */ - getPipeline(pipelineName: string): Phaser.Renderer.WebGL.WebGLPipeline; + hasExtension(extensionName: string): boolean; /** - * Removes a pipeline by name. - * @param pipelineName The name of the pipeline to be removed. + * Loads a WebGL extension + * @param extensionName The name of the extension to load. */ - removePipeline(pipelineName: string): this; + getExtension(extensionName: string): object; /** - * Adds a pipeline instance into the collection of pipelines - * @param pipelineName A unique string-based key for the pipeline. - * @param pipelineInstance A pipeline instance which must extend WebGLPipeline. + * Flushes the current pipeline if the pipeline is bound */ - addPipeline(pipelineName: string, pipelineInstance: Phaser.Renderer.WebGL.WebGLPipeline): Phaser.Renderer.WebGL.WebGLPipeline; + flush(): void; /** * Pushes a new scissor state. This is used to set nested scissor states. @@ -74807,7 +82512,7 @@ declare namespace Phaser { * @param height The height of the scissor. * @param drawingBufferHeight Optional drawingBufferHeight override value. */ - pushScissor(x: integer, y: integer, width: integer, height: integer, drawingBufferHeight?: integer): integer[]; + pushScissor(x: number, y: number, width: number, height: number, drawingBufferHeight?: number): number[]; /** * Sets the current scissor state. @@ -74817,19 +82522,18 @@ declare namespace Phaser { * @param height The height of the scissor. * @param drawingBufferHeight Optional drawingBufferHeight override value. */ - setScissor(x: integer, y: integer, width: integer, height: integer, drawingBufferHeight?: integer): void; + setScissor(x: number, y: number, width: number, height: number, drawingBufferHeight?: number): void; /** - * Pops the last scissor state and sets it. + * Resets the gl scissor state to be whatever the current scissor is, if there is one, without + * modifying the scissor stack. */ - popScissor(): void; + resetScissor(): void; /** - * Binds a WebGLPipeline and sets it as the current pipeline to be used. - * @param pipelineInstance The pipeline instance to be activated. - * @param gameObject The Game Object that invoked this pipeline, if any. + * Pops the last scissor state and sets it. */ - setPipeline(pipelineInstance: Phaser.Renderer.WebGL.WebGLPipeline, gameObject?: Phaser.GameObjects.GameObject): Phaser.Renderer.WebGL.WebGLPipeline; + popScissor(): void; /** * Is there an active stencil mask? @@ -74837,29 +82541,9 @@ declare namespace Phaser { hasActiveStencilMask(): boolean; /** - * Use this to reset the gl context to the state that Phaser requires to continue rendering. - * Calling this will: - * - * * Disable `DEPTH_TEST`, `CULL_FACE` and `STENCIL_TEST`. - * * Clear the depth buffer and stencil buffers. - * * Reset the viewport size. - * * Reset the blend mode. - * * Bind a blank texture as the active texture on texture unit zero. - * * Rebinds the given pipeline instance. - * - * You should call this having previously called `clearPipeline` and then wishing to return - * control to Phaser again. - * @param pipelineInstance The pipeline instance to be activated. - */ - rebindPipeline(pipelineInstance: Phaser.Renderer.WebGL.WebGLPipeline): void; - - /** - * Flushes the current WebGLPipeline being used and then clears it, along with the - * the current shader program and vertex buffer. Then resets the blend mode to NORMAL. - * Call this before jumping to your own gl context handler, and then call `rebindPipeline` when - * you wish to return control to Phaser again. + * Resets the gl viewport to the current renderer dimensions. */ - clearPipeline(): void; + resetViewport(): void; /** * Sets the blend mode to the value given. @@ -74869,7 +82553,7 @@ declare namespace Phaser { * @param blendModeId The blend mode to be set. Can be a `BlendModes` const or an integer value. * @param force Force the blend mode to be set, regardless of the currently set blend mode. Default false. */ - setBlendMode(blendModeId: integer, force?: boolean): boolean; + setBlendMode(blendModeId: number, force?: boolean): boolean; /** * Creates a new custom blend mode for the renderer. @@ -74878,7 +82562,7 @@ declare namespace Phaser { * @param func An array containing the WebGL functions to use for the source and the destination blending factors, respectively. See the possible constants for {@link WebGLRenderingContext#blendFunc()}. * @param equation The equation to use for combining the RGB and alpha components of a new pixel with a rendered one. See the possible constants for {@link WebGLRenderingContext#blendEquation()}. */ - addBlendMode(func: GLenum[], equation: GLenum): integer; + addBlendMode(func: GLenum[], equation: GLenum): number; /** * Updates the function bound to a given custom blend mode. @@ -74886,48 +82570,128 @@ declare namespace Phaser { * @param func The function to use for the blend mode. * @param equation The equation to use for the blend mode. */ - updateBlendMode(index: integer, func: Function, equation: Function): this; + updateBlendMode(index: number, func: Function, equation: Function): this; /** * Removes a custom blend mode from the renderer. * Any Game Objects still using this blend mode will error, so be sure to clear them first. * @param index The index of the custom blend mode to be removed. */ - removeBlendMode(index: integer): this; + removeBlendMode(index: number): this; + + /** + * Activates the Texture Source and assigns it the next available texture unit. + * If none are available, it will flush the current pipeline first. + * @param textureSource The Texture Source to be assigned the texture unit. + */ + setTextureSource(textureSource: Phaser.Textures.TextureSource): number; + + /** + * Checks to see if the given diffuse and normal map textures are already bound, or not. + * @param texture The WebGL diffuse texture. + * @param normalMap The WebGL normal map texture. + */ + isNewNormalMap(texture: WebGLTexture, normalMap: WebGLTexture): boolean; + + /** + * Binds a texture directly to texture unit zero then activates it. + * If the texture is already at unit zero, it skips the bind. + * Make sure to call `clearTextureZero` after using this method. + * @param texture The WebGL texture that needs to be bound. + * @param flush Flush the pipeline if the texture is different? Default false. + */ + setTextureZero(texture: WebGLTexture, flush?: boolean): void; + + /** + * Clears the texture that was directly bound to texture unit zero. + */ + clearTextureZero(): void; + + /** + * Binds a texture directly to texture unit one then activates it. + * If the texture is already at unit one, it skips the bind. + * Make sure to call `clearNormalMap` after using this method. + * @param texture The WebGL texture that needs to be bound. + */ + setNormalMap(texture: WebGLTexture): void; + + /** + * Clears the texture that was directly bound to texture unit one and + * increases the start active texture counter. + */ + clearNormalMap(): void; + + /** + * Activates each texture, in turn, then binds them all to `null`. + * @param all Reset all textures, or just the first two? Default false. + */ + unbindTextures(all?: boolean): void; + + /** + * Flushes the current pipeline, then resets the first two textures + * back to the default temporary textures, resets the start active + * counter and sets texture unit 1 as being active. + * @param all Reset all textures, or just the first two? Default false. + */ + resetTextures(all?: boolean): void; /** * Binds a texture at a texture unit. If a texture is already * bound to that unit it will force a flush on the current pipeline. * @param texture The WebGL texture that needs to be bound. - * @param textureUnit The texture unit to which the texture will be bound. - * @param flush Will the current pipeline be flushed if this is a new texture, or not? Default true. */ - setTexture2D(texture: WebGLTexture, textureUnit: integer, flush?: boolean): this; + setTexture2D(texture: WebGLTexture): number; /** - * Binds a framebuffer. If there was another framebuffer already bound it will force a pipeline flush. + * Pushes a new framebuffer onto the FBO stack and makes it the currently bound framebuffer. + * + * If there was another framebuffer already bound it will force a pipeline flush. + * + * Call `popFramebuffer` to remove it again. + * @param framebuffer The framebuffer that needs to be bound. + * @param updateScissor Set the gl scissor to match the frame buffer size? Or, if `null` given, pop the scissor from the stack. Default false. + * @param resetTextures Should the WebGL Textures be reset after the new framebuffer is bound? Default false. + * @param setViewport Should the WebGL viewport be set? Default true. + */ + pushFramebuffer(framebuffer: WebGLFramebuffer, updateScissor?: boolean, resetTextures?: boolean, setViewport?: boolean): this; + + /** + * Sets the given framebuffer as the active and currently bound framebuffer. + * + * If there was another framebuffer already bound it will force a pipeline flush. + * + * Typically, you should call `pushFramebuffer` instead of this method. * @param framebuffer The framebuffer that needs to be bound. * @param updateScissor If a framebuffer is given, set the gl scissor to match the frame buffer size? Or, if `null` given, pop the scissor from the stack. Default false. + * @param resetTextures Should the WebGL Textures be reset after the new framebuffer is bound? Default false. + * @param setViewport Should the WebGL viewport be set? Default true. */ - setFramebuffer(framebuffer: WebGLFramebuffer, updateScissor?: boolean): this; + setFramebuffer(framebuffer: WebGLFramebuffer, updateScissor?: boolean, resetTextures?: boolean, setViewport?: boolean): this; /** - * Binds a program. If there was another program already bound it will force a pipeline flush. - * @param program The program that needs to be bound. + * Pops the previous framebuffer from the fbo stack and sets it. + * @param updateScissor If a framebuffer is given, set the gl scissor to match the frame buffer size? Or, if `null` given, pop the scissor from the stack. Default false. + * @param resetTextures Should the WebGL Textures be reset after the new framebuffer is bound? Default false. + * @param setViewport Should the WebGL viewport be set? Default true. */ - setProgram(program: WebGLProgram): this; + popFramebuffer(updateScissor?: boolean, resetTextures?: boolean, setViewport?: boolean): WebGLFramebuffer; /** - * Bounds a vertex buffer. If there is a vertex buffer already bound it'll force a pipeline flush. - * @param vertexBuffer The buffer that needs to be bound. + * Binds a shader program. + * + * If there was a different program already bound it will force a pipeline flush first. + * + * If the same program given to this method is already set as the current program, no change + * will take place and this method will return `false`. + * @param program The program that needs to be bound. */ - setVertexBuffer(vertexBuffer: WebGLBuffer): this; + setProgram(program: WebGLProgram): boolean; /** - * Bounds a index buffer. If there is a index buffer already bound it'll force a pipeline flush. - * @param indexBuffer The buffer the needs to be bound. + * Rebinds whatever program `WebGLRenderer.currentProgram` is set as, without + * changing anything, or flushing. */ - setIndexBuffer(indexBuffer: WebGLBuffer): this; + resetProgram(): this; /** * Creates a texture from an image source. If the source is not valid it creates an empty texture. @@ -74936,7 +82700,7 @@ declare namespace Phaser { * @param height The height of the texture. * @param scaleMode The scale mode to be used by the texture. */ - createTextureFromSource(source: object, width: integer, height: integer, scaleMode: integer): WebGLTexture; + createTextureFromSource(source: object, width: number, height: number, scaleMode: number): WebGLTexture; /** * A wrapper for creating a WebGLTexture. If no pixel data is passed it will create an empty texture. @@ -74953,21 +82717,23 @@ declare namespace Phaser { * @param forceSize If `true` it will use the width and height passed to this method, regardless of the pixels dimension. Default false. * @param flipY Sets the `UNPACK_FLIP_Y_WEBGL` flag the WebGL Texture uses during upload. Default false. */ - createTexture2D(mipLevel: integer, minFilter: integer, magFilter: integer, wrapT: integer, wrapS: integer, format: integer, pixels: object, width: integer, height: integer, pma?: boolean, forceSize?: boolean, flipY?: boolean): WebGLTexture; + createTexture2D(mipLevel: number, minFilter: number, magFilter: number, wrapT: number, wrapS: number, format: number, pixels: object, width: number, height: number, pma?: boolean, forceSize?: boolean, flipY?: boolean): WebGLTexture; /** - * Wrapper for creating WebGLFramebuffer. - * @param width Width in pixels of the framebuffer - * @param height Height in pixels of the framebuffer - * @param renderTexture The color texture to where the color pixels are written - * @param addDepthStencilBuffer Indicates if the current framebuffer support depth and stencil buffers + * Creates a WebGL Framebuffer object and optionally binds a depth stencil render buffer. + * @param width If `addDepthStencilBuffer` is true, this controls the width of the depth stencil. + * @param height If `addDepthStencilBuffer` is true, this controls the height of the depth stencil. + * @param renderTexture The color texture where the color pixels are written. + * @param addDepthStencilBuffer Create a Renderbuffer for the depth stencil? Default false. */ - createFramebuffer(width: integer, height: integer, renderTexture: WebGLTexture, addDepthStencilBuffer: boolean): WebGLFramebuffer; + createFramebuffer(width: number, height: number, renderTexture: WebGLTexture, addDepthStencilBuffer?: boolean): WebGLFramebuffer; /** - * Wrapper for creating a WebGLProgram - * @param vertexShader Source to the vertex shader - * @param fragmentShader Source to the fragment shader + * Creates a WebGLProgram instance based on the given vertex and fragment shader source. + * + * Then compiles, attaches and links the program before returning it. + * @param vertexShader The vertex shader source code as a single string. + * @param fragmentShader The fragment shader source code as a single string. */ createProgram(vertexShader: string, fragmentShader: string): WebGLProgram; @@ -74976,20 +82742,22 @@ declare namespace Phaser { * @param initialDataOrSize It's either ArrayBuffer or an integer indicating the size of the vbo * @param bufferUsage How the buffer is used. gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW */ - createVertexBuffer(initialDataOrSize: ArrayBuffer, bufferUsage: integer): WebGLBuffer; + createVertexBuffer(initialDataOrSize: ArrayBuffer, bufferUsage: number): WebGLBuffer; /** * Wrapper for creating a vertex buffer. * @param initialDataOrSize Either ArrayBuffer or an integer indicating the size of the vbo. * @param bufferUsage How the buffer is used. gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW. */ - createIndexBuffer(initialDataOrSize: ArrayBuffer, bufferUsage: integer): WebGLBuffer; + createIndexBuffer(initialDataOrSize: ArrayBuffer, bufferUsage: number): WebGLBuffer; /** - * Removes the given texture from the nativeTextures array and then deletes it from the GPU. + * Calls `GL.deleteTexture` on the given WebGLTexture and also optionally + * resets the currently defined textures. * @param texture The WebGL Texture to be deleted. + * @param reset Call the `resetTextures` method after deleting this texture? Default false. */ - deleteTexture(texture: WebGLTexture): this; + deleteTexture(texture: WebGLTexture, reset?: boolean): this; /** * Deletes a WebGLFramebuffer from the GL instance. @@ -75018,7 +82786,8 @@ declare namespace Phaser { /** * Controls the post-render operations for the given camera. - * Renders the foreground camera effects like flash and fading. It resets the current scissor state. + * + * Renders the foreground camera effects like flash and fading, then resets the current scissor state. * @param camera The Camera to post-render. */ postRenderCamera(camera: Phaser.Cameras.Scene2D.Camera): void; @@ -75031,18 +82800,17 @@ declare namespace Phaser { /** * The core render step for a Scene Camera. * - * Iterates through the given Game Object's array and renders them with the given Camera. + * Iterates through the given array of Game Objects and renders them with the given Camera. * * This is called by the `CameraManager.render` method. The Camera Manager instance belongs to a Scene, and is invoked * by the Scene Systems.render method. * * This method is not called if `Camera.visible` is `false`, or `Camera.alpha` is zero. * @param scene The Scene to render. - * @param children The Game Object's within the Scene to be rendered. - * @param interpolationPercentage The interpolation percentage to apply. Currently un-used. + * @param children An array of filtered Game Objects that can be rendered by the given Camera. * @param camera The Scene Camera to render with. */ - render(scene: Phaser.Scene, children: Phaser.GameObjects.GameObject, interpolationPercentage: number, camera: Phaser.Cameras.Scene2D.Camera): void; + render(scene: Phaser.Scene, children: Phaser.GameObjects.GameObject[], camera: Phaser.Cameras.Scene2D.Camera): void; /** * The post-render step happens after all Cameras in all Scenes have been rendered. @@ -75087,7 +82855,7 @@ declare namespace Phaser { * @param type The format of the image to create, usually `image/png` or `image/jpeg`. Default 'image/png'. * @param encoderOptions The image quality, between 0 and 1. Used for image formats with lossy compression, such as `image/jpeg`. Default 0.92. */ - snapshotArea(x: integer, y: integer, width: integer, height: integer, callback: Phaser.Types.Renderer.Snapshot.SnapshotCallback, type?: string, encoderOptions?: number): this; + snapshotArea(x: number, y: number, width: number, height: number, callback: Phaser.Types.Renderer.Snapshot.SnapshotCallback, type?: string, encoderOptions?: number): this; /** * Schedules a snapshot of the given pixel from the game viewport to be taken after the current frame is rendered. @@ -75104,7 +82872,7 @@ declare namespace Phaser { * @param y The y coordinate of the pixel to get. * @param callback The Function to invoke after the snapshot pixel data is extracted. */ - snapshotPixel(x: integer, y: integer, callback: Phaser.Types.Renderer.Snapshot.SnapshotCallback): this; + snapshotPixel(x: number, y: number, callback: Phaser.Types.Renderer.Snapshot.SnapshotCallback): this; /** * Takes a snapshot of the given area of the given frame buffer. @@ -75127,7 +82895,7 @@ declare namespace Phaser { * @param type The format of the image to create, usually `image/png` or `image/jpeg`. Default 'image/png'. * @param encoderOptions The image quality, between 0 and 1. Used for image formats with lossy compression, such as `image/jpeg`. Default 0.92. */ - snapshotFramebuffer(framebuffer: WebGLFramebuffer, bufferWidth: integer, bufferHeight: integer, callback: Phaser.Types.Renderer.Snapshot.SnapshotCallback, getPixel?: boolean, x?: integer, y?: integer, width?: integer, height?: integer, type?: string, encoderOptions?: number): this; + snapshotFramebuffer(framebuffer: WebGLFramebuffer, bufferWidth: number, bufferHeight: number, callback: Phaser.Types.Renderer.Snapshot.SnapshotCallback, getPixel?: boolean, x?: number, y?: number, width?: number, height?: number, type?: string, encoderOptions?: number): this; /** * Creates a new WebGL Texture based on the given Canvas Element. @@ -75177,157 +82945,511 @@ declare namespace Phaser { * @param texture The texture to set the filter for. * @param filter The filter to set. 0 for linear filtering, 1 for nearest neighbor (blocky) filtering. */ - setTextureFilter(texture: integer, filter: integer): this; + setTextureFilter(texture: number, filter: number): this; + + /** + * Returns the largest texture size (either width or height) that can be created. + * Note that VRAM may not allow a texture of any given size, it just expresses + * hardware / driver support for a given size. + */ + getMaxTextureSize(): number; + + /** + * Destroy this WebGLRenderer, cleaning up all related resources such as pipelines, native textures, etc. + */ + destroy(): void; + + } + + /** + * Instances of the WebGLShader class belong to the WebGL Pipeline classes. When the pipeline is + * created it will create an instance of this class for each one of its shaders, as defined in + * the pipeline configuration. + * + * This class encapsulates everything needed to manage a shader in a pipeline, including the + * shader attributes and uniforms, as well as lots of handy methods such as `set2f`, for setting + * uniform values on this shader. + * + * Typically, you do not create an instance of this class directly, as it works in unison with + * the pipeline to which it belongs. You can gain access to this class via a pipeline's `shaders` + * array, post-creation. + */ + class WebGLShader { + /** + * + * @param pipeline The WebGLPipeline to which this Shader belongs. + * @param name The name of this Shader. + * @param vertexShader The vertex shader source code as a single string. + * @param fragmentShader The fragment shader source code as a single string. + * @param attributes An array of attributes. + */ + constructor(pipeline: Phaser.Renderer.WebGL.WebGLPipeline, name: string, vertexShader: string, fragmentShader: string, attributes: Phaser.Types.Renderer.WebGL.WebGLPipelineAttributesConfig[]); + + /** + * A reference to the WebGLPipeline that owns this Shader. + * + * A Shader class can only belong to a single pipeline. + */ + pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + + /** + * The name of this shader. + */ + name: string; + + /** + * A reference to the WebGLRenderer instance. + */ + renderer: Phaser.Renderer.WebGL.WebGLRenderer; + + /** + * A reference to the WebGL Rendering Context the WebGL Renderer is using. + */ + gl: WebGLRenderingContext; + + /** + * The WebGLProgram created from the vertex and fragment shaders. + */ + program: WebGLProgram; + + /** + * Array of objects that describe the vertex attributes. + */ + attributes: Phaser.Types.Renderer.WebGL.WebGLPipelineAttribute[]; + + /** + * The amount of vertex attribute components of 32 bit length. + */ + vertexComponentCount: number; + + /** + * The size, in bytes, of a single vertex. + * + * This is derived by adding together all of the vertex attributes. + * + * For example, the Multi Pipeline has the following attributes: + * + * inPosition - (size 2 x gl.FLOAT) = 8 + * inTexCoord - (size 2 x gl.FLOAT) = 8 + * inTexId - (size 1 x gl.FLOAT) = 4 + * inTintEffect - (size 1 x gl.FLOAT) = 4 + * inTint - (size 4 x gl.UNSIGNED_BYTE) = 4 + * + * The total, in this case, is 8 + 8 + 4 + 4 + 4 = 28. + * + * This is calculated automatically during the `createAttributes` method. + */ + readonly vertexSize: number; + + /** + * The active uniforms that this shader has. + * + * This is an object that maps the uniform names to their WebGL location and cached values. + * + * It is populated automatically via the `createUniforms` method. + */ + uniforms: Phaser.Types.Renderer.WebGL.WebGLPipelineUniformsConfig; + + /** + * Takes the vertex attributes config and parses it, creating the resulting array that is stored + * in this shaders `attributes` property, calculating the offset, normalization and location + * in the process. + * + * Calling this method resets `WebGLShader.attributes`, `WebGLShader.vertexSize` and + * `WebGLShader.vertexComponentCount`. + * + * It is called automatically when this class is created, but can be called manually if required. + * @param attributes An array of attributes configs. + */ + createAttributes(attributes: Phaser.Types.Renderer.WebGL.WebGLPipelineAttributesConfig[]): void; + + /** + * Sets the program this shader uses as being the active shader in the WebGL Renderer. + * + * This method is called every time the parent pipeline is made the current active pipeline. + * @param setAttributes Should the vertex attribute pointers be set? Default false. + * @param flush Flush the pipeline before binding this shader? Default false. + */ + bind(setAttributes?: boolean, flush?: boolean): this; + + /** + * Sets the program this shader uses as being the active shader in the WebGL Renderer. + * + * Then resets all of the attribute pointers. + */ + rebind(): this; + + /** + * Sets the vertex attribute pointers. + * + * This should only be called after the vertex buffer has been bound. + * + * It is called automatically during the `bind` method. + * @param reset Reset the vertex attribute locations? Default false. + */ + setAttribPointers(reset?: boolean): this; + + /** + * Sets up the `WebGLShader.uniforms` object, populating it with the names + * and locations of the shader uniforms this shader requires. + * + * It works by first calling `gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS)` to + * find out how many active uniforms this shader has. It then iterates through them, + * calling `gl.getActiveUniform` to get the WebGL Active Info from each one. Finally, + * the name and location are stored in the local array. + * + * This method is called automatically when this class is created. + */ + createUniforms(): this; + + /** + * Checks to see if the given uniform name exists and is active in this shader. + * @param name The name of the uniform to check for. + */ + hasUniform(name: string): boolean; + + /** + * Resets the cached values of the given uniform. + * @param name The name of the uniform to reset. + */ + resetUniform(name: string): this; /** - * [description] - * @param program The target WebGLProgram from which the uniform location will be looked-up. - * @param name The name of the uniform to look-up and modify. - * @param x [description] + * Sets the given uniform value/s based on the name and GL function. + * + * This method is called internally by other methods such as `set1f` and `set3iv`. + * + * The uniform is only set if the value/s given are different to those previously set. + * + * This method works by first setting this shader as being the current shader within the + * WebGL Renderer, if it isn't already. It also sets this shader as being the current + * one within the pipeline it belongs to. + * @param setter The GL function to call. + * @param name The name of the uniform to set. + * @param value1 The new value of the uniform. */ - setFloat1(program: WebGLProgram, name: string, x: number): this; + setUniform1(setter: Function, name: string, value1: boolean | number | number[] | Float32Array): this; /** - * [description] - * @param program The target WebGLProgram from which the uniform location will be looked-up. - * @param name The name of the uniform to look-up and modify. - * @param x [description] - * @param y [description] + * Sets the given uniform value/s based on the name and GL function. + * + * This method is called internally by other methods such as `set1f` and `set3iv`. + * + * The uniform is only set if the value/s given are different to those previously set. + * + * This method works by first setting this shader as being the current shader within the + * WebGL Renderer, if it isn't already. It also sets this shader as being the current + * one within the pipeline it belongs to. + * @param setter The GL function to call. + * @param name The name of the uniform to set. + * @param value1 The new value of the uniform. + * @param value2 The new value of the uniform. */ - setFloat2(program: WebGLProgram, name: string, x: number, y: number): this; + setUniform2(setter: Function, name: string, value1: boolean | number | number[] | Float32Array, value2: boolean | number | number[] | Float32Array): this; /** - * [description] - * @param program The target WebGLProgram from which the uniform location will be looked-up. - * @param name The name of the uniform to look-up and modify. - * @param x [description] - * @param y [description] - * @param z [description] + * Sets the given uniform value/s based on the name and GL function. + * + * This method is called internally by other methods such as `set1f` and `set3iv`. + * + * The uniform is only set if the value/s given are different to those previously set. + * + * This method works by first setting this shader as being the current shader within the + * WebGL Renderer, if it isn't already. It also sets this shader as being the current + * one within the pipeline it belongs to. + * @param setter The GL function to call. + * @param name The name of the uniform to set. + * @param value1 The new value of the uniform. + * @param value2 The new value of the uniform. + * @param value3 The new value of the uniform. */ - setFloat3(program: WebGLProgram, name: string, x: number, y: number, z: number): this; + setUniform3(setter: Function, name: string, value1: boolean | number | number[] | Float32Array, value2: boolean | number | number[] | Float32Array, value3: boolean | number | number[] | Float32Array): this; /** - * Sets uniform of a WebGLProgram - * @param program The target WebGLProgram from which the uniform location will be looked-up. - * @param name The name of the uniform to look-up and modify. - * @param x X component - * @param y Y component - * @param z Z component - * @param w W component + * Sets the given uniform value/s based on the name and GL function. + * + * This method is called internally by other methods such as `set1f` and `set3iv`. + * + * The uniform is only set if the value/s given are different to those previously set. + * + * This method works by first setting this shader as being the current shader within the + * WebGL Renderer, if it isn't already. It also sets this shader as being the current + * one within the pipeline it belongs to. + * @param setter The GL function to call. + * @param name The name of the uniform to set. + * @param value1 The new value of the uniform. + * @param value2 The new value of the uniform. + * @param value3 The new value of the uniform. + * @param value4 The new value of the uniform. */ - setFloat4(program: WebGLProgram, name: string, x: number, y: number, z: number, w: number): this; + setUniform4(setter: Function, name: string, value1: boolean | number | number[] | Float32Array, value2: boolean | number | number[] | Float32Array, value3: boolean | number | number[] | Float32Array, value4: boolean | number | number[] | Float32Array): this; /** - * Sets the value of a uniform variable in the given WebGLProgram. - * @param program The target WebGLProgram from which the uniform location will be looked-up. - * @param name The name of the uniform to look-up and modify. + * Sets a 1f uniform value based on the given name on this shader. + * + * The uniform is only set if the value/s given are different to those previously set. + * + * This method works by first setting this shader as being the current shader within the + * WebGL Renderer, if it isn't already. It also sets this shader as being the current + * one within the pipeline it belongs to. + * @param name The name of the uniform to set. + * @param x The new value of the `float` uniform. + */ + set1f(name: string, x: number): this; + + /** + * Sets a 2f uniform value based on the given name on this shader. + * + * The uniform is only set if the value/s given are different to those previously set. + * + * This method works by first setting this shader as being the current shader within the + * WebGL Renderer, if it isn't already. It also sets this shader as being the current + * one within the pipeline it belongs to. + * @param name The name of the uniform to set. + * @param x The new X component of the `vec2` uniform. + * @param y The new Y component of the `vec2` uniform. + */ + set2f(name: string, x: number, y: number): this; + + /** + * Sets a 3f uniform value based on the given name on this shader. + * + * The uniform is only set if the value/s given are different to those previously set. + * + * This method works by first setting this shader as being the current shader within the + * WebGL Renderer, if it isn't already. It also sets this shader as being the current + * one within the pipeline it belongs to. + * @param name The name of the uniform to set. + * @param x The new X component of the `vec3` uniform. + * @param y The new Y component of the `vec3` uniform. + * @param z The new Z component of the `vec3` uniform. + */ + set3f(name: string, x: number, y: number, z: number): this; + + /** + * Sets a 4f uniform value based on the given name on this shader. + * + * The uniform is only set if the value/s given are different to those previously set. + * + * This method works by first setting this shader as being the current shader within the + * WebGL Renderer, if it isn't already. It also sets this shader as being the current + * one within the pipeline it belongs to. + * @param name The name of the uniform to set. + * @param x X component of the uniform + * @param y Y component of the uniform + * @param z Z component of the uniform + * @param w W component of the uniform + */ + set4f(name: string, x: number, y: number, z: number, w: number): this; + + /** + * Sets a 1fv uniform value based on the given name on this shader. + * + * The uniform is only set if the value/s given are different to those previously set. + * + * This method works by first setting this shader as being the current shader within the + * WebGL Renderer, if it isn't already. It also sets this shader as being the current + * one within the pipeline it belongs to. + * @param name The name of the uniform to set. + * @param arr The new value to be used for the uniform variable. + */ + set1fv(name: string, arr: number[] | Float32Array): this; + + /** + * Sets a 2fv uniform value based on the given name on this shader. + * + * The uniform is only set if the value/s given are different to those previously set. + * + * This method works by first setting this shader as being the current shader within the + * WebGL Renderer, if it isn't already. It also sets this shader as being the current + * one within the pipeline it belongs to. + * @param name The name of the uniform to set. + * @param arr The new value to be used for the uniform variable. + */ + set2fv(name: string, arr: number[] | Float32Array): this; + + /** + * Sets a 3fv uniform value based on the given name on this shader. + * + * The uniform is only set if the value/s given are different to those previously set. + * + * This method works by first setting this shader as being the current shader within the + * WebGL Renderer, if it isn't already. It also sets this shader as being the current + * one within the pipeline it belongs to. + * @param name The name of the uniform to set. * @param arr The new value to be used for the uniform variable. */ - setFloat1v(program: WebGLProgram, name: string, arr: Float32Array): this; + set3fv(name: string, arr: number[] | Float32Array): this; /** - * Sets the value of a uniform variable in the given WebGLProgram. - * @param program The target WebGLProgram from which the uniform location will be looked-up. - * @param name The name of the uniform to look-up and modify. + * Sets a 4fv uniform value based on the given name on this shader. + * + * The uniform is only set if the value/s given are different to those previously set. + * + * This method works by first setting this shader as being the current shader within the + * WebGL Renderer, if it isn't already. It also sets this shader as being the current + * one within the pipeline it belongs to. + * @param name The name of the uniform to set. * @param arr The new value to be used for the uniform variable. */ - setFloat2v(program: WebGLProgram, name: string, arr: Float32Array): this; + set4fv(name: string, arr: number[] | Float32Array): this; /** - * Sets the value of a uniform variable in the given WebGLProgram. - * @param program The target WebGLProgram from which the uniform location will be looked-up. - * @param name The name of the uniform to look-up and modify. + * Sets a 1iv uniform value based on the given name on this shader. + * + * The uniform is only set if the value/s given are different to those previously set. + * + * This method works by first setting this shader as being the current shader within the + * WebGL Renderer, if it isn't already. It also sets this shader as being the current + * one within the pipeline it belongs to. + * @param name The name of the uniform to set. * @param arr The new value to be used for the uniform variable. */ - setFloat3v(program: WebGLProgram, name: string, arr: Float32Array): this; + set1iv(name: string, arr: number[] | Float32Array): this; /** - * Sets the value of a uniform variable in the given WebGLProgram. - * @param program The target WebGLProgram from which the uniform location will be looked-up. - * @param name The name of the uniform to look-up and modify. + * Sets a 2iv uniform value based on the given name on this shader. + * + * The uniform is only set if the value/s given are different to those previously set. + * + * This method works by first setting this shader as being the current shader within the + * WebGL Renderer, if it isn't already. It also sets this shader as being the current + * one within the pipeline it belongs to. + * @param name The name of the uniform to set. * @param arr The new value to be used for the uniform variable. */ - setFloat4v(program: WebGLProgram, name: string, arr: Float32Array): this; + set2iv(name: string, arr: number[] | Float32Array): this; /** - * Sets the value of a uniform variable in the given WebGLProgram. - * @param program The target WebGLProgram from which the uniform location will be looked-up. - * @param name The name of the uniform to look-up and modify. - * @param x [description] + * Sets a 3iv uniform value based on the given name on this shader. + * + * The uniform is only set if the value/s given are different to those previously set. + * + * This method works by first setting this shader as being the current shader within the + * WebGL Renderer, if it isn't already. It also sets this shader as being the current + * one within the pipeline it belongs to. + * @param name The name of the uniform to set. + * @param arr The new value to be used for the uniform variable. */ - setInt1(program: WebGLProgram, name: string, x: integer): this; + set3iv(name: string, arr: number[] | Float32Array): this; /** - * Sets the value of a uniform variable in the given WebGLProgram. - * @param program The target WebGLProgram from which the uniform location will be looked-up. - * @param name The name of the uniform to look-up and modify. - * @param x The new X component - * @param y The new Y component + * Sets a 4iv uniform value based on the given name on this shader. + * + * The uniform is only set if the value/s given are different to those previously set. + * + * This method works by first setting this shader as being the current shader within the + * WebGL Renderer, if it isn't already. It also sets this shader as being the current + * one within the pipeline it belongs to. + * @param name The name of the uniform to set. + * @param arr The new value to be used for the uniform variable. */ - setInt2(program: WebGLProgram, name: string, x: integer, y: integer): this; + set4iv(name: string, arr: number[] | Float32Array): this; /** - * Sets the value of a uniform variable in the given WebGLProgram. - * @param program The target WebGLProgram from which the uniform location will be looked-up. - * @param name The name of the uniform to look-up and modify. - * @param x The new X component - * @param y The new Y component - * @param z The new Z component + * Sets a 1i uniform value based on the given name on this shader. + * + * The uniform is only set if the value/s given are different to those previously set. + * + * This method works by first setting this shader as being the current shader within the + * WebGL Renderer, if it isn't already. It also sets this shader as being the current + * one within the pipeline it belongs to. + * @param name The name of the uniform to set. + * @param x The new value of the `int` uniform. */ - setInt3(program: WebGLProgram, name: string, x: integer, y: integer, z: integer): this; + set1i(name: string, x: number): this; /** - * Sets the value of a uniform variable in the given WebGLProgram. - * @param program The target WebGLProgram from which the uniform location will be looked-up. - * @param name The name of the uniform to look-up and modify. - * @param x X component - * @param y Y component - * @param z Z component - * @param w W component + * Sets a 2i uniform value based on the given name on this shader. + * + * The uniform is only set if the value/s given are different to those previously set. + * + * This method works by first setting this shader as being the current shader within the + * WebGL Renderer, if it isn't already. It also sets this shader as being the current + * one within the pipeline it belongs to. + * @param name The name of the uniform to set. + * @param x The new X component of the `ivec2` uniform. + * @param y The new Y component of the `ivec2` uniform. */ - setInt4(program: WebGLProgram, name: string, x: integer, y: integer, z: integer, w: integer): this; + set2i(name: string, x: number, y: number): this; /** - * Sets the value of a 2x2 matrix uniform variable in the given WebGLProgram. - * @param program The target WebGLProgram from which the uniform location will be looked-up. - * @param name The name of the uniform to look-up and modify. - * @param transpose The value indicating whether to transpose the matrix. Must be false. - * @param matrix The new matrix value. + * Sets a 3i uniform value based on the given name on this shader. + * + * The uniform is only set if the value/s given are different to those previously set. + * + * This method works by first setting this shader as being the current shader within the + * WebGL Renderer, if it isn't already. It also sets this shader as being the current + * one within the pipeline it belongs to. + * @param name The name of the uniform to set. + * @param x The new X component of the `ivec3` uniform. + * @param y The new Y component of the `ivec3` uniform. + * @param z The new Z component of the `ivec3` uniform. */ - setMatrix2(program: WebGLProgram, name: string, transpose: boolean, matrix: Float32Array): this; + set3i(name: string, x: number, y: number, z: number): this; /** - * [description] - * @param program The target WebGLProgram from which the uniform location will be looked-up. - * @param name The name of the uniform to look-up and modify. - * @param transpose [description] - * @param matrix [description] + * Sets a 4i uniform value based on the given name on this shader. + * + * The uniform is only set if the value/s given are different to those previously set. + * + * This method works by first setting this shader as being the current shader within the + * WebGL Renderer, if it isn't already. It also sets this shader as being the current + * one within the pipeline it belongs to. + * @param name The name of the uniform to set. + * @param x X component of the uniform + * @param y Y component of the uniform + * @param z Z component of the uniform + * @param w W component of the uniform */ - setMatrix3(program: WebGLProgram, name: string, transpose: boolean, matrix: Float32Array): this; + set4i(name: string, x: number, y: number, z: number, w: number): this; /** - * Sets uniform of a WebGLProgram - * @param program The target WebGLProgram from which the uniform location will be looked-up. - * @param name The name of the uniform to look-up and modify. - * @param transpose Is the matrix transposed - * @param matrix Matrix data + * Sets a matrix 2fv uniform value based on the given name on this shader. + * + * The uniform is only set if the value/s given are different to those previously set. + * + * This method works by first setting this shader as being the current shader within the + * WebGL Renderer, if it isn't already. It also sets this shader as being the current + * one within the pipeline it belongs to. + * @param name The name of the uniform to set. + * @param transpose Whether to transpose the matrix. Should be `false`. + * @param matrix The new values for the `mat2` uniform. */ - setMatrix4(program: WebGLProgram, name: string, transpose: boolean, matrix: Float32Array): this; + setMatrix2fv(name: string, transpose: boolean, matrix: number[] | Float32Array): this; /** - * Returns the maximum number of texture units that can be used in a fragment shader. + * Sets a matrix 3fv uniform value based on the given name on this shader. + * + * The uniform is only set if the value/s given are different to those previously set. + * + * This method works by first setting this shader as being the current shader within the + * WebGL Renderer, if it isn't already. It also sets this shader as being the current + * one within the pipeline it belongs to. + * @param name The name of the uniform to set. + * @param transpose Whether to transpose the matrix. Should be `false`. + * @param matrix The new values for the `mat3` uniform. */ - getMaxTextures(): integer; + setMatrix3fv(name: string, transpose: boolean, matrix: Float32Array): this; /** - * Returns the largest texture size (either width or height) that can be created. - * Note that VRAM may not allow a texture of any given size, it just expresses - * hardware / driver support for a given size. + * Sets a matrix 4fv uniform value based on the given name on this shader. + * + * The uniform is only set if the value/s given are different to those previously set. + * + * This method works by first setting this shader as being the current shader within the + * WebGL Renderer, if it isn't already. It also sets this shader as being the current + * one within the pipeline it belongs to. + * @param name The name of the uniform to set. + * @param transpose Should the matrix be transpose + * @param matrix Matrix data */ - getMaxTextureSize(): integer; + setMatrix4fv(name: string, transpose: boolean, matrix: Float32Array): this; /** - * Destroy this WebGLRenderer, cleaning up all related resources such as pipelines, native textures, etc. + * Removes all external references from this class and deletes the WebGL program from the WebGL context. + * + * Does not remove this shader from the parent pipeline. */ destroy(): void; @@ -75515,6 +83637,8 @@ declare namespace Phaser { /** * The Scale Manager Orientation Change Event. + * + * This event is dispatched whenever the Scale Manager detects an orientation change event from the browser. */ const ORIENTATION_CHANGE: any; @@ -75675,7 +83799,7 @@ declare namespace Phaser { /** * The Base Size component. * - * The modified game size, which is the gameSize * resolution, used to set the canvas width and height + * The modified game size, which is the auto-rounded gameSize, used to set the canvas width and height * (but not the CSS style) */ baseSize: Phaser.Structs.Size; @@ -75692,13 +83816,6 @@ declare namespace Phaser { */ scaleMode: Phaser.Scale.ScaleModeType; - /** - * The canvas resolution. - * - * This is hard-coded to a value of 1 in the 3.16 release of Phaser and will be enabled at a later date. - */ - resolution: number; - /** * The game zoom factor. * @@ -75772,7 +83889,7 @@ declare namespace Phaser { * more traditional 'size check' based on a time interval. You can control how often it is * checked here. */ - resizeInterval: integer; + resizeInterval: number; /** * Called _before_ the canvas object is created and added to the DOM. @@ -75860,7 +83977,7 @@ declare namespace Phaser { * Sets the zoom value of the Scale Manager. * @param value The new zoom value of the game. */ - setZoom(value: integer): this; + setZoom(value: number): this; /** * Sets the zoom to be the maximum possible based on the _current_ parent size. @@ -75896,7 +84013,7 @@ declare namespace Phaser { * parent and game sizes. If the parent has no dimensions (i.e. an unstyled div), * or is smaller than the un-zoomed game, then this will return a value of 1 (no zoom) */ - getMaxZoom(): integer; + getMaxZoom(): number; /** * Calculates and updates the canvas CSS style in order to center it within the @@ -75936,7 +84053,7 @@ declare namespace Phaser { * * If the browser does not support this, a `FULLSCREEN_UNSUPPORTED` event will be emitted. * - * This method _must_ be called from a user-input gesture, such as `pointerup`. You cannot launch + * This method _must_ be called from a `pointerup` user-input gesture (**not** `pointerdown`). You cannot launch * games fullscreen without this, as most browsers block it. Games within an iframe will also be blocked * from fullscreen unless the iframe has the `allowfullscreen` attribute. * @@ -75994,7 +84111,7 @@ declare namespace Phaser { /** * Triggered when a fullscreenchange event is dispatched by the DOM. */ - onFullScreenChange(): void; + protected onFullScreenChange(): void; /** * Triggered when a fullscreenerror event is dispatched by the DOM. @@ -76071,7 +84188,7 @@ declare namespace Phaser { * The game canvas is not centered within the parent by Phaser. * You can still center it yourself via CSS. */ - const NO_CENTER: integer; + const NO_CENTER: number; /** * The game canvas is centered both horizontally and vertically within the parent. @@ -76080,7 +84197,7 @@ declare namespace Phaser { * Centering is achieved by setting the margin left and top properties of the * game canvas, and does not factor in any other CSS styles you may have applied. */ - const CENTER_BOTH: integer; + const CENTER_BOTH: number; /** * The game canvas is centered horizontally within the parent. @@ -76089,7 +84206,7 @@ declare namespace Phaser { * Centering is achieved by setting the margin left and top properties of the * game canvas, and does not factor in any other CSS styles you may have applied. */ - const CENTER_HORIZONTALLY: integer; + const CENTER_HORIZONTALLY: number; /** * The game canvas is centered both vertically within the parent. @@ -76098,7 +84215,7 @@ declare namespace Phaser { * Centering is achieved by setting the margin left and top properties of the * game canvas, and does not factor in any other CSS styles you may have applied. */ - const CENTER_VERTICALLY: integer; + const CENTER_VERTICALLY: number; /** * A landscape orientation. @@ -76115,56 +84232,56 @@ declare namespace Phaser { * again from that point on. If you change the canvas size, either via CSS, or directly via code, then you need * to call the Scale Managers `resize` method to give the new dimensions, or input events will stop working. */ - const NONE: integer; + const NONE: number; /** * The height is automatically adjusted based on the width. */ - const WIDTH_CONTROLS_HEIGHT: integer; + const WIDTH_CONTROLS_HEIGHT: number; /** * The width is automatically adjusted based on the height. */ - const HEIGHT_CONTROLS_WIDTH: integer; + const HEIGHT_CONTROLS_WIDTH: number; /** * The width and height are automatically adjusted to fit inside the given target area, * while keeping the aspect ratio. Depending on the aspect ratio there may be some space * inside the area which is not covered. */ - const FIT: integer; + const FIT: number; /** * The width and height are automatically adjusted to make the size cover the entire target * area while keeping the aspect ratio. This may extend further out than the target size. */ - const ENVELOP: integer; + const ENVELOP: number; /** * The Canvas is resized to fit all available _parent_ space, regardless of aspect ratio. */ - const RESIZE: integer; + const RESIZE: number; /** * The game canvas will not be zoomed by Phaser. */ - const NO_ZOOM: integer; + const NO_ZOOM: number; /** * The game canvas will be 2x zoomed by Phaser. */ - const ZOOM_2X: integer; + const ZOOM_2X: number; /** * The game canvas will be 4x zoomed by Phaser. */ - const ZOOM_4X: integer; + const ZOOM_4X: number; /** * Calculate the zoom value based on the maximum multiplied game size that will * fit into the parent, or browser window if no parent is set. */ - const MAX_ZOOM: integer; + const MAX_ZOOM: number; } @@ -76172,54 +84289,63 @@ declare namespace Phaser { /** * Scene state. */ - var PENDING: integer; + var PENDING: number; /** * Scene state. */ - var INIT: integer; + var INIT: number; /** * Scene state. */ - var START: integer; + var START: number; /** * Scene state. */ - var LOADING: integer; + var LOADING: number; /** * Scene state. */ - var CREATING: integer; + var CREATING: number; /** * Scene state. */ - var RUNNING: integer; + var RUNNING: number; /** * Scene state. */ - var PAUSED: integer; + var PAUSED: number; /** * Scene state. */ - var SLEEPING: integer; + var SLEEPING: number; /** * Scene state. */ - var SHUTDOWN: integer; + var SHUTDOWN: number; /** * Scene state. */ - var DESTROYED: integer; + var DESTROYED: number; namespace Events { + /** + * The Game Object Added to Scene Event. + * + * This event is dispatched when a Game Object is added to a Scene. + * + * Listen for it from a Scene using `this.scene.events.on('addedtoscene', listener)`. + */ + const ADDED_TO_SCENE: any; + /** * The Scene Systems Boot Event. * @@ -76312,6 +84438,15 @@ declare namespace Phaser { */ const READY: any; + /** + * The Game Object Removed from Scene Event. + * + * This event is dispatched when a Game Object is removed from a Scene. + * + * Listen for it from a Scene using `this.scene.events.on('removedfromscene', listener)`. + */ + const REMOVED_FROM_SCENE: any; + /** * The Scene Systems Render Event. * @@ -76520,6 +84655,7 @@ declare namespace Phaser { * * The Scene Manager is a Game level system, responsible for creating, processing and updating all of the * Scenes in a Game instance. + * ó * */ class SceneManager { /** @@ -76581,7 +84717,7 @@ declare namespace Phaser { * @param key A unique key used to reference the Scene, i.e. `MainMenu` or `Level1`. * @param sceneConfig The config for the Scene * @param autoStart If `true` the Scene will be started immediately after being added. Default false. - * @param data Optional data object. This will be set as Scene.settings.data and passed to `Scene.init`. + * @param data Optional data object. This will be set as `Scene.settings.data` and passed to `Scene.init`, and `Scene.create`. */ add(key: string, sceneConfig: Phaser.Scene | Phaser.Types.Scenes.SettingsConfig | Phaser.Types.Scenes.CreateSceneFromObjectConfig | Function, autoStart?: boolean, data?: object): Phaser.Scene; @@ -76694,7 +84830,7 @@ declare namespace Phaser { /** * Starts the given Scene. * @param key The Scene to start. - * @param data Optional data object to pass to Scene.Settings and Scene.init. + * @param data Optional data object to pass to `Scene.Settings` and `Scene.init`, and `Scene.create`. */ start(key: string, data?: object): Phaser.Scenes.SceneManager; @@ -76716,13 +84852,13 @@ declare namespace Phaser { * Retrieves a Scene by numeric index. * @param index The index of the Scene to retrieve. */ - getAt(index: integer): Phaser.Scene | undefined; + getAt(index: number): Phaser.Scene | undefined; /** * Retrieves the numeric index of a Scene. * @param key The key of the Scene. */ - getIndex(key: string | Phaser.Scene): integer; + getIndex(key: string | Phaser.Scene): number; /** * Brings a Scene to the top of the Scenes list. @@ -77082,7 +85218,7 @@ declare namespace Phaser { * Retrieves the numeric index of a Scene in the Scenes list. * @param key The Scene to get the index of. */ - getIndex(key?: string | Phaser.Scene): integer; + getIndex(key?: string | Phaser.Scene): number; } @@ -77544,12 +85680,6 @@ declare namespace Phaser { */ physics: Phaser.Physics.Arcade.ArcadePhysics; - /** - * A scene level Impact Physics Plugin. - * This property will only be available if defined in the Scene Injection Map, the plugin is installed and configured. - */ - impact: Phaser.Physics.Impact.ImpactPhysics; - /** * A scene level Matter Physics Plugin. * This property will only be available if defined in the Scene Injection Map, the plugin is installed and configured. @@ -77576,6 +85706,11 @@ declare namespace Phaser { */ plugins: Phaser.Plugins.PluginManager; + /** + * A reference to the renderer instance Phaser is using, either Canvas or WebGL. + */ + renderer: Phaser.Renderer.Canvas.CanvasRenderer | Phaser.Renderer.WebGL.WebGLRenderer; + /** * Should be overridden by your own Scenes. * This method is called once per game step while the scene is running. @@ -77716,12 +85851,7 @@ declare namespace Phaser { } /** - * The sound manager is responsible for playing back audio via Web Audio API or HTML Audio tag as fallback. - * The audio file type and the encoding of those files are extremely important. - * - * Not all browsers can play all audio formats. - * - * There is a good guide to what's supported [here](https://developer.mozilla.org/en-US/Apps/Fundamentals/Audio_and_video_delivery/Cross-browser_audio_basics#Audio_Codec_Support). + * Base class for other Sound Manager classes. */ class BaseSoundManager extends Phaser.Events.EventEmitter { /** @@ -77779,6 +85909,18 @@ declare namespace Phaser { */ addAudioSprite(key: string, config?: Phaser.Types.Sound.SoundConfig): Phaser.Sound.HTML5AudioSound | Phaser.Sound.WebAudioSound; + /** + * Gets the first sound in the manager matching the given key, if any. + * @param key Sound asset key. + */ + get(key: string): Phaser.Sound.BaseSound; + + /** + * Gets any sounds in the manager matching the given key. + * @param key Sound asset key. + */ + getAll(key: string): Phaser.Sound.BaseSound[]; + /** * Adds a new sound to the sound manager and plays it. * The sound will be automatically removed (destroyed) once playback ends. @@ -77789,8 +85931,9 @@ declare namespace Phaser { play(key: string, extra?: Phaser.Types.Sound.SoundConfig | Phaser.Types.Sound.SoundMarker): boolean; /** - * Enables playing audio sprite sound on the fly without the need to keep a reference to it. - * Sound will auto destroy once its playback ends. + * Adds a new audio sprite sound to the sound manager and plays it. + * The sprite will be automatically removed (destroyed) once playback ends. + * This lets you play a new sound on the fly without the need to keep a reference to it. * @param key Asset key for the sound. * @param spriteName The name of the sound sprite to play. * @param config An optional config object containing default sound settings. @@ -77804,6 +85947,11 @@ declare namespace Phaser { */ remove(sound: Phaser.Sound.BaseSound): boolean; + /** + * Removes all sounds from the manager, destroying the sounds. + */ + removeAll(): void; + /** * Removes all sounds from the sound manager that have an asset key matching the given value. * The removed sounds are destroyed before removal. @@ -77826,6 +85974,12 @@ declare namespace Phaser { */ stopAll(): void; + /** + * Stops any sounds matching the given key. + * @param key Sound asset key. + */ + stopByKey(key: string): number; + /** * Method used internally for unlocking audio playback on devices that * require user interaction before any sound can be played on a web page. @@ -78063,6 +86217,22 @@ declare namespace Phaser { */ const MUTE: any; + /** + * The Sound Pan Event. + * + * This event is dispatched by both Web Audio and HTML5 Audio Sound objects when their pan changes. + * + * Listen to it from a Sound instance using `Sound.on('pan', listener)`, i.e.: + * + * ```javascript + * var sound = this.sound.add('key'); + * sound.on('pan', listener); + * sound.play(); + * sound.setPan(0.5); + * ``` + */ + const PAN: any; + /** * The Pause All Sounds Event. * @@ -78260,9 +86430,8 @@ declare namespace Phaser { /** * Update method called automatically by sound manager on every game step. * @param time The current timestamp as generated by the Request Animation Frame or SetTimeout. - * @param delta The delta time elapsed since the last frame. */ - protected update(time: number, delta: number): void; + protected update(time: number): void; /** * Calls Phaser.Sound.BaseSound#destroy method @@ -78285,7 +86454,7 @@ declare namespace Phaser { * Sets the muted state of this Sound. * @param value `true` to mute this sound, `false` to unmute it. */ - setMute(value: boolean): Phaser.Sound.HTML5AudioSound; + setMute(value: boolean): this; /** * Gets or sets the volume of this sound, a value between 0 (silence) and 1 (full volume). @@ -78296,7 +86465,319 @@ declare namespace Phaser { * Sets the volume of this Sound. * @param value The volume of the sound. */ - setVolume(value: number): Phaser.Sound.HTML5AudioSound; + setVolume(value: number): this; + + /** + * Rate at which this Sound will be played. + * Value of 1.0 plays the audio at full speed, 0.5 plays the audio at half speed + * and 2.0 doubles the audios playback speed. + */ + rate: number; + + /** + * Sets the playback rate of this Sound. + * + * For example, a value of 1.0 plays the audio at full speed, 0.5 plays the audio at half speed + * and 2.0 doubles the audios playback speed. + * @param value The playback rate at of this Sound. + */ + setRate(value: number): this; + + /** + * The detune value of this Sound, given in [cents](https://en.wikipedia.org/wiki/Cent_%28music%29). + * The range of the value is -1200 to 1200, but we recommend setting it to [50](https://en.wikipedia.org/wiki/50_Cent). + */ + detune: number; + + /** + * Sets the detune value of this Sound, given in [cents](https://en.wikipedia.org/wiki/Cent_%28music%29). + * The range of the value is -1200 to 1200, but we recommend setting it to [50](https://en.wikipedia.org/wiki/50_Cent). + * @param value The range of the value is -1200 to 1200, but we recommend setting it to [50](https://en.wikipedia.org/wiki/50_Cent). + */ + setDetune(value: number): this; + + /** + * Property representing the position of playback for this sound, in seconds. + * Setting it to a specific value moves current playback to that position. + * The value given is clamped to the range 0 to current marker duration. + * Setting seek of a stopped sound has no effect. + */ + seek: number; + + /** + * Seeks to a specific point in this sound. + * @param value The point in the sound to seek to. + */ + setSeek(value: number): this; + + /** + * Flag indicating whether or not the sound or current sound marker will loop. + */ + loop: boolean; + + /** + * Sets the loop state of this Sound. + * @param value `true` to loop this sound, `false` to not loop it. + */ + setLoop(value: boolean): Phaser.Sound.HTML5AudioSound; + + /** + * Gets or sets the pan of this sound, a value between -1 (full left pan) and 1 (full right pan). + * + * Has no audible effect on HTML5 Audio Sound, but still generates the PAN Event. + */ + pan: number; + + /** + * Sets the pan of this sound, a value between -1 (full left pan) and 1 (full right pan). + * + * Has no audible effect on HTML5 Audio Sound, but still generates the PAN Event. + * @param value The pan of the sound. A value between -1 (full left pan) and 1 (full right pan). + */ + setPan(value: number): this; + + } + + /** + * HTML5AudioSoundManager + */ + class HTML5AudioSoundManager extends Phaser.Sound.BaseSoundManager { + /** + * + * @param game Reference to the current game instance. + */ + constructor(game: Phaser.Game); + + /** + * Flag indicating whether if there are no idle instances of HTML5 Audio tag, + * for any particular sound, if one of the used tags should be hijacked and used + * for succeeding playback or if succeeding Phaser.Sound.HTML5AudioSound#play + * call should be ignored. + */ + override: boolean; + + /** + * Value representing time difference, in seconds, between calling + * play method on an audio tag and when it actually starts playing. + * It is used to achieve more accurate delayed sound playback. + * + * You might need to tweak this value to get the desired results + * since audio play delay varies depending on the browser/platform. + */ + audioPlayDelay: number; + + /** + * A value by which we should offset the loop end marker of the + * looping sound to compensate for lag, caused by changing audio + * tag playback position, in order to achieve gapless looping. + * + * You might need to tweak this value to get the desired results + * since loop lag varies depending on the browser/platform. + */ + loopEndOffset: number; + + /** + * Adds a new sound into the sound manager. + * @param key Asset key for the sound. + * @param config An optional config object containing default sound settings. + */ + add(key: string, config?: Phaser.Types.Sound.SoundConfig): Phaser.Sound.HTML5AudioSound; + + /** + * Unlocks HTML5 Audio loading and playback on mobile + * devices on the initial explicit user interaction. + */ + unlock(): void; + + /** + * Method used internally for pausing sound manager if + * Phaser.Sound.HTML5AudioSoundManager#pauseOnBlur is set to true. + */ + protected onBlur(): void; + + /** + * Method used internally for resuming sound manager if + * Phaser.Sound.HTML5AudioSoundManager#pauseOnBlur is set to true. + */ + protected onFocus(): void; + + /** + * Calls Phaser.Sound.BaseSoundManager#destroy method + * and cleans up all HTML5 Audio related stuff. + */ + destroy(): void; + + /** + * Method used internally by Phaser.Sound.HTML5AudioSound class methods and property setters + * to check if sound manager is locked and then either perform action immediately or queue it + * to be performed once the sound manager gets unlocked. + * @param sound Sound object on which to perform queued action. + * @param prop Name of the method to be called or property to be assigned a value to. + * @param value An optional parameter that either holds an array of arguments to be passed to the method call or value to be set to the property. + */ + protected isLocked(sound: Phaser.Sound.HTML5AudioSound, prop: string, value?: any): boolean; + + /** + * Sets the muted state of all this Sound Manager. + * @param value `true` to mute all sounds, `false` to unmute them. + */ + setMute(value: boolean): Phaser.Sound.HTML5AudioSoundManager; + + mute: boolean; + + /** + * Sets the volume of this Sound Manager. + * @param value The global volume of this Sound Manager. + */ + setVolume(value: number): Phaser.Sound.HTML5AudioSoundManager; + + volume: number; + + } + + /** + * No audio implementation of the sound. It is used if audio has been + * disabled in the game config or the device doesn't support any audio. + * + * It represents a graceful degradation of sound logic that provides + * minimal functionality and prevents Phaser projects that use audio from + * breaking on devices that don't support any audio playback technologies. + */ + class NoAudioSound { + /** + * + * @param manager Reference to the current sound manager instance. + * @param key Asset key for the sound. + * @param config An optional config object containing default sound settings. Default {}. + */ + constructor(manager: Phaser.Sound.NoAudioSoundManager, key: string, config?: Phaser.Types.Sound.SoundConfig); + + /** + * + * @param marker Marker object. + */ + addMarker(marker: Phaser.Types.Sound.SoundMarker): boolean; + + /** + * + * @param marker Marker object with updated values. + */ + updateMarker(marker: Phaser.Types.Sound.SoundMarker): boolean; + + /** + * + * @param markerName The name of the marker to remove. + */ + removeMarker(markerName: string): null; + + /** + * + * @param markerName If you want to play a marker then provide the marker name here. Alternatively, this parameter can be a SoundConfig object. Default ''. + * @param config Optional sound config object to be applied to this marker or entire sound if no marker name is provided. It gets memorized for future plays of current section of the sound. + */ + play(markerName?: string | Phaser.Types.Sound.SoundConfig, config?: Phaser.Types.Sound.SoundConfig): boolean; + + pause(): boolean; + + /** + * Resumes the sound. + */ + resume(): boolean; + + /** + * Stop playing this sound. + */ + stop(): boolean; + + /** + * Destroys this sound and all associated events and marks it for removal from the sound manager. + */ + destroy(): void; + + } + + /** + * No-audio implementation of the Sound Manager. It is used if audio has been + * disabled in the game config or the device doesn't support any audio. + * + * It represents a graceful degradation of Sound Manager logic that provides + * minimal functionality and prevents Phaser projects that use audio from + * breaking on devices that don't support any audio playback technologies. + */ + class NoAudioSoundManager extends Phaser.Sound.BaseSoundManager { + /** + * + * @param game Reference to the current game instance. + */ + constructor(game: Phaser.Game); + + } + + /** + * Creates a Web Audio, HTML5 Audio or No Audio Sound Manager based on config and device settings. + * + * Be aware of https://developers.google.com/web/updates/2017/09/autoplay-policy-changes + * @param game Reference to the current game instance. + */ + function SoundManagerCreator(game: Phaser.Game): Phaser.Sound.HTML5AudioSoundManager | Phaser.Sound.WebAudioSoundManager | Phaser.Sound.NoAudioSoundManager; + + /** + * Web Audio API implementation of the sound. + */ + class WebAudioSound extends Phaser.Sound.BaseSound { + /** + * + * @param manager Reference to the current sound manager instance. + * @param key Asset key for the sound. + * @param config An optional config object containing default sound settings. Default {}. + */ + constructor(manager: Phaser.Sound.WebAudioSoundManager, key: string, config?: Phaser.Types.Sound.SoundConfig); + + /** + * Play this sound, or a marked section of it. + * + * It always plays the sound from the start. If you want to start playback from a specific time + * you can set 'seek' setting of the config object, provided to this call, to that value. + * @param markerName If you want to play a marker then provide the marker name here. Alternatively, this parameter can be a SoundConfig object. Default ''. + * @param config Optional sound config object to be applied to this marker or entire sound if no marker name is provided. It gets memorized for future plays of current section of the sound. + */ + play(markerName?: string | Phaser.Types.Sound.SoundConfig, config?: Phaser.Types.Sound.SoundConfig): boolean; + + /** + * Pauses the sound. + */ + pause(): boolean; + + /** + * Resumes the sound. + */ + resume(): boolean; + + /** + * Stop playing this sound. + */ + stop(): boolean; + + /** + * Method used internally for applying config values to some of the sound properties. + */ + protected applyConfig(): void; + + /** + * Update method called automatically by sound manager on every game step. + */ + protected update(): void; + + /** + * Calls Phaser.Sound.BaseSound#destroy method + * and cleans up all Web Audio API related stuff. + */ + destroy(): void; + + /** + * Method used internally to calculate total playback rate of the sound. + */ + protected calculateRate(): void; /** * Rate at which this Sound will be played. @@ -78312,7 +86793,7 @@ declare namespace Phaser { * and 2.0 doubles the audios playback speed. * @param value The playback rate at of this Sound. */ - setRate(value: number): Phaser.Sound.HTML5AudioSound; + setRate(value: number): this; /** * The detune value of this Sound, given in [cents](https://en.wikipedia.org/wiki/Cent_%28music%29). @@ -78325,7 +86806,30 @@ declare namespace Phaser { * The range of the value is -1200 to 1200, but we recommend setting it to [50](https://en.wikipedia.org/wiki/50_Cent). * @param value The range of the value is -1200 to 1200, but we recommend setting it to [50](https://en.wikipedia.org/wiki/50_Cent). */ - setDetune(value: number): Phaser.Sound.HTML5AudioSound; + setDetune(value: number): this; + + /** + * Boolean indicating whether the sound is muted or not. + * Gets or sets the muted state of this sound. + */ + mute: boolean; + + /** + * Sets the muted state of this Sound. + * @param value `true` to mute this sound, `false` to unmute it. + */ + setMute(value: boolean): this; + + /** + * Gets or sets the volume of this sound, a value between 0 (silence) and 1 (full volume). + */ + volume: number; + + /** + * Sets the volume of this Sound. + * @param value The volume of the sound. + */ + setVolume(value: number): this; /** * Property representing the position of playback for this sound, in seconds. @@ -78339,7 +86843,7 @@ declare namespace Phaser { * Seeks to a specific point in this sound. * @param value The point in the sound to seek to. */ - setSeek(value: number): Phaser.Sound.HTML5AudioSound; + setSeek(value: number): this; /** * Flag indicating whether or not the sound or current sound marker will loop. @@ -78350,292 +86854,27 @@ declare namespace Phaser { * Sets the loop state of this Sound. * @param value `true` to loop this sound, `false` to not loop it. */ - setLoop(value: boolean): Phaser.Sound.HTML5AudioSound; - - } - - /** - * HTML5AudioSoundManager - */ - class HTML5AudioSoundManager extends Phaser.Sound.BaseSoundManager { - /** - * - * @param game Reference to the current game instance. - */ - constructor(game: Phaser.Game); - - /** - * Flag indicating whether if there are no idle instances of HTML5 Audio tag, - * for any particular sound, if one of the used tags should be hijacked and used - * for succeeding playback or if succeeding Phaser.Sound.HTML5AudioSound#play - * call should be ignored. - */ - override: boolean; - - /** - * Value representing time difference, in seconds, between calling - * play method on an audio tag and when it actually starts playing. - * It is used to achieve more accurate delayed sound playback. - * - * You might need to tweak this value to get the desired results - * since audio play delay varies depending on the browser/platform. - */ - audioPlayDelay: number; - - /** - * A value by which we should offset the loop end marker of the - * looping sound to compensate for lag, caused by changing audio - * tag playback position, in order to achieve gapless looping. - * - * You might need to tweak this value to get the desired results - * since loop lag varies depending on the browser/platform. - */ - loopEndOffset: number; - - /** - * Adds a new sound into the sound manager. - * @param key Asset key for the sound. - * @param config An optional config object containing default sound settings. - */ - add(key: string, config?: Phaser.Types.Sound.SoundConfig): Phaser.Sound.HTML5AudioSound; - - /** - * Unlocks HTML5 Audio loading and playback on mobile - * devices on the initial explicit user interaction. - */ - unlock(): void; + setLoop(value: boolean): this; /** - * Method used internally for pausing sound manager if - * Phaser.Sound.HTML5AudioSoundManager#pauseOnBlur is set to true. + * Gets or sets the pan of this sound, a value between -1 (full left pan) and 1 (full right pan). */ - protected onBlur(): void; + pan: number; /** - * Method used internally for resuming sound manager if - * Phaser.Sound.HTML5AudioSoundManager#pauseOnBlur is set to true. + * Sets the pan of this sound, a value between -1 (full left pan) and 1 (full right pan). + * @param value The pan of the sound. A value between -1 (full left pan) and 1 (full right pan). */ - protected onFocus(): void; - - /** - * Calls Phaser.Sound.BaseSoundManager#destroy method - * and cleans up all HTML5 Audio related stuff. - */ - destroy(): void; - - /** - * Method used internally by Phaser.Sound.HTML5AudioSound class methods and property setters - * to check if sound manager is locked and then either perform action immediately or queue it - * to be performed once the sound manager gets unlocked. - * @param sound Sound object on which to perform queued action. - * @param prop Name of the method to be called or property to be assigned a value to. - * @param value An optional parameter that either holds an array of arguments to be passed to the method call or value to be set to the property. - */ - protected isLocked(sound: Phaser.Sound.HTML5AudioSound, prop: string, value?: any): boolean; - - /** - * Sets the muted state of all this Sound Manager. - * @param value `true` to mute all sounds, `false` to unmute them. - */ - setMute(value: boolean): Phaser.Sound.HTML5AudioSoundManager; - - mute: boolean; - - /** - * Sets the volume of this Sound Manager. - * @param value The global volume of this Sound Manager. - */ - setVolume(value: number): Phaser.Sound.HTML5AudioSoundManager; - - volume: number; + setPan(value: number): this; } /** - * No audio implementation of the sound. It is used if audio has been - * disabled in the game config or the device doesn't support any audio. + * Web Audio API implementation of the Sound Manager. * - * It represents a graceful degradation of sound logic that provides - * minimal functionality and prevents Phaser projects that use audio from - * breaking on devices that don't support any audio playback technologies. - */ - class NoAudioSound extends Phaser.Sound.BaseSound { - /** - * - * @param manager Reference to the current sound manager instance. - * @param key Asset key for the sound. - * @param config An optional config object containing default sound settings. Default {}. - */ - constructor(manager: Phaser.Sound.NoAudioSoundManager, key: string, config?: Phaser.Types.Sound.SoundConfig); - - } - - /** - * No audio implementation of the sound manager. It is used if audio has been - * disabled in the game config or the device doesn't support any audio. - * - * It represents a graceful degradation of sound manager logic that provides - * minimal functionality and prevents Phaser projects that use audio from - * breaking on devices that don't support any audio playback technologies. - */ - class NoAudioSoundManager extends Phaser.Sound.BaseSoundManager { - /** - * - * @param game Reference to the current game instance. - */ - constructor(game: Phaser.Game); - - } - - /** - * Creates a Web Audio, HTML5 Audio or No Audio Sound Manager based on config and device settings. + * Not all browsers can play all audio formats. * - * Be aware of https://developers.google.com/web/updates/2017/09/autoplay-policy-changes - * @param game Reference to the current game instance. - */ - function SoundManagerCreator(game: Phaser.Game): Phaser.Sound.HTML5AudioSoundManager | Phaser.Sound.WebAudioSoundManager | Phaser.Sound.NoAudioSoundManager; - - /** - * Web Audio API implementation of the sound. - */ - class WebAudioSound extends Phaser.Sound.BaseSound { - /** - * - * @param manager Reference to the current sound manager instance. - * @param key Asset key for the sound. - * @param config An optional config object containing default sound settings. Default {}. - */ - constructor(manager: Phaser.Sound.WebAudioSoundManager, key: string, config?: Phaser.Types.Sound.SoundConfig); - - /** - * Play this sound, or a marked section of it. - * - * It always plays the sound from the start. If you want to start playback from a specific time - * you can set 'seek' setting of the config object, provided to this call, to that value. - * @param markerName If you want to play a marker then provide the marker name here. Alternatively, this parameter can be a SoundConfig object. Default ''. - * @param config Optional sound config object to be applied to this marker or entire sound if no marker name is provided. It gets memorized for future plays of current section of the sound. - */ - play(markerName?: string | Phaser.Types.Sound.SoundConfig, config?: Phaser.Types.Sound.SoundConfig): boolean; - - /** - * Pauses the sound. - */ - pause(): boolean; - - /** - * Resumes the sound. - */ - resume(): boolean; - - /** - * Stop playing this sound. - */ - stop(): boolean; - - /** - * Method used internally for applying config values to some of the sound properties. - */ - protected applyConfig(): void; - - /** - * Update method called automatically by sound manager on every game step. - * @param time The current timestamp as generated by the Request Animation Frame or SetTimeout. - * @param delta The delta time elapsed since the last frame. - */ - protected update(time: number, delta: number): void; - - /** - * Calls Phaser.Sound.BaseSound#destroy method - * and cleans up all Web Audio API related stuff. - */ - destroy(): void; - - /** - * Method used internally to calculate total playback rate of the sound. - */ - protected calculateRate(): void; - - /** - * Rate at which this Sound will be played. - * Value of 1.0 plays the audio at full speed, 0.5 plays the audio at half speed - * and 2.0 doubles the audios playback speed. - */ - rate: number; - - /** - * Sets the playback rate of this Sound. - * - * For example, a value of 1.0 plays the audio at full speed, 0.5 plays the audio at half speed - * and 2.0 doubles the audios playback speed. - * @param value The playback rate at of this Sound. - */ - setRate(value: number): Phaser.Sound.WebAudioSound; - - /** - * The detune value of this Sound, given in [cents](https://en.wikipedia.org/wiki/Cent_%28music%29). - * The range of the value is -1200 to 1200, but we recommend setting it to [50](https://en.wikipedia.org/wiki/50_Cent). - */ - detune: number; - - /** - * Sets the detune value of this Sound, given in [cents](https://en.wikipedia.org/wiki/Cent_%28music%29). - * The range of the value is -1200 to 1200, but we recommend setting it to [50](https://en.wikipedia.org/wiki/50_Cent). - * @param value The range of the value is -1200 to 1200, but we recommend setting it to [50](https://en.wikipedia.org/wiki/50_Cent). - */ - setDetune(value: number): Phaser.Sound.WebAudioSound; - - /** - * Boolean indicating whether the sound is muted or not. - * Gets or sets the muted state of this sound. - */ - mute: boolean; - - /** - * Sets the muted state of this Sound. - * @param value `true` to mute this sound, `false` to unmute it. - */ - setMute(value: boolean): Phaser.Sound.WebAudioSound; - - /** - * Gets or sets the volume of this sound, a value between 0 (silence) and 1 (full volume). - */ - volume: number; - - /** - * Sets the volume of this Sound. - * @param value The volume of the sound. - */ - setVolume(value: number): Phaser.Sound.WebAudioSound; - - /** - * Property representing the position of playback for this sound, in seconds. - * Setting it to a specific value moves current playback to that position. - * The value given is clamped to the range 0 to current marker duration. - * Setting seek of a stopped sound has no effect. - */ - seek: number; - - /** - * Seeks to a specific point in this sound. - * @param value The point in the sound to seek to. - */ - setSeek(value: number): Phaser.Sound.WebAudioSound; - - /** - * Flag indicating whether or not the sound or current sound marker will loop. - */ - loop: boolean; - - /** - * Sets the loop state of this Sound. - * @param value `true` to loop this sound, `false` to not loop it. - */ - setLoop(value: boolean): Phaser.Sound.WebAudioSound; - - } - - /** - * Web Audio API implementation of the sound manager. + * There is a good guide to what's supported: [Cross-browser audio basics: Audio codec support](https://developer.mozilla.org/en-US/Apps/Fundamentals/Audio_and_video_delivery/Cross-browser_audio_basics#Audio_Codec_Support). */ class WebAudioSoundManager extends Phaser.Sound.BaseSoundManager { /** @@ -78775,7 +87014,7 @@ declare namespace Phaser { * * This is used internally when iterating through the list with the {@link #first}, {@link #last}, {@link #get}, and {@link #previous} properties. */ - position: integer; + position: number; /** * A callback that is invoked every time a child is added to this list. @@ -78805,19 +87044,19 @@ declare namespace Phaser { * @param index The index in the list at which the element(s) will be inserted. Default 0. * @param skipCallback Skip calling the List.addCallback if this child is added successfully. Default false. */ - addAt(child: T, index?: integer, skipCallback?: boolean): T; + addAt(child: T, index?: number, skipCallback?: boolean): T; /** * Retrieves the item at a given position inside the List. * @param index The index of the item. */ - getAt(index: integer): T; + getAt(index: number): T; /** * Locates an item within the List and returns its index. * @param child The item to locate. */ - getIndex(child: T): integer; + getIndex(child: T): number; /** * Sort the contents of this List so the items are in order based on the given property. @@ -78840,7 +87079,7 @@ declare namespace Phaser { * @param startIndex Offset from the front of the group (lowest child). Default 0. * @param length Restriction on the number of values you want to randomly select from. Default (to top). */ - getRandom(startIndex?: integer, length?: integer): T | null; + getRandom(startIndex?: number, length?: number): T | null; /** * Returns the first element in a given part of the List which matches a specific criterion. @@ -78870,14 +87109,14 @@ declare namespace Phaser { * @param startIndex The first child index to start the search from. * @param endIndex The last child index to search up until. */ - getAll(property?: string, value?: T, startIndex?: integer, endIndex?: integer): T[]; + getAll(property?: string, value?: T, startIndex?: number, endIndex?: number): T[]; /** * Returns the total number of items in the List which have a property matching the given value. * @param property The property to test on each item. * @param value The value to test the property against. */ - count(property: string, value: T): integer; + count(property: string, value: T): number; /** * Swaps the positions of two items in the list. @@ -78891,7 +87130,7 @@ declare namespace Phaser { * @param child The item to move. * @param index Moves an item in the List to a new position. */ - moveTo(child: T, index: integer): T; + moveTo(child: T, index: number): T; /** * Removes one or many items from the List. @@ -78905,7 +87144,7 @@ declare namespace Phaser { * @param index The position to remove the item from. * @param skipCallback Skip calling the List.removeCallback. Default false. */ - removeAt(index: integer, skipCallback?: boolean): T; + removeAt(index: number, skipCallback?: boolean): T; /** * Removes the items within the given range in the List. @@ -78913,7 +87152,7 @@ declare namespace Phaser { * @param endIndex The position to stop removing at. The item at this position won't be removed. * @param skipCallback Skip calling the List.removeCallback. Default false. */ - removeBetween(startIndex?: integer, endIndex?: integer, skipCallback?: boolean): T[]; + removeBetween(startIndex?: number, endIndex?: number, skipCallback?: boolean): T[]; /** * Removes all the items. @@ -78975,7 +87214,7 @@ declare namespace Phaser { * @param startIndex The first child index to start the search from. * @param endIndex The last child index to search up until. */ - setAll(property: string, value: T, startIndex?: integer, endIndex?: integer): void; + setAll(property: string, value: T, startIndex?: number, endIndex?: number): void; /** * Passes all children to the given callback. @@ -78998,7 +87237,7 @@ declare namespace Phaser { /** * The number of items inside the List. */ - readonly length: integer; + readonly length: number; /** * The first item in the List or `null` for an empty List. @@ -79106,7 +87345,9 @@ declare namespace Phaser { dump(): void; /** - * Passes all entries in this Map to the given callback. + * Iterates through all entries in this Map, passing each one to the given callback. + * + * If the callback returns `false`, the iteration will break. * @param callback The callback which will receive the keys and entries held in this Map. */ each(callback: EachMapCallback): Phaser.Structs.Map; @@ -79140,6 +87381,11 @@ declare namespace Phaser { * time, rather than at the time of the request from the API. */ class ProcessQueue extends Phaser.Events.EventEmitter { + /** + * If `true` only unique objects will be allowed in the queue. + */ + checkQueue: boolean; + /** * Adds a new item to the Process Queue. * @@ -79182,7 +87428,7 @@ declare namespace Phaser { /** * The number of entries in the active list. */ - readonly length: integer; + readonly length: number; /** * Immediately destroys this process queue, clearing all of its internal arrays and resetting the process totals. @@ -79308,7 +87554,7 @@ declare namespace Phaser { * Changing the size will truncate the Set if the given value is smaller than the current size. * Increasing the size larger than the current size has no effect. */ - size: integer; + size: number; } @@ -79327,13 +87573,13 @@ declare namespace Phaser { * @param aspectMode The aspect mode of the Size component. Defaults to 0, no mode. Default 0. * @param parent The parent of this Size component. Can be any object with public `width` and `height` properties. Dimensions are clamped to keep them within the parent bounds where possible. Default null. */ - constructor(width?: number, height?: number, aspectMode?: integer, parent?: any); + constructor(width?: number, height?: number, aspectMode?: number, parent?: any); /** * The aspect mode this Size component will use when calculating its dimensions. * This property is read-only. To change it use the `setAspectMode` method. */ - readonly aspectMode: integer; + readonly aspectMode: number; /** * The proportional relationship between the width and height. @@ -79394,7 +87640,7 @@ declare namespace Phaser { * Calling this method automatically recalculates the `width` and the `height`, if required. * @param value The aspect mode value. Default 0. */ - setAspectMode(value?: integer): this; + setAspectMode(value?: number): this; /** * By setting a Snap To value when this Size component is modified its dimensions will automatically @@ -79616,27 +87862,27 @@ declare namespace Phaser { /** * Do not make the size fit the aspect ratio. Change the ratio when the size changes. */ - static readonly NONE: integer; + static readonly NONE: number; /** * The height is automatically adjusted based on the width. */ - static readonly WIDTH_CONTROLS_HEIGHT: integer; + static readonly WIDTH_CONTROLS_HEIGHT: number; /** * The width is automatically adjusted based on the height. */ - static readonly HEIGHT_CONTROLS_WIDTH: integer; + static readonly HEIGHT_CONTROLS_WIDTH: number; /** * The width and height are automatically adjusted to fit inside the given target area, while keeping the aspect ratio. Depending on the aspect ratio there may be some space inside the area which is not covered. */ - static readonly FIT: integer; + static readonly FIT: number; /** * The width and height are automatically adjusted to make the size cover the entire target area while keeping the aspect ratio. This may extend further out than the target size. */ - static readonly ENVELOP: integer; + static readonly ENVELOP: number; } @@ -79671,7 +87917,7 @@ declare namespace Phaser { * @param width The width of the canvas. * @param height The height of the canvas. */ - constructor(manager: Phaser.Textures.TextureManager, key: string, source: HTMLCanvasElement, width: integer, height: integer); + constructor(manager: Phaser.Textures.TextureManager, key: string, source: HTMLCanvasElement, width: number, height: number); /** * The source Canvas Element. @@ -79687,13 +87933,13 @@ declare namespace Phaser { * The width of the Canvas. * This property is read-only, if you wish to change it use the `setSize` method. */ - readonly width: integer; + readonly width: number; /** * The height of the Canvas. * This property is read-only, if you wish to change it use the `setSize` method. */ - readonly height: integer; + readonly height: number; /** * The context image data. @@ -79733,7 +87979,7 @@ declare namespace Phaser { * @param y The y coordinate to draw the source at. * @param source The element to draw to this canvas. */ - draw(x: integer, y: integer, source: HTMLImageElement | HTMLCanvasElement): Phaser.Textures.CanvasTexture; + draw(x: number, y: number, source: HTMLImageElement | HTMLCanvasElement): Phaser.Textures.CanvasTexture; /** * Draws the given texture frame to this CanvasTexture, then updates the internal @@ -79743,7 +87989,7 @@ declare namespace Phaser { * @param x The x coordinate to draw the source at. Default 0. * @param y The y coordinate to draw the source at. Default 0. */ - drawFrame(key: string, frame?: string | integer, x?: integer, y?: integer): Phaser.Textures.CanvasTexture; + drawFrame(key: string, frame?: string | number, x?: number, y?: number): Phaser.Textures.CanvasTexture; /** * Sets a pixel in the CanvasTexture to the given color and alpha values. @@ -79756,7 +88002,7 @@ declare namespace Phaser { * @param blue The blue color value. A number between 0 and 255. * @param alpha The alpha value. A number between 0 and 255. Default 255. */ - setPixel(x: integer, y: integer, red: integer, green: integer, blue: integer, alpha?: integer): this; + setPixel(x: number, y: number, red: number, green: number, blue: number, alpha?: number): this; /** * Puts the ImageData into the context of this CanvasTexture at the given coordinates. @@ -79768,7 +88014,7 @@ declare namespace Phaser { * @param dirtyWidth Width of the rectangle to be painted. Defaults to the width of the image data. * @param dirtyHeight Height of the rectangle to be painted. Defaults to the height of the image data. */ - putData(imageData: ImageData, x: integer, y: integer, dirtyX?: integer, dirtyY?: integer, dirtyWidth?: integer, dirtyHeight?: integer): this; + putData(imageData: ImageData, x: number, y: number, dirtyX?: number, dirtyY?: number, dirtyWidth?: number, dirtyHeight?: number): this; /** * Gets an ImageData region from this CanvasTexture from the position and size specified. @@ -79778,7 +88024,7 @@ declare namespace Phaser { * @param width The width of the rectangle from which the ImageData will be extracted. Positive values are to the right, and negative to the left. * @param height The height of the rectangle from which the ImageData will be extracted. Positive values are down, and negative are up. */ - getData(x: integer, y: integer, width: integer, height: integer): ImageData; + getData(x: number, y: number, width: number, height: number): ImageData; /** * Get the color of a specific pixel from this texture and store it in a Color object. @@ -79789,7 +88035,7 @@ declare namespace Phaser { * @param y The y coordinate of the pixel to get. Must lay within the dimensions of this CanvasTexture and be an integer. * @param out A Color object to store the pixel values in. If not provided a new Color object will be created. */ - getPixel(x: integer, y: integer, out?: Phaser.Display.Color): Phaser.Display.Color; + getPixel(x: number, y: number, out?: Phaser.Display.Color): Phaser.Display.Color; /** * Returns an array containing all of the pixels in the given region. @@ -79804,7 +88050,7 @@ declare namespace Phaser { * @param width The width of the region to get. Must be an integer. Defaults to the canvas width if not given. * @param height The height of the region to get. Must be an integer. If not given will be set to the `width`. */ - getPixels(x?: integer, y?: integer, width?: integer, height?: integer): Phaser.Types.Textures.PixelConfig[]; + getPixels(x?: number, y?: number, width?: number, height?: number): Phaser.Types.Textures.PixelConfig[][]; /** * Returns the Image Data index for the given pixel in this CanvasTexture. @@ -79816,7 +88062,7 @@ declare namespace Phaser { * @param x The x coordinate of the pixel to get. Must lay within the dimensions of this CanvasTexture and be an integer. * @param y The y coordinate of the pixel to get. Must lay within the dimensions of this CanvasTexture and be an integer. */ - getIndex(x: integer, y: integer): integer; + getIndex(x: number, y: number): number; /** * This should be called manually if you are running under WebGL. @@ -79843,14 +88089,14 @@ declare namespace Phaser { * @param width The width of the region. * @param height The height of the region. */ - clear(x?: integer, y?: integer, width?: integer, height?: integer): Phaser.Textures.CanvasTexture; + clear(x?: number, y?: number, width?: number, height?: number): Phaser.Textures.CanvasTexture; /** * Changes the size of this Canvas Texture. * @param width The new width of the Canvas. * @param height The new height of the Canvas. If not given it will use the width as the height. */ - setSize(width: integer, height?: integer): Phaser.Textures.CanvasTexture; + setSize(width: number, height?: number): Phaser.Textures.CanvasTexture; /** * Destroys this Texture and releases references to its sources and frames. @@ -79942,7 +88188,7 @@ declare namespace Phaser { * @param width The width of this Frame. * @param height The height of this Frame. */ - constructor(texture: Phaser.Textures.Texture, name: integer | string, sourceIndex: integer, x: number, y: number, width: number, height: number); + constructor(texture: Phaser.Textures.Texture, name: number | string, sourceIndex: number, x: number, y: number, width: number, height: number); /** * The Texture this Frame is a part of. @@ -79963,7 +88209,7 @@ declare namespace Phaser { /** * The index of the TextureSource in the Texture sources array. */ - sourceIndex: integer; + sourceIndex: number; /** * A reference to the Texture Source WebGL Texture that this Frame is using. @@ -79973,64 +88219,64 @@ declare namespace Phaser { /** * X position within the source image to cut from. */ - cutX: integer; + cutX: number; /** * Y position within the source image to cut from. */ - cutY: integer; + cutY: number; /** * The width of the area in the source image to cut. */ - cutWidth: integer; + cutWidth: number; /** * The height of the area in the source image to cut. */ - cutHeight: integer; + cutHeight: number; /** * The X rendering offset of this Frame, taking trim into account. */ - x: integer; + x: number; /** * The Y rendering offset of this Frame, taking trim into account. */ - y: integer; + y: number; /** * The rendering width of this Frame, taking trim into account. */ - width: integer; + width: number; /** * The rendering height of this Frame, taking trim into account. */ - height: integer; + height: number; /** * Half the width, floored. * Precalculated for the renderer. */ - halfWidth: integer; + halfWidth: number; /** * Half the height, floored. * Precalculated for the renderer. */ - halfHeight: integer; + halfHeight: number; /** * The x center of this frame, floored. */ - centerX: integer; + centerX: number; /** * The y center of this frame, floored. */ - centerY: integer; + centerY: number; /** * The horizontal pivot point of this Frame. @@ -80062,7 +88308,7 @@ declare namespace Phaser { * 0 = No rounding * 1 = Round */ - autoRound: integer; + autoRound: number; /** * Any Frame specific custom data can be stored here. @@ -80099,7 +88345,7 @@ declare namespace Phaser { * @param x The x coordinate of the top-left of this Frame. Default 0. * @param y The y coordinate of the top-left of this Frame. Default 0. */ - setSize(width: integer, height: integer, x?: integer, y?: integer): Phaser.Textures.Frame; + setSize(width: number, height: number, x?: number, y?: number): Phaser.Textures.Frame; /** * If the frame was trimmed when added to the Texture Atlas, this records the trim and source data. @@ -80137,6 +88383,20 @@ declare namespace Phaser { */ updateCropUVs(crop: object, flipX: boolean, flipY: boolean): object; + /** + * Directly sets the canvas and WebGL UV data for this frame. + * + * Use this if you need to override the values that are generated automatically + * when the Frame is created. + * @param width Width of this frame for the Canvas data. + * @param height Height of this frame for the Canvas data. + * @param u0 UV u0 value. + * @param v0 UV v0 value. + * @param u1 UV u1 value. + * @param v1 UV v1 value. + */ + setUVs(width: number, height: number, u0: number, v0: number, u1: number, v1: number): Phaser.Textures.Frame; + /** * Updates the internal WebGL UV cache and the drawImage cache. */ @@ -80189,12 +88449,12 @@ declare namespace Phaser { /** * Linear filter type. */ - const LINEAR: integer; + const LINEAR: number; /** * Nearest Neighbor filter type. */ - const NEAREST: integer; + const NEAREST: number; namespace Parsers { } @@ -80268,7 +88528,7 @@ declare namespace Phaser { * A Texture will always contain at least 1 frame because every Texture contains a `__BASE` frame by default, * in addition to any extra frames that have been added to it, such as when parsing a Sprite Sheet or Texture Atlas. */ - frameTotal: integer; + frameTotal: number; /** * Adds a new Frame to this Texture. @@ -80283,7 +88543,7 @@ declare namespace Phaser { * @param width The width of this Frame. * @param height The height of this Frame. */ - add(name: integer | string, sourceIndex: integer, x: number, y: number, width: number, height: number): Phaser.Textures.Frame; + add(name: number | string, sourceIndex: number, x: number, y: number, width: number, height: number): Phaser.Textures.Frame; /** * Removes the given Frame from this Texture. The Frame is destroyed immediately. @@ -80308,7 +88568,7 @@ declare namespace Phaser { * Passing no value for the name returns the base texture. * @param name The string-based name, or integer based index, of the Frame to get from this Texture. */ - get(name?: string | integer): Phaser.Textures.Frame; + get(name?: string | number): Phaser.Textures.Frame; /** * Takes the given TextureSource and returns the index of it within this Texture. @@ -80317,14 +88577,14 @@ declare namespace Phaser { * method will always return zero or -1. * @param source The TextureSource to check. */ - getTextureSourceIndex(source: Phaser.Textures.TextureSource): integer; + getTextureSourceIndex(source: Phaser.Textures.TextureSource): number; /** * Returns an array of all the Frames in the given TextureSource. * @param sourceIndex The index of the TextureSource to get the Frames from. * @param includeBase Include the `__BASE` Frame in the output array? Default false. */ - getFramesFromTextureSource(sourceIndex: integer, includeBase?: boolean): Phaser.Textures.Frame[]; + getFramesFromTextureSource(sourceIndex: number, includeBase?: boolean): Phaser.Textures.Frame[]; /** * Returns an array with all of the names of the Frames in this Texture. @@ -80341,7 +88601,7 @@ declare namespace Phaser { * This will return the actual DOM Image or Canvas element. * @param name The string-based name, or integer based index, of the Frame to get from this Texture. */ - getSourceImage(name?: string | integer): HTMLImageElement | HTMLCanvasElement | Phaser.GameObjects.RenderTexture; + getSourceImage(name?: string | number): HTMLImageElement | HTMLCanvasElement | Phaser.GameObjects.RenderTexture; /** * Given a Frame name, return the data source image it uses to render with. @@ -80350,7 +88610,7 @@ declare namespace Phaser { * This will return the actual DOM Image. * @param name The string-based name, or integer based index, of the Frame to get from this Texture. */ - getDataSourceImage(name?: string | integer): HTMLImageElement | HTMLCanvasElement; + getDataSourceImage(name?: string | number): HTMLImageElement | HTMLCanvasElement; /** * Adds a data source image to this Texture. @@ -80438,6 +88698,10 @@ declare namespace Phaser { /** * Adds a new Texture to the Texture Manager created from the given Base64 encoded data. + * + * It works by creating an `Image` DOM object, then setting the `src` attribute to + * the given base64 encoded data. As a result, the process is asynchronous by its nature, + * so be sure to listen for the events this method dispatches before using the texture. * @param key The unique string-based key of the Texture. * @param data The Base64 encoded data. */ @@ -80453,10 +88717,10 @@ declare namespace Phaser { * see the WebGL Snapshot function instead. * @param key The unique string-based key of the Texture. * @param frame The string-based name, or integer based index, of the Frame to get from the Texture. - * @param type [description] Default 'image/png'. - * @param encoderOptions [description] Default 0.92. + * @param type A DOMString indicating the image format. The default format type is image/png. Default 'image/png'. + * @param encoderOptions A Number between 0 and 1 indicating the image quality to use for image formats that use lossy compression such as image/jpeg and image/webp. If this argument is anything else, the default value for image quality is used. The default value is 0.92. Other arguments are ignored. Default 0.92. */ - getBase64(key: string, frame?: string | integer, type?: string, encoderOptions?: number): string; + getBase64(key: string, frame?: string | number, type?: string, encoderOptions?: number): string; /** * Adds a new Texture to the Texture Manager created from the given Image element. @@ -80471,13 +88735,16 @@ declare namespace Phaser { * * This allows you to then use the Texture as a normal texture for texture based Game Objects like Sprites. * + * If the `width` and `height` arguments are omitted, but the WebGL Texture was created by Phaser's WebGL Renderer + * and has `glTexture.width` and `glTexture.height` properties, these values will be used instead. + * * This is a WebGL only feature. * @param key The unique string-based key of the Texture. * @param glTexture The source Render Texture. - * @param width The new width of the Texture. - * @param height The new height of the Texture. + * @param width The new width of the Texture. Read from `glTexture.width` if omitted. + * @param height The new height of the Texture. Read from `glTexture.height` if omitted. */ - addGLTexture(key: string, glTexture: WebGLTexture, width: number, height: number): Phaser.Textures.Texture; + addGLTexture(key: string, glTexture: WebGLTexture, width?: number, height?: number): Phaser.Textures.Texture; /** * Adds a Render Texture to the Texture Manager using the given key. @@ -80489,12 +88756,42 @@ declare namespace Phaser { /** * Creates a new Texture using the given config values. + * * Generated textures consist of a Canvas element to which the texture data is drawn. - * See the Phaser.Create function for the more direct way to create textures. + * + * Generates a texture based on the given Create configuration object. + * + * The texture is drawn using a fixed-size indexed palette of 16 colors, where the hex value in the + * data cells map to a single color. For example, if the texture config looked like this: + * + * ```javascript + * var star = [ + * '.....828.....', + * '....72227....', + * '....82228....', + * '...7222227...', + * '2222222222222', + * '8222222222228', + * '.72222222227.', + * '..787777787..', + * '..877777778..', + * '.78778887787.', + * '.27887.78872.', + * '.787.....787.' + * ]; + * + * this.textures.generate('star', { data: star, pixelWidth: 4 }); + * ``` + * + * Then it would generate a texture that is 52 x 48 pixels in size, because each cell of the data array + * represents 1 pixel multiplied by the `pixelWidth` value. The cell values, such as `8`, maps to color + * number 8 in the palette. If a cell contains a period character `.` then it is transparent. + * + * The default palette is Arne16, but you can specify your own using the `palette` property. * @param key The unique string-based key of the Texture. * @param config The configuration object needed to generate the texture. */ - generate(key: string, config: object): Phaser.Textures.Texture; + generate(key: string, config: Phaser.Types.Create.GenerateTextureConfig): Phaser.Textures.Texture; /** * Creates a new Texture using a blank Canvas element of the size given. @@ -80505,7 +88802,7 @@ declare namespace Phaser { * @param width The width of the Canvas element. Default 256. * @param height The height of the Canvas element. Default 256. */ - createCanvas(key: string, width?: integer, height?: integer): Phaser.Textures.CanvasTexture; + createCanvas(key: string, width?: number, height?: number): Phaser.Textures.CanvasTexture; /** * Creates a new Canvas Texture object from an existing Canvas element @@ -80596,1529 +88893,1053 @@ declare namespace Phaser { * @param width The width of the Texture. * @param height The height of the Texture. */ - create(key: string, source: HTMLImageElement, width: integer, height: integer): Phaser.Textures.Texture; + create(key: string, source: HTMLImageElement, width: number, height: number): Phaser.Textures.Texture; /** * Checks the given key to see if a Texture using it exists within this Texture Manager. - * @param key The unique string-based key of the Texture. - */ - exists(key: string): boolean; - - /** - * Returns a Texture from the Texture Manager that matches the given key. - * - * If the key is `undefined` it will return the `__DEFAULT` Texture. - * - * If the key is an instance of a Texture, it will return the key directly. - * - * Finally. if the key is given, but not found and not a Texture instance, it will return the `__MISSING` Texture. - * @param key The unique string-based key of the Texture, or a Texture instance. - */ - get(key: string | Phaser.Textures.Texture): Phaser.Textures.Texture; - - /** - * Takes a Texture key and Frame name and returns a clone of that Frame if found. - * @param key The unique string-based key of the Texture. - * @param frame The string or index of the Frame to be cloned. - */ - cloneFrame(key: string, frame: string | integer): Phaser.Textures.Frame; - - /** - * Takes a Texture key and Frame name and returns a reference to that Frame, if found. - * @param key The unique string-based key of the Texture. - * @param frame The string-based name, or integer based index, of the Frame to get from the Texture. - */ - getFrame(key: string, frame?: string | integer): Phaser.Textures.Frame; - - /** - * Returns an array with all of the keys of all Textures in this Texture Manager. - * The output array will exclude the `__DEFAULT` and `__MISSING` keys. - */ - getTextureKeys(): string[]; - - /** - * Given a Texture and an `x` and `y` coordinate this method will return a new - * Color object that has been populated with the color and alpha values of the pixel - * at that location in the Texture. - * @param x The x coordinate of the pixel within the Texture. - * @param y The y coordinate of the pixel within the Texture. - * @param key The unique string-based key of the Texture. - * @param frame The string or index of the Frame. - */ - getPixel(x: integer, y: integer, key: string, frame?: string | integer): Phaser.Display.Color; - - /** - * Given a Texture and an `x` and `y` coordinate this method will return a value between 0 and 255 - * corresponding to the alpha value of the pixel at that location in the Texture. If the coordinate - * is out of bounds it will return null. - * @param x The x coordinate of the pixel within the Texture. - * @param y The y coordinate of the pixel within the Texture. - * @param key The unique string-based key of the Texture. - * @param frame The string or index of the Frame. - */ - getPixelAlpha(x: integer, y: integer, key: string, frame?: string | integer): integer; - - /** - * Sets the given Game Objects `texture` and `frame` properties so that it uses - * the Texture and Frame specified in the `key` and `frame` arguments to this method. - * @param gameObject The Game Object the texture would be set on. - * @param key The unique string-based key of the Texture. - * @param frame The string or index of the Frame. - */ - setTexture(gameObject: Phaser.GameObjects.GameObject, key: string, frame?: string | integer): Phaser.GameObjects.GameObject; - - /** - * Changes the key being used by a Texture to the new key provided. - * - * The old key is removed, allowing it to be re-used. - * - * Game Objects are linked to Textures by a reference to the Texture object, so - * all existing references will be retained. - * @param currentKey The current string-based key of the Texture you wish to rename. - * @param newKey The new unique string-based key to use for the Texture. - */ - renameTexture(currentKey: string, newKey: string): boolean; - - /** - * Passes all Textures to the given callback. - * @param callback The callback function to be sent the Textures. - * @param scope The value to use as `this` when executing the callback. - * @param args Additional arguments that will be passed to the callback, after the child. - */ - each(callback: EachTextureCallback, scope: object, ...args: any[]): void; - - /** - * Destroys the Texture Manager and all Textures stored within it. - */ - destroy(): void; - - } - - /** - * A Texture Source is the encapsulation of the actual source data for a Texture. - * - * This is typically an Image Element, loaded from the file system or network, a Canvas Element or a Video Element. - * - * A Texture can contain multiple Texture Sources, which only happens when a multi-atlas is loaded. - */ - class TextureSource { - /** - * - * @param texture The Texture this TextureSource belongs to. - * @param source The source image data. - * @param width Optional width of the source image. If not given it's derived from the source itself. - * @param height Optional height of the source image. If not given it's derived from the source itself. - * @param flipY Sets the `UNPACK_FLIP_Y_WEBGL` flag the WebGL Texture uses during upload. Default false. - */ - constructor(texture: Phaser.Textures.Texture, source: HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | Phaser.GameObjects.RenderTexture | WebGLTexture, width?: integer, height?: integer, flipY?: boolean); - - /** - * The Texture this TextureSource belongs to. - */ - renderer: Phaser.Renderer.Canvas.CanvasRenderer | Phaser.Renderer.WebGL.WebGLRenderer; - - /** - * The Texture this TextureSource belongs to. - */ - texture: Phaser.Textures.Texture; - - /** - * The source of the image data. - * - * This is either an Image Element, a Canvas Element, a Video Element, a RenderTexture or a WebGLTexture. - */ - source: HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | Phaser.GameObjects.RenderTexture | WebGLTexture; - - /** - * The image data. - * - * This is either an Image element, Canvas element or a Video Element. - */ - image: HTMLImageElement | HTMLCanvasElement | HTMLVideoElement; - - /** - * Currently un-used. - */ - compressionAlgorithm: integer; - - /** - * The resolution of the source image. - */ - resolution: number; - - /** - * The width of the source image. If not specified in the constructor it will check - * the `naturalWidth` and then `width` properties of the source image. - */ - width: integer; - - /** - * The height of the source image. If not specified in the constructor it will check - * the `naturalHeight` and then `height` properties of the source image. - */ - height: integer; - - /** - * The Scale Mode the image will use when rendering. - * Either Linear or Nearest. - */ - scaleMode: number; - - /** - * Is the source image a Canvas Element? - */ - isCanvas: boolean; - - /** - * Is the source image a Video Element? - */ - isVideo: boolean; - - /** - * Is the source image a Render Texture? - */ - isRenderTexture: boolean; - - /** - * Is the source image a WebGLTexture? - */ - isGLTexture: boolean; - - /** - * Are the source image dimensions a power of two? - */ - isPowerOf2: boolean; - - /** - * The WebGL Texture of the source image. If this TextureSource is driven from a WebGLTexture - * already, then this is a reference to that WebGLTexture. - */ - glTexture: WebGLTexture; - - /** - * Sets the `UNPACK_FLIP_Y_WEBGL` flag the WebGL Texture uses during upload. - */ - flipY: boolean; - - /** - * Creates a WebGL Texture, if required, and sets the Texture filter mode. - * @param game A reference to the Phaser Game instance. - */ - init(game: Phaser.Game): void; - - /** - * Sets the Filter Mode for this Texture. - * - * The mode can be either Linear, the default, or Nearest. - * - * For pixel-art you should use Nearest. - * @param filterMode The Filter Mode. - */ - setFilter(filterMode: Phaser.Textures.FilterMode): void; - - /** - * Sets the `UNPACK_FLIP_Y_WEBGL` flag for the WebGL Texture during texture upload. - * @param value Should the WebGL Texture be flipped on the Y axis on texture upload or not? Default true. - */ - setFlipY(value?: boolean): void; - - /** - * If this TextureSource is backed by a Canvas and is running under WebGL, - * it updates the WebGLTexture using the canvas data. - */ - update(): void; - - /** - * Destroys this Texture Source and nulls the references. - */ - destroy(): void; - - } - - } - - namespace Tilemaps { - namespace Components { - } - - /** - * A Dynamic Tilemap Layer is a Game Object that renders LayerData from a Tilemap when used in combination - * with one, or more, Tilesets. - * - * A Dynamic Tilemap Layer trades some speed for being able to apply powerful effects. Unlike a - * Static Tilemap Layer, you can apply per-tile effects like tint or alpha, and you can change the - * tiles in a DynamicTilemapLayer. - * - * Use this over a Static Tilemap Layer when you need those features. - */ - class DynamicTilemapLayer extends Phaser.GameObjects.GameObject implements Phaser.GameObjects.Components.Alpha, Phaser.GameObjects.Components.BlendMode, Phaser.GameObjects.Components.ComputedSize, Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.Flip, Phaser.GameObjects.Components.GetBounds, Phaser.GameObjects.Components.Origin, Phaser.GameObjects.Components.Pipeline, Phaser.GameObjects.Components.ScrollFactor, Phaser.GameObjects.Components.Transform, Phaser.GameObjects.Components.Visible { - /** - * - * @param scene The Scene to which this Game Object belongs. - * @param tilemap The Tilemap this layer is a part of. - * @param layerIndex The index of the LayerData associated with this layer. - * @param tileset The tileset, or an array of tilesets, used to render this layer. Can be a string or a Tileset object. - * @param x The world x position where the top left of this layer will be placed. Default 0. - * @param y The world y position where the top left of this layer will be placed. Default 0. - */ - constructor(scene: Phaser.Scene, tilemap: Phaser.Tilemaps.Tilemap, layerIndex: integer, tileset: string | string[] | Phaser.Tilemaps.Tileset | Phaser.Tilemaps.Tileset[], x?: number, y?: number); - - /** - * Used internally by physics system to perform fast type checks. - */ - readonly isTilemap: boolean; - - /** - * The Tilemap that this layer is a part of. - */ - tilemap: Phaser.Tilemaps.Tilemap; - - /** - * The index of the LayerData associated with this layer. - */ - layerIndex: integer; - - /** - * The LayerData associated with this layer. LayerData can only be associated with one - * tilemap layer. - */ - layer: Phaser.Tilemaps.LayerData; - - /** - * The Tileset/s associated with this layer. - * - * As of Phaser 3.14 this property is now an array of Tileset objects, previously it was a single reference. - */ - tileset: Phaser.Tilemaps.Tileset[]; - - /** - * Used internally with the canvas render. This holds the tiles that are visible within the - * camera. - */ - culledTiles: any[]; - - /** - * You can control if the Cameras should cull tiles before rendering them or not. - * By default the camera will try to cull the tiles in this layer, to avoid over-drawing to the renderer. - * - * However, there are some instances when you may wish to disable this, and toggling this flag allows - * you to do so. Also see `setSkipCull` for a chainable method that does the same thing. - */ - skipCull: boolean; - - /** - * The total number of tiles drawn by the renderer in the last frame. - */ - readonly tilesDrawn: integer; - - /** - * The total number of tiles in this layer. Updated every frame. - */ - readonly tilesTotal: integer; - - /** - * The amount of extra tiles to add into the cull rectangle when calculating its horizontal size. - * - * See the method `setCullPadding` for more details. - */ - cullPaddingX: integer; - - /** - * The amount of extra tiles to add into the cull rectangle when calculating its vertical size. - * - * See the method `setCullPadding` for more details. - */ - cullPaddingY: integer; - - /** - * The callback that is invoked when the tiles are culled. - * - * By default it will call `TilemapComponents.CullTiles` but you can override this to call any function you like. - * - * It will be sent 3 arguments: - * - * 1. The Phaser.Tilemaps.LayerData object for this Layer - * 2. The Camera that is culling the layer. You can check its `dirty` property to see if it has changed since the last cull. - * 3. A reference to the `culledTiles` array, which should be used to store the tiles you want rendered. - * - * See the `TilemapComponents.CullTiles` source code for details on implementing your own culling system. - */ - cullCallback: Function; - - /** - * An array holding the mapping between the tile indexes and the tileset they belong to. - */ - gidMap: Phaser.Tilemaps.Tileset[]; - - /** - * Sets the rendering (draw) order of the tiles in this layer. - * - * The default is 'right-down', meaning it will order the tiles starting from the top-left, - * drawing to the right and then moving down to the next row. - * - * The draw orders are: - * - * 0 = right-down - * 1 = left-down - * 2 = right-up - * 3 = left-up - * - * Setting the render order does not change the tiles or how they are stored in the layer, - * it purely impacts the order in which they are rendered. - * - * You can provide either an integer (0 to 3), or the string version of the order. - * @param renderOrder The render (draw) order value. Either an integer between 0 and 3, or a string: 'right-down', 'left-down', 'right-up' or 'left-up'. - */ - setRenderOrder(renderOrder: integer | string): this; - - /** - * Calculates interesting faces at the given tile coordinates of the specified layer. Interesting - * faces are used internally for optimizing collisions against tiles. This method is mostly used - * internally to optimize recalculating faces when only one tile has been changed. - * @param tileX The x coordinate. - * @param tileY The y coordinate. - */ - calculateFacesAt(tileX: integer, tileY: integer): Phaser.Tilemaps.DynamicTilemapLayer; - - /** - * Calculates interesting faces within the rectangular area specified (in tile coordinates) of the - * layer. Interesting faces are used internally for optimizing collisions against tiles. This method - * is mostly used internally. - * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param width How many tiles wide from the `tileX` index the area will be. Default max width based on tileX. - * @param height How many tiles tall from the `tileY` index the area will be. Default max height based on tileY. - */ - calculateFacesWithin(tileX?: integer, tileY?: integer, width?: integer, height?: integer): Phaser.Tilemaps.DynamicTilemapLayer; - - /** - * Creates a Sprite for every object matching the given tile indexes in the layer. You can - * optionally specify if each tile will be replaced with a new tile after the Sprite has been - * created. This is useful if you want to lay down special tiles in a level that are converted to - * Sprites, but want to replace the tile itself with a floor tile or similar once converted. - * @param indexes The tile index, or array of indexes, to create Sprites from. - * @param replacements The tile index, or array of indexes, to change a converted - * tile to. Set to `null` to leave the tiles unchanged. If an array is given, it is assumed to be a - * one-to-one mapping with the indexes array. - * @param spriteConfig The config object to pass into the Sprite creator (i.e. - * scene.make.sprite). - * @param scene The Scene to create the Sprites within. Default scene the map is within. - * @param camera The Camera to use when determining the world XY Default main camera. - */ - createFromTiles(indexes: integer | any[], replacements: integer | any[], spriteConfig: Phaser.Types.GameObjects.Sprite.SpriteConfig, scene?: Phaser.Scene, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.GameObjects.Sprite[]; - - /** - * Returns the tiles in the given layer that are within the cameras viewport. - * This is used internally. - * @param camera The Camera to run the cull check against. - */ - cull(camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Tilemaps.Tile[]; - - /** - * Copies the tiles in the source rectangular area to a new destination (all specified in tile - * coordinates) within the layer. This copies all tile properties & recalculates collision - * information in the destination region. - * @param srcTileX The x coordinate of the area to copy from, in tiles, not pixels. - * @param srcTileY The y coordinate of the area to copy from, in tiles, not pixels. - * @param width The width of the area to copy, in tiles, not pixels. - * @param height The height of the area to copy, in tiles, not pixels. - * @param destTileX The x coordinate of the area to copy to, in tiles, not pixels. - * @param destTileY The y coordinate of the area to copy to, in tiles, not pixels. - * @param recalculateFaces `true` if the faces data should be recalculated. Default true. - */ - copy(srcTileX: integer, srcTileY: integer, width: integer, height: integer, destTileX: integer, destTileY: integer, recalculateFaces?: boolean): Phaser.Tilemaps.DynamicTilemapLayer; - - /** - * Destroys this DynamicTilemapLayer and removes its link to the associated LayerData. - * @param removeFromTilemap Remove this layer from the parent Tilemap? Default true. - */ - destroy(removeFromTilemap?: boolean): void; - - /** - * Sets the tiles in the given rectangular area (in tile coordinates) of the layer with the - * specified index. Tiles will be set to collide if the given index is a colliding index. - * Collision information in the region will be recalculated. - * @param index The tile index to fill the area with. - * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param width How many tiles wide from the `tileX` index the area will be. Default max width based on tileX. - * @param height How many tiles tall from the `tileY` index the area will be. Default max height based on tileY. - * @param recalculateFaces `true` if the faces data should be recalculated. Default true. - */ - fill(index: integer, tileX?: integer, tileY?: integer, width?: integer, height?: integer, recalculateFaces?: boolean): Phaser.Tilemaps.DynamicTilemapLayer; - - /** - * For each tile in the given rectangular area (in tile coordinates) of the layer, run the given - * filter callback function. Any tiles that pass the filter test (i.e. where the callback returns - * true) will returned as a new array. Similar to Array.prototype.Filter in vanilla JS. - * @param callback The callback. Each tile in the given area will be passed to this - * callback as the first and only parameter. The callback should return true for tiles that pass the - * filter. - * @param context The context under which the callback should be run. - * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area to filter. Default 0. - * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area to filter. Default 0. - * @param width How many tiles wide from the `tileX` index the area will be. Default max width based on tileX. - * @param height How many tiles tall from the `tileY` index the area will be. Default max height based on tileY. - * @param filteringOptions Optional filters to apply when getting the tiles. - */ - filterTiles(callback: Function, context?: object, tileX?: integer, tileY?: integer, width?: integer, height?: integer, filteringOptions?: Phaser.Types.Tilemaps.FilteringOptions): Phaser.Tilemaps.Tile[]; - - /** - * Searches the entire map layer for the first tile matching the given index, then returns that Tile - * object. If no match is found, it returns null. The search starts from the top-left tile and - * continues horizontally until it hits the end of the row, then it drops down to the next column. - * If the reverse boolean is true, it scans starting from the bottom-right corner traveling up to - * the top-left. - * @param index The tile index value to search for. - * @param skip The number of times to skip a matching tile before returning. Default 0. - * @param reverse If true it will scan the layer in reverse, starting at the - * bottom-right. Otherwise it scans from the top-left. Default false. - */ - findByIndex(index: integer, skip?: integer, reverse?: boolean): Phaser.Tilemaps.Tile; - - /** - * Find the first tile in the given rectangular area (in tile coordinates) of the layer that - * satisfies the provided testing function. I.e. finds the first tile for which `callback` returns - * true. Similar to Array.prototype.find in vanilla JS. - * @param callback The callback. Each tile in the given area will be passed to this callback as the first and only parameter. - * @param context The context under which the callback should be run. - * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area to search. Default 0. - * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area to search. Default 0. - * @param width How many tiles wide from the `tileX` index the area will be. Default max width based on tileX. - * @param height How many tiles tall from the `tileY` index the area will be. Default max height based on tileY. - * @param filteringOptions Optional filters to apply when getting the tiles. - */ - findTile(callback: FindTileCallback, context?: object, tileX?: integer, tileY?: integer, width?: integer, height?: integer, filteringOptions?: Phaser.Types.Tilemaps.FilteringOptions): Phaser.Tilemaps.Tile; - - /** - * For each tile in the given rectangular area (in tile coordinates) of the layer, run the given - * callback. Similar to Array.prototype.forEach in vanilla JS. - * @param callback The callback. Each tile in the given area will be passed to this callback as the first and only parameter. - * @param context The context under which the callback should be run. - * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area to search. Default 0. - * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area to search. Default 0. - * @param width How many tiles wide from the `tileX` index the area will be. Default max width based on tileX. - * @param height How many tiles tall from the `tileY` index the area will be. Default max height based on tileY. - * @param filteringOptions Optional filters to apply when getting the tiles. - */ - forEachTile(callback: EachTileCallback, context?: object, tileX?: integer, tileY?: integer, width?: integer, height?: integer, filteringOptions?: Phaser.Types.Tilemaps.FilteringOptions): Phaser.Tilemaps.DynamicTilemapLayer; - - /** - * Gets a tile at the given tile coordinates from the given layer. - * @param tileX X position to get the tile from (given in tile units, not pixels). - * @param tileY Y position to get the tile from (given in tile units, not pixels). - * @param nonNull If true getTile won't return null for empty tiles, but a Tile object with an index of -1. Default false. - */ - getTileAt(tileX: integer, tileY: integer, nonNull?: boolean): Phaser.Tilemaps.Tile; - - /** - * Gets a tile at the given world coordinates from the given layer. - * @param worldX X position to get the tile from (given in pixels) - * @param worldY Y position to get the tile from (given in pixels) - * @param nonNull If true, function won't return null for empty tiles, but a Tile object with an index of -1. Default false. - * @param camera The Camera to use when calculating the tile index from the world values. Default main camera. - */ - getTileAtWorldXY(worldX: number, worldY: number, nonNull?: boolean, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Tilemaps.Tile; - - /** - * Gets the tiles in the given rectangular area (in tile coordinates) of the layer. - * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param width How many tiles wide from the `tileX` index the area will be. Default max width based on tileX. - * @param height How many tiles tall from the `tileY` index the area will be. Default max height based on tileY. - * @param filteringOptions Optional filters to apply when getting the tiles. - */ - getTilesWithin(tileX?: integer, tileY?: integer, width?: integer, height?: integer, filteringOptions?: Phaser.Types.Tilemaps.FilteringOptions): Phaser.Tilemaps.Tile[]; - - /** - * Gets the tiles that overlap with the given shape in the given layer. The shape must be a Circle, - * Line, Rectangle or Triangle. The shape should be in world coordinates. - * @param shape A shape in world (pixel) coordinates - * @param filteringOptions Optional filters to apply when getting the tiles. - * @param camera The Camera to use when factoring in which tiles to return. Default main camera. + * @param key The unique string-based key of the Texture. */ - getTilesWithinShape(shape: Phaser.Geom.Circle | Phaser.Geom.Line | Phaser.Geom.Rectangle | Phaser.Geom.Triangle, filteringOptions?: Phaser.Types.Tilemaps.FilteringOptions, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Tilemaps.Tile[]; + exists(key: string): boolean; /** - * Gets the tiles in the given rectangular area (in world coordinates) of the layer. - * @param worldX The world x coordinate for the top-left of the area. - * @param worldY The world y coordinate for the top-left of the area. - * @param width The width of the area. - * @param height The height of the area. - * @param filteringOptions Optional filters to apply when getting the tiles. - * @param camera The Camera to use when factoring in which tiles to return. Default main camera. + * Returns a Texture from the Texture Manager that matches the given key. + * + * If the key is `undefined` it will return the `__DEFAULT` Texture. + * + * If the key is an instance of a Texture, it will return the key directly. + * + * Finally. if the key is given, but not found and not a Texture instance, it will return the `__MISSING` Texture. + * @param key The unique string-based key of the Texture, or a Texture instance. */ - getTilesWithinWorldXY(worldX: number, worldY: number, width: number, height: number, filteringOptions?: Phaser.Types.Tilemaps.FilteringOptions, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Tilemaps.Tile[]; + get(key: string | Phaser.Textures.Texture): Phaser.Textures.Texture; /** - * Checks if there is a tile at the given location (in tile coordinates) in the given layer. Returns - * false if there is no tile or if the tile at that location has an index of -1. - * @param tileX The x coordinate, in tiles, not pixels. - * @param tileY The y coordinate, in tiles, not pixels. + * Takes a Texture key and Frame name and returns a clone of that Frame if found. + * @param key The unique string-based key of the Texture. + * @param frame The string or index of the Frame to be cloned. */ - hasTileAt(tileX: integer, tileY: integer): boolean; + cloneFrame(key: string, frame: string | number): Phaser.Textures.Frame; /** - * Checks if there is a tile at the given location (in world coordinates) in the given layer. Returns - * false if there is no tile or if the tile at that location has an index of -1. - * @param worldX The x coordinate, in pixels. - * @param worldY The y coordinate, in pixels. - * @param camera The Camera to use when factoring in which tiles to return. Default main camera. + * Takes a Texture key and Frame name and returns a reference to that Frame, if found. + * @param key The unique string-based key of the Texture. + * @param frame The string-based name, or integer based index, of the Frame to get from the Texture. */ - hasTileAtWorldXY(worldX: number, worldY: number, camera?: Phaser.Cameras.Scene2D.Camera): boolean; + getFrame(key: string, frame?: string | number): Phaser.Textures.Frame; /** - * Puts a tile at the given tile coordinates in the specified layer. You can pass in either an index - * or a Tile object. If you pass in a Tile, all attributes will be copied over to the specified - * location. If you pass in an index, only the index at the specified location will be changed. - * Collision information will be recalculated at the specified location. - * @param tile The index of this tile to set or a Tile object. - * @param tileX The x coordinate, in tiles, not pixels. - * @param tileY The y coordinate, in tiles, not pixels. - * @param recalculateFaces `true` if the faces data should be recalculated. Default true. + * Returns an array with all of the keys of all Textures in this Texture Manager. + * The output array will exclude the `__DEFAULT` and `__MISSING` keys. */ - putTileAt(tile: integer | Phaser.Tilemaps.Tile, tileX: integer, tileY: integer, recalculateFaces?: boolean): Phaser.Tilemaps.Tile; + getTextureKeys(): string[]; /** - * Puts a tile at the given world coordinates (pixels) in the specified layer. You can pass in either - * an index or a Tile object. If you pass in a Tile, all attributes will be copied over to the - * specified location. If you pass in an index, only the index at the specified location will be - * changed. Collision information will be recalculated at the specified location. - * @param tile The index of this tile to set or a Tile object. - * @param worldX The x coordinate, in pixels. - * @param worldY The y coordinate, in pixels. - * @param recalculateFaces `true` if the faces data should be recalculated. Default true. - * @param camera The Camera to use when calculating the tile index from the world values. Default main camera. + * Given a Texture and an `x` and `y` coordinate this method will return a new + * Color object that has been populated with the color and alpha values of the pixel + * at that location in the Texture. + * @param x The x coordinate of the pixel within the Texture. + * @param y The y coordinate of the pixel within the Texture. + * @param key The unique string-based key of the Texture. + * @param frame The string or index of the Frame. */ - putTileAtWorldXY(tile: integer | Phaser.Tilemaps.Tile, worldX: number, worldY: number, recalculateFaces?: boolean, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Tilemaps.Tile; + getPixel(x: number, y: number, key: string, frame?: string | number): Phaser.Display.Color; /** - * Puts an array of tiles or a 2D array of tiles at the given tile coordinates in the specified - * layer. The array can be composed of either tile indexes or Tile objects. If you pass in a Tile, - * all attributes will be copied over to the specified location. If you pass in an index, only the - * index at the specified location will be changed. Collision information will be recalculated - * within the region tiles were changed. - * @param tile A row (array) or grid (2D array) of Tiles or tile indexes to place. - * @param tileX The x coordinate, in tiles, not pixels. - * @param tileY The y coordinate, in tiles, not pixels. - * @param recalculateFaces `true` if the faces data should be recalculated. Default true. + * Given a Texture and an `x` and `y` coordinate this method will return a value between 0 and 255 + * corresponding to the alpha value of the pixel at that location in the Texture. If the coordinate + * is out of bounds it will return null. + * @param x The x coordinate of the pixel within the Texture. + * @param y The y coordinate of the pixel within the Texture. + * @param key The unique string-based key of the Texture. + * @param frame The string or index of the Frame. */ - putTilesAt(tile: integer[] | integer[][] | Phaser.Tilemaps.Tile[] | Phaser.Tilemaps.Tile[][], tileX: integer, tileY: integer, recalculateFaces?: boolean): Phaser.Tilemaps.DynamicTilemapLayer; + getPixelAlpha(x: number, y: number, key: string, frame?: string | number): number; /** - * Randomizes the indexes of a rectangular region of tiles (in tile coordinates) within the - * specified layer. Each tile will receive a new index. If an array of indexes is passed in, then - * those will be used for randomly assigning new tile indexes. If an array is not provided, the - * indexes found within the region (excluding -1) will be used for randomly assigning new tile - * indexes. This method only modifies tile indexes and does not change collision information. - * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param width How many tiles wide from the `tileX` index the area will be. Default max width based on tileX. - * @param height How many tiles tall from the `tileY` index the area will be. Default max height based on tileY. - * @param indexes An array of indexes to randomly draw from during randomization. + * Sets the given Game Objects `texture` and `frame` properties so that it uses + * the Texture and Frame specified in the `key` and `frame` arguments to this method. + * @param gameObject The Game Object the texture would be set on. + * @param key The unique string-based key of the Texture. + * @param frame The string or index of the Frame. */ - randomize(tileX?: integer, tileY?: integer, width?: integer, height?: integer, indexes?: integer[]): Phaser.Tilemaps.DynamicTilemapLayer; + setTexture(gameObject: Phaser.GameObjects.GameObject, key: string, frame?: string | number): Phaser.GameObjects.GameObject; /** - * Removes the tile at the given tile coordinates in the specified layer and updates the layer's - * collision information. - * @param tileX The x coordinate, in tiles, not pixels. - * @param tileY The y coordinate, in tiles, not pixels. - * @param replaceWithNull If true, this will replace the tile at the specified location with null instead of a Tile with an index of -1. Default true. - * @param recalculateFaces `true` if the faces data should be recalculated. Default true. + * Changes the key being used by a Texture to the new key provided. + * + * The old key is removed, allowing it to be re-used. + * + * Game Objects are linked to Textures by a reference to the Texture object, so + * all existing references will be retained. + * @param currentKey The current string-based key of the Texture you wish to rename. + * @param newKey The new unique string-based key to use for the Texture. */ - removeTileAt(tileX: integer, tileY: integer, replaceWithNull?: boolean, recalculateFaces?: boolean): Phaser.Tilemaps.Tile; + renameTexture(currentKey: string, newKey: string): boolean; /** - * Removes the tile at the given world coordinates in the specified layer and updates the layer's - * collision information. - * @param worldX The x coordinate, in pixels. - * @param worldY The y coordinate, in pixels. - * @param replaceWithNull If true, this will replace the tile at the specified location with null instead of a Tile with an index of -1. Default true. - * @param recalculateFaces `true` if the faces data should be recalculated. Default true. - * @param camera The Camera to use when calculating the tile index from the world values. Default main camera. + * Passes all Textures to the given callback. + * @param callback The callback function to be sent the Textures. + * @param scope The value to use as `this` when executing the callback. + * @param args Additional arguments that will be passed to the callback, after the child. */ - removeTileAtWorldXY(worldX: number, worldY: number, replaceWithNull?: boolean, recalculateFaces?: boolean, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Tilemaps.Tile; + each(callback: EachTextureCallback, scope: object, ...args: any[]): void; /** - * Draws a debug representation of the layer to the given Graphics. This is helpful when you want to - * get a quick idea of which of your tiles are colliding and which have interesting faces. The tiles - * are drawn starting at (0, 0) in the Graphics, allowing you to place the debug representation - * wherever you want on the screen. - * @param graphics The target Graphics object to draw upon. - * @param styleConfig An object specifying the colors to use for the debug drawing. + * Destroys the Texture Manager and all Textures stored within it. */ - renderDebug(graphics: Phaser.GameObjects.Graphics, styleConfig: Phaser.Types.Tilemaps.StyleConfig): Phaser.Tilemaps.DynamicTilemapLayer; + destroy(): void; + + } + /** + * A Texture Source is the encapsulation of the actual source data for a Texture. + * + * This is typically an Image Element, loaded from the file system or network, a Canvas Element or a Video Element. + * + * A Texture can contain multiple Texture Sources, which only happens when a multi-atlas is loaded. + */ + class TextureSource { /** - * Scans the given rectangular area (given in tile coordinates) for tiles with an index matching - * `findIndex` and updates their index to match `newIndex`. This only modifies the index and does - * not change collision information. - * @param findIndex The index of the tile to search for. - * @param newIndex The index of the tile to replace it with. - * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param width How many tiles wide from the `tileX` index the area will be. Default max width based on tileX. - * @param height How many tiles tall from the `tileY` index the area will be. Default max height based on tileY. + * + * @param texture The Texture this TextureSource belongs to. + * @param source The source image data. + * @param width Optional width of the source image. If not given it's derived from the source itself. + * @param height Optional height of the source image. If not given it's derived from the source itself. + * @param flipY Sets the `UNPACK_FLIP_Y_WEBGL` flag the WebGL Texture uses during upload. Default false. */ - replaceByIndex(findIndex: integer, newIndex: integer, tileX?: integer, tileY?: integer, width?: integer, height?: integer): Phaser.Tilemaps.DynamicTilemapLayer; + constructor(texture: Phaser.Textures.Texture, source: HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | Phaser.GameObjects.RenderTexture | WebGLTexture, width?: number, height?: number, flipY?: boolean); /** - * You can control if the Cameras should cull tiles before rendering them or not. - * By default the camera will try to cull the tiles in this layer, to avoid over-drawing to the renderer. - * - * However, there are some instances when you may wish to disable this. - * @param value Set to `true` to stop culling tiles. Set to `false` to enable culling again. Default true. + * The Texture this TextureSource belongs to. */ - setSkipCull(value?: boolean): this; + renderer: Phaser.Renderer.Canvas.CanvasRenderer | Phaser.Renderer.WebGL.WebGLRenderer; /** - * When a Camera culls the tiles in this layer it does so using its view into the world, building up a - * rectangle inside which the tiles must exist or they will be culled. Sometimes you may need to expand the size - * of this 'cull rectangle', especially if you plan on rotating the Camera viewing the layer. Do so - * by providing the padding values. The values given are in tiles, not pixels. So if the tile width was 32px - * and you set `paddingX` to be 4, it would add 32px x 4 to the cull rectangle (adjusted for scale) - * @param paddingX The amount of extra horizontal tiles to add to the cull check padding. Default 1. - * @param paddingY The amount of extra vertical tiles to add to the cull check padding. Default 1. + * The Texture this TextureSource belongs to. */ - setCullPadding(paddingX?: integer, paddingY?: integer): this; + texture: Phaser.Textures.Texture; /** - * Sets collision on the given tile or tiles within a layer by index. You can pass in either a - * single numeric index or an array of indexes: [2, 3, 15, 20]. The `collides` parameter controls if - * collision will be enabled (true) or disabled (false). + * The source of the image data. * - * If no layer specified, the map's current layer is used. - * @param indexes Either a single tile index, or an array of tile indexes. - * @param collides If true it will enable collision. If false it will clear collision. Default true. - * @param recalculateFaces Whether or not to recalculate the tile faces after the update. Default true. - * @param updateLayer If true, updates the current tiles on the layer. Set to - * false if no tiles have been placed for significant performance boost. Default true. + * This is either an Image Element, a Canvas Element, a Video Element, a RenderTexture or a WebGLTexture. */ - setCollision(indexes: integer | any[], collides?: boolean, recalculateFaces?: boolean, updateLayer?: boolean): Phaser.Tilemaps.Tilemap; + source: HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | Phaser.GameObjects.RenderTexture | WebGLTexture; /** - * Sets collision on a range of tiles in a layer whose index is between the specified `start` and - * `stop` (inclusive). Calling this with a start value of 10 and a stop value of 14 would set - * collision for tiles 10, 11, 12, 13 and 14. The `collides` parameter controls if collision will be - * enabled (true) or disabled (false). - * @param start The first index of the tile to be set for collision. - * @param stop The last index of the tile to be set for collision. - * @param collides If true it will enable collision. If false it will clear collision. Default true. - * @param recalculateFaces Whether or not to recalculate the tile faces after the update. Default true. + * The image data. + * + * This is either an Image element, Canvas element or a Video Element. */ - setCollisionBetween(start: integer, stop: integer, collides?: boolean, recalculateFaces?: boolean): Phaser.Tilemaps.DynamicTilemapLayer; + image: HTMLImageElement | HTMLCanvasElement | HTMLVideoElement; /** - * Sets collision on the tiles within a layer by checking tile properties. If a tile has a property - * that matches the given properties object, its collision flag will be set. The `collides` - * parameter controls if collision will be enabled (true) or disabled (false). Passing in - * `{ collides: true }` would update the collision flag on any tiles with a "collides" property that - * has a value of true. Any tile that doesn't have "collides" set to true will be ignored. You can - * also use an array of values, e.g. `{ types: ["stone", "lava", "sand" ] }`. If a tile has a - * "types" property that matches any of those values, its collision flag will be updated. - * @param properties An object with tile properties and corresponding values that should be checked. - * @param collides If true it will enable collision. If false it will clear collision. Default true. - * @param recalculateFaces Whether or not to recalculate the tile faces after the update. Default true. + * Currently un-used. */ - setCollisionByProperty(properties: object, collides?: boolean, recalculateFaces?: boolean): Phaser.Tilemaps.DynamicTilemapLayer; + compressionAlgorithm: number; /** - * Sets collision on all tiles in the given layer, except for tiles that have an index specified in - * the given array. The `collides` parameter controls if collision will be enabled (true) or - * disabled (false). - * @param indexes An array of the tile indexes to not be counted for collision. - * @param collides If true it will enable collision. If false it will clear collision. Default true. - * @param recalculateFaces Whether or not to recalculate the tile faces after the update. Default true. + * The resolution of the source image. */ - setCollisionByExclusion(indexes: integer[], collides?: boolean, recalculateFaces?: boolean): Phaser.Tilemaps.DynamicTilemapLayer; + resolution: number; /** - * Sets collision on the tiles within a layer by checking each tiles collision group data - * (typically defined in Tiled within the tileset collision editor). If any objects are found within - * a tiles collision group, the tile's colliding information will be set. The `collides` parameter - * controls if collision will be enabled (true) or disabled (false). - * @param collides If true it will enable collision. If false it will clear collision. Default true. - * @param recalculateFaces Whether or not to recalculate the tile faces after the update. Default true. + * The width of the source image. If not specified in the constructor it will check + * the `naturalWidth` and then `width` properties of the source image. */ - setCollisionFromCollisionGroup(collides?: boolean, recalculateFaces?: boolean): Phaser.Tilemaps.DynamicTilemapLayer; + width: number; /** - * Sets a global collision callback for the given tile index within the layer. This will affect all - * tiles on this layer that have the same index. If a callback is already set for the tile index it - * will be replaced. Set the callback to null to remove it. If you want to set a callback for a tile - * at a specific location on the map then see setTileLocationCallback. - * @param indexes Either a single tile index, or an array of tile indexes to have a collision callback set for. - * @param callback The callback that will be invoked when the tile is collided with. - * @param callbackContext The context under which the callback is called. + * The height of the source image. If not specified in the constructor it will check + * the `naturalHeight` and then `height` properties of the source image. */ - setTileIndexCallback(indexes: integer | integer[], callback: Function, callbackContext: object): Phaser.Tilemaps.DynamicTilemapLayer; + height: number; /** - * Sets a collision callback for the given rectangular area (in tile coordinates) within the layer. - * If a callback is already set for the tile index it will be replaced. Set the callback to null to - * remove it. - * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param width How many tiles wide from the `tileX` index the area will be. Default max width based on tileX. - * @param height How many tiles tall from the `tileY` index the area will be. Default max height based on tileY. - * @param callback The callback that will be invoked when the tile is collided with. - * @param callbackContext The context under which the callback is called. + * The Scale Mode the image will use when rendering. + * Either Linear or Nearest. */ - setTileLocationCallback(tileX?: integer, tileY?: integer, width?: integer, height?: integer, callback?: Function, callbackContext?: object): Phaser.Tilemaps.DynamicTilemapLayer; + scaleMode: number; /** - * Shuffles the tiles in a rectangular region (specified in tile coordinates) within the given - * layer. It will only randomize the tiles in that area, so if they're all the same nothing will - * appear to have changed! This method only modifies tile indexes and does not change collision - * information. - * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param width How many tiles wide from the `tileX` index the area will be. Default max width based on tileX. - * @param height How many tiles tall from the `tileY` index the area will be. Default max height based on tileY. + * Is the source image a Canvas Element? */ - shuffle(tileX?: integer, tileY?: integer, width?: integer, height?: integer): Phaser.Tilemaps.DynamicTilemapLayer; + isCanvas: boolean; /** - * Scans the given rectangular area (given in tile coordinates) for tiles with an index matching - * `indexA` and swaps then with `indexB`. This only modifies the index and does not change collision - * information. - * @param tileA First tile index. - * @param tileB Second tile index. - * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param width How many tiles wide from the `tileX` index the area will be. Default max width based on tileX. - * @param height How many tiles tall from the `tileY` index the area will be. Default max height based on tileY. + * Is the source image a Video Element? */ - swapByIndex(tileA: integer, tileB: integer, tileX?: integer, tileY?: integer, width?: integer, height?: integer): Phaser.Tilemaps.DynamicTilemapLayer; + isVideo: boolean; /** - * Converts from tile X coordinates (tile units) to world X coordinates (pixels), factoring in the - * layers position, scale and scroll. - * @param tileX The x coordinate, in tiles, not pixels. - * @param camera The Camera to use when calculating the tile index from the world values. Default main camera. + * Is the source image a Render Texture? */ - tileToWorldX(tileX: integer, camera?: Phaser.Cameras.Scene2D.Camera): number; + isRenderTexture: boolean; /** - * Converts from tile Y coordinates (tile units) to world Y coordinates (pixels), factoring in the - * layers position, scale and scroll. - * @param tileY The y coordinate, in tiles, not pixels. - * @param camera The Camera to use when calculating the tile index from the world values. Default main camera. + * Is the source image a WebGLTexture? */ - tileToWorldY(tileY: integer, camera?: Phaser.Cameras.Scene2D.Camera): number; + isGLTexture: boolean; /** - * Converts from tile XY coordinates (tile units) to world XY coordinates (pixels), factoring in the - * layers position, scale and scroll. This will return a new Vector2 object or update the given - * `point` object. - * @param tileX The x coordinate, in tiles, not pixels. - * @param tileY The y coordinate, in tiles, not pixels. - * @param point A Vector2 to store the coordinates in. If not given a new Vector2 is created. - * @param camera The Camera to use when calculating the tile index from the world values. Default main camera. + * Are the source image dimensions a power of two? */ - tileToWorldXY(tileX: integer, tileY: integer, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + isPowerOf2: boolean; /** - * Randomizes the indexes of a rectangular region of tiles (in tile coordinates) within the - * specified layer. Each tile will receive a new index. New indexes are drawn from the given - * weightedIndexes array. An example weighted array: - * - * [ - * { index: 6, weight: 4 }, // Probability of index 6 is 4 / 8 - * { index: 7, weight: 2 }, // Probability of index 7 would be 2 / 8 - * { index: 8, weight: 1.5 }, // Probability of index 8 would be 1.5 / 8 - * { index: 26, weight: 0.5 } // Probability of index 27 would be 0.5 / 8 - * ] - * - * The probability of any index being choose is (the index's weight) / (sum of all weights). This - * method only modifies tile indexes and does not change collision information. - * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param width How many tiles wide from the `tileX` index the area will be. Default max width based on tileX. - * @param height How many tiles tall from the `tileY` index the area will be. Default max height based on tileY. - * @param weightedIndexes An array of objects to randomly draw from during - * randomization. They should be in the form: { index: 0, weight: 4 } or - * { index: [0, 1], weight: 4 } if you wish to draw from multiple tile indexes. + * The WebGL Texture of the source image. If this TextureSource is driven from a WebGLTexture + * already, then this is a reference to that WebGLTexture. */ - weightedRandomize(tileX?: integer, tileY?: integer, width?: integer, height?: integer, weightedIndexes?: object[]): Phaser.Tilemaps.DynamicTilemapLayer; + glTexture: WebGLTexture; /** - * Converts from world X coordinates (pixels) to tile X coordinates (tile units), factoring in the - * layers position, scale and scroll. - * @param worldX The x coordinate to be converted, in pixels, not tiles. - * @param snapToFloor Whether or not to round the tile coordinate down to the nearest integer. Default true. - * @param camera The Camera to use when calculating the tile index from the world values. Default main camera. + * The current texture unit index as assigned by the WebGL Renderer. + * Un-used in canvas. Should be treated as read-only. */ - worldToTileX(worldX: number, snapToFloor?: boolean, camera?: Phaser.Cameras.Scene2D.Camera): number; + glIndex: number; /** - * Converts from world Y coordinates (pixels) to tile Y coordinates (tile units), factoring in the - * layers position, scale and scroll. - * @param worldY The y coordinate to be converted, in pixels, not tiles. - * @param snapToFloor Whether or not to round the tile coordinate down to the nearest integer. Default true. - * @param camera The Camera to use when calculating the tile index from the world values. Default main camera. + * The counter value when this texture was last assigned an index by the WebGL Renderer. + * Un-used in canvas. Should be treated as read-only. */ - worldToTileY(worldY: number, snapToFloor?: boolean, camera?: Phaser.Cameras.Scene2D.Camera): number; + glIndexCounter: number; /** - * Converts from world XY coordinates (pixels) to tile XY coordinates (tile units), factoring in the - * layers position, scale and scroll. This will return a new Vector2 object or update the given - * `point` object. - * @param worldX The x coordinate to be converted, in pixels, not tiles. - * @param worldY The y coordinate to be converted, in pixels, not tiles. - * @param snapToFloor Whether or not to round the tile coordinate down to the nearest integer. Default true. - * @param point A Vector2 to store the coordinates in. If not given a new Vector2 is created. - * @param camera The Camera to use when calculating the tile index from the world values. Default main camera. + * Sets the `UNPACK_FLIP_Y_WEBGL` flag the WebGL Texture uses during upload. */ - worldToTileXY(worldX: number, worldY: number, snapToFloor?: boolean, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + flipY: boolean; /** - * Clears all alpha values associated with this Game Object. - * - * Immediately sets the alpha levels back to 1 (fully opaque). + * Creates a WebGL Texture, if required, and sets the Texture filter mode. + * @param game A reference to the Phaser Game instance. */ - clearAlpha(): this; + init(game: Phaser.Game): void; /** - * Set the Alpha level of this Game Object. The alpha controls the opacity of the Game Object as it renders. - * Alpha values are provided as a float between 0, fully transparent, and 1, fully opaque. + * Sets the Filter Mode for this Texture. * - * If your game is running under WebGL you can optionally specify four different alpha values, each of which - * correspond to the four corners of the Game Object. Under Canvas only the `topLeft` value given is used. - * @param topLeft The alpha value used for the top-left of the Game Object. If this is the only value given it's applied across the whole Game Object. Default 1. - * @param topRight The alpha value used for the top-right of the Game Object. WebGL only. - * @param bottomLeft The alpha value used for the bottom-left of the Game Object. WebGL only. - * @param bottomRight The alpha value used for the bottom-right of the Game Object. WebGL only. + * The mode can be either Linear, the default, or Nearest. + * + * For pixel-art you should use Nearest. + * @param filterMode The Filter Mode. */ - setAlpha(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; + setFilter(filterMode: Phaser.Textures.FilterMode): void; /** - * The alpha value of the Game Object. - * - * This is a global value, impacting the entire Game Object, not just a region of it. + * Sets the `UNPACK_FLIP_Y_WEBGL` flag for the WebGL Texture during texture upload. + * @param value Should the WebGL Texture be flipped on the Y axis on texture upload or not? Default true. */ - alpha: number; + setFlipY(value?: boolean): void; /** - * The alpha value starting from the top-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * If this TextureSource is backed by a Canvas and is running under WebGL, + * it updates the WebGLTexture using the canvas data. */ - alphaTopLeft: number; + update(): void; /** - * The alpha value starting from the top-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * Destroys this Texture Source and nulls the references. */ - alphaTopRight: number; + destroy(): void; + + } + } + + namespace Tilemaps { + namespace Components { /** - * The alpha value starting from the bottom-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * Calculates interesting faces at the given tile coordinates of the specified layer. Interesting + * faces are used internally for optimizing collisions against tiles. This method is mostly used + * internally to optimize recalculating faces when only one tile has been changed. + * @param tileX The x coordinate. + * @param tileY The y coordinate. + * @param layer The Tilemap Layer to act upon. */ - alphaBottomLeft: number; + function CalculateFacesAt(tileX: number, tileY: number, layer: Phaser.Tilemaps.LayerData): void; /** - * The alpha value starting from the bottom-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * Calculates interesting faces within the rectangular area specified (in tile coordinates) of the + * layer. Interesting faces are used internally for optimizing collisions against tiles. This method + * is mostly used internally. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. + * @param layer The Tilemap Layer to act upon. */ - alphaBottomRight: number; + function CalculateFacesWithin(tileX: number, tileY: number, width: number, height: number, layer: Phaser.Tilemaps.LayerData): void; /** - * Sets the Blend Mode being used by this Game Object. - * - * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) - * - * Under WebGL only the following Blend Modes are available: - * - * * ADD - * * MULTIPLY - * * SCREEN - * * ERASE - * - * Canvas has more available depending on browser support. - * - * You can also create your own custom Blend Modes in WebGL. - * - * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending - * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these - * reasons try to be careful about the construction of your Scene and the frequency of which blend modes - * are used. + * Checks if the given tile coordinate is within the isometric layer bounds, or not. + * @param tileX The x coordinate, in tiles, not pixels. + * @param tileY The y coordinate, in tiles, not pixels. + * @param layer The Tilemap Layer to check against. + * @param camera The Camera to run the cull check against. */ - blendMode: Phaser.BlendModes | string; + function CheckIsoBounds(tileX: number, tileY: number, layer: Phaser.Tilemaps.LayerData, camera?: Phaser.Cameras.Scene2D.Camera): boolean; /** - * Sets the Blend Mode being used by this Game Object. - * - * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) - * - * Under WebGL only the following Blend Modes are available: - * - * * ADD - * * MULTIPLY - * * SCREEN - * * ERASE (only works when rendering to a framebuffer, like a Render Texture) - * - * Canvas has more available depending on browser support. - * - * You can also create your own custom Blend Modes in WebGL. - * - * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending - * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these - * reasons try to be careful about the construction of your Scene and the frequency in which blend modes - * are used. - * @param value The BlendMode value. Either a string or a CONST. + * Copies the tiles in the source rectangular area to a new destination (all specified in tile + * coordinates) within the layer. This copies all tile properties & recalculates collision + * information in the destination region. + * @param srcTileX The x coordinate of the area to copy from, in tiles, not pixels. + * @param srcTileY The y coordinate of the area to copy from, in tiles, not pixels. + * @param width The width of the area to copy, in tiles, not pixels. + * @param height The height of the area to copy, in tiles, not pixels. + * @param destTileX The x coordinate of the area to copy to, in tiles, not pixels. + * @param destTileY The y coordinate of the area to copy to, in tiles, not pixels. + * @param recalculateFaces `true` if the faces data should be recalculated. + * @param layer The Tilemap Layer to act upon. */ - setBlendMode(value: string | Phaser.BlendModes): this; + function Copy(srcTileX: number, srcTileY: number, width: number, height: number, destTileX: number, destTileY: number, recalculateFaces: boolean, layer: Phaser.Tilemaps.LayerData): void; /** - * The native (un-scaled) width of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayWidth` property. + * Creates a Sprite for every object matching the given tile indexes in the layer. You can + * optionally specify if each tile will be replaced with a new tile after the Sprite has been + * created. This is useful if you want to lay down special tiles in a level that are converted to + * Sprites, but want to replace the tile itself with a floor tile or similar once converted. + * @param indexes The tile index, or array of indexes, to create Sprites from. + * @param replacements The tile index, or array of indexes, to change a converted tile to. Set to `null` to leave the tiles unchanged. If an array is given, it is assumed to be a one-to-one mapping with the indexes array. + * @param spriteConfig The config object to pass into the Sprite creator (i.e. scene.make.sprite). + * @param scene The Scene to create the Sprites within. + * @param camera The Camera to use when determining the world XY + * @param layer The Tilemap Layer to act upon. */ - width: number; + function CreateFromTiles(indexes: number | number[], replacements: number | number[], spriteConfig: Phaser.Types.GameObjects.Sprite.SpriteConfig, scene: Phaser.Scene, camera: Phaser.Cameras.Scene2D.Camera, layer: Phaser.Tilemaps.LayerData): Phaser.GameObjects.Sprite[]; /** - * The native (un-scaled) height of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayHeight` property. + * Returns the bounds in the given orthogonal layer that are within the cameras viewport. + * This is used internally by the cull tiles function. + * @param layer The Tilemap Layer to act upon. + * @param camera The Camera to run the cull check against. */ - height: number; + function CullBounds(layer: Phaser.Tilemaps.LayerData, camera: Phaser.Cameras.Scene2D.Camera): Phaser.Geom.Rectangle; /** - * The displayed width of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. + * Returns the tiles in the given layer that are within the cameras viewport. This is used internally. + * @param layer The Tilemap Layer to act upon. + * @param camera The Camera to run the cull check against. + * @param outputArray An optional array to store the Tile objects within. + * @param renderOrder The rendering order constant. Default 0. */ - displayWidth: number; + function CullTiles(layer: Phaser.Tilemaps.LayerData, camera: Phaser.Cameras.Scene2D.Camera, outputArray?: any[], renderOrder?: number): Phaser.Tilemaps.Tile[]; /** - * The displayed height of this Game Object. - * - * This value takes into account the scale factor. - * - * Setting this value will adjust the Game Object's scale property. + * Sets the tiles in the given rectangular area (in tile coordinates) of the layer with the + * specified index. Tiles will be set to collide if the given index is a colliding index. + * Collision information in the region will be recalculated. + * @param index The tile index to fill the area with. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. + * @param recalculateFaces `true` if the faces data should be recalculated. + * @param layer The tile layer to use. If not given the current layer is used. */ - displayHeight: number; + function Fill(index: number, tileX: number, tileY: number, width: number, height: number, recalculateFaces: boolean, layer: Phaser.Tilemaps.LayerData): void; /** - * Sets the internal size of this Game Object, as used for frame or physics body creation. - * - * This will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or call the - * `setDisplaySize` method, which is the same thing as changing the scale but allows you - * to do so by giving pixel values. - * - * If you have enabled this Game Object for input, changing the size will _not_ change the - * size of the hit area. To do this you should adjust the `input.hitArea` object directly. - * @param width The width of this Game Object. - * @param height The height of this Game Object. + * For each tile in the given rectangular area (in tile coordinates) of the layer, run the given + * filter callback function. Any tiles that pass the filter test (i.e. where the callback returns + * true) will returned as a new array. Similar to Array.prototype.Filter in vanilla JS. + * @param callback The callback. Each tile in the given area will be passed to this + * callback as the first and only parameter. The callback should return true for tiles that pass the + * filter. + * @param context The context under which the callback should be run. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area to filter. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area to filter. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. + * @param filteringOptions Optional filters to apply when getting the tiles. + * @param layer The Tilemap Layer to act upon. */ - setSize(width: number, height: number): this; + function FilterTiles(callback: Function, context: object, tileX: number, tileY: number, width: number, height: number, filteringOptions: Phaser.Types.Tilemaps.FilteringOptions, layer: Phaser.Tilemaps.LayerData): Phaser.Tilemaps.Tile[]; /** - * Sets the display size of this Game Object. - * - * Calling this will adjust the scale. - * @param width The width of this Game Object. - * @param height The height of this Game Object. + * Searches the entire map layer for the first tile matching the given index, then returns that Tile + * object. If no match is found, it returns null. The search starts from the top-left tile and + * continues horizontally until it hits the end of the row, then it drops down to the next column. + * If the reverse boolean is true, it scans starting from the bottom-right corner traveling up to + * the top-left. + * @param index The tile index value to search for. + * @param skip The number of times to skip a matching tile before returning. + * @param reverse If true it will scan the layer in reverse, starting at the bottom-right. Otherwise it scans from the top-left. + * @param layer The Tilemap Layer to act upon. */ - setDisplaySize(width: number, height: number): this; + function FindByIndex(index: number, skip: number, reverse: boolean, layer: Phaser.Tilemaps.LayerData): Phaser.Tilemaps.Tile; /** - * The depth of this Game Object within the Scene. - * - * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order - * of Game Objects, without actually moving their position in the display list. - * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth - * value will always render in front of one with a lower value. - * - * Setting the depth will queue a depth sort event within the Scene. + * Find the first tile in the given rectangular area (in tile coordinates) of the layer that + * satisfies the provided testing function. I.e. finds the first tile for which `callback` returns + * true. Similar to Array.prototype.find in vanilla JS. + * @param callback The callback. Each tile in the given area will be passed to this callback as the first and only parameter. + * @param context The context under which the callback should be run. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area to filter. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area to filter. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. + * @param filteringOptions Optional filters to apply when getting the tiles. + * @param layer The Tilemap Layer to act upon. */ - depth: number; + function FindTile(callback: FindTileCallback, context: object, tileX: number, tileY: number, width: number, height: number, filteringOptions: Phaser.Types.Tilemaps.FilteringOptions, layer: Phaser.Tilemaps.LayerData): Phaser.Tilemaps.Tile; /** - * The depth of this Game Object within the Scene. - * - * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order - * of Game Objects, without actually moving their position in the display list. - * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth - * value will always render in front of one with a lower value. - * - * Setting the depth will queue a depth sort event within the Scene. - * @param value The depth of this Game Object. + * For each tile in the given rectangular area (in tile coordinates) of the layer, run the given + * callback. Similar to Array.prototype.forEach in vanilla JS. + * @param callback The callback. Each tile in the given area will be passed to this callback as the first and only parameter. + * @param context The context under which the callback should be run. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area to filter. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area to filter. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. + * @param filteringOptions Optional filters to apply when getting the tiles. + * @param layer The Tilemap Layer to act upon. */ - setDepth(value: integer): this; + function ForEachTile(callback: EachTileCallback, context: object, tileX: number, tileY: number, width: number, height: number, filteringOptions: Phaser.Types.Tilemaps.FilteringOptions, layer: Phaser.Tilemaps.LayerData): void; /** - * The horizontally flipped state of the Game Object. - * - * A Game Object that is flipped horizontally will render inversed on the horizontal axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * Gets the correct function to use to cull tiles, based on the map orientation. + * @param orientation The Tilemap orientation constant. */ - flipX: boolean; + function GetCullTilesFunction(orientation: number): Function; /** - * The vertically flipped state of the Game Object. - * - * A Game Object that is flipped vertically will render inversed on the vertical axis (i.e. upside down) - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * Gets a tile at the given tile coordinates from the given layer. + * @param tileX X position to get the tile from (given in tile units, not pixels). + * @param tileY Y position to get the tile from (given in tile units, not pixels). + * @param nonNull If true getTile won't return null for empty tiles, but a Tile object with an index of -1. + * @param layer The Tilemap Layer to act upon. */ - flipY: boolean; + function GetTileAt(tileX: number, tileY: number, nonNull: boolean, layer: Phaser.Tilemaps.LayerData): Phaser.Tilemaps.Tile; /** - * Toggles the horizontal flipped state of this Game Object. - * - * A Game Object that is flipped horizontally will render inversed on the horizontal axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * Gets a tile at the given world coordinates from the given layer. + * @param worldX X position to get the tile from (given in pixels) + * @param worldY Y position to get the tile from (given in pixels) + * @param nonNull If true, function won't return null for empty tiles, but a Tile object with an index of -1. + * @param camera The Camera to use when calculating the tile index from the world values. + * @param layer The Tilemap Layer to act upon. */ - toggleFlipX(): this; + function GetTileAtWorldXY(worldX: number, worldY: number, nonNull: boolean, camera: Phaser.Cameras.Scene2D.Camera, layer: Phaser.Tilemaps.LayerData): Phaser.Tilemaps.Tile; /** - * Toggles the vertical flipped state of this Game Object. + * Gets the tiles in the given rectangular area (in tile coordinates) of the layer. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. + * @param filteringOptions Optional filters to apply when getting the tiles. + * @param layer The Tilemap Layer to act upon. */ - toggleFlipY(): this; + function GetTilesWithin(tileX: number, tileY: number, width: number, height: number, filteringOptions: Phaser.Types.Tilemaps.FilteringOptions, layer: Phaser.Tilemaps.LayerData): Phaser.Tilemaps.Tile[]; /** - * Sets the horizontal flipped state of this Game Object. - * - * A Game Object that is flipped horizontally will render inversed on the horizontal axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. - * @param value The flipped state. `false` for no flip, or `true` to be flipped. + * Gets the tiles that overlap with the given shape in the given layer. The shape must be a Circle, + * Line, Rectangle or Triangle. The shape should be in world coordinates. + * @param shape A shape in world (pixel) coordinates + * @param filteringOptions Optional filters to apply when getting the tiles. + * @param camera The Camera to use when calculating the tile index from the world values. + * @param layer The Tilemap Layer to act upon. */ - setFlipX(value: boolean): this; + function GetTilesWithinShape(shape: Phaser.Geom.Circle | Phaser.Geom.Line | Phaser.Geom.Rectangle | Phaser.Geom.Triangle, filteringOptions: Phaser.Types.Tilemaps.FilteringOptions, camera: Phaser.Cameras.Scene2D.Camera, layer: Phaser.Tilemaps.LayerData): Phaser.Tilemaps.Tile[]; /** - * Sets the vertical flipped state of this Game Object. - * @param value The flipped state. `false` for no flip, or `true` to be flipped. + * Gets the tiles in the given rectangular area (in world coordinates) of the layer. + * @param worldX The world x coordinate for the top-left of the area. + * @param worldY The world y coordinate for the top-left of the area. + * @param width The width of the area. + * @param height The height of the area. + * @param filteringOptions Optional filters to apply when getting the tiles. + * @param camera The Camera to use when factoring in which tiles to return. + * @param layer The Tilemap Layer to act upon. */ - setFlipY(value: boolean): this; + function GetTilesWithinWorldXY(worldX: number, worldY: number, width: number, height: number, filteringOptions: Phaser.Types.Tilemaps.FilteringOptions, camera: Phaser.Cameras.Scene2D.Camera, layer: Phaser.Tilemaps.LayerData): Phaser.Tilemaps.Tile[]; /** - * Sets the horizontal and vertical flipped state of this Game Object. - * - * A Game Object that is flipped will render inversed on the flipped axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. - * @param x The horizontal flipped state. `false` for no flip, or `true` to be flipped. - * @param y The horizontal flipped state. `false` for no flip, or `true` to be flipped. + * Gets the correct function to use to translate tiles, based on the map orientation. + * @param orientation The Tilemap orientation constant. */ - setFlip(x: boolean, y: boolean): this; + function GetTileToWorldXFunction(orientation: number): Function; /** - * Resets the horizontal and vertical flipped state of this Game Object back to their default un-flipped state. + * Gets the correct function to use to translate tiles, based on the map orientation. + * @param orientation The Tilemap orientation constant. */ - resetFlip(): this; + function GetTileToWorldXYFunction(orientation: number): Function; /** - * Gets the center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. + * Gets the correct function to use to translate tiles, based on the map orientation. + * @param orientation The Tilemap orientation constant. */ - getCenter(output?: O): O; + function GetTileToWorldYFunction(orientation: number): Function; /** - * Gets the top-left corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * Gets the correct function to use to translate tiles, based on the map orientation. + * @param orientation The Tilemap orientation constant. */ - getTopLeft(output?: O, includeParent?: boolean): O; + function GetWorldToTileXFunction(orientation: number): Function; /** - * Gets the top-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * Gets the correct function to use to translate tiles, based on the map orientation. + * @param orientation The Tilemap orientation constant. */ - getTopCenter(output?: O, includeParent?: boolean): O; + function GetWorldToTileXYFunction(orientation: number): Function; /** - * Gets the top-right corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * Gets the correct function to use to translate tiles, based on the map orientation. + * @param orientation The Tilemap orientation constant. */ - getTopRight(output?: O, includeParent?: boolean): O; + function GetWorldToTileYFunction(orientation: number): Function; /** - * Gets the left-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * Checks if there is a tile at the given location (in tile coordinates) in the given layer. Returns + * false if there is no tile or if the tile at that location has an index of -1. + * @param tileX X position to get the tile from (given in tile units, not pixels). + * @param tileY Y position to get the tile from (given in tile units, not pixels). + * @param layer The Tilemap Layer to act upon. */ - getLeftCenter(output?: O, includeParent?: boolean): O; + function HasTileAt(tileX: number, tileY: number, layer: Phaser.Tilemaps.LayerData): boolean; /** - * Gets the right-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * Checks if there is a tile at the given location (in world coordinates) in the given layer. Returns + * false if there is no tile or if the tile at that location has an index of -1. + * @param worldX The X coordinate of the world position. + * @param worldY The Y coordinate of the world position. + * @param camera The Camera to use when factoring in which tiles to return. + * @param layer The Tilemap Layer to act upon. */ - getRightCenter(output?: O, includeParent?: boolean): O; + function HasTileAtWorldXY(worldX: number, worldY: number, camera: Phaser.Cameras.Scene2D.Camera, layer: Phaser.Tilemaps.LayerData): boolean; /** - * Gets the bottom-left corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * Returns the bounds in the given layer that are within the camera's viewport. + * This is used internally by the cull tiles function. + * @param layer The Tilemap Layer to act upon. + * @param camera The Camera to run the cull check against. */ - getBottomLeft(output?: O, includeParent?: boolean): O; + function HexagonalCullBounds(layer: Phaser.Tilemaps.LayerData, camera: Phaser.Cameras.Scene2D.Camera): object; /** - * Gets the bottom-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * Returns the tiles in the given layer that are within the cameras viewport. This is used internally. + * @param layer The Tilemap Layer to act upon. + * @param camera The Camera to run the cull check against. + * @param outputArray An optional array to store the Tile objects within. + * @param renderOrder The rendering order constant. Default 0. */ - getBottomCenter(output?: O, includeParent?: boolean): O; + function HexagonalCullTiles(layer: Phaser.Tilemaps.LayerData, camera: Phaser.Cameras.Scene2D.Camera, outputArray?: any[], renderOrder?: number): Phaser.Tilemaps.Tile[]; /** - * Gets the bottom-right corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * Converts from hexagonal tile XY coordinates (tile units) to world XY coordinates (pixels), factoring in the + * layer's position, scale and scroll. This will return a new Vector2 object or update the given + * `point` object. + * @param tileX The x coordinate, in tiles, not pixels. + * @param tileY The y coordinate, in tiles, not pixels. + * @param point A Vector2 to store the coordinates in. If not given a new Vector2 is created. + * @param camera The Camera to use when calculating the tile index from the world values. + * @param layer The Tilemap Layer to act upon. */ - getBottomRight(output?: O, includeParent?: boolean): O; + function HexagonalTileToWorldXY(tileX: number, tileY: number, point: Phaser.Math.Vector2, camera: Phaser.Cameras.Scene2D.Camera, layer: Phaser.Tilemaps.LayerData): Phaser.Math.Vector2; /** - * Gets the bounds of this Game Object, regardless of origin. - * The values are stored and returned in a Rectangle, or Rectangle-like, object. - * @param output An object to store the values in. If not provided a new Rectangle will be created. + * Converts from hexagonal tile Y coordinates (tile units) to world Y coordinates (pixels), factoring in the + * layer's position, scale and scroll. + * @param tileY The y coordinate, in tiles, not pixels. + * @param camera The Camera to use when calculating the tile index from the world values. + * @param layer The Tilemap Layer to act upon. */ - getBounds(output?: O): O; + function HexagonalTileToWorldY(tileY: number, camera: Phaser.Cameras.Scene2D.Camera, layer: Phaser.Tilemaps.LayerData): number; /** - * The horizontal origin of this Game Object. - * The origin maps the relationship between the size and position of the Game Object. - * The default value is 0.5, meaning all Game Objects are positioned based on their center. - * Setting the value to 0 means the position now relates to the left of the Game Object. + * Converts from world XY coordinates (pixels) to hexagonal tile XY coordinates (tile units), factoring in the + * layer's position, scale and scroll. This will return a new Vector2 object or update the given + * `point` object. + * @param worldX The x coordinate to be converted, in pixels, not tiles. + * @param worldY The y coordinate to be converted, in pixels, not tiles. + * @param snapToFloor Whether or not to round the tile coordinates down to the nearest integer. + * @param point A Vector2 to store the coordinates in. If not given a new Vector2 is created. + * @param camera The Camera to use when calculating the tile index from the world values. + * @param layer The Tilemap Layer to act upon. */ - originX: number; + function HexagonalWorldToTileXY(worldX: number, worldY: number, snapToFloor: boolean, point: Phaser.Math.Vector2, camera: Phaser.Cameras.Scene2D.Camera, layer: Phaser.Tilemaps.LayerData): Phaser.Math.Vector2; /** - * The vertical origin of this Game Object. - * The origin maps the relationship between the size and position of the Game Object. - * The default value is 0.5, meaning all Game Objects are positioned based on their center. - * Setting the value to 0 means the position now relates to the top of the Game Object. + * Converts from world Y coordinates (pixels) to hexagonal tile Y coordinates (tile units), factoring in the + * layers position, scale and scroll. + * @param worldY The y coordinate to be converted, in pixels, not tiles. + * @param snapToFloor Whether or not to round the tile coordinate down to the nearest integer. + * @param camera The Camera to use when calculating the tile index from the world values. + * @param layer The Tilemap Layer to act upon. */ - originY: number; + function HexagonalWorldToTileY(worldY: number, snapToFloor: boolean, camera: Phaser.Cameras.Scene2D.Camera, layer: Phaser.Tilemaps.LayerData): number; /** - * The horizontal display origin of this Game Object. - * The origin is a normalized value between 0 and 1. - * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. + * Checks if the given tile coordinates are within the bounds of the layer. + * @param tileX The x coordinate, in tiles, not pixels. + * @param tileY The y coordinate, in tiles, not pixels. + * @param layer The Tilemap Layer to act upon. */ - displayOriginX: number; + function IsInLayerBounds(tileX: number, tileY: number, layer: Phaser.Tilemaps.LayerData): boolean; /** - * The vertical display origin of this Game Object. - * The origin is a normalized value between 0 and 1. - * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. + * Returns the tiles in the given layer that are within the cameras viewport. This is used internally. + * @param layer The Tilemap Layer to act upon. + * @param camera The Camera to run the cull check against. + * @param outputArray An optional array to store the Tile objects within. + * @param renderOrder The rendering order constant. Default 0. */ - displayOriginY: number; + function IsometricCullTiles(layer: Phaser.Tilemaps.LayerData, camera: Phaser.Cameras.Scene2D.Camera, outputArray?: any[], renderOrder?: number): Phaser.Tilemaps.Tile[]; /** - * Sets the origin of this Game Object. - * - * The values are given in the range 0 to 1. - * @param x The horizontal origin value. Default 0.5. - * @param y The vertical origin value. If not defined it will be set to the value of `x`. Default x. + * Converts from isometric tile XY coordinates (tile units) to world XY coordinates (pixels), factoring in the + * layer's position, scale and scroll. This will return a new Vector2 object or update the given + * `point` object. + * @param tileX The x coordinate, in tiles, not pixels. + * @param tileY The y coordinate, in tiles, not pixels. + * @param point A Vector2 to store the coordinates in. If not given a new Vector2 is created. + * @param camera The Camera to use when calculating the tile index from the world values. + * @param layer The Tilemap Layer to act upon. */ - setOrigin(x?: number, y?: number): this; + function IsometricTileToWorldXY(tileX: number, tileY: number, point: Phaser.Math.Vector2, camera: Phaser.Cameras.Scene2D.Camera, layer: Phaser.Tilemaps.LayerData): Phaser.Math.Vector2; /** - * Sets the origin of this Game Object based on the Pivot values in its Frame. + * Converts from world XY coordinates (pixels) to isometric tile XY coordinates (tile units), factoring in the + * layer's position, scale and scroll. This will return a new Vector2 object or update the given + * `point` object. + * @param worldX The x coordinate to be converted, in pixels, not tiles. + * @param worldY The y coordinate to be converted, in pixels, not tiles. + * @param snapToFloor Whether or not to round the tile coordinate down to the nearest integer. + * @param point A Vector2 to store the coordinates in. If not given a new Vector2 is created. + * @param camera The Camera to use when calculating the tile index from the world values. + * @param layer The Tilemap Layer to act upon. */ - setOriginFromFrame(): this; + function IsometricWorldToTileXY(worldX: number, worldY: number, snapToFloor: boolean, point: Phaser.Math.Vector2, camera: Phaser.Cameras.Scene2D.Camera, layer: Phaser.Tilemaps.LayerData): Phaser.Math.Vector2; /** - * Sets the display origin of this Game Object. - * The difference between this and setting the origin is that you can use pixel values for setting the display origin. - * @param x The horizontal display origin value. Default 0. - * @param y The vertical display origin value. If not defined it will be set to the value of `x`. Default x. + * Puts a tile at the given tile coordinates in the specified layer. You can pass in either an index + * or a Tile object. If you pass in a Tile, all attributes will be copied over to the specified + * location. If you pass in an index, only the index at the specified location will be changed. + * Collision information will be recalculated at the specified location. + * @param tile The index of this tile to set or a Tile object. + * @param tileX The x coordinate, in tiles, not pixels. + * @param tileY The y coordinate, in tiles, not pixels. + * @param recalculateFaces `true` if the faces data should be recalculated. + * @param layer The Tilemap Layer to act upon. */ - setDisplayOrigin(x?: number, y?: number): this; + function PutTileAt(tile: number | Phaser.Tilemaps.Tile, tileX: number, tileY: number, recalculateFaces: boolean, layer: Phaser.Tilemaps.LayerData): Phaser.Tilemaps.Tile; /** - * Updates the Display Origin cached values internally stored on this Game Object. - * You don't usually call this directly, but it is exposed for edge-cases where you may. + * Puts a tile at the given world coordinates (pixels) in the specified layer. You can pass in either + * an index or a Tile object. If you pass in a Tile, all attributes will be copied over to the + * specified location. If you pass in an index, only the index at the specified location will be + * changed. Collision information will be recalculated at the specified location. + * @param tile The index of this tile to set or a Tile object. + * @param worldX The x coordinate, in pixels. + * @param worldY The y coordinate, in pixels. + * @param recalculateFaces `true` if the faces data should be recalculated. + * @param camera The Camera to use when calculating the tile index from the world values. + * @param layer The Tilemap Layer to act upon. */ - updateDisplayOrigin(): this; + function PutTileAtWorldXY(tile: number | Phaser.Tilemaps.Tile, worldX: number, worldY: number, recalculateFaces: boolean, camera: Phaser.Cameras.Scene2D.Camera, layer: Phaser.Tilemaps.LayerData): Phaser.Tilemaps.Tile; /** - * The initial WebGL pipeline of this Game Object. + * Puts an array of tiles or a 2D array of tiles at the given tile coordinates in the specified + * layer. The array can be composed of either tile indexes or Tile objects. If you pass in a Tile, + * all attributes will be copied over to the specified location. If you pass in an index, only the + * index at the specified location will be changed. Collision information will be recalculated + * within the region tiles were changed. + * @param tile A row (array) or grid (2D array) of Tiles or tile indexes to place. + * @param tileX The x coordinate, in tiles, not pixels. + * @param tileY The y coordinate, in tiles, not pixels. + * @param recalculateFaces `true` if the faces data should be recalculated. + * @param layer The Tilemap Layer to act upon. */ - defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; + function PutTilesAt(tile: number[] | number[][] | Phaser.Tilemaps.Tile[] | Phaser.Tilemaps.Tile[][], tileX: number, tileY: number, recalculateFaces: boolean, layer: Phaser.Tilemaps.LayerData): void; /** - * The current WebGL pipeline of this Game Object. + * Randomizes the indexes of a rectangular region of tiles (in tile coordinates) within the + * specified layer. Each tile will receive a new index. If an array of indexes is passed in, then + * those will be used for randomly assigning new tile indexes. If an array is not provided, the + * indexes found within the region (excluding -1) will be used for randomly assigning new tile + * indexes. This method only modifies tile indexes and does not change collision information. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. + * @param indexes An array of indexes to randomly draw from during randomization. + * @param layer The Tilemap Layer to act upon. */ - pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + function Randomize(tileX: number, tileY: number, width: number, height: number, indexes: number[], layer: Phaser.Tilemaps.LayerData): void; /** - * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. + * Removes the tile at the given tile coordinates in the specified layer and updates the layer's + * collision information. + * @param tileX The x coordinate. + * @param tileY The y coordinate. + * @param replaceWithNull If true, this will replace the tile at the specified location with null instead of a Tile with an index of -1. + * @param recalculateFaces `true` if the faces data should be recalculated. + * @param layer The Tilemap Layer to act upon. */ - initPipeline(pipelineName?: string): boolean; + function RemoveTileAt(tileX: number, tileY: number, replaceWithNull: boolean, recalculateFaces: boolean, layer: Phaser.Tilemaps.LayerData): Phaser.Tilemaps.Tile; /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. + * Removes the tile at the given world coordinates in the specified layer and updates the layer's + * collision information. + * @param worldX The x coordinate, in pixels. + * @param worldY The y coordinate, in pixels. + * @param replaceWithNull If true, this will replace the tile at the specified location with null instead of a Tile with an index of -1. + * @param recalculateFaces `true` if the faces data should be recalculated. + * @param camera The Camera to use when calculating the tile index from the world values. + * @param layer The Tilemap Layer to act upon. */ - setPipeline(pipelineName: string): this; + function RemoveTileAtWorldXY(worldX: number, worldY: number, replaceWithNull: boolean, recalculateFaces: boolean, camera: Phaser.Cameras.Scene2D.Camera, layer: Phaser.Tilemaps.LayerData): Phaser.Tilemaps.Tile; /** - * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * Draws a debug representation of the layer to the given Graphics. This is helpful when you want to + * get a quick idea of which of your tiles are colliding and which have interesting faces. The tiles + * are drawn starting at (0, 0) in the Graphics, allowing you to place the debug representation + * wherever you want on the screen. + * @param graphics The target Graphics object to draw upon. + * @param styleConfig An object specifying the colors to use for the debug drawing. + * @param layer The Tilemap Layer to act upon. */ - resetPipeline(): boolean; + function RenderDebug(graphics: Phaser.GameObjects.Graphics, styleConfig: Phaser.Types.Tilemaps.DebugStyleOptions, layer: Phaser.Tilemaps.LayerData): void; /** - * Gets the name of the WebGL Pipeline this Game Object is currently using. + * Scans the given rectangular area (given in tile coordinates) for tiles with an index matching + * `findIndex` and updates their index to match `newIndex`. This only modifies the index and does + * not change collision information. + * @param findIndex The index of the tile to search for. + * @param newIndex The index of the tile to replace it with. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. + * @param layer The Tilemap Layer to act upon. */ - getPipelineName(): string; + function ReplaceByIndex(findIndex: number, newIndex: number, tileX: number, tileY: number, width: number, height: number, layer: Phaser.Tilemaps.LayerData): void; /** - * The horizontal scroll factor of this Game Object. - * - * The scroll factor controls the influence of the movement of a Camera upon this Game Object. - * - * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. - * It does not change the Game Objects actual position values. - * - * A value of 1 means it will move exactly in sync with a camera. - * A value of 0 means it will not move at all, even if the camera moves. - * Other values control the degree to which the camera movement is mapped to this Game Object. - * - * Please be aware that scroll factor values other than 1 are not taken in to consideration when - * calculating physics collisions. Bodies always collide based on their world position, but changing - * the scroll factor is a visual adjustment to where the textures are rendered, which can offset - * them from physics bodies if not accounted for in your code. + * Returns the tiles in the given layer that are within the cameras viewport. This is used internally. + * @param layer The Tilemap Layer to act upon. + * @param bounds An object containing the `left`, `right`, `top` and `bottom` bounds. + * @param renderOrder The rendering order constant. + * @param outputArray The array to store the Tile objects within. */ - scrollFactorX: number; + function RunCull(layer: Phaser.Tilemaps.LayerData, bounds: object, renderOrder: number, outputArray: any[]): Phaser.Tilemaps.Tile[]; /** - * The vertical scroll factor of this Game Object. - * - * The scroll factor controls the influence of the movement of a Camera upon this Game Object. - * - * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. - * It does not change the Game Objects actual position values. - * - * A value of 1 means it will move exactly in sync with a camera. - * A value of 0 means it will not move at all, even if the camera moves. - * Other values control the degree to which the camera movement is mapped to this Game Object. - * - * Please be aware that scroll factor values other than 1 are not taken in to consideration when - * calculating physics collisions. Bodies always collide based on their world position, but changing - * the scroll factor is a visual adjustment to where the textures are rendered, which can offset - * them from physics bodies if not accounted for in your code. + * Sets collision on the given tile or tiles within a layer by index. You can pass in either a + * single numeric index or an array of indexes: [2, 3, 15, 20]. The `collides` parameter controls if + * collision will be enabled (true) or disabled (false). + * @param indexes Either a single tile index, or an array of tile indexes. + * @param collides If true it will enable collision. If false it will clear collision. + * @param recalculateFaces Whether or not to recalculate the tile faces after the update. + * @param layer The Tilemap Layer to act upon. + * @param updateLayer If true, updates the current tiles on the layer. Set to false if no tiles have been placed for significant performance boost. Default true. */ - scrollFactorY: number; + function SetCollision(indexes: number | any[], collides: boolean, recalculateFaces: boolean, layer: Phaser.Tilemaps.LayerData, updateLayer?: boolean): void; /** - * Sets the scroll factor of this Game Object. - * - * The scroll factor controls the influence of the movement of a Camera upon this Game Object. - * - * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. - * It does not change the Game Objects actual position values. - * - * A value of 1 means it will move exactly in sync with a camera. - * A value of 0 means it will not move at all, even if the camera moves. - * Other values control the degree to which the camera movement is mapped to this Game Object. - * - * Please be aware that scroll factor values other than 1 are not taken in to consideration when - * calculating physics collisions. Bodies always collide based on their world position, but changing - * the scroll factor is a visual adjustment to where the textures are rendered, which can offset - * them from physics bodies if not accounted for in your code. - * @param x The horizontal scroll factor of this Game Object. - * @param y The vertical scroll factor of this Game Object. If not set it will use the `x` value. Default x. + * Sets collision on a range of tiles in a layer whose index is between the specified `start` and + * `stop` (inclusive). Calling this with a start value of 10 and a stop value of 14 would set + * collision for tiles 10, 11, 12, 13 and 14. The `collides` parameter controls if collision will be + * enabled (true) or disabled (false). + * @param start The first index of the tile to be set for collision. + * @param stop The last index of the tile to be set for collision. + * @param collides If true it will enable collision. If false it will clear collision. + * @param recalculateFaces Whether or not to recalculate the tile faces after the update. + * @param layer The Tilemap Layer to act upon. + * @param updateLayer If true, updates the current tiles on the layer. Set to false if no tiles have been placed for significant performance boost. Default true. */ - setScrollFactor(x: number, y?: number): this; + function SetCollisionBetween(start: number, stop: number, collides: boolean, recalculateFaces: boolean, layer: Phaser.Tilemaps.LayerData, updateLayer?: boolean): void; /** - * The x position of this Game Object. + * Sets collision on all tiles in the given layer, except for tiles that have an index specified in + * the given array. The `collides` parameter controls if collision will be enabled (true) or + * disabled (false). Tile indexes not currently in the layer are not affected. + * @param indexes An array of the tile indexes to not be counted for collision. + * @param collides If true it will enable collision. If false it will clear collision. + * @param recalculateFaces Whether or not to recalculate the tile faces after the update. + * @param layer The Tilemap Layer to act upon. */ - x: number; + function SetCollisionByExclusion(indexes: number[], collides: boolean, recalculateFaces: boolean, layer: Phaser.Tilemaps.LayerData): void; /** - * The y position of this Game Object. + * Sets collision on the tiles within a layer by checking tile properties. If a tile has a property + * that matches the given properties object, its collision flag will be set. The `collides` + * parameter controls if collision will be enabled (true) or disabled (false). Passing in + * `{ collides: true }` would update the collision flag on any tiles with a "collides" property that + * has a value of true. Any tile that doesn't have "collides" set to true will be ignored. You can + * also use an array of values, e.g. `{ types: ["stone", "lava", "sand" ] }`. If a tile has a + * "types" property that matches any of those values, its collision flag will be updated. + * @param properties An object with tile properties and corresponding values that should be checked. + * @param collides If true it will enable collision. If false it will clear collision. + * @param recalculateFaces Whether or not to recalculate the tile faces after the update. + * @param layer The Tilemap Layer to act upon. */ - y: number; + function SetCollisionByProperty(properties: object, collides: boolean, recalculateFaces: boolean, layer: Phaser.Tilemaps.LayerData): void; /** - * The z position of this Game Object. - * - * Note: The z position does not control the rendering order of 2D Game Objects. Use - * {@link Phaser.GameObjects.Components.Depth#depth} instead. + * Sets collision on the tiles within a layer by checking each tile's collision group data + * (typically defined in Tiled within the tileset collision editor). If any objects are found within + * a tile's collision group, the tile's colliding information will be set. The `collides` parameter + * controls if collision will be enabled (true) or disabled (false). + * @param collides If true it will enable collision. If false it will clear collision. + * @param recalculateFaces Whether or not to recalculate the tile faces after the update. + * @param layer The Tilemap Layer to act upon. */ - z: number; + function SetCollisionFromCollisionGroup(collides: boolean, recalculateFaces: boolean, layer: Phaser.Tilemaps.LayerData): void; /** - * The w position of this Game Object. + * Internally used method to keep track of the tile indexes that collide within a layer. This + * updates LayerData.collideIndexes to either contain or not contain the given `tileIndex`. + * @param tileIndex The tile index to set the collision boolean for. + * @param collides Should the tile index collide or not? + * @param layer The Tilemap Layer to act upon. */ - w: number; + function SetLayerCollisionIndex(tileIndex: number, collides: boolean, layer: Phaser.Tilemaps.LayerData): void; /** - * This is a special setter that allows you to set both the horizontal and vertical scale of this Game Object - * to the same value, at the same time. When reading this value the result returned is `(scaleX + scaleY) / 2`. - * - * Use of this property implies you wish the horizontal and vertical scales to be equal to each other. If this - * isn't the case, use the `scaleX` or `scaleY` properties instead. + * Internally used method to set the colliding state of a tile. This does not recalculate + * interesting faces. + * @param tile The Tile to set the collision on. + * @param collides Should the tile index collide or not? Default true. */ - scale: number; + function SetTileCollision(tile: Phaser.Tilemaps.Tile, collides?: boolean): void; /** - * The horizontal scale of this Game Object. + * Sets a global collision callback for the given tile index within the layer. This will affect all + * tiles on this layer that have the same index. If a callback is already set for the tile index it + * will be replaced. Set the callback to null to remove it. If you want to set a callback for a tile + * at a specific location on the map then see setTileLocationCallback. + * @param indexes Either a single tile index, or an array of tile indexes to have a collision callback set for. + * @param callback The callback that will be invoked when the tile is collided with. + * @param callbackContext The context under which the callback is called. + * @param layer The Tilemap Layer to act upon. */ - scaleX: number; + function SetTileIndexCallback(indexes: number | any[], callback: Function, callbackContext: object, layer: Phaser.Tilemaps.LayerData): void; /** - * The vertical scale of this Game Object. + * Sets a collision callback for the given rectangular area (in tile coordinates) within the layer. + * If a callback is already set for the tile index it will be replaced. Set the callback to null to + * remove it. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. + * @param callback The callback that will be invoked when the tile is collided with. + * @param callbackContext The context under which the callback is called. + * @param layer The Tilemap Layer to act upon. */ - scaleY: number; + function SetTileLocationCallback(tileX: number, tileY: number, width: number, height: number, callback: Function, callbackContext: object, layer: Phaser.Tilemaps.LayerData): void; /** - * The angle of this Game Object as expressed in degrees. - * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. - * - * If you prefer to work in radians, see the `rotation` property instead. + * Shuffles the tiles in a rectangular region (specified in tile coordinates) within the given + * layer. It will only randomize the tiles in that area, so if they're all the same nothing will + * appear to have changed! This method only modifies tile indexes and does not change collision + * information. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. + * @param layer The Tilemap Layer to act upon. */ - angle: integer; + function Shuffle(tileX: number, tileY: number, width: number, height: number, layer: Phaser.Tilemaps.LayerData): void; /** - * The angle of this Game Object in radians. - * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. - * - * If you prefer to work in degrees, see the `angle` property instead. + * Returns the bounds in the given layer that are within the camera's viewport. + * This is used internally by the cull tiles function. + * @param layer The Tilemap Layer to act upon. + * @param camera The Camera to run the cull check against. */ - rotation: number; + function StaggeredCullBounds(layer: Phaser.Tilemaps.LayerData, camera: Phaser.Cameras.Scene2D.Camera): object; /** - * Sets the position of this Game Object. - * @param x The x position of this Game Object. Default 0. - * @param y The y position of this Game Object. If not set it will use the `x` value. Default x. - * @param z The z position of this Game Object. Default 0. - * @param w The w position of this Game Object. Default 0. + * Returns the tiles in the given layer that are within the cameras viewport. This is used internally. + * @param layer The Tilemap Layer to act upon. + * @param camera The Camera to run the cull check against. + * @param outputArray An optional array to store the Tile objects within. + * @param renderOrder The rendering order constant. Default 0. */ - setPosition(x?: number, y?: number, z?: number, w?: number): this; + function StaggeredCullTiles(layer: Phaser.Tilemaps.LayerData, camera: Phaser.Cameras.Scene2D.Camera, outputArray?: any[], renderOrder?: number): Phaser.Tilemaps.Tile[]; /** - * Sets the position of this Game Object to be a random position within the confines of - * the given area. - * - * If no area is specified a random position between 0 x 0 and the game width x height is used instead. - * - * The position does not factor in the size of this Game Object, meaning that only the origin is - * guaranteed to be within the area. - * @param x The x position of the top-left of the random area. Default 0. - * @param y The y position of the top-left of the random area. Default 0. - * @param width The width of the random area. - * @param height The height of the random area. + * Converts from staggered tile XY coordinates (tile units) to world XY coordinates (pixels), factoring in the + * layer's position, scale and scroll. This will return a new Vector2 object or update the given + * `point` object. + * @param tileX The x coordinate, in tiles, not pixels. + * @param tileY The y coordinate, in tiles, not pixels. + * @param point A Vector2 to store the coordinates in. If not given a new Vector2 is created. + * @param camera The Camera to use when calculating the tile index from the world values. + * @param layer The Tilemap Layer to act upon. */ - setRandomPosition(x?: number, y?: number, width?: number, height?: number): this; + function StaggeredTileToWorldXY(tileX: number, tileY: number, point: Phaser.Math.Vector2, camera: Phaser.Cameras.Scene2D.Camera, layer: Phaser.Tilemaps.LayerData): Phaser.Math.Vector2; /** - * Sets the rotation of this Game Object. - * @param radians The rotation of this Game Object, in radians. Default 0. + * Converts from staggered tile Y coordinates (tile units) to world Y coordinates (pixels), factoring in the + * layers position, scale and scroll. + * @param tileY The y coordinate, in tiles, not pixels. + * @param camera The Camera to use when calculating the tile index from the world values. + * @param layer The Tilemap Layer to act upon. */ - setRotation(radians?: number): this; + function StaggeredTileToWorldY(tileY: number, camera: Phaser.Cameras.Scene2D.Camera, layer: Phaser.Tilemaps.LayerData): number; /** - * Sets the angle of this Game Object. - * @param degrees The rotation of this Game Object, in degrees. Default 0. + * Converts from world XY coordinates (pixels) to staggered tile XY coordinates (tile units), factoring in the + * layer's position, scale and scroll. This will return a new Vector2 object or update the given + * `point` object. + * @param worldX The x coordinate to be converted, in pixels, not tiles. + * @param worldY The y coordinate to be converted, in pixels, not tiles. + * @param snapToFloor Whether or not to round the tile coordinate down to the nearest integer. + * @param point A Vector2 to store the coordinates in. If not given a new Vector2 is created. + * @param camera The Camera to use when calculating the tile index from the world values. + * @param layer The Tilemap Layer to act upon. */ - setAngle(degrees?: number): this; + function StaggeredWorldToTileXY(worldX: number, worldY: number, snapToFloor: boolean, point: Phaser.Math.Vector2, camera: Phaser.Cameras.Scene2D.Camera, layer: Phaser.Tilemaps.LayerData): Phaser.Math.Vector2; /** - * Sets the scale of this Game Object. - * @param x The horizontal scale of this Game Object. - * @param y The vertical scale of this Game Object. If not set it will use the `x` value. Default x. + * Converts from world Y coordinates (pixels) to staggered tile Y coordinates (tile units), factoring in the + * layers position, scale and scroll. + * @param worldY The y coordinate to be converted, in pixels, not tiles. + * @param snapToFloor Whether or not to round the tile coordinate down to the nearest integer. + * @param camera The Camera to use when calculating the tile index from the world values. + * @param layer The Tilemap Layer to act upon. */ - setScale(x: number, y?: number): this; + function StaggeredWorldToTileY(worldY: number, snapToFloor: boolean, camera: Phaser.Cameras.Scene2D.Camera, layer: Phaser.Tilemaps.LayerData): number; /** - * Sets the x position of this Game Object. - * @param value The x position of this Game Object. Default 0. + * Scans the given rectangular area (given in tile coordinates) for tiles with an index matching + * `indexA` and swaps then with `indexB`. This only modifies the index and does not change collision + * information. + * @param tileA First tile index. + * @param tileB Second tile index. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. + * @param layer The Tilemap Layer to act upon. */ - setX(value?: number): this; + function SwapByIndex(tileA: number, tileB: number, tileX: number, tileY: number, width: number, height: number, layer: Phaser.Tilemaps.LayerData): void; /** - * Sets the y position of this Game Object. - * @param value The y position of this Game Object. Default 0. + * Converts from tile X coordinates (tile units) to world X coordinates (pixels), factoring in the + * layer's position, scale and scroll. + * @param tileX The x coordinate, in tiles, not pixels. + * @param camera The Camera to use when calculating the tile index from the world values. + * @param layer The Tilemap Layer to act upon. */ - setY(value?: number): this; + function TileToWorldX(tileX: number, camera: Phaser.Cameras.Scene2D.Camera, layer: Phaser.Tilemaps.LayerData): number; /** - * Sets the z position of this Game Object. - * - * Note: The z position does not control the rendering order of 2D Game Objects. Use - * {@link Phaser.GameObjects.Components.Depth#setDepth} instead. - * @param value The z position of this Game Object. Default 0. + * Converts from tile XY coordinates (tile units) to world XY coordinates (pixels), factoring in the + * layer's position, scale and scroll. This will return a new Vector2 object or update the given + * `point` object. + * @param tileX The x coordinate, in tiles, not pixels. + * @param tileY The y coordinate, in tiles, not pixels. + * @param point A Vector2 to store the coordinates in. If not given a new Vector2 is created. + * @param camera The Camera to use when calculating the tile index from the world values. + * @param layer The Tilemap Layer to act upon. */ - setZ(value?: number): this; + function TileToWorldXY(tileX: number, tileY: number, point: Phaser.Math.Vector2, camera: Phaser.Cameras.Scene2D.Camera, layer: Phaser.Tilemaps.LayerData): Phaser.Math.Vector2; /** - * Sets the w position of this Game Object. - * @param value The w position of this Game Object. Default 0. + * Converts from tile Y coordinates (tile units) to world Y coordinates (pixels), factoring in the + * layer's position, scale and scroll. + * @param tileY The y coordinate, in tiles, not pixels. + * @param camera The Camera to use when calculating the tile index from the world values. + * @param layer The Tilemap Layer to act upon. */ - setW(value?: number): this; + function TileToWorldY(tileY: number, camera: Phaser.Cameras.Scene2D.Camera, layer: Phaser.Tilemaps.LayerData): number; /** - * Gets the local transform matrix for this Game Object. - * @param tempMatrix The matrix to populate with the values from this Game Object. + * Randomizes the indexes of a rectangular region of tiles (in tile coordinates) within the + * specified layer. Each tile will receive a new index. New indexes are drawn from the given + * weightedIndexes array. An example weighted array: + * + * [ + * { index: 6, weight: 4 }, // Probability of index 6 is 4 / 8 + * { index: 7, weight: 2 }, // Probability of index 7 would be 2 / 8 + * { index: 8, weight: 1.5 }, // Probability of index 8 would be 1.5 / 8 + * { index: 26, weight: 0.5 } // Probability of index 27 would be 0.5 / 8 + * ] + * + * The probability of any index being choose is (the index's weight) / (sum of all weights). This + * method only modifies tile indexes and does not change collision information. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. + * @param weightedIndexes An array of objects to randomly draw from during + * randomization. They should be in the form: { index: 0, weight: 4 } or + * { index: [0, 1], weight: 4 } if you wish to draw from multiple tile indexes. + * @param layer The Tilemap Layer to act upon. */ - getLocalTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + function WeightedRandomize(tileX: number, tileY: number, width: number, height: number, weightedIndexes: object[], layer: Phaser.Tilemaps.LayerData): void; /** - * Gets the world transform matrix for this Game Object, factoring in any parent Containers. - * @param tempMatrix The matrix to populate with the values from this Game Object. - * @param parentMatrix A temporary matrix to hold parent values during the calculations. + * Converts from world X coordinates (pixels) to tile X coordinates (tile units), factoring in the + * layer's position, scale and scroll. + * @param worldX The x coordinate to be converted, in pixels, not tiles. + * @param snapToFloor Whether or not to round the tile coordinate down to the nearest integer. + * @param camera The Camera to use when calculating the tile index from the world values. + * @param layer The Tilemap Layer to act upon. */ - getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + function WorldToTileX(worldX: number, snapToFloor: boolean, camera: Phaser.Cameras.Scene2D.Camera, layer: Phaser.Tilemaps.LayerData): number; /** - * Gets the sum total rotation of all of this Game Objects parent Containers. - * - * The returned value is in radians and will be zero if this Game Object has no parent container. + * Converts from world XY coordinates (pixels) to tile XY coordinates (tile units), factoring in the + * layer's position, scale and scroll. This will return a new Vector2 object or update the given + * `point` object. + * @param worldX The x coordinate to be converted, in pixels, not tiles. + * @param worldY The y coordinate to be converted, in pixels, not tiles. + * @param snapToFloor Whether or not to round the tile coordinate down to the nearest integer. + * @param point A Vector2 to store the coordinates in. If not given a new Vector2 is created. + * @param camera The Camera to use when calculating the tile index from the world values. + * @param layer The Tilemap Layer to act upon. */ - getParentRotation(): number; + function WorldToTileXY(worldX: number, worldY: number, snapToFloor: boolean, point: Phaser.Math.Vector2, camera: Phaser.Cameras.Scene2D.Camera, layer: Phaser.Tilemaps.LayerData): Phaser.Math.Vector2; /** - * The visible state of the Game Object. - * - * An invisible Game Object will skip rendering, but will still process update logic. + * Converts from world Y coordinates (pixels) to tile Y coordinates (tile units), factoring in the + * layer's position, scale and scroll. + * @param worldY The y coordinate to be converted, in pixels, not tiles. + * @param snapToFloor Whether or not to round the tile coordinate down to the nearest integer. + * @param camera The Camera to use when calculating the tile index from the world values. + * @param layer The Tilemap Layer to act upon. */ - visible: boolean; + function WorldToTileY(worldY: number, snapToFloor: boolean, camera: Phaser.Cameras.Scene2D.Camera, layer: Phaser.Tilemaps.LayerData): number; + } + + /** + * Phaser Tilemap constants for orientation. + */ + enum Orientation { /** - * Sets the visibility of this Game Object. - * - * An invisible Game Object will skip rendering, but will still process update logic. - * @param value The visible state of the Game Object. + * Orthogonal Tilemap orientation constant. + */ + ORTHOGONAL, + /** + * Isometric Tilemap orientation constant. + */ + ISOMETRIC, + /** + * Staggered Tilemap orientation constant. */ - setVisible(value: boolean): this; - + STAGGERED, + /** + * Hexagonal Tilemap orientation constant. + */ + HEXAGONAL, } + /** + * Phaser Tilemap constants for orientation. + * + * To find out what each mode does please see [Phaser.Tilemaps.Orientation]{@link Phaser.Tilemaps.Orientation}. + */ + type OrientationType = Phaser.Tilemaps.Orientation; + namespace Formats { /** * CSV Map Type @@ -82158,7 +89979,7 @@ declare namespace Phaser { * @param spacing The spacing between each image in the collection (in pixels). Default 0. * @param properties Custom Image Collection properties. Default {}. */ - constructor(name: string, firstgid: integer, width?: integer, height?: integer, margin?: integer, spacing?: integer, properties?: object); + constructor(name: string, firstgid: number, width?: number, height?: number, margin?: number, spacing?: number, properties?: object); /** * The name of the Image Collection. @@ -82169,29 +89990,29 @@ declare namespace Phaser { * The Tiled firstgid value. * This is the starting index of the first image index this Image Collection contains. */ - firstgid: integer; + firstgid: number; /** * The width of the widest image (in pixels). */ - readonly imageWidth: integer; + readonly imageWidth: number; /** * The height of the tallest image (in pixels). */ - readonly imageHeight: integer; + readonly imageHeight: number; /** * The margin around the images in the collection (in pixels). * Use `setSpacing` to change. */ - readonly imageMarge: integer; + readonly imageMarge: number; /** * The spacing between each image in the collection (in pixels). * Use `setSpacing` to change. */ - readonly imageSpacing: integer; + readonly imageSpacing: number; /** * Image Collection-specific properties that are typically defined in the Tiled editor. @@ -82206,34 +90027,34 @@ declare namespace Phaser { /** * The total number of images in the image collection. */ - readonly total: integer; + readonly total: number; /** * Returns true if and only if this image collection contains the given image index. * @param imageIndex The image index to search for. */ - containsImageIndex(imageIndex: integer): boolean; + containsImageIndex(imageIndex: number): boolean; /** * Add an image to this Image Collection. * @param gid The gid of the image in the Image Collection. * @param image The the key of the image in the Image Collection and in the cache. */ - addImage(gid: integer, image: string): Phaser.Tilemaps.ImageCollection; + addImage(gid: number, image: string): Phaser.Tilemaps.ImageCollection; } /** * A class for representing data about about a layer in a map. Maps are parsed from CSV, Tiled, - * etc. into this format. Tilemap, StaticTilemapLayer and DynamicTilemapLayer have a reference + * etc. into this format. Tilemap and TilemapLayer objects have a reference * to this data and use it to look up and perform operations on tiles. */ class LayerData { /** * - * @param config [description] + * @param config The Layer Data configuration object. */ - constructor(config?: object); + constructor(config?: Phaser.Types.Tilemaps.LayerDataConfig); /** * The name of the layer, if specified in Tiled. @@ -82241,22 +90062,22 @@ declare namespace Phaser { name: string; /** - * The x offset of where to draw from the top left + * The x offset of where to draw from the top left. */ x: number; /** - * The y offset of where to draw from the top left + * The y offset of where to draw from the top left. */ y: number; /** - * The width in tile of the layer. + * The width of the layer in tiles. */ width: number; /** - * The height in tiles of the layer. + * The height of the layer in tiles. */ height: number; @@ -82271,15 +90092,20 @@ declare namespace Phaser { tileHeight: number; /** - * [description] + * The base tile width. */ baseTileWidth: number; /** - * [description] + * The base tile height. */ baseTileHeight: number; + /** + * The layers orientation, necessary to be able to determine a tiles pixelX and pixelY as well as the layers width and height. + */ + orientation: Phaser.Tilemaps.OrientationType; + /** * The width in pixels of the entire layer. */ @@ -82291,49 +90117,55 @@ declare namespace Phaser { heightInPixels: number; /** - * [description] + * The alpha value of the layer. */ alpha: number; /** - * [description] + * Is the layer visible or not? */ visible: boolean; /** * Layer specific properties (can be specified in Tiled) */ - properties: object; + properties: object[]; /** - * [description] + * Tile ID index map. */ indexes: any[]; /** - * [description] + * Tile Collision ID index map. */ collideIndexes: any[]; /** - * [description] + * An array of callbacks. */ callbacks: any[]; /** - * [description] + * An array of physics bodies. */ bodies: any[]; /** - * An array of the tile indexes + * An array of the tile data indexes. */ data: Phaser.Tilemaps.Tile[][]; /** - * [description] + * A reference to the Tilemap layer that owns this data. + */ + tilemapLayer: Phaser.Tilemaps.TilemapLayer; + + /** + * The length of the horizontal sides of the hexagon. + * Only used for hexagonal orientation Tilemaps. */ - tilemapLayer: Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer; + hexSideLength: number; } @@ -82390,14 +90222,14 @@ declare namespace Phaser { heightInPixels: number; /** - * [description] + * The format of the map data. */ - format: integer; + format: number; /** * The orientation of the map data (i.e. orthogonal, isometric, hexagonal), default 'orthogonal'. */ - orientation: string; + orientation: Phaser.Tilemaps.OrientationType; /** * Determines the draw order of tilemap. Default is right-down @@ -82450,10 +90282,16 @@ declare namespace Phaser { imageCollections: any[]; /** - * [description] + * An array of tile instances. */ tiles: any[]; + /** + * The length of the horizontal sides of the hexagon. + * Only used for hexagonal orientation Tilemaps. + */ + hexSideLength: number; + } /** @@ -82525,17 +90363,24 @@ declare namespace Phaser { } namespace Parsers { + /** + * Get the Tilemap orientation from the given string. + * @param orientation The orientation type as a string. + */ + function FromOrientationString(orientation?: string): Phaser.Tilemaps.OrientationType; + namespace Impact { /** - * [description] - * @param json [description] - * @param insertNull [description] + * Parses all tilemap layers in an Impact JSON object into new LayerData objects. + * @param json The Impact JSON object. + * @param insertNull Controls how empty tiles, tiles with an index of -1, in the map + * data are handled (see {@link Phaser.Tilemaps.Parsers.Tiled.ParseJSONTiled}). */ - function ParseTileLayers(json: object, insertNull: boolean): any[]; + function ParseTileLayers(json: object, insertNull: boolean): Phaser.Tilemaps.LayerData[]; /** - * [description] - * @param json [description] + * Tilesets and Image Collections + * @param json The Impact JSON data. */ function ParseTilesets(json: object): any[]; @@ -82550,7 +90395,7 @@ declare namespace Phaser { * consumption. However if your map is small or you need to update the tiles dynamically, then leave * the default value set. */ - function ParseWeltmeister(name: string, json: object, insertNull: boolean): object; + function ParseWeltmeister(name: string, json: object, insertNull: boolean): Phaser.Tilemaps.MapData; } @@ -82573,7 +90418,7 @@ declare namespace Phaser { * consumption. However if your map is small or you need to update the tiles dynamically, then leave * the default value set. */ - function Parse(name: string, mapFormat: integer, data: integer[][] | string | object, tileWidth: integer, tileHeight: integer, insertNull: boolean): Phaser.Tilemaps.MapData; + function Parse(name: string, mapFormat: number, data: number[][] | string | object, tileWidth: number, tileHeight: number, insertNull: boolean): Phaser.Tilemaps.MapData; /** * Parses a 2D array of tile indexes into a new MapData object with a single layer. @@ -82588,7 +90433,7 @@ declare namespace Phaser { * consumption. However if your map is small or you need to update the tiles dynamically, then leave * the default value set. */ - function Parse2DArray(name: string, data: integer[][], tileWidth: integer, tileHeight: integer, insertNull: boolean): Phaser.Tilemaps.MapData; + function Parse2DArray(name: string, data: number[][], tileWidth: number, tileHeight: number, insertNull: boolean): Phaser.Tilemaps.MapData; /** * Parses a CSV string of tile indexes into a new MapData object with a single layer. @@ -82603,12 +90448,12 @@ declare namespace Phaser { * consumption. However if your map is small or you need to update the tiles dynamically, then leave * the default value set. */ - function ParseCSV(name: string, data: string, tileWidth: integer, tileHeight: integer, insertNull: boolean): Phaser.Tilemaps.MapData; + function ParseCSV(name: string, data: string, tileWidth: number, tileHeight: number, insertNull: boolean): Phaser.Tilemaps.MapData; namespace Tiled { /** * Copy properties from tileset to tiles. - * @param mapData [description] + * @param mapData The Map Data object. */ function AssignTileProperties(mapData: Phaser.Tilemaps.MapData): void; @@ -82620,7 +90465,7 @@ declare namespace Phaser { /** * Master list of tiles -> x, y, index in tileset. - * @param mapData [description] + * @param mapData The Map Data object. */ function BuildTilesetIndex(mapData: Phaser.Tilemaps.MapData): any[]; @@ -82635,9 +90480,9 @@ declare namespace Phaser { /** * See Tiled documentation on tile flipping: * http://docs.mapeditor.org/en/latest/reference/tmx-map-format/ - * @param gid [description] + * @param gid A Tiled GID. */ - function ParseGID(gid: number): object; + function ParseGID(gid: number): Phaser.Types.Tilemaps.GIDData; /** * Parses a Tiled JSON object into an array of objects with details about the image layers. @@ -82682,7 +90527,7 @@ declare namespace Phaser { /** * Tilesets and Image Collections - * @param json [description] + * @param json The Tiled JSON data. */ function ParseTilesets(json: object): object; @@ -82710,703 +90555,402 @@ declare namespace Phaser { * consumption. However if your map is small or you need to update the tiles dynamically, then leave * the default value set. Default false. */ - function ParseToTilemap(scene: Phaser.Scene, key?: string, tileWidth?: integer, tileHeight?: integer, width?: integer, height?: integer, data?: integer[][], insertNull?: boolean): Phaser.Tilemaps.Tilemap; + function ParseToTilemap(scene: Phaser.Scene, key?: string, tileWidth?: number, tileHeight?: number, width?: number, height?: number, data?: number[][], insertNull?: boolean): Phaser.Tilemaps.Tilemap; /** - * A Static Tilemap Layer is a Game Object that renders LayerData from a Tilemap when used in combination - * with one, or more, Tilesets. - * - * A Static Tilemap Layer is optimized for rendering speed over flexibility. You cannot apply per-tile - * effects like tint or alpha, or change the tiles or tilesets the layer uses. - * - * Use a Static Tilemap Layer instead of a Dynamic Tilemap Layer when you don't need tile manipulation features. + * A Tile is a representation of a single tile within the Tilemap. This is a lightweight data + * representation, so its position information is stored without factoring in scroll, layer + * scale or layer position. */ - class StaticTilemapLayer extends Phaser.GameObjects.GameObject implements Phaser.GameObjects.Components.Alpha, Phaser.GameObjects.Components.BlendMode, Phaser.GameObjects.Components.ComputedSize, Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.Flip, Phaser.GameObjects.Components.GetBounds, Phaser.GameObjects.Components.Origin, Phaser.GameObjects.Components.Pipeline, Phaser.GameObjects.Components.Transform, Phaser.GameObjects.Components.Visible, Phaser.GameObjects.Components.ScrollFactor { + class Tile implements Phaser.GameObjects.Components.Alpha, Phaser.GameObjects.Components.Flip, Phaser.GameObjects.Components.Visible { /** * - * @param scene The Scene to which this Game Object belongs. - * @param tilemap The Tilemap this layer is a part of. - * @param layerIndex The index of the LayerData associated with this layer. - * @param tileset The tileset, or an array of tilesets, used to render this layer. Can be a string or a Tileset object. - * @param x The world x position where the top left of this layer will be placed. Default 0. - * @param y The world y position where the top left of this layer will be placed. Default 0. - */ - constructor(scene: Phaser.Scene, tilemap: Phaser.Tilemaps.Tilemap, layerIndex: integer, tileset: string | string[] | Phaser.Tilemaps.Tileset | Phaser.Tilemaps.Tileset[], x?: number, y?: number); - - /** - * Used internally by physics system to perform fast type checks. - */ - readonly isTilemap: boolean; - - /** - * The Tilemap that this layer is a part of. - */ - tilemap: Phaser.Tilemaps.Tilemap; - - /** - * The index of the LayerData associated with this layer. + * @param layer The LayerData object in the Tilemap that this tile belongs to. + * @param index The unique index of this tile within the map. + * @param x The x coordinate of this tile in tile coordinates. + * @param y The y coordinate of this tile in tile coordinates. + * @param width Width of the tile in pixels. + * @param height Height of the tile in pixels. + * @param baseWidth The base width a tile in the map (in pixels). Tiled maps support + * multiple tileset sizes within one map, but they are still placed at intervals of the base + * tile width. + * @param baseHeight The base height of the tile in pixels (in pixels). Tiled maps + * support multiple tileset sizes within one map, but they are still placed at intervals of the + * base tile height. */ - layerIndex: integer; + constructor(layer: Phaser.Tilemaps.LayerData, index: number, x: number, y: number, width: number, height: number, baseWidth: number, baseHeight: number); /** - * The LayerData associated with this layer. LayerData can only be associated with one - * tilemap layer. + * The LayerData in the Tilemap data that this tile belongs to. */ layer: Phaser.Tilemaps.LayerData; /** - * The Tileset/s associated with this layer. - * - * As of Phaser 3.14 this property is now an array of Tileset objects, previously it was a single reference. - */ - tileset: Phaser.Tilemaps.Tileset[]; - - /** - * Used internally by the Canvas renderer. - * This holds the tiles that are visible within the camera in the last frame. + * The index of this tile within the map data corresponding to the tileset, or -1 if this + * represents a blank tile. */ - culledTiles: any[]; + index: number; /** - * Canvas only. - * - * You can control if the Cameras should cull tiles before rendering them or not. - * By default the camera will try to cull the tiles in this layer, to avoid over-drawing to the renderer. - * - * However, there are some instances when you may wish to disable this, and toggling this flag allows - * you to do so. Also see `setSkipCull` for a chainable method that does the same thing. + * The x map coordinate of this tile in tile units. */ - skipCull: boolean; + x: number; /** - * Canvas only. - * - * The total number of tiles drawn by the renderer in the last frame. - * - * This only works when rending with Canvas. + * The y map coordinate of this tile in tile units. */ - readonly tilesDrawn: integer; + y: number; /** - * Canvas only. - * - * The total number of tiles in this layer. Updated every frame. + * The width of the tile in pixels. */ - readonly tilesTotal: integer; + width: number; /** - * Canvas only. - * - * The amount of extra tiles to add into the cull rectangle when calculating its horizontal size. - * - * See the method `setCullPadding` for more details. + * The height of the tile in pixels. */ - cullPaddingX: integer; + height: number; /** - * Canvas only. - * - * The amount of extra tiles to add into the cull rectangle when calculating its vertical size. + * The right of the tile in pixels. * - * See the method `setCullPadding` for more details. + * Set in the `updatePixelXY` method. */ - cullPaddingY: integer; + right: number; /** - * Canvas only. - * - * The callback that is invoked when the tiles are culled. - * - * By default it will call `TilemapComponents.CullTiles` but you can override this to call any function you like. - * - * It will be sent 3 arguments: - * - * 1. The Phaser.Tilemaps.LayerData object for this Layer - * 2. The Camera that is culling the layer. You can check its `dirty` property to see if it has changed since the last cull. - * 3. A reference to the `culledTiles` array, which should be used to store the tiles you want rendered. + * The bottom of the tile in pixels. * - * See the `TilemapComponents.CullTiles` source code for details on implementing your own culling system. - */ - cullCallback: Function; - - /** - * An array holding the mapping between the tile indexes and the tileset they belong to. + * Set in the `updatePixelXY` method. */ - gidMap: Phaser.Tilemaps.Tileset[]; + bottom: number; /** - * Upload the tile data to a VBO. - * @param camera The camera to render to. - * @param tilesetIndex The tileset index. + * The maps base width of a tile in pixels. Tiled maps support multiple tileset sizes + * within one map, but they are still placed at intervals of the base tile size. */ - upload(camera: Phaser.Cameras.Scene2D.Camera, tilesetIndex: integer): Phaser.Tilemaps.StaticTilemapLayer; + baseWidth: number; /** - * Sets the rendering (draw) order of the tiles in this layer. - * - * The default is 'right-down', meaning it will order the tiles starting from the top-left, - * drawing to the right and then moving down to the next row. - * - * The draw orders are: - * - * 0 = right-down - * 1 = left-down - * 2 = right-up - * 3 = left-up - * - * Setting the render order does not change the tiles or how they are stored in the layer, - * it purely impacts the order in which they are rendered. - * - * You can provide either an integer (0 to 3), or the string version of the order. - * @param renderOrder The render (draw) order value. Either an integer between 0 and 3, or a string: 'right-down', 'left-down', 'right-up' or 'left-up'. + * The maps base height of a tile in pixels. Tiled maps support multiple tileset sizes + * within one map, but they are still placed at intervals of the base tile size. */ - setRenderOrder(renderOrder: integer | string): this; + baseHeight: number; /** - * Calculates interesting faces at the given tile coordinates of the specified layer. Interesting - * faces are used internally for optimizing collisions against tiles. This method is mostly used - * internally to optimize recalculating faces when only one tile has been changed. - * @param tileX The x coordinate. - * @param tileY The y coordinate. + * The x coordinate of the top left of this tile in pixels. This is relative to the top left + * of the layer this tile is being rendered within. This property does NOT factor in camera + * scroll, layer scale or layer position. */ - calculateFacesAt(tileX: integer, tileY: integer): Phaser.Tilemaps.StaticTilemapLayer; + pixelX: number; /** - * Calculates interesting faces within the rectangular area specified (in tile coordinates) of the - * layer. Interesting faces are used internally for optimizing collisions against tiles. This method - * is mostly used internally. - * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param width How many tiles wide from the `tileX` index the area will be. Default max width based on tileX. - * @param height How many tiles tall from the `tileY` index the area will be. Default max height based on tileY. + * The y coordinate of the top left of this tile in pixels. This is relative to the top left + * of the layer this tile is being rendered within. This property does NOT factor in camera + * scroll, layer scale or layer position. */ - calculateFacesWithin(tileX?: integer, tileY?: integer, width?: integer, height?: integer): Phaser.Tilemaps.StaticTilemapLayer; + pixelY: number; /** - * Creates a Sprite for every object matching the given tile indexes in the layer. You can - * optionally specify if each tile will be replaced with a new tile after the Sprite has been - * created. This is useful if you want to lay down special tiles in a level that are converted to - * Sprites, but want to replace the tile itself with a floor tile or similar once converted. - * @param indexes The tile index, or array of indexes, to create Sprites from. - * @param replacements The tile index, or array of indexes, to change a converted - * tile to. Set to `null` to leave the tiles unchanged. If an array is given, it is assumed to be a - * one-to-one mapping with the indexes array. - * @param spriteConfig The config object to pass into the Sprite creator (i.e. - * scene.make.sprite). - * @param scene The Scene to create the Sprites within. Default scene the map is within. - * @param camera The Camera to use when determining the world XY Default main camera. + * Tile specific properties. These usually come from Tiled. */ - createFromTiles(indexes: integer | any[], replacements: integer | any[], spriteConfig: Phaser.Types.GameObjects.Sprite.SpriteConfig, scene?: Phaser.Scene, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.GameObjects.Sprite[]; + properties: any; /** - * Returns the tiles in the given layer that are within the cameras viewport. - * This is used internally. - * @param camera The Camera to run the cull check against. + * The rotation angle of this tile. */ - cull(camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Tilemaps.Tile[]; + rotation: number; /** - * Canvas only. - * - * You can control if the Cameras should cull tiles before rendering them or not. - * By default the camera will try to cull the tiles in this layer, to avoid over-drawing to the renderer. - * - * However, there are some instances when you may wish to disable this. - * @param value Set to `true` to stop culling tiles. Set to `false` to enable culling again. Default true. + * Whether the tile should collide with any object on the left side. */ - setSkipCull(value?: boolean): this; + collideLeft: boolean; /** - * Canvas only. - * - * When a Camera culls the tiles in this layer it does so using its view into the world, building up a - * rectangle inside which the tiles must exist or they will be culled. Sometimes you may need to expand the size - * of this 'cull rectangle', especially if you plan on rotating the Camera viewing the layer. Do so - * by providing the padding values. The values given are in tiles, not pixels. So if the tile width was 32px - * and you set `paddingX` to be 4, it would add 32px x 4 to the cull rectangle (adjusted for scale) - * @param paddingX The amount of extra horizontal tiles to add to the cull check padding. Default 1. - * @param paddingY The amount of extra vertical tiles to add to the cull check padding. Default 1. + * Whether the tile should collide with any object on the right side. */ - setCullPadding(paddingX?: integer, paddingY?: integer): this; + collideRight: boolean; /** - * Searches the entire map layer for the first tile matching the given index, then returns that Tile - * object. If no match is found, it returns null. The search starts from the top-left tile and - * continues horizontally until it hits the end of the row, then it drops down to the next column. - * If the reverse boolean is true, it scans starting from the bottom-right corner traveling up to - * the top-left. - * @param index The tile index value to search for. - * @param skip The number of times to skip a matching tile before returning. Default 0. - * @param reverse If true it will scan the layer in reverse, starting at the - * bottom-right. Otherwise it scans from the top-left. Default false. + * Whether the tile should collide with any object on the top side. */ - findByIndex(index: integer, skip?: integer, reverse?: boolean): Phaser.Tilemaps.Tile; + collideUp: boolean; /** - * Find the first tile in the given rectangular area (in tile coordinates) of the layer that - * satisfies the provided testing function. I.e. finds the first tile for which `callback` returns - * true. Similar to Array.prototype.find in vanilla JS. - * @param callback The callback. Each tile in the given area will be passed to this - * callback as the first and only parameter. - * @param context The context under which the callback should be run. - * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area to filter. Default 0. - * @param tileY The topmost tile index (in tile coordinates) to use as the origin of the area to filter. Default 0. - * @param width How many tiles wide from the `tileX` index the area will be. Default max width based on tileX. - * @param height How many tiles tall from the `tileY` index the area will be. Default max height based on tileY. - * @param filteringOptions Optional filters to apply when getting the tiles. + * Whether the tile should collide with any object on the bottom side. */ - findTile(callback: Function, context?: object, tileX?: integer, tileY?: integer, width?: integer, height?: integer, filteringOptions?: Phaser.Types.Tilemaps.FilteringOptions): Phaser.Tilemaps.Tile; + collideDown: boolean; /** - * For each tile in the given rectangular area (in tile coordinates) of the layer, run the given - * filter callback function. Any tiles that pass the filter test (i.e. where the callback returns - * true) will returned as a new array. Similar to Array.prototype.Filter in vanilla JS. - * @param callback The callback. Each tile in the given area will be passed to this - * callback as the first and only parameter. The callback should return true for tiles that pass the - * filter. - * @param context The context under which the callback should be run. - * @param tileX The leftmost tile index (in tile coordinates) to use as the origin of the area to filter. Default 0. - * @param tileY The topmost tile index (in tile coordinates) to use as the origin of the area to filter. Default 0. - * @param width How many tiles wide from the `tileX` index the area will be. Default max width based on tileX. - * @param height How many tiles tall from the `tileY` index the area will be. Default max height based on tileY. - * @param filteringOptions Optional filters to apply when getting the tiles. + * Whether the tiles left edge is interesting for collisions. */ - filterTiles(callback: Function, context?: object, tileX?: integer, tileY?: integer, width?: integer, height?: integer, filteringOptions?: Phaser.Types.Tilemaps.FilteringOptions): Phaser.Tilemaps.Tile[]; + faceLeft: boolean; /** - * For each tile in the given rectangular area (in tile coordinates) of the layer, run the given - * callback. Similar to Array.prototype.forEach in vanilla JS. - * @param callback The callback. Each tile in the given area will be passed to this - * callback as the first and only parameter. - * @param context The context under which the callback should be run. - * @param tileX The leftmost tile index (in tile coordinates) to use as the origin of the area to filter. Default 0. - * @param tileY The topmost tile index (in tile coordinates) to use as the origin of the area to filter. Default 0. - * @param width How many tiles wide from the `tileX` index the area will be. Default max width based on tileX. - * @param height How many tiles tall from the `tileY` index the area will be. Default max height based on tileY. - * @param filteringOptions Optional filters to apply when getting the tiles. + * Whether the tiles right edge is interesting for collisions. */ - forEachTile(callback: Function, context?: object, tileX?: integer, tileY?: integer, width?: integer, height?: integer, filteringOptions?: Phaser.Types.Tilemaps.FilteringOptions): Phaser.Tilemaps.StaticTilemapLayer; + faceRight: boolean; /** - * Gets a tile at the given tile coordinates from the given layer. - * @param tileX X position to get the tile from (given in tile units, not pixels). - * @param tileY Y position to get the tile from (given in tile units, not pixels). - * @param nonNull If true getTile won't return null for empty tiles, but a Tile - * object with an index of -1. Default false. + * Whether the tiles top edge is interesting for collisions. */ - getTileAt(tileX: integer, tileY: integer, nonNull?: boolean): Phaser.Tilemaps.Tile; + faceTop: boolean; /** - * Gets a tile at the given world coordinates from the given layer. - * @param worldX X position to get the tile from (given in pixels) - * @param worldY Y position to get the tile from (given in pixels) - * @param nonNull If true, function won't return null for empty tiles, but a Tile - * object with an index of -1. Default false. - * @param camera The Camera to use when calculating the tile index from the world values. Default main camera. + * Whether the tiles bottom edge is interesting for collisions. */ - getTileAtWorldXY(worldX: number, worldY: number, nonNull?: boolean, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Tilemaps.Tile; + faceBottom: boolean; /** - * Gets the tiles in the given rectangular area (in tile coordinates) of the layer. - * @param tileX The leftmost tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param tileY The topmost tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param width How many tiles wide from the `tileX` index the area will be. Default max width based on tileX. - * @param height How many tiles tall from the `tileY` index the area will be. Default max height based on tileY. - * @param filteringOptions Optional filters to apply when getting the tiles. + * Tile collision callback. */ - getTilesWithin(tileX?: integer, tileY?: integer, width?: integer, height?: integer, filteringOptions?: Phaser.Types.Tilemaps.FilteringOptions): Phaser.Tilemaps.Tile[]; + collisionCallback: Function; /** - * Gets the tiles in the given rectangular area (in world coordinates) of the layer. - * @param worldX The leftmost tile index (in tile coordinates) to use as the origin of the area to filter. - * @param worldY The topmost tile index (in tile coordinates) to use as the origin of the area to filter. - * @param width How many tiles wide from the `tileX` index the area will be. - * @param height How many tiles high from the `tileY` index the area will be. - * @param filteringOptions Optional filters to apply when getting the tiles. - * @param camera The Camera to use when factoring in which tiles to return. Default main camera. + * The context in which the collision callback will be called. */ - getTilesWithinWorldXY(worldX: number, worldY: number, width: number, height: number, filteringOptions?: Phaser.Types.Tilemaps.FilteringOptions, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Tilemaps.Tile[]; + collisionCallbackContext: object; /** - * Gets the tiles that overlap with the given shape in the given layer. The shape must be a Circle, - * Line, Rectangle or Triangle. The shape should be in world coordinates. - * @param shape A shape in world (pixel) coordinates - * @param filteringOptions Optional filters to apply when getting the tiles. - * @param camera The Camera to use when calculating the tile index from the world values. Default main camera. + * The tint to apply to this tile. Note: tint is currently a single color value instead of + * the 4 corner tint component on other GameObjects. */ - getTilesWithinShape(shape: Phaser.Geom.Circle | Phaser.Geom.Line | Phaser.Geom.Rectangle | Phaser.Geom.Triangle, filteringOptions?: Phaser.Types.Tilemaps.FilteringOptions, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Tilemaps.Tile[]; + tint: number; /** - * Checks if there is a tile at the given location (in tile coordinates) in the given layer. Returns - * false if there is no tile or if the tile at that location has an index of -1. - * @param tileX X position to get the tile from in tile coordinates. - * @param tileY Y position to get the tile from in tile coordinates. + * An empty object where physics-engine specific information (e.g. bodies) may be stored. */ - hasTileAt(tileX: integer, tileY: integer): boolean; + physics: object; /** - * Checks if there is a tile at the given location (in world coordinates) in the given layer. Returns - * false if there is no tile or if the tile at that location has an index of -1. - * @param worldX The X coordinate of the world position. - * @param worldY The Y coordinate of the world position. - * @param camera The Camera to use when calculating the tile index from the world values. Default main camera. + * Check if the given x and y world coordinates are within this Tile. This does not factor in + * camera scroll, layer scale or layer position. + * @param x The x coordinate to test. + * @param y The y coordinate to test. */ - hasTileAtWorldXY(worldX: number, worldY: number, camera?: Phaser.Cameras.Scene2D.Camera): boolean; + containsPoint(x: number, y: number): boolean; /** - * Draws a debug representation of the layer to the given Graphics. This is helpful when you want to - * get a quick idea of which of your tiles are colliding and which have interesting faces. The tiles - * are drawn starting at (0, 0) in the Graphics, allowing you to place the debug representation - * wherever you want on the screen. - * @param graphics The target Graphics object to draw upon. - * @param styleConfig An object specifying the colors to use for the debug drawing. + * Copies the tile data & properties from the given tile to this tile. This copies everything + * except for position and interesting faces. + * @param tile The tile to copy from. */ - renderDebug(graphics: Phaser.GameObjects.Graphics, styleConfig: Phaser.Types.Tilemaps.StyleConfig): Phaser.Tilemaps.StaticTilemapLayer; + copy(tile: Phaser.Tilemaps.Tile): this; /** - * Sets collision on the given tile or tiles within a layer by index. You can pass in either a - * single numeric index or an array of indexes: [2, 3, 15, 20]. The `collides` parameter controls if - * collision will be enabled (true) or disabled (false). - * @param indexes Either a single tile index, or an array of tile indexes. - * @param collides If true it will enable collision. If false it will clear - * collision. Default true. - * @param recalculateFaces Whether or not to recalculate the tile faces after the - * update. Default true. - * @param updateLayer If true, updates the current tiles on the layer. Set to - * false if no tiles have been placed for significant performance boost. Default true. + * The collision group for this Tile, defined within the Tileset. This returns a reference to + * the collision group stored within the Tileset, so any modification of the returned object + * will impact all tiles that have the same index as this tile. */ - setCollision(indexes: integer | any[], collides?: boolean, recalculateFaces?: boolean, updateLayer?: boolean): Phaser.Tilemaps.StaticTilemapLayer; + getCollisionGroup(): object; /** - * Sets collision on a range of tiles in a layer whose index is between the specified `start` and - * `stop` (inclusive). Calling this with a start value of 10 and a stop value of 14 would set - * collision for tiles 10, 11, 12, 13 and 14. The `collides` parameter controls if collision will be - * enabled (true) or disabled (false). - * @param start The first index of the tile to be set for collision. - * @param stop The last index of the tile to be set for collision. - * @param collides If true it will enable collision. If false it will clear - * collision. Default true. - * @param recalculateFaces Whether or not to recalculate the tile faces after the - * update. Default true. + * The tile data for this Tile, defined within the Tileset. This typically contains Tiled + * collision data, tile animations and terrain information. This returns a reference to the tile + * data stored within the Tileset, so any modification of the returned object will impact all + * tiles that have the same index as this tile. */ - setCollisionBetween(start: integer, stop: integer, collides?: boolean, recalculateFaces?: boolean): Phaser.Tilemaps.StaticTilemapLayer; + getTileData(): object; /** - * Sets collision on the tiles within a layer by checking tile properties. If a tile has a property - * that matches the given properties object, its collision flag will be set. The `collides` - * parameter controls if collision will be enabled (true) or disabled (false). Passing in - * `{ collides: true }` would update the collision flag on any tiles with a "collides" property that - * has a value of true. Any tile that doesn't have "collides" set to true will be ignored. You can - * also use an array of values, e.g. `{ types: ["stone", "lava", "sand" ] }`. If a tile has a - * "types" property that matches any of those values, its collision flag will be updated. - * @param properties An object with tile properties and corresponding values that should - * be checked. - * @param collides If true it will enable collision. If false it will clear - * collision. Default true. - * @param recalculateFaces Whether or not to recalculate the tile faces after the - * update. Default true. + * Gets the world X position of the left side of the tile, factoring in the layers position, + * scale and scroll. + * @param camera The Camera to use to perform the check. */ - setCollisionByProperty(properties: object, collides?: boolean, recalculateFaces?: boolean): Phaser.Tilemaps.StaticTilemapLayer; + getLeft(camera?: Phaser.Cameras.Scene2D.Camera): number; /** - * Sets collision on all tiles in the given layer, except for tiles that have an index specified in - * the given array. The `collides` parameter controls if collision will be enabled (true) or - * disabled (false). - * @param indexes An array of the tile indexes to not be counted for collision. - * @param collides If true it will enable collision. If false it will clear - * collision. Default true. - * @param recalculateFaces Whether or not to recalculate the tile faces after the - * update. Default true. + * Gets the world X position of the right side of the tile, factoring in the layer's position, + * scale and scroll. + * @param camera The Camera to use to perform the check. */ - setCollisionByExclusion(indexes: integer[], collides?: boolean, recalculateFaces?: boolean): Phaser.Tilemaps.StaticTilemapLayer; + getRight(camera?: Phaser.Cameras.Scene2D.Camera): number; /** - * Sets a global collision callback for the given tile index within the layer. This will affect all - * tiles on this layer that have the same index. If a callback is already set for the tile index it - * will be replaced. Set the callback to null to remove it. If you want to set a callback for a tile - * at a specific location on the map then see setTileLocationCallback. - * @param indexes Either a single tile index, or an array of tile indexes to have a - * collision callback set for. - * @param callback The callback that will be invoked when the tile is collided with. - * @param callbackContext The context under which the callback is called. + * Gets the world Y position of the top side of the tile, factoring in the layer's position, + * scale and scroll. + * @param camera The Camera to use to perform the check. */ - setTileIndexCallback(indexes: integer | any[], callback: Function, callbackContext: object): Phaser.Tilemaps.StaticTilemapLayer; + getTop(camera?: Phaser.Cameras.Scene2D.Camera): number; /** - * Sets collision on the tiles within a layer by checking each tiles collision group data - * (typically defined in Tiled within the tileset collision editor). If any objects are found within - * a tiles collision group, the tile's colliding information will be set. The `collides` parameter - * controls if collision will be enabled (true) or disabled (false). - * @param collides If true it will enable collision. If false it will clear - * collision. Default true. - * @param recalculateFaces Whether or not to recalculate the tile faces after the - * update. Default true. + * Gets the world Y position of the bottom side of the tile, factoring in the layer's position, + * scale and scroll. + * @param camera The Camera to use to perform the check. */ - setCollisionFromCollisionGroup(collides?: boolean, recalculateFaces?: boolean): Phaser.Tilemaps.StaticTilemapLayer; + getBottom(camera?: Phaser.Cameras.Scene2D.Camera): number; /** - * Sets a collision callback for the given rectangular area (in tile coordinates) within the layer. - * If a callback is already set for the tile index it will be replaced. Set the callback to null to - * remove it. - * @param tileX The leftmost tile index (in tile coordinates) to use as the origin of the area. - * @param tileY The topmost tile index (in tile coordinates) to use as the origin of the area. - * @param width How many tiles wide from the `tileX` index the area will be. - * @param height How many tiles tall from the `tileY` index the area will be. - * @param callback The callback that will be invoked when the tile is collided with. - * @param callbackContext The context under which the callback is called. + * Gets the world rectangle bounding box for the tile, factoring in the layers position, + * scale and scroll. + * @param camera The Camera to use to perform the check. + * @param output Optional Rectangle object to store the results in. */ - setTileLocationCallback(tileX: integer, tileY: integer, width: integer, height: integer, callback: Function, callbackContext?: object): Phaser.Tilemaps.StaticTilemapLayer; + getBounds(camera?: Phaser.Cameras.Scene2D.Camera, output?: Phaser.Geom.Rectangle): Phaser.Geom.Rectangle | object; /** - * Converts from tile X coordinates (tile units) to world X coordinates (pixels), factoring in the - * layers position, scale and scroll. - * @param tileX The X coordinate, in tile coordinates. - * @param camera The Camera to use when calculating the world values from the tile index. Default main camera. + * Gets the world X position of the center of the tile, factoring in the layer's position, + * scale and scroll. + * @param camera The Camera to use to perform the check. */ - tileToWorldX(tileX: integer, camera?: Phaser.Cameras.Scene2D.Camera): number; + getCenterX(camera?: Phaser.Cameras.Scene2D.Camera): number; /** - * Converts from tile Y coordinates (tile units) to world Y coordinates (pixels), factoring in the - * layers position, scale and scroll. - * @param tileY The Y coordinate, in tile coordinates. - * @param camera The Camera to use when calculating the world values from the tile index. Default main camera. + * Gets the world Y position of the center of the tile, factoring in the layer's position, + * scale and scroll. + * @param camera The Camera to use to perform the check. */ - tileToWorldY(tileY: integer, camera?: Phaser.Cameras.Scene2D.Camera): number; + getCenterY(camera?: Phaser.Cameras.Scene2D.Camera): number; /** - * Converts from tile XY coordinates (tile units) to world XY coordinates (pixels), factoring in the - * layers position, scale and scroll. This will return a new Vector2 object or update the given - * `point` object. - * @param tileX The X coordinate, in tile coordinates. - * @param tileY The Y coordinate, in tile coordinates. - * @param point A Vector2 to store the coordinates in. If not given, a new Vector2 is created. - * @param camera The Camera to use when calculating the world values from the tile index. Default main camera. + * Check for intersection with this tile. This does not factor in camera scroll, layer scale or + * layer position. + * @param x The x axis in pixels. + * @param y The y axis in pixels. + * @param right The right point. + * @param bottom The bottom point. */ - tileToWorldXY(tileX: integer, tileY: integer, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + intersects(x: number, y: number, right: number, bottom: number): boolean; /** - * Converts from world X coordinates (pixels) to tile X coordinates (tile units), factoring in the - * layers position, scale and scroll. - * @param worldX The X coordinate, in world pixels. - * @param snapToFloor Whether or not to round the tile coordinate down to the - * nearest integer. Default true. - * @param camera The Camera to use when calculating the tile index from the world values.] Default main camera. + * Checks if the tile is interesting. + * @param collides If true, will consider the tile interesting if it collides on any side. + * @param faces If true, will consider the tile interesting if it has an interesting face. */ - worldToTileX(worldX: number, snapToFloor?: boolean, camera?: Phaser.Cameras.Scene2D.Camera): number; + isInteresting(collides: boolean, faces: boolean): boolean; /** - * Converts from world Y coordinates (pixels) to tile Y coordinates (tile units), factoring in the - * layers position, scale and scroll. - * @param worldY The Y coordinate, in world pixels. - * @param snapToFloor Whether or not to round the tile coordinate down to the - * nearest integer. Default true. - * @param camera The Camera to use when calculating the tile index from the world values. Default main camera. + * Reset collision status flags. + * @param recalculateFaces Whether or not to recalculate interesting faces for this tile and its neighbors. Default true. */ - worldToTileY(worldY: number, snapToFloor?: boolean, camera?: Phaser.Cameras.Scene2D.Camera): number; + resetCollision(recalculateFaces?: boolean): this; /** - * Converts from world XY coordinates (pixels) to tile XY coordinates (tile units), factoring in the - * layers position, scale and scroll. This will return a new Vector2 object or update the given - * `point` object. - * @param worldX The X coordinate, in world pixels. - * @param worldY The Y coordinate, in world pixels. - * @param snapToFloor Whether or not to round the tile coordinate down to the - * nearest integer. Default true. - * @param point A Vector2 to store the coordinates in. If not given, a new Vector2 is created. - * @param camera The Camera to use when calculating the tile index from the world values. Default main camera. + * Reset faces. */ - worldToTileXY(worldX: number, worldY: number, snapToFloor?: boolean, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; + resetFaces(): this; /** - * Destroys this StaticTilemapLayer and removes its link to the associated LayerData. - * @param removeFromTilemap Remove this layer from the parent Tilemap? Default true. + * Sets the collision flags for each side of this tile and updates the interesting faces list. + * @param left Indicating collide with any object on the left. + * @param right Indicating collide with any object on the right. + * @param up Indicating collide with any object on the top. + * @param down Indicating collide with any object on the bottom. + * @param recalculateFaces Whether or not to recalculate interesting faces for this tile and its neighbors. Default true. */ - destroy(removeFromTilemap?: boolean): void; + setCollision(left: boolean, right?: boolean, up?: boolean, down?: boolean, recalculateFaces?: boolean): this; /** - * Clears all alpha values associated with this Game Object. - * - * Immediately sets the alpha levels back to 1 (fully opaque). + * Set a callback to be called when this tile is hit by an object. The callback must true for + * collision processing to take place. + * @param callback Callback function. + * @param context Callback will be called within this context. */ - clearAlpha(): this; + setCollisionCallback(callback: Function, context: object): this; /** - * Set the Alpha level of this Game Object. The alpha controls the opacity of the Game Object as it renders. - * Alpha values are provided as a float between 0, fully transparent, and 1, fully opaque. - * - * If your game is running under WebGL you can optionally specify four different alpha values, each of which - * correspond to the four corners of the Game Object. Under Canvas only the `topLeft` value given is used. - * @param topLeft The alpha value used for the top-left of the Game Object. If this is the only value given it's applied across the whole Game Object. Default 1. - * @param topRight The alpha value used for the top-right of the Game Object. WebGL only. - * @param bottomLeft The alpha value used for the bottom-left of the Game Object. WebGL only. - * @param bottomRight The alpha value used for the bottom-right of the Game Object. WebGL only. + * Sets the size of the tile and updates its pixelX and pixelY. + * @param tileWidth The width of the tile in pixels. + * @param tileHeight The height of the tile in pixels. + * @param baseWidth The base width a tile in the map (in pixels). + * @param baseHeight The base height of the tile in pixels (in pixels). */ - setAlpha(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; + setSize(tileWidth: number, tileHeight: number, baseWidth: number, baseHeight: number): this; /** - * The alpha value of the Game Object. - * - * This is a global value, impacting the entire Game Object, not just a region of it. + * Used internally. Updates the tiles world XY position based on the current tile size. */ - alpha: number; + updatePixelXY(): this; /** - * The alpha value starting from the top-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * Clean up memory. */ - alphaTopLeft: number; + destroy(): void; /** - * The alpha value starting from the top-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * True if this tile can collide on any of its faces or has a collision callback set. */ - alphaTopRight: number; + readonly canCollide: boolean; /** - * The alpha value starting from the bottom-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * True if this tile can collide on any of its faces. */ - alphaBottomLeft: number; + readonly collides: boolean; /** - * The alpha value starting from the bottom-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * True if this tile has any interesting faces. */ - alphaBottomRight: number; + readonly hasInterestingFace: boolean; /** - * Sets the Blend Mode being used by this Game Object. - * - * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) - * - * Under WebGL only the following Blend Modes are available: - * - * * ADD - * * MULTIPLY - * * SCREEN - * * ERASE - * - * Canvas has more available depending on browser support. - * - * You can also create your own custom Blend Modes in WebGL. - * - * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending - * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these - * reasons try to be careful about the construction of your Scene and the frequency of which blend modes - * are used. + * The tileset that contains this Tile. This is null if accessed from a LayerData instance + * before the tile is placed in a TilemapLayer, or if the tile has an index that doesn't correspond + * to any of the maps tilesets. */ - blendMode: Phaser.BlendModes | string; + readonly tileset: Phaser.Tilemaps.Tileset; /** - * Sets the Blend Mode being used by this Game Object. - * - * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) - * - * Under WebGL only the following Blend Modes are available: - * - * * ADD - * * MULTIPLY - * * SCREEN - * * ERASE (only works when rendering to a framebuffer, like a Render Texture) - * - * Canvas has more available depending on browser support. - * - * You can also create your own custom Blend Modes in WebGL. - * - * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending - * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these - * reasons try to be careful about the construction of your Scene and the frequency in which blend modes - * are used. - * @param value The BlendMode value. Either a string or a CONST. + * The tilemap layer that contains this Tile. This will only return null if accessed from a + * LayerData instance before the tile is placed within a TilemapLayer. */ - setBlendMode(value: string | Phaser.BlendModes): this; + readonly tilemapLayer: Phaser.Tilemaps.TilemapLayer; /** - * The native (un-scaled) width of this Game Object. - * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayWidth` property. + * The tilemap that contains this Tile. This will only return null if accessed from a LayerData + * instance before the tile is placed within a TilemapLayer. */ - width: number; + readonly tilemap: Phaser.Tilemaps.Tilemap; /** - * The native (un-scaled) height of this Game Object. + * Clears all alpha values associated with this Game Object. * - * Changing this value will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or use - * the `displayHeight` property. + * Immediately sets the alpha levels back to 1 (fully opaque). */ - height: number; + clearAlpha(): this; /** - * The displayed width of this Game Object. - * - * This value takes into account the scale factor. + * Set the Alpha level of this Game Object. The alpha controls the opacity of the Game Object as it renders. + * Alpha values are provided as a float between 0, fully transparent, and 1, fully opaque. * - * Setting this value will adjust the Game Object's scale property. + * If your game is running under WebGL you can optionally specify four different alpha values, each of which + * correspond to the four corners of the Game Object. Under Canvas only the `topLeft` value given is used. + * @param topLeft The alpha value used for the top-left of the Game Object. If this is the only value given it's applied across the whole Game Object. Default 1. + * @param topRight The alpha value used for the top-right of the Game Object. WebGL only. + * @param bottomLeft The alpha value used for the bottom-left of the Game Object. WebGL only. + * @param bottomRight The alpha value used for the bottom-right of the Game Object. WebGL only. */ - displayWidth: number; + setAlpha(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; - /** - * The displayed height of this Game Object. - * - * This value takes into account the scale factor. + /** + * The alpha value of the Game Object. * - * Setting this value will adjust the Game Object's scale property. + * This is a global value, impacting the entire Game Object, not just a region of it. */ - displayHeight: number; + alpha: number; /** - * Sets the internal size of this Game Object, as used for frame or physics body creation. - * - * This will not change the size that the Game Object is rendered in-game. - * For that you need to either set the scale of the Game Object (`setScale`) or call the - * `setDisplaySize` method, which is the same thing as changing the scale but allows you - * to do so by giving pixel values. - * - * If you have enabled this Game Object for input, changing the size will _not_ change the - * size of the hit area. To do this you should adjust the `input.hitArea` object directly. - * @param width The width of this Game Object. - * @param height The height of this Game Object. + * The alpha value starting from the top-left of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. */ - setSize(width: number, height: number): this; + alphaTopLeft: number; /** - * Sets the display size of this Game Object. - * - * Calling this will adjust the scale. - * @param width The width of this Game Object. - * @param height The height of this Game Object. + * The alpha value starting from the top-right of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. */ - setDisplaySize(width: number, height: number): this; + alphaTopRight: number; /** - * The depth of this Game Object within the Scene. - * - * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order - * of Game Objects, without actually moving their position in the display list. - * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth - * value will always render in front of one with a lower value. - * - * Setting the depth will queue a depth sort event within the Scene. + * The alpha value starting from the bottom-left of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. */ - depth: number; + alphaBottomLeft: number; /** - * The depth of this Game Object within the Scene. - * - * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order - * of Game Objects, without actually moving their position in the display list. - * - * The depth starts from zero (the default value) and increases from that point. A Game Object with a higher depth - * value will always render in front of one with a lower value. - * - * Setting the depth will queue a depth sort event within the Scene. - * @param value The depth of this Game Object. + * The alpha value starting from the bottom-right of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. */ - setDepth(value: integer): this; + alphaBottomRight: number; /** * The horizontally flipped state of the Game Object. @@ -83473,1888 +91017,2471 @@ declare namespace Phaser { resetFlip(): this; /** - * Gets the center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. + * The visible state of the Game Object. + * + * An invisible Game Object will skip rendering, but will still process update logic. */ - getCenter(output?: O): O; + visible: boolean; /** - * Gets the top-left corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * Sets the visibility of this Game Object. + * + * An invisible Game Object will skip rendering, but will still process update logic. + * @param value The visible state of the Game Object. */ - getTopLeft(output?: O, includeParent?: boolean): O; + setVisible(value: boolean): this; + } + + /** + * A Tilemap is a container for Tilemap data. This isn't a display object, rather, it holds data + * about the map and allows you to add tilesets and tilemap layers to it. A map can have one or + * more tilemap layers, which are the display objects that actually render the tiles. + * + * The Tilemap data can be parsed from a Tiled JSON file, a CSV file or a 2D array. Tiled is a free + * software package specifically for creating tile maps, and is available from: + * http://www.mapeditor.org + * + * As of Phaser 3.50.0 the Tilemap API now supports the following types of map: + * + * 1) Orthogonal + * 2) Isometric + * 3) Hexagonal + * 4) Staggered + * + * Prior to this release, only orthogonal maps were supported. + * + * Another large change in 3.50 was the consolidation of Tilemap Layers. Previously, you created + * either a Static or Dynamic Tilemap Layer. However, as of 3.50 the features of both have been + * merged and the API simplified, so now there is just the single `TilemapLayer` class. + * + * A Tilemap has handy methods for getting and manipulating the tiles within a layer, allowing + * you to build or modify the tilemap data at runtime. + * + * Note that all Tilemaps use a base tile size to calculate dimensions from, but that a + * TilemapLayer may have its own unique tile size that overrides this. + * + * As of Phaser 3.21.0, if your tilemap includes layer groups (a feature of Tiled 1.2.0+) these + * will be traversed and the following properties will impact children: + * + * - Opacity (blended with parent) and visibility (parent overrides child) + * - Vertical and horizontal offset + * + * The grouping hierarchy is not preserved and all layers will be flattened into a single array. + * + * Group layers are parsed during Tilemap construction but are discarded after parsing so dynamic + * layers will NOT continue to be affected by a parent. + * + * To avoid duplicate layer names, a layer that is a child of a group layer will have its parent + * group name prepended with a '/'. For example, consider a group called 'ParentGroup' with a + * child called 'Layer 1'. In the Tilemap object, 'Layer 1' will have the name + * 'ParentGroup/Layer 1'. + */ + class Tilemap { /** - * Gets the top-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * + * @param scene The Scene to which this Tilemap belongs. + * @param mapData A MapData instance containing Tilemap data. */ - getTopCenter(output?: O, includeParent?: boolean): O; + constructor(scene: Phaser.Scene, mapData: Phaser.Tilemaps.MapData); + + scene: Phaser.Scene; /** - * Gets the top-right corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * The base width of a tile in pixels. Note that individual layers may have a different tile + * width. */ - getTopRight(output?: O, includeParent?: boolean): O; + tileWidth: number; /** - * Gets the left-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * The base height of a tile in pixels. Note that individual layers may have a different + * tile height. */ - getLeftCenter(output?: O, includeParent?: boolean): O; + tileHeight: number; /** - * Gets the right-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * The width of the map (in tiles). */ - getRightCenter(output?: O, includeParent?: boolean): O; + width: number; /** - * Gets the bottom-left corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * The height of the map (in tiles). */ - getBottomLeft(output?: O, includeParent?: boolean): O; + height: number; /** - * Gets the bottom-center coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * The orientation of the map data (as specified in Tiled), usually 'orthogonal'. */ - getBottomCenter(output?: O, includeParent?: boolean): O; + orientation: string; /** - * Gets the bottom-right corner coordinate of this Game Object, regardless of origin. - * The returned point is calculated in local space and does not factor in any parent containers - * @param output An object to store the values in. If not provided a new Vector2 will be created. - * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. + * The render (draw) order of the map data (as specified in Tiled), usually 'right-down'. + * + * The draw orders are: + * + * right-down + * left-down + * right-up + * left-up + * + * This can be changed via the `setRenderOrder` method. */ - getBottomRight(output?: O, includeParent?: boolean): O; + renderOrder: string; /** - * Gets the bounds of this Game Object, regardless of origin. - * The values are stored and returned in a Rectangle, or Rectangle-like, object. - * @param output An object to store the values in. If not provided a new Rectangle will be created. + * The format of the map data. */ - getBounds(output?: O): O; + format: number; /** - * The horizontal origin of this Game Object. - * The origin maps the relationship between the size and position of the Game Object. - * The default value is 0.5, meaning all Game Objects are positioned based on their center. - * Setting the value to 0 means the position now relates to the left of the Game Object. + * The version of the map data (as specified in Tiled, usually 1). */ - originX: number; + version: number; /** - * The vertical origin of this Game Object. - * The origin maps the relationship between the size and position of the Game Object. - * The default value is 0.5, meaning all Game Objects are positioned based on their center. - * Setting the value to 0 means the position now relates to the top of the Game Object. + * Map specific properties as specified in Tiled. */ - originY: number; + properties: object; /** - * The horizontal display origin of this Game Object. - * The origin is a normalized value between 0 and 1. - * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. + * The width of the map in pixels based on width * tileWidth. */ - displayOriginX: number; + widthInPixels: number; /** - * The vertical display origin of this Game Object. - * The origin is a normalized value between 0 and 1. - * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. + * The height of the map in pixels based on height * tileHeight. */ - displayOriginY: number; + heightInPixels: number; /** - * Sets the origin of this Game Object. + * A collection of Images, as parsed from Tiled map data. + */ + imageCollections: Phaser.Tilemaps.ImageCollection[]; + + /** + * An array of Tiled Image Layers. + */ + images: any[]; + + /** + * An array of Tilemap layer data. + */ + layers: Phaser.Tilemaps.LayerData[]; + + /** + * An array of Tilesets used in the map. + */ + tilesets: Phaser.Tilemaps.Tileset[]; + + /** + * An array of ObjectLayer instances parsed from Tiled object layers. + */ + objects: Phaser.Tilemaps.ObjectLayer[]; + + /** + * The index of the currently selected LayerData object. + */ + currentLayerIndex: number; + + /** + * The length of the horizontal sides of the hexagon. + * Only used for hexagonal orientation Tilemaps. + */ + hexSideLength: number; + + /** + * Sets the rendering (draw) order of the tiles in this map. * - * The values are given in the range 0 to 1. - * @param x The horizontal origin value. Default 0.5. - * @param y The vertical origin value. If not defined it will be set to the value of `x`. Default x. + * The default is 'right-down', meaning it will order the tiles starting from the top-left, + * drawing to the right and then moving down to the next row. + * + * The draw orders are: + * + * 0 = right-down + * 1 = left-down + * 2 = right-up + * 3 = left-up + * + * Setting the render order does not change the tiles or how they are stored in the layer, + * it purely impacts the order in which they are rendered. + * + * You can provide either an integer (0 to 3), or the string version of the order. + * + * Calling this method _after_ creating Tilemap Layers will **not** automatically + * update them to use the new render order. If you call this method after creating layers, use their + * own `setRenderOrder` methods to change them as needed. + * @param renderOrder The render (draw) order value. Either an integer between 0 and 3, or a string: 'right-down', 'left-down', 'right-up' or 'left-up'. */ - setOrigin(x?: number, y?: number): this; + setRenderOrder(renderOrder: number | string): this; /** - * Sets the origin of this Game Object based on the Pivot values in its Frame. + * Adds an image to the map to be used as a tileset. A single map may use multiple tilesets. + * Note that the tileset name can be found in the JSON file exported from Tiled, or in the Tiled + * editor. + * @param tilesetName The name of the tileset as specified in the map data. + * @param key The key of the Phaser.Cache image used for this tileset. If + * `undefined` or `null` it will look for an image with a key matching the tilesetName parameter. + * @param tileWidth The width of the tile (in pixels) in the Tileset Image. If not + * given it will default to the map's tileWidth value, or the tileWidth specified in the Tiled + * JSON file. + * @param tileHeight The height of the tiles (in pixels) in the Tileset Image. If + * not given it will default to the map's tileHeight value, or the tileHeight specified in the + * Tiled JSON file. + * @param tileMargin The margin around the tiles in the sheet (in pixels). If not + * specified, it will default to 0 or the value specified in the Tiled JSON file. + * @param tileSpacing The spacing between each the tile in the sheet (in pixels). + * If not specified, it will default to 0 or the value specified in the Tiled JSON file. + * @param gid If adding multiple tilesets to a blank map, specify the starting + * GID this set will use here. Default 0. */ - setOriginFromFrame(): this; + addTilesetImage(tilesetName: string, key?: string, tileWidth?: number, tileHeight?: number, tileMargin?: number, tileSpacing?: number, gid?: number): Phaser.Tilemaps.Tileset; /** - * Sets the display origin of this Game Object. - * The difference between this and setting the origin is that you can use pixel values for setting the display origin. - * @param x The horizontal display origin value. Default 0. - * @param y The vertical display origin value. If not defined it will be set to the value of `x`. Default x. + * Copies the tiles in the source rectangular area to a new destination (all specified in tile + * coordinates) within the layer. This copies all tile properties & recalculates collision + * information in the destination region. + * + * If no layer specified, the map's current layer is used. This cannot be applied to StaticTilemapLayers. + * @param srcTileX The x coordinate of the area to copy from, in tiles, not pixels. + * @param srcTileY The y coordinate of the area to copy from, in tiles, not pixels. + * @param width The width of the area to copy, in tiles, not pixels. + * @param height The height of the area to copy, in tiles, not pixels. + * @param destTileX The x coordinate of the area to copy to, in tiles, not pixels. + * @param destTileY The y coordinate of the area to copy to, in tiles, not pixels. + * @param recalculateFaces `true` if the faces data should be recalculated. Default true. + * @param layer The tile layer to use. If not given the current layer is used. */ - setDisplayOrigin(x?: number, y?: number): this; + copy(srcTileX: number, srcTileY: number, width: number, height: number, destTileX: number, destTileY: number, recalculateFaces?: boolean, layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tilemap; /** - * Updates the Display Origin cached values internally stored on this Game Object. - * You don't usually call this directly, but it is exposed for edge-cases where you may. + * Creates a new and empty Tilemap Layer. The currently selected layer in the map is set to this new layer. + * + * Prior to v3.50.0 this method was called `createBlankDynamicLayer`. + * @param name The name of this layer. Must be unique within the map. + * @param tileset The tileset, or an array of tilesets, used to render this layer. Can be a string or a Tileset object. + * @param x The world x position where the top left of this layer will be placed. Default 0. + * @param y The world y position where the top left of this layer will be placed. Default 0. + * @param width The width of the layer in tiles. If not specified, it will default to the map's width. + * @param height The height of the layer in tiles. If not specified, it will default to the map's height. + * @param tileWidth The width of the tiles the layer uses for calculations. If not specified, it will default to the map's tileWidth. + * @param tileHeight The height of the tiles the layer uses for calculations. If not specified, it will default to the map's tileHeight. */ - updateDisplayOrigin(): this; + createBlankLayer(name: string, tileset: string | string[] | Phaser.Tilemaps.Tileset | Phaser.Tilemaps.Tileset[], x?: number, y?: number, width?: number, height?: number, tileWidth?: number, tileHeight?: number): Phaser.Tilemaps.TilemapLayer; /** - * The initial WebGL pipeline of this Game Object. + * Creates a new Tilemap Layer that renders the LayerData associated with the given + * `layerID`. The currently selected layer in the map is set to this new layer. + * + * The `layerID` is important. If you've created your map in Tiled then you can get this by + * looking in Tiled and looking at the layer name. Or you can open the JSON file it exports and + * look at the layers[].name value. Either way it must match. + * + * Prior to v3.50.0 this method was called `createDynamicLayer`. + * @param layerID The layer array index value, or if a string is given, the layer name from Tiled. + * @param tileset The tileset, or an array of tilesets, used to render this layer. Can be a string or a Tileset object. + * @param x The x position to place the layer in the world. If not specified, it will default to the layer offset from Tiled or 0. Default 0. + * @param y The y position to place the layer in the world. If not specified, it will default to the layer offset from Tiled or 0. Default 0. */ - defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; + createLayer(layerID: number | string, tileset: string | string[] | Phaser.Tilemaps.Tileset | Phaser.Tilemaps.Tileset[], x?: number, y?: number): Phaser.Tilemaps.TilemapLayer; /** - * The current WebGL pipeline of this Game Object. + * This method will iterate through all of the objects defined in a Tiled Object Layer and then + * convert the matching results into Phaser Game Objects (by default, Sprites) + * + * Objects are matched on one of 3 criteria: The Object ID, the Object GID or the Object Name. + * + * Within Tiled, Object IDs are unique per Object. Object GIDs, however, are shared by all objects + * using the same image. Finally, Object Names are strings and the same name can be used on multiple + * Objects in Tiled, they do not have to be unique. + * + * You set the configuration parameter accordingly, based on which type of criteria you wish + * to match against. For example, to convert all items on an Object Layer with a `gid` of 26: + * + * ```javascript + * createFromObjects(layerName, { + * gid: 26 + * }); + * ``` + * + * Or, to convert objects with the name 'bonus': + * + * ```javascript + * createFromObjects(layerName, { + * name: 'bonus' + * }); + * ``` + * + * Or, to convert an object with a specific id: + * + * ```javascript + * createFromObjects(layerName, { + * id: 9 + * }); + * ``` + * + * You should only specify either `id`, `gid`, `name`, or none of them. Do not add more than + * one criteria to your config. If you do not specify any criteria, then _all_ objects in the + * Object Layer will be converted. + * + * By default this method will convert objects into `Sprite` instances, but you can override + * this by providing your own class type: + * + * ```javascript + * createFromObjects(layerName, { + * gid: 26, + * classType: Coin + * }); + * ``` + * + * This will convert all Objects with a gid of 26 into your custom `Coin` class. You can pass + * any class type here, but it _must_ extend `Phaser.GameObjects.GameObject` as its base class. + * Your class will always be passed 1 parameter: `scene`, which is a reference to either the Scene + * specified in the config object or, if not given, the Scene to which this Tilemap belongs. + * + * All properties from object are copied into the Game Object, so you can use this as an easy + * way to configure properties from within the map editor. For example giving an object a + * property of `alpha: 0.5` in Tiled will be reflected in the Game Object that is created. + * + * Custom object properties that do not exist as a Game Object property are set in the + * Game Objects {@link Phaser.GameObjects.GameObject#data data store}. + * + * You can use set a `container` property in the config. If given, the class will be added to + * the Container instance instead of the Scene. + * + * Finally, you can provide an array of config objects, to convert multiple types of object in + * a single call: + * + * ```javascript + * createFromObjects(layerName, [ + * { + * gid: 26, + * classType: Coin + * }, + * { + * id: 9, + * classType: BossMonster + * }, + * { + * name: 'lava', + * classType: LavaTile + * } + * ]); + * ``` + * + * The signature of this method changed significantly in v3.50.0. Prior to this, it did not take config objects. + * @param objectLayerName The name of the Tiled object layer to create the Game Objects from. + * @param config A CreateFromObjects configuration object, or an array of them. */ - pipeline: Phaser.Renderer.WebGL.WebGLPipeline; + createFromObjects(objectLayerName: string, config: Phaser.Types.Tilemaps.CreateFromObjectLayerConfig | Phaser.Types.Tilemaps.CreateFromObjectLayerConfig[]): Phaser.GameObjects.GameObject[]; /** - * Sets the initial WebGL Pipeline of this Game Object. - * This should only be called during the instantiation of the Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. Defaults to the Texture Tint Pipeline. Default TextureTintPipeline. + * Creates a Sprite for every object matching the given tile indexes in the layer. You can + * optionally specify if each tile will be replaced with a new tile after the Sprite has been + * created. This is useful if you want to lay down special tiles in a level that are converted to + * Sprites, but want to replace the tile itself with a floor tile or similar once converted. + * @param indexes The tile index, or array of indexes, to create Sprites from. + * @param replacements The tile index, or array of indexes, to change a converted + * tile to. Set to `null` to leave the tiles unchanged. If an array is given, it is assumed to be a + * one-to-one mapping with the indexes array. + * @param spriteConfig The config object to pass into the Sprite creator (i.e. scene.make.sprite). + * @param scene The Scene to create the Sprites within. + * @param camera The Camera to use when calculating the tile index from the world values. + * @param layer The tile layer to use. If not given the current layer is used. */ - initPipeline(pipelineName?: string): boolean; + createFromTiles(indexes: number | any[], replacements: number | any[], spriteConfig: Phaser.Types.GameObjects.Sprite.SpriteConfig, scene?: Phaser.Scene, camera?: Phaser.Cameras.Scene2D.Camera, layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.GameObjects.Sprite[]; /** - * Sets the active WebGL Pipeline of this Game Object. - * @param pipelineName The name of the pipeline to set on this Game Object. + * Sets the tiles in the given rectangular area (in tile coordinates) of the layer with the + * specified index. Tiles will be set to collide if the given index is a colliding index. + * Collision information in the region will be recalculated. + * + * If no layer specified, the map's current layer is used. + * This cannot be applied to StaticTilemapLayers. + * @param index The tile index to fill the area with. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. + * @param recalculateFaces `true` if the faces data should be recalculated. Default true. + * @param layer The tile layer to use. If not given the current layer is used. */ - setPipeline(pipelineName: string): this; + fill(index: number, tileX?: number, tileY?: number, width?: number, height?: number, recalculateFaces?: boolean, layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tilemap; /** - * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * For each object in the given object layer, run the given filter callback function. Any + * objects that pass the filter test (i.e. where the callback returns true) will returned as a + * new array. Similar to Array.prototype.Filter in vanilla JS. + * @param objectLayer The name of an object layer (from Tiled) or an ObjectLayer instance. + * @param callback The callback. Each object in the given area will be passed to this callback as the first and only parameter. + * @param context The context under which the callback should be run. */ - resetPipeline(): boolean; + filterObjects(objectLayer: Phaser.Tilemaps.ObjectLayer | string, callback: TilemapFilterCallback, context?: object): Phaser.Types.Tilemaps.TiledObject[]; /** - * Gets the name of the WebGL Pipeline this Game Object is currently using. + * For each tile in the given rectangular area (in tile coordinates) of the layer, run the given + * filter callback function. Any tiles that pass the filter test (i.e. where the callback returns + * true) will returned as a new array. Similar to Array.prototype.Filter in vanilla JS. + * If no layer specified, the map's current layer is used. + * @param callback The callback. Each tile in the given area will be passed to this + * callback as the first and only parameter. The callback should return true for tiles that pass the + * filter. + * @param context The context under which the callback should be run. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area to filter. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area to filter. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. + * @param filteringOptions Optional filters to apply when getting the tiles. + * @param layer The tile layer to use. If not given the current layer is used. */ - getPipelineName(): string; + filterTiles(callback: Function, context?: object, tileX?: number, tileY?: number, width?: number, height?: number, filteringOptions?: Phaser.Types.Tilemaps.FilteringOptions, layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tile[]; /** - * The x position of this Game Object. + * Searches the entire map layer for the first tile matching the given index, then returns that Tile + * object. If no match is found, it returns null. The search starts from the top-left tile and + * continues horizontally until it hits the end of the row, then it drops down to the next column. + * If the reverse boolean is true, it scans starting from the bottom-right corner traveling up to + * the top-left. + * If no layer specified, the map's current layer is used. + * @param index The tile index value to search for. + * @param skip The number of times to skip a matching tile before returning. Default 0. + * @param reverse If true it will scan the layer in reverse, starting at the bottom-right. Otherwise it scans from the top-left. Default false. + * @param layer The tile layer to use. If not given the current layer is used. */ - x: number; + findByIndex(index: number, skip?: number, reverse?: boolean, layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tile; /** - * The y position of this Game Object. + * Find the first object in the given object layer that satisfies the provided testing function. + * I.e. finds the first object for which `callback` returns true. Similar to + * Array.prototype.find in vanilla JS. + * @param objectLayer The name of an object layer (from Tiled) or an ObjectLayer instance. + * @param callback The callback. Each object in the given area will be passed to this callback as the first and only parameter. + * @param context The context under which the callback should be run. */ - y: number; + findObject(objectLayer: Phaser.Tilemaps.ObjectLayer | string, callback: TilemapFindCallback, context?: object): Phaser.Types.Tilemaps.TiledObject; /** - * The z position of this Game Object. + * Find the first tile in the given rectangular area (in tile coordinates) of the layer that + * satisfies the provided testing function. I.e. finds the first tile for which `callback` returns + * true. Similar to Array.prototype.find in vanilla JS. + * If no layer specified, the maps current layer is used. + * @param callback The callback. Each tile in the given area will be passed to this callback as the first and only parameter. + * @param context The context under which the callback should be run. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area to search. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area to search. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. + * @param filteringOptions Optional filters to apply when getting the tiles. + * @param layer The Tile layer to run the search on. If not provided will use the current layer. + */ + findTile(callback: FindTileCallback, context?: object, tileX?: number, tileY?: number, width?: number, height?: number, filteringOptions?: Phaser.Types.Tilemaps.FilteringOptions, layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tile; + + /** + * For each tile in the given rectangular area (in tile coordinates) of the layer, run the given + * callback. Similar to Array.prototype.forEach in vanilla JS. * - * Note: The z position does not control the rendering order of 2D Game Objects. Use - * {@link Phaser.GameObjects.Components.Depth#depth} instead. + * If no layer specified, the map's current layer is used. + * @param callback The callback. Each tile in the given area will be passed to this callback as the first and only parameter. + * @param context The context under which the callback should be run. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area to search. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area to search. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. + * @param filteringOptions Optional filters to apply when getting the tiles. + * @param layer The Tile layer to run the search on. If not provided will use the current layer. + */ + forEachTile(callback: EachTileCallback, context?: object, tileX?: number, tileY?: number, width?: number, height?: number, filteringOptions?: Phaser.Types.Tilemaps.FilteringOptions, layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tilemap; + + /** + * Gets the image layer index based on its name. + * @param name The name of the image to get. + */ + getImageIndex(name: string): number; + + /** + * Return a list of all valid imagelayer names loaded in this Tilemap. + */ + getImageLayerNames(): string[]; + + /** + * Internally used. Returns the index of the object in one of the Tilemaps arrays whose name + * property matches the given `name`. + * @param location The Tilemap array to search. + * @param name The name of the array element to get. + */ + getIndex(location: any[], name: string): number; + + /** + * Gets the LayerData from `this.layers` that is associated with the given `layer`, or null if the layer is invalid. + * @param layer The name of the layer from Tiled, the index of the layer in the map or Tilemap Layer. If not given will default to the maps current layer index. + */ + getLayer(layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.LayerData; + + /** + * Gets the ObjectLayer from `this.objects` that has the given `name`, or null if no ObjectLayer is found with that name. + * @param name The name of the object layer from Tiled. + */ + getObjectLayer(name?: string): Phaser.Tilemaps.ObjectLayer; + + /** + * Return a list of all valid objectgroup names loaded in this Tilemap. + */ + getObjectLayerNames(): string[]; + + /** + * Gets the LayerData index of the given `layer` within this.layers, or null if an invalid + * `layer` is given. + * @param layer The name of the layer from Tiled, the index of the layer in the map or a Tilemap Layer. If not given will default to the map's current layer index. + */ + getLayerIndex(layer?: string | number | Phaser.Tilemaps.TilemapLayer): number; + + /** + * Gets the index of the LayerData within this.layers that has the given `name`, or null if an + * invalid `name` is given. + * @param name The name of the layer to get. + */ + getLayerIndexByName(name: string): number; + + /** + * Gets a tile at the given tile coordinates from the given layer. + * + * If no layer is specified, the maps current layer is used. + * @param tileX X position to get the tile from (given in tile units, not pixels). + * @param tileY Y position to get the tile from (given in tile units, not pixels). + * @param nonNull If true getTile won't return null for empty tiles, but a Tile object with an index of -1. + * @param layer The tile layer to use. If not given the current layer is used. + */ + getTileAt(tileX: number, tileY: number, nonNull?: boolean, layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tile; + + /** + * Gets a tile at the given world coordinates from the given layer. + * + * If no layer is specified, the maps current layer is used. + * @param worldX X position to get the tile from (given in pixels) + * @param worldY Y position to get the tile from (given in pixels) + * @param nonNull If true, function won't return null for empty tiles, but a Tile object with an index of -1. + * @param camera The Camera to use when calculating the tile index from the world values. + * @param layer The tile layer to use. If not given the current layer is used. + */ + getTileAtWorldXY(worldX: number, worldY: number, nonNull?: boolean, camera?: Phaser.Cameras.Scene2D.Camera, layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tile; + + /** + * Return a list of all valid tilelayer names loaded in this Tilemap. + */ + getTileLayerNames(): string[]; + + /** + * Gets the tiles in the given rectangular area (in tile coordinates) of the layer. + * + * If no layer is specified, the maps current layer is used. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. + * @param filteringOptions Optional filters to apply when getting the tiles. + * @param layer The tile layer to use. If not given the current layer is used. */ - z: number; + getTilesWithin(tileX?: number, tileY?: number, width?: number, height?: number, filteringOptions?: Phaser.Types.Tilemaps.FilteringOptions, layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tile[]; /** - * The w position of this Game Object. + * Gets the tiles that overlap with the given shape in the given layer. The shape must be a Circle, + * Line, Rectangle or Triangle. The shape should be in world coordinates. + * + * If no layer is specified, the maps current layer is used. + * @param shape A shape in world (pixel) coordinates + * @param filteringOptions Optional filters to apply when getting the tiles. + * @param camera The Camera to use when factoring in which tiles to return. + * @param layer The tile layer to use. If not given the current layer is used. */ - w: number; + getTilesWithinShape(shape: Phaser.Geom.Circle | Phaser.Geom.Line | Phaser.Geom.Rectangle | Phaser.Geom.Triangle, filteringOptions?: Phaser.Types.Tilemaps.FilteringOptions, camera?: Phaser.Cameras.Scene2D.Camera, layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tile[]; /** - * This is a special setter that allows you to set both the horizontal and vertical scale of this Game Object - * to the same value, at the same time. When reading this value the result returned is `(scaleX + scaleY) / 2`. + * Gets the tiles in the given rectangular area (in world coordinates) of the layer. * - * Use of this property implies you wish the horizontal and vertical scales to be equal to each other. If this - * isn't the case, use the `scaleX` or `scaleY` properties instead. + * If no layer is specified, the maps current layer is used. + * @param worldX The world x coordinate for the top-left of the area. + * @param worldY The world y coordinate for the top-left of the area. + * @param width The width of the area. + * @param height The height of the area. + * @param filteringOptions Optional filters to apply when getting the tiles. + * @param camera The Camera to use when factoring in which tiles to return. + * @param layer The tile layer to use. If not given the current layer is used. */ - scale: number; + getTilesWithinWorldXY(worldX: number, worldY: number, width: number, height: number, filteringOptions?: Phaser.Types.Tilemaps.FilteringOptions, camera?: Phaser.Cameras.Scene2D.Camera, layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tile[]; /** - * The horizontal scale of this Game Object. + * Gets the Tileset that has the given `name`, or null if an invalid `name` is given. + * @param name The name of the Tileset to get. */ - scaleX: number; + getTileset(name: string): Phaser.Tilemaps.Tileset; /** - * The vertical scale of this Game Object. + * Gets the index of the Tileset within this.tilesets that has the given `name`, or null if an + * invalid `name` is given. + * @param name The name of the Tileset to get. */ - scaleY: number; + getTilesetIndex(name: string): number; /** - * The angle of this Game Object as expressed in degrees. - * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Checks if there is a tile at the given location (in tile coordinates) in the given layer. Returns + * false if there is no tile or if the tile at that location has an index of -1. * - * If you prefer to work in radians, see the `rotation` property instead. + * If no layer is specified, the maps current layer is used. + * @param tileX The x coordinate, in tiles, not pixels. + * @param tileY The y coordinate, in tiles, not pixels. + * @param layer The tile layer to use. If not given the current layer is used. */ - angle: integer; + hasTileAt(tileX: number, tileY: number, layer?: string | number | Phaser.Tilemaps.TilemapLayer): boolean; /** - * The angle of this Game Object in radians. - * - * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left - * and -90 is up. + * Checks if there is a tile at the given location (in world coordinates) in the given layer. Returns + * false if there is no tile or if the tile at that location has an index of -1. * - * If you prefer to work in degrees, see the `angle` property instead. + * If no layer is specified, the maps current layer is used. + * @param worldX The x coordinate, in pixels. + * @param worldY The y coordinate, in pixels. + * @param camera The Camera to use when factoring in which tiles to return. + * @param layer The tile layer to use. If not given the current layer is used. */ - rotation: number; + hasTileAtWorldXY(worldX: number, worldY: number, camera?: Phaser.Cameras.Scene2D.Camera, layer?: string | number | Phaser.Tilemaps.TilemapLayer): boolean; /** - * Sets the position of this Game Object. - * @param x The x position of this Game Object. Default 0. - * @param y The y position of this Game Object. If not set it will use the `x` value. Default x. - * @param z The z position of this Game Object. Default 0. - * @param w The w position of this Game Object. Default 0. + * The LayerData object that is currently selected in the map. You can set this property using + * any type supported by setLayer. */ - setPosition(x?: number, y?: number, z?: number, w?: number): this; + layer: Phaser.Tilemaps.LayerData; /** - * Sets the position of this Game Object to be a random position within the confines of - * the given area. - * - * If no area is specified a random position between 0 x 0 and the game width x height is used instead. + * Puts a tile at the given tile coordinates in the specified layer. You can pass in either an index + * or a Tile object. If you pass in a Tile, all attributes will be copied over to the specified + * location. If you pass in an index, only the index at the specified location will be changed. + * Collision information will be recalculated at the specified location. * - * The position does not factor in the size of this Game Object, meaning that only the origin is - * guaranteed to be within the area. - * @param x The x position of the top-left of the random area. Default 0. - * @param y The y position of the top-left of the random area. Default 0. - * @param width The width of the random area. - * @param height The height of the random area. + * If no layer is specified, the maps current layer is used. + * @param tile The index of this tile to set or a Tile object. + * @param tileX The x coordinate, in tiles, not pixels. + * @param tileY The y coordinate, in tiles, not pixels. + * @param recalculateFaces `true` if the faces data should be recalculated. + * @param layer The tile layer to use. If not given the current layer is used. */ - setRandomPosition(x?: number, y?: number, width?: number, height?: number): this; + putTileAt(tile: number | Phaser.Tilemaps.Tile, tileX: number, tileY: number, recalculateFaces?: boolean, layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tile; /** - * Sets the rotation of this Game Object. - * @param radians The rotation of this Game Object, in radians. Default 0. + * Puts a tile at the given world coordinates (pixels) in the specified layer. You can pass in either + * an index or a Tile object. If you pass in a Tile, all attributes will be copied over to the + * specified location. If you pass in an index, only the index at the specified location will be + * changed. Collision information will be recalculated at the specified location. + * + * If no layer is specified, the maps current layer is used. + * @param tile The index of this tile to set or a Tile object. + * @param worldX The x coordinate, in pixels. + * @param worldY The y coordinate, in pixels. + * @param recalculateFaces `true` if the faces data should be recalculated. + * @param camera The Camera to use when calculating the tile index from the world values. + * @param layer The tile layer to use. If not given the current layer is used. */ - setRotation(radians?: number): this; + putTileAtWorldXY(tile: number | Phaser.Tilemaps.Tile, worldX: number, worldY: number, recalculateFaces?: boolean, camera?: Phaser.Cameras.Scene2D.Camera, layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tile; /** - * Sets the angle of this Game Object. - * @param degrees The rotation of this Game Object, in degrees. Default 0. + * Puts an array of tiles or a 2D array of tiles at the given tile coordinates in the specified + * layer. The array can be composed of either tile indexes or Tile objects. If you pass in a Tile, + * all attributes will be copied over to the specified location. If you pass in an index, only the + * index at the specified location will be changed. Collision information will be recalculated + * within the region tiles were changed. + * + * If no layer is specified, the maps current layer is used. + * @param tile A row (array) or grid (2D array) of Tiles or tile indexes to place. + * @param tileX The x coordinate, in tiles, not pixels. + * @param tileY The y coordinate, in tiles, not pixels. + * @param recalculateFaces `true` if the faces data should be recalculated. + * @param layer The tile layer to use. If not given the current layer is used. */ - setAngle(degrees?: number): this; + putTilesAt(tile: number[] | number[][] | Phaser.Tilemaps.Tile[] | Phaser.Tilemaps.Tile[][], tileX: number, tileY: number, recalculateFaces?: boolean, layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tilemap; /** - * Sets the scale of this Game Object. - * @param x The horizontal scale of this Game Object. - * @param y The vertical scale of this Game Object. If not set it will use the `x` value. Default x. + * Randomizes the indexes of a rectangular region of tiles (in tile coordinates) within the + * specified layer. Each tile will receive a new index. If an array of indexes is passed in, then + * those will be used for randomly assigning new tile indexes. If an array is not provided, the + * indexes found within the region (excluding -1) will be used for randomly assigning new tile + * indexes. This method only modifies tile indexes and does not change collision information. + * + * If no layer is specified, the maps current layer is used. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. + * @param indexes An array of indexes to randomly draw from during randomization. + * @param layer The tile layer to use. If not given the current layer is used. */ - setScale(x: number, y?: number): this; + randomize(tileX?: number, tileY?: number, width?: number, height?: number, indexes?: number[], layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tilemap; /** - * Sets the x position of this Game Object. - * @param value The x position of this Game Object. Default 0. + * Calculates interesting faces at the given tile coordinates of the specified layer. Interesting + * faces are used internally for optimizing collisions against tiles. This method is mostly used + * internally to optimize recalculating faces when only one tile has been changed. + * + * If no layer is specified, the maps current layer is used. + * @param tileX The x coordinate, in tiles, not pixels. + * @param tileY The y coordinate, in tiles, not pixels. + * @param layer The tile layer to use. If not given the current layer is used. */ - setX(value?: number): this; + calculateFacesAt(tileX: number, tileY: number, layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tilemap; /** - * Sets the y position of this Game Object. - * @param value The y position of this Game Object. Default 0. + * Calculates interesting faces within the rectangular area specified (in tile coordinates) of the + * layer. Interesting faces are used internally for optimizing collisions against tiles. This method + * is mostly used internally. + * + * If no layer is specified, the maps current layer is used. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. + * @param layer The tile layer to use. If not given the current layer is used. */ - setY(value?: number): this; + calculateFacesWithin(tileX?: number, tileY?: number, width?: number, height?: number, layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tilemap; /** - * Sets the z position of this Game Object. + * Removes the given TilemapLayer from this Tilemap without destroying it. * - * Note: The z position does not control the rendering order of 2D Game Objects. Use - * {@link Phaser.GameObjects.Components.Depth#setDepth} instead. - * @param value The z position of this Game Object. Default 0. + * If no layer is specified, the maps current layer is used. + * @param layer The tile layer to be removed. */ - setZ(value?: number): this; + removeLayer(layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tilemap; /** - * Sets the w position of this Game Object. - * @param value The w position of this Game Object. Default 0. + * Destroys the given TilemapLayer and removes it from this Tilemap. + * + * If no layer is specified, the maps current layer is used. + * @param layer The tile layer to be destroyed. */ - setW(value?: number): this; + destroyLayer(layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tilemap; /** - * Gets the local transform matrix for this Game Object. - * @param tempMatrix The matrix to populate with the values from this Game Object. + * Removes all Tilemap Layers from this Tilemap and calls `destroy` on each of them. */ - getLocalTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + removeAllLayers(): this; /** - * Gets the world transform matrix for this Game Object, factoring in any parent Containers. - * @param tempMatrix The matrix to populate with the values from this Game Object. - * @param parentMatrix A temporary matrix to hold parent values during the calculations. + * Removes the given Tile, or an array of Tiles, from the layer to which they belong, + * and optionally recalculates the collision information. + * @param tiles The Tile to remove, or an array of Tiles. + * @param replaceIndex After removing the Tile, insert a brand new Tile into its location with the given index. Leave as -1 to just remove the tile. Default -1. + * @param recalculateFaces `true` if the faces data should be recalculated. Default true. */ - getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + removeTile(tiles: Phaser.Tilemaps.Tile | Phaser.Tilemaps.Tile[], replaceIndex?: number, recalculateFaces?: boolean): Phaser.Tilemaps.Tile[]; /** - * Gets the sum total rotation of all of this Game Objects parent Containers. + * Removes the tile at the given tile coordinates in the specified layer and updates the layers collision information. * - * The returned value is in radians and will be zero if this Game Object has no parent container. + * If no layer is specified, the maps current layer is used. + * @param tileX The x coordinate, in tiles, not pixels. + * @param tileY The y coordinate, in tiles, not pixels. + * @param replaceWithNull If `true` (the default), this will replace the tile at the specified location with null instead of a Tile with an index of -1. + * @param recalculateFaces If `true` (the default), the faces data will be recalculated. + * @param layer The tile layer to use. If not given the current layer is used. */ - getParentRotation(): number; + removeTileAt(tileX: number, tileY: number, replaceWithNull?: boolean, recalculateFaces?: boolean, layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tile; /** - * The visible state of the Game Object. + * Removes the tile at the given world coordinates in the specified layer and updates the layers collision information. * - * An invisible Game Object will skip rendering, but will still process update logic. + * If no layer is specified, the maps current layer is used. + * @param worldX The x coordinate, in pixels. + * @param worldY The y coordinate, in pixels. + * @param replaceWithNull If `true` (the default), this will replace the tile at the specified location with null instead of a Tile with an index of -1. + * @param recalculateFaces If `true` (the default), the faces data will be recalculated. + * @param camera The Camera to use when calculating the tile index from the world values. + * @param layer The tile layer to use. If not given the current layer is used. */ - visible: boolean; + removeTileAtWorldXY(worldX: number, worldY: number, replaceWithNull?: boolean, recalculateFaces?: boolean, camera?: Phaser.Cameras.Scene2D.Camera, layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tile; /** - * Sets the visibility of this Game Object. + * Draws a debug representation of the layer to the given Graphics object. This is helpful when you want to + * get a quick idea of which of your tiles are colliding and which have interesting faces. The tiles + * are drawn starting at (0, 0) in the Graphics, allowing you to place the debug representation + * wherever you want on the screen. * - * An invisible Game Object will skip rendering, but will still process update logic. - * @param value The visible state of the Game Object. + * If no layer is specified, the maps current layer is used. + * + * **Note:** This method currently only works with orthogonal tilemap layers. + * @param graphics The target Graphics object to draw upon. + * @param styleConfig An object specifying the colors to use for the debug drawing. + * @param layer The tile layer to use. If not given the current layer is used. */ - setVisible(value: boolean): this; + renderDebug(graphics: Phaser.GameObjects.Graphics, styleConfig?: Phaser.Types.Tilemaps.StyleConfig, layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tilemap; /** - * The horizontal scroll factor of this Game Object. - * - * The scroll factor controls the influence of the movement of a Camera upon this Game Object. - * - * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. - * It does not change the Game Objects actual position values. - * - * A value of 1 means it will move exactly in sync with a camera. - * A value of 0 means it will not move at all, even if the camera moves. - * Other values control the degree to which the camera movement is mapped to this Game Object. + * Draws a debug representation of all layers within this Tilemap to the given Graphics object. * - * Please be aware that scroll factor values other than 1 are not taken in to consideration when - * calculating physics collisions. Bodies always collide based on their world position, but changing - * the scroll factor is a visual adjustment to where the textures are rendered, which can offset - * them from physics bodies if not accounted for in your code. + * This is helpful when you want to get a quick idea of which of your tiles are colliding and which + * have interesting faces. The tiles are drawn starting at (0, 0) in the Graphics, allowing you to + * place the debug representation wherever you want on the screen. + * @param graphics The target Graphics object to draw upon. + * @param styleConfig An object specifying the colors to use for the debug drawing. */ - scrollFactorX: number; + renderDebugFull(graphics: Phaser.GameObjects.Graphics, styleConfig?: Phaser.Types.Tilemaps.StyleConfig): this; /** - * The vertical scroll factor of this Game Object. - * - * The scroll factor controls the influence of the movement of a Camera upon this Game Object. - * - * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. - * It does not change the Game Objects actual position values. - * - * A value of 1 means it will move exactly in sync with a camera. - * A value of 0 means it will not move at all, even if the camera moves. - * Other values control the degree to which the camera movement is mapped to this Game Object. + * Scans the given rectangular area (given in tile coordinates) for tiles with an index matching + * `findIndex` and updates their index to match `newIndex`. This only modifies the index and does + * not change collision information. * - * Please be aware that scroll factor values other than 1 are not taken in to consideration when - * calculating physics collisions. Bodies always collide based on their world position, but changing - * the scroll factor is a visual adjustment to where the textures are rendered, which can offset - * them from physics bodies if not accounted for in your code. + * If no layer is specified, the maps current layer is used. + * @param findIndex The index of the tile to search for. + * @param newIndex The index of the tile to replace it with. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. + * @param layer The tile layer to use. If not given the current layer is used. */ - scrollFactorY: number; + replaceByIndex(findIndex: number, newIndex: number, tileX?: number, tileY?: number, width?: number, height?: number, layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tilemap; /** - * Sets the scroll factor of this Game Object. - * - * The scroll factor controls the influence of the movement of a Camera upon this Game Object. - * - * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. - * It does not change the Game Objects actual position values. - * - * A value of 1 means it will move exactly in sync with a camera. - * A value of 0 means it will not move at all, even if the camera moves. - * Other values control the degree to which the camera movement is mapped to this Game Object. + * Sets collision on the given tile or tiles within a layer by index. You can pass in either a + * single numeric index or an array of indexes: [2, 3, 15, 20]. The `collides` parameter controls if + * collision will be enabled (true) or disabled (false). * - * Please be aware that scroll factor values other than 1 are not taken in to consideration when - * calculating physics collisions. Bodies always collide based on their world position, but changing - * the scroll factor is a visual adjustment to where the textures are rendered, which can offset - * them from physics bodies if not accounted for in your code. - * @param x The horizontal scroll factor of this Game Object. - * @param y The vertical scroll factor of this Game Object. If not set it will use the `x` value. Default x. + * If no layer is specified, the maps current layer is used. + * @param indexes Either a single tile index, or an array of tile indexes. + * @param collides If true it will enable collision. If false it will clear collision. + * @param recalculateFaces Whether or not to recalculate the tile faces after the update. + * @param layer The tile layer to use. If not given the current layer is used. + * @param updateLayer If true, updates the current tiles on the layer. Set to false if no tiles have been placed for significant performance boost. Default true. */ - setScrollFactor(x: number, y?: number): this; + setCollision(indexes: number | any[], collides?: boolean, recalculateFaces?: boolean, layer?: string | number | Phaser.Tilemaps.TilemapLayer, updateLayer?: boolean): Phaser.Tilemaps.Tilemap; - } + /** + * Sets collision on a range of tiles in a layer whose index is between the specified `start` and + * `stop` (inclusive). Calling this with a start value of 10 and a stop value of 14 would set + * collision for tiles 10, 11, 12, 13 and 14. The `collides` parameter controls if collision will be + * enabled (true) or disabled (false). + * + * If no layer is specified, the maps current layer is used. + * @param start The first index of the tile to be set for collision. + * @param stop The last index of the tile to be set for collision. + * @param collides If true it will enable collision. If false it will clear collision. + * @param recalculateFaces Whether or not to recalculate the tile faces after the update. + * @param layer The tile layer to use. If not given the current layer is used. + */ + setCollisionBetween(start: number, stop: number, collides?: boolean, recalculateFaces?: boolean, layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tilemap; - /** - * A Tile is a representation of a single tile within the Tilemap. This is a lightweight data - * representation, so its position information is stored without factoring in scroll, layer - * scale or layer position. - */ - class Tile implements Phaser.GameObjects.Components.Alpha, Phaser.GameObjects.Components.Flip, Phaser.GameObjects.Components.Visible { /** + * Sets collision on the tiles within a layer by checking tile properties. If a tile has a property + * that matches the given properties object, its collision flag will be set. The `collides` + * parameter controls if collision will be enabled (true) or disabled (false). Passing in + * `{ collides: true }` would update the collision flag on any tiles with a "collides" property that + * has a value of true. Any tile that doesn't have "collides" set to true will be ignored. You can + * also use an array of values, e.g. `{ types: ["stone", "lava", "sand" ] }`. If a tile has a + * "types" property that matches any of those values, its collision flag will be updated. * - * @param layer The LayerData object in the Tilemap that this tile belongs to. - * @param index The unique index of this tile within the map. - * @param x The x coordinate of this tile in tile coordinates. - * @param y The y coordinate of this tile in tile coordinates. - * @param width Width of the tile in pixels. - * @param height Height of the tile in pixels. - * @param baseWidth The base width a tile in the map (in pixels). Tiled maps support - * multiple tileset sizes within one map, but they are still placed at intervals of the base - * tile width. - * @param baseHeight The base height of the tile in pixels (in pixels). Tiled maps - * support multiple tileset sizes within one map, but they are still placed at intervals of the - * base tile height. + * If no layer is specified, the maps current layer is used. + * @param properties An object with tile properties and corresponding values that should be checked. + * @param collides If true it will enable collision. If false it will clear collision. + * @param recalculateFaces Whether or not to recalculate the tile faces after the update. + * @param layer The tile layer to use. If not given the current layer is used. */ - constructor(layer: Phaser.Tilemaps.LayerData, index: integer, x: integer, y: integer, width: integer, height: integer, baseWidth: integer, baseHeight: integer); + setCollisionByProperty(properties: object, collides?: boolean, recalculateFaces?: boolean, layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tilemap; /** - * The LayerData in the Tilemap data that this tile belongs to. + * Sets collision on all tiles in the given layer, except for tiles that have an index specified in + * the given array. The `collides` parameter controls if collision will be enabled (true) or + * disabled (false). Tile indexes not currently in the layer are not affected. + * + * If no layer is specified, the maps current layer is used. + * @param indexes An array of the tile indexes to not be counted for collision. + * @param collides If true it will enable collision. If false it will clear collision. + * @param recalculateFaces Whether or not to recalculate the tile faces after the update. + * @param layer The tile layer to use. If not given the current layer is used. */ - layer: Phaser.Tilemaps.LayerData; + setCollisionByExclusion(indexes: number[], collides?: boolean, recalculateFaces?: boolean, layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tilemap; /** - * The index of this tile within the map data corresponding to the tileset, or -1 if this - * represents a blank tile. + * Sets collision on the tiles within a layer by checking each tiles collision group data + * (typically defined in Tiled within the tileset collision editor). If any objects are found within + * a tiles collision group, the tiles colliding information will be set. The `collides` parameter + * controls if collision will be enabled (true) or disabled (false). + * + * If no layer is specified, the maps current layer is used. + * @param collides If true it will enable collision. If false it will clear collision. + * @param recalculateFaces Whether or not to recalculate the tile faces after the update. + * @param layer The tile layer to use. If not given the current layer is used. */ - index: integer; + setCollisionFromCollisionGroup(collides?: boolean, recalculateFaces?: boolean, layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tilemap; /** - * The x map coordinate of this tile in tile units. + * Sets a global collision callback for the given tile index within the layer. This will affect all + * tiles on this layer that have the same index. If a callback is already set for the tile index it + * will be replaced. Set the callback to null to remove it. If you want to set a callback for a tile + * at a specific location on the map then see `setTileLocationCallback`. + * + * If no layer is specified, the maps current layer is used. + * @param indexes Either a single tile index, or an array of tile indexes to have a collision callback set for. All values should be integers. + * @param callback The callback that will be invoked when the tile is collided with. + * @param callbackContext The context under which the callback is called. + * @param layer The tile layer to use. If not given the current layer is used. */ - x: integer; + setTileIndexCallback(indexes: number | number[], callback: Function, callbackContext: object, layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tilemap; /** - * The y map coordinate of this tile in tile units. + * Sets a collision callback for the given rectangular area (in tile coordinates) within the layer. + * If a callback is already set for the tile index it will be replaced. Set the callback to null to + * remove it. + * + * If no layer is specified, the maps current layer is used. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. + * @param callback The callback that will be invoked when the tile is collided with. + * @param callbackContext The context under which the callback is called. + * @param layer The tile layer to use. If not given the current layer is used. */ - y: integer; + setTileLocationCallback(tileX: number, tileY: number, width: number, height: number, callback: Function, callbackContext?: object, layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tilemap; /** - * The width of the tile in pixels. + * Sets the current layer to the LayerData associated with `layer`. + * @param layer The name of the layer from Tiled, the index of the layer in the map or a TilemapLayer. If not given will default to the maps current layer index. */ - width: integer; + setLayer(layer?: string | number | Phaser.Tilemaps.TilemapLayer): this; /** - * The height of the tile in pixels. + * Sets the base tile size for the map. Note: this does not necessarily match the tileWidth and + * tileHeight for all layers. This also updates the base size on all tiles across all layers. + * @param tileWidth The width of the tiles the map uses for calculations. + * @param tileHeight The height of the tiles the map uses for calculations. */ - height: integer; + setBaseTileSize(tileWidth: number, tileHeight: number): this; /** - * The map's base width of a tile in pixels. Tiled maps support multiple tileset sizes - * within one map, but they are still placed at intervals of the base tile size. + * Sets the tile size for a specific `layer`. Note: this does not necessarily match the maps + * tileWidth and tileHeight for all layers. This will set the tile size for the layer and any + * tiles the layer has. + * @param tileWidth The width of the tiles (in pixels) in the layer. + * @param tileHeight The height of the tiles (in pixels) in the layer. + * @param layer The name of the layer from Tiled, the index of the layer in the map or a TilemapLayer. If not given will default to the maps current layer index. */ - baseWidth: integer; + setLayerTileSize(tileWidth: number, tileHeight: number, layer?: string | number | Phaser.Tilemaps.TilemapLayer): this; /** - * The map's base height of a tile in pixels. Tiled maps support multiple tileset sizes - * within one map, but they are still placed at intervals of the base tile size. + * Shuffles the tiles in a rectangular region (specified in tile coordinates) within the given + * layer. It will only randomize the tiles in that area, so if they're all the same nothing will + * appear to have changed! This method only modifies tile indexes and does not change collision + * information. + * + * If no layer is specified, the maps current layer is used. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. + * @param layer The tile layer to use. If not given the current layer is used. */ - baseHeight: integer; + shuffle(tileX?: number, tileY?: number, width?: number, height?: number, layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tilemap; /** - * The x coordinate of the top left of this tile in pixels. This is relative to the top left - * of the layer this tile is being rendered within. This property does NOT factor in camera - * scroll, layer scale or layer position. + * Scans the given rectangular area (given in tile coordinates) for tiles with an index matching + * `indexA` and swaps then with `indexB`. This only modifies the index and does not change collision + * information. + * + * If no layer is specified, the maps current layer is used. + * @param tileA First tile index. + * @param tileB Second tile index. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. + * @param layer The tile layer to use. If not given the current layer is used. */ - pixelX: number; + swapByIndex(tileA: number, tileB: number, tileX?: number, tileY?: number, width?: number, height?: number, layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tilemap; /** - * The y coordinate of the top left of this tile in pixels. This is relative to the top left - * of the layer this tile is being rendered within. This property does NOT factor in camera - * scroll, layer scale or layer position. + * Converts from tile X coordinates (tile units) to world X coordinates (pixels), factoring in the + * layers position, scale and scroll. + * + * If no layer is specified, the maps current layer is used. + * @param tileX The x coordinate, in tiles, not pixels. + * @param camera The Camera to use when calculating the tile index from the world values. + * @param layer The tile layer to use. If not given the current layer is used. */ - pixelY: number; + tileToWorldX(tileX: number, camera?: Phaser.Cameras.Scene2D.Camera, layer?: string | number | Phaser.Tilemaps.TilemapLayer): number; /** - * Tile specific properties. These usually come from Tiled. + * Converts from tile Y coordinates (tile units) to world Y coordinates (pixels), factoring in the + * layers position, scale and scroll. + * + * If no layer is specified, the maps current layer is used. + * @param tileY The y coordinate, in tiles, not pixels. + * @param camera The Camera to use when calculating the tile index from the world values. + * @param layer The tile layer to use. If not given the current layer is used. */ - properties: any; + tileToWorldY(tileY: number, camera?: Phaser.Cameras.Scene2D.Camera, layer?: string | number | Phaser.Tilemaps.TilemapLayer): number; /** - * The rotation angle of this tile. + * Converts from tile XY coordinates (tile units) to world XY coordinates (pixels), factoring in the + * layers position, scale and scroll. This will return a new Vector2 object or update the given + * `point` object. + * + * If no layer is specified, the maps current layer is used. + * @param tileX The x coordinate, in tiles, not pixels. + * @param tileY The y coordinate, in tiles, not pixels. + * @param vec2 A Vector2 to store the coordinates in. If not given a new Vector2 is created. + * @param camera The Camera to use when calculating the tile index from the world values. + * @param layer The tile layer to use. If not given the current layer is used. */ - rotation: number; + tileToWorldXY(tileX: number, tileY: number, vec2?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera, layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Math.Vector2; /** - * Whether the tile should collide with any object on the left side. + * Randomizes the indexes of a rectangular region of tiles (in tile coordinates) within the + * specified layer. Each tile will receive a new index. New indexes are drawn from the given + * weightedIndexes array. An example weighted array: + * + * [ + * { index: 6, weight: 4 }, // Probability of index 6 is 4 / 8 + * { index: 7, weight: 2 }, // Probability of index 7 would be 2 / 8 + * { index: 8, weight: 1.5 }, // Probability of index 8 would be 1.5 / 8 + * { index: 26, weight: 0.5 } // Probability of index 27 would be 0.5 / 8 + * ] + * + * The probability of any index being picked is (the indexs weight) / (sum of all weights). This + * method only modifies tile indexes and does not change collision information. + * + * If no layer is specified, the maps current layer is used. + * @param weightedIndexes An array of objects to randomly draw from during randomization. They should be in the form: { index: 0, weight: 4 } or { index: [0, 1], weight: 4 } if you wish to draw from multiple tile indexes. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. + * @param layer The tile layer to use. If not given the current layer is used. */ - collideLeft: boolean; + weightedRandomize(weightedIndexes: object[], tileX?: number, tileY?: number, width?: number, height?: number, layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tilemap; /** - * Whether the tile should collide with any object on the right side. + * Converts from world X coordinates (pixels) to tile X coordinates (tile units), factoring in the + * layers position, scale and scroll. + * + * If no layer is specified, the maps current layer is used. + * @param worldX The x coordinate to be converted, in pixels, not tiles. + * @param snapToFloor Whether or not to round the tile coordinate down to the nearest integer. + * @param camera The Camera to use when calculating the tile index from the world values. + * @param layer The tile layer to use. If not given the current layer is used. */ - collideRight: boolean; + worldToTileX(worldX: number, snapToFloor?: boolean, camera?: Phaser.Cameras.Scene2D.Camera, layer?: string | number | Phaser.Tilemaps.TilemapLayer): number; /** - * Whether the tile should collide with any object on the top side. + * Converts from world Y coordinates (pixels) to tile Y coordinates (tile units), factoring in the + * layers position, scale and scroll. + * + * If no layer is specified, the maps current layer is used. + * @param worldY The y coordinate to be converted, in pixels, not tiles. + * @param snapToFloor Whether or not to round the tile coordinate down to the nearest integer. + * @param camera The Camera to use when calculating the tile index from the world values. + * @param layer The tile layer to use. If not given the current layer is used. */ - collideUp: boolean; + worldToTileY(worldY: number, snapToFloor?: boolean, camera?: Phaser.Cameras.Scene2D.Camera, layer?: string | number | Phaser.Tilemaps.TilemapLayer): number; /** - * Whether the tile should collide with any object on the bottom side. + * Converts from world XY coordinates (pixels) to tile XY coordinates (tile units), factoring in the + * layers position, scale and scroll. This will return a new Vector2 object or update the given + * `point` object. + * + * If no layer is specified, the maps current layer is used. + * @param worldX The x coordinate to be converted, in pixels, not tiles. + * @param worldY The y coordinate to be converted, in pixels, not tiles. + * @param snapToFloor Whether or not to round the tile coordinate down to the nearest integer. + * @param vec2 A Vector2 to store the coordinates in. If not given a new Vector2 is created. + * @param camera The Camera to use when calculating the tile index from the world values. + * @param layer The tile layer to use. If not given the current layer is used. */ - collideDown: boolean; + worldToTileXY(worldX: number, worldY: number, snapToFloor?: boolean, vec2?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera, layer?: string | number | Phaser.Tilemaps.TilemapLayer): Phaser.Math.Vector2; /** - * Whether the tile's left edge is interesting for collisions. + * Removes all layer data from this Tilemap and nulls the scene reference. This will destroy any + * TilemapLayers that have been created. */ - faceLeft: boolean; + destroy(): void; + } + + /** + * A Tilemap Layer is a Game Object that renders LayerData from a Tilemap when used in combination + * with one, or more, Tilesets. + */ + class TilemapLayer extends Phaser.GameObjects.GameObject implements Phaser.GameObjects.Components.Alpha, Phaser.GameObjects.Components.BlendMode, Phaser.GameObjects.Components.ComputedSize, Phaser.GameObjects.Components.Depth, Phaser.GameObjects.Components.Flip, Phaser.GameObjects.Components.GetBounds, Phaser.GameObjects.Components.Origin, Phaser.GameObjects.Components.Pipeline, Phaser.GameObjects.Components.ScrollFactor, Phaser.GameObjects.Components.Transform, Phaser.GameObjects.Components.Visible { /** - * Whether the tile's right edge is interesting for collisions. + * + * @param scene The Scene to which this Game Object belongs. + * @param tilemap The Tilemap this layer is a part of. + * @param layerIndex The index of the LayerData associated with this layer. + * @param tileset The tileset, or an array of tilesets, used to render this layer. Can be a string or a Tileset object. + * @param x The world x position where the top left of this layer will be placed. Default 0. + * @param y The world y position where the top left of this layer will be placed. Default 0. */ - faceRight: boolean; + constructor(scene: Phaser.Scene, tilemap: Phaser.Tilemaps.Tilemap, layerIndex: number, tileset: string | string[] | Phaser.Tilemaps.Tileset | Phaser.Tilemaps.Tileset[], x?: number, y?: number); /** - * Whether the tile's top edge is interesting for collisions. + * Used internally by physics system to perform fast type checks. */ - faceTop: boolean; + readonly isTilemap: boolean; /** - * Whether the tile's bottom edge is interesting for collisions. + * The Tilemap that this layer is a part of. */ - faceBottom: boolean; + tilemap: Phaser.Tilemaps.Tilemap; /** - * Tile collision callback. + * The index of the LayerData associated with this layer. */ - collisionCallback: Function; + layerIndex: number; /** - * The context in which the collision callback will be called. + * The LayerData associated with this layer. LayerData can only be associated with one + * tilemap layer. */ - collisionCallbackContext: object; + layer: Phaser.Tilemaps.LayerData; /** - * The tint to apply to this tile. Note: tint is currently a single color value instead of - * the 4 corner tint component on other GameObjects. + * An array of `Tileset` objects associated with this layer. */ - tint: number; + tileset: Phaser.Tilemaps.Tileset[]; /** - * An empty object where physics-engine specific information (e.g. bodies) may be stored. + * The total number of tiles drawn by the renderer in the last frame. */ - physics: object; + readonly tilesDrawn: number; /** - * Check if the given x and y world coordinates are within this Tile. This does not factor in - * camera scroll, layer scale or layer position. - * @param x The x coordinate to test. - * @param y The y coordinate to test. + * The total number of tiles in this layer. Updated every frame. */ - containsPoint(x: number, y: number): boolean; + readonly tilesTotal: number; /** - * Copies the tile data & properties from the given tile to this tile. This copies everything - * except for position and interesting faces. - * @param tile The tile to copy from. + * Used internally during rendering. This holds the tiles that are visible within the Camera. */ - copy(tile: Phaser.Tilemaps.Tile): Phaser.Tilemaps.Tile; + culledTiles: Phaser.Tilemaps.Tile[]; /** - * The collision group for this Tile, defined within the Tileset. This returns a reference to - * the collision group stored within the Tileset, so any modification of the returned object - * will impact all tiles that have the same index as this tile. + * You can control if the camera should cull tiles on this layer before rendering them or not. + * + * By default the camera will try to cull the tiles in this layer, to avoid over-drawing to the renderer. + * + * However, there are some instances when you may wish to disable this, and toggling this flag allows + * you to do so. Also see `setSkipCull` for a chainable method that does the same thing. */ - getCollisionGroup(): object; + skipCull: boolean; /** - * The tile data for this Tile, defined within the Tileset. This typically contains Tiled - * collision data, tile animations and terrain information. This returns a reference to the tile - * data stored within the Tileset, so any modification of the returned object will impact all - * tiles that have the same index as this tile. + * The amount of extra tiles to add into the cull rectangle when calculating its horizontal size. + * + * See the method `setCullPadding` for more details. */ - getTileData(): object; + cullPaddingX: number; /** - * Gets the world X position of the left side of the tile, factoring in the layers position, - * scale and scroll. - * @param camera The Camera to use to perform the check. + * The amount of extra tiles to add into the cull rectangle when calculating its vertical size. + * + * See the method `setCullPadding` for more details. */ - getLeft(camera?: Phaser.Cameras.Scene2D.Camera): number; + cullPaddingY: number; /** - * Gets the world X position of the right side of the tile, factoring in the layer's position, - * scale and scroll. - * @param camera The Camera to use to perform the check. + * The callback that is invoked when the tiles are culled. + * + * It will call a different function based on the map orientation: + * + * Orthogonal (the default) is `TilemapComponents.CullTiles` + * Isometric is `TilemapComponents.IsometricCullTiles` + * Hexagonal is `TilemapComponents.HexagonalCullTiles` + * Staggered is `TilemapComponents.StaggeredCullTiles` + * + * However, you can override this to call any function you like. + * + * It will be sent 4 arguments: + * + * 1. The Phaser.Tilemaps.LayerData object for this Layer + * 2. The Camera that is culling the layer. You can check its `dirty` property to see if it has changed since the last cull. + * 3. A reference to the `culledTiles` array, which should be used to store the tiles you want rendered. + * 4. The Render Order constant. + * + * See the `TilemapComponents.CullTiles` source code for details on implementing your own culling system. */ - getRight(camera?: Phaser.Cameras.Scene2D.Camera): number; + cullCallback: Function; /** - * Gets the world Y position of the top side of the tile, factoring in the layer's position, - * scale and scroll. - * @param camera The Camera to use to perform the check. + * An array holding the mapping between the tile indexes and the tileset they belong to. */ - getTop(camera?: Phaser.Cameras.Scene2D.Camera): number; + gidMap: Phaser.Tilemaps.Tileset[]; /** - * Gets the world Y position of the bottom side of the tile, factoring in the layer's position, - * scale and scroll. - * @param camera The Camera to use to perform the check. + * Sets the rendering (draw) order of the tiles in this layer. + * + * The default is 'right-down', meaning it will order the tiles starting from the top-left, + * drawing to the right and then moving down to the next row. + * + * The draw orders are: + * + * 0 = right-down + * 1 = left-down + * 2 = right-up + * 3 = left-up + * + * Setting the render order does not change the tiles or how they are stored in the layer, + * it purely impacts the order in which they are rendered. + * + * You can provide either an integer (0 to 3), or the string version of the order. + * @param renderOrder The render (draw) order value. Either an integer between 0 and 3, or a string: 'right-down', 'left-down', 'right-up' or 'left-up'. */ - getBottom(camera?: Phaser.Cameras.Scene2D.Camera): number; + setRenderOrder(renderOrder: number | string): this; /** - * Gets the world rectangle bounding box for the tile, factoring in the layers position, - * scale and scroll. - * @param camera The Camera to use to perform the check. - * @param output [description] + * Calculates interesting faces at the given tile coordinates of the specified layer. Interesting + * faces are used internally for optimizing collisions against tiles. This method is mostly used + * internally to optimize recalculating faces when only one tile has been changed. + * @param tileX The x coordinate. + * @param tileY The y coordinate. */ - getBounds(camera?: Phaser.Cameras.Scene2D.Camera, output?: object): Phaser.Geom.Rectangle | object; + calculateFacesAt(tileX: number, tileY: number): this; /** - * Gets the world X position of the center of the tile, factoring in the layer's position, - * scale and scroll. - * @param camera The Camera to use to perform the check. + * Calculates interesting faces within the rectangular area specified (in tile coordinates) of the + * layer. Interesting faces are used internally for optimizing collisions against tiles. This method + * is mostly used internally. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. */ - getCenterX(camera?: Phaser.Cameras.Scene2D.Camera): number; + calculateFacesWithin(tileX?: number, tileY?: number, width?: number, height?: number): this; /** - * Gets the world Y position of the center of the tile, factoring in the layer's position, - * scale and scroll. - * @param camera The Camera to use to perform the check. + * Creates a Sprite for every object matching the given tile indexes in the layer. You can + * optionally specify if each tile will be replaced with a new tile after the Sprite has been + * created. This is useful if you want to lay down special tiles in a level that are converted to + * Sprites, but want to replace the tile itself with a floor tile or similar once converted. + * @param indexes The tile index, or array of indexes, to create Sprites from. + * @param replacements The tile index, or array of indexes, to change a converted + * tile to. Set to `null` to leave the tiles unchanged. If an array is given, it is assumed to be a + * one-to-one mapping with the indexes array. + * @param spriteConfig The config object to pass into the Sprite creator (i.e. + * scene.make.sprite). + * @param scene The Scene to create the Sprites within. + * @param camera The Camera to use when determining the world XY */ - getCenterY(camera?: Phaser.Cameras.Scene2D.Camera): number; + createFromTiles(indexes: number | any[], replacements: number | any[], spriteConfig?: Phaser.Types.GameObjects.Sprite.SpriteConfig, scene?: Phaser.Scene, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.GameObjects.Sprite[]; /** - * Clean up memory. + * Returns the tiles in the given layer that are within the cameras viewport. + * This is used internally during rendering. + * @param camera The Camera to run the cull check against. */ - destroy(): void; + cull(camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Tilemaps.Tile[]; /** - * Check for intersection with this tile. This does not factor in camera scroll, layer scale or - * layer position. - * @param x The x axis in pixels. - * @param y The y axis in pixels. - * @param right The right point. - * @param bottom The bottom point. + * Copies the tiles in the source rectangular area to a new destination (all specified in tile + * coordinates) within the layer. This copies all tile properties & recalculates collision + * information in the destination region. + * @param srcTileX The x coordinate of the area to copy from, in tiles, not pixels. + * @param srcTileY The y coordinate of the area to copy from, in tiles, not pixels. + * @param width The width of the area to copy, in tiles, not pixels. + * @param height The height of the area to copy, in tiles, not pixels. + * @param destTileX The x coordinate of the area to copy to, in tiles, not pixels. + * @param destTileY The y coordinate of the area to copy to, in tiles, not pixels. + * @param recalculateFaces `true` if the faces data should be recalculated. Default true. */ - intersects(x: number, y: number, right: number, bottom: number): boolean; + copy(srcTileX: number, srcTileY: number, width: number, height: number, destTileX: number, destTileY: number, recalculateFaces?: boolean): this; /** - * Checks if the tile is interesting. - * @param collides If true, will consider the tile interesting if it collides on any side. - * @param faces If true, will consider the tile interesting if it has an interesting face. + * Sets the tiles in the given rectangular area (in tile coordinates) of the layer with the + * specified index. Tiles will be set to collide if the given index is a colliding index. + * Collision information in the region will be recalculated. + * @param index The tile index to fill the area with. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. + * @param recalculateFaces `true` if the faces data should be recalculated. Default true. */ - isInteresting(collides: boolean, faces: boolean): boolean; + fill(index: number, tileX?: number, tileY?: number, width?: number, height?: number, recalculateFaces?: boolean): this; /** - * Reset collision status flags. - * @param recalculateFaces Whether or not to recalculate interesting faces for this tile and its neighbors. Default true. + * For each tile in the given rectangular area (in tile coordinates) of the layer, run the given + * filter callback function. Any tiles that pass the filter test (i.e. where the callback returns + * true) will returned as a new array. Similar to Array.prototype.Filter in vanilla JS. + * @param callback The callback. Each tile in the given area will be passed to this + * callback as the first and only parameter. The callback should return true for tiles that pass the + * filter. + * @param context The context under which the callback should be run. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area to filter. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area to filter. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. + * @param filteringOptions Optional filters to apply when getting the tiles. */ - resetCollision(recalculateFaces?: boolean): Phaser.Tilemaps.Tile; + filterTiles(callback: Function, context?: object, tileX?: number, tileY?: number, width?: number, height?: number, filteringOptions?: Phaser.Types.Tilemaps.FilteringOptions): Phaser.Tilemaps.Tile[]; /** - * Reset faces. + * Searches the entire map layer for the first tile matching the given index, then returns that Tile + * object. If no match is found, it returns null. The search starts from the top-left tile and + * continues horizontally until it hits the end of the row, then it drops down to the next column. + * If the reverse boolean is true, it scans starting from the bottom-right corner traveling up to + * the top-left. + * @param index The tile index value to search for. + * @param skip The number of times to skip a matching tile before returning. Default 0. + * @param reverse If true it will scan the layer in reverse, starting at the bottom-right. Otherwise it scans from the top-left. Default false. */ - resetFaces(): Phaser.Tilemaps.Tile; + findByIndex(index: number, skip?: number, reverse?: boolean): Phaser.Tilemaps.Tile; /** - * Sets the collision flags for each side of this tile and updates the interesting faces list. - * @param left Indicating collide with any object on the left. - * @param right Indicating collide with any object on the right. - * @param up Indicating collide with any object on the top. - * @param down Indicating collide with any object on the bottom. - * @param recalculateFaces Whether or not to recalculate interesting faces - * for this tile and its neighbors. Default true. + * Find the first tile in the given rectangular area (in tile coordinates) of the layer that + * satisfies the provided testing function. I.e. finds the first tile for which `callback` returns + * true. Similar to Array.prototype.find in vanilla JS. + * @param callback The callback. Each tile in the given area will be passed to this callback as the first and only parameter. + * @param context The context under which the callback should be run. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area to search. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area to search. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. + * @param filteringOptions Optional filters to apply when getting the tiles. */ - setCollision(left: boolean, right?: boolean, up?: boolean, down?: boolean, recalculateFaces?: boolean): Phaser.Tilemaps.Tile; + findTile(callback: FindTileCallback, context?: object, tileX?: number, tileY?: number, width?: number, height?: number, filteringOptions?: Phaser.Types.Tilemaps.FilteringOptions): Phaser.Tilemaps.Tile; /** - * Set a callback to be called when this tile is hit by an object. The callback must true for - * collision processing to take place. - * @param callback Callback function. - * @param context Callback will be called within this context. + * For each tile in the given rectangular area (in tile coordinates) of the layer, run the given + * callback. Similar to Array.prototype.forEach in vanilla JS. + * @param callback The callback. Each tile in the given area will be passed to this callback as the first and only parameter. + * @param context The context, or scope, under which the callback should be run. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area to search. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area to search. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. + * @param filteringOptions Optional filters to apply when getting the tiles. */ - setCollisionCallback(callback: Function, context: object): Phaser.Tilemaps.Tile; + forEachTile(callback: EachTileCallback, context?: object, tileX?: number, tileY?: number, width?: number, height?: number, filteringOptions?: Phaser.Types.Tilemaps.FilteringOptions): this; /** - * Sets the size of the tile and updates its pixelX and pixelY. - * @param tileWidth The width of the tile in pixels. - * @param tileHeight The height of the tile in pixels. - * @param baseWidth The base width a tile in the map (in pixels). - * @param baseHeight The base height of the tile in pixels (in pixels). + * Gets a tile at the given tile coordinates from the given layer. + * @param tileX X position to get the tile from (given in tile units, not pixels). + * @param tileY Y position to get the tile from (given in tile units, not pixels). + * @param nonNull If true getTile won't return null for empty tiles, but a Tile object with an index of -1. Default false. */ - setSize(tileWidth: integer, tileHeight: integer, baseWidth: integer, baseHeight: integer): Phaser.Tilemaps.Tile; + getTileAt(tileX: number, tileY: number, nonNull?: boolean): Phaser.Tilemaps.Tile; /** - * Used internally. Updates the tile's world XY position based on the current tile size. + * Gets a tile at the given world coordinates from the given layer. + * @param worldX X position to get the tile from (given in pixels) + * @param worldY Y position to get the tile from (given in pixels) + * @param nonNull If true, function won't return null for empty tiles, but a Tile object with an index of -1. Default false. + * @param camera The Camera to use when calculating the tile index from the world values. */ - updatePixelXY(): Phaser.Tilemaps.Tile; + getTileAtWorldXY(worldX: number, worldY: number, nonNull?: boolean, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Tilemaps.Tile; /** - * True if this tile can collide on any of its faces or has a collision callback set. + * Gets the tiles in the given rectangular area (in tile coordinates) of the layer. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. + * @param filteringOptions Optional filters to apply when getting the tiles. */ - readonly canCollide: boolean; + getTilesWithin(tileX?: number, tileY?: number, width?: number, height?: number, filteringOptions?: Phaser.Types.Tilemaps.FilteringOptions): Phaser.Tilemaps.Tile[]; /** - * True if this tile can collide on any of its faces. + * Gets the tiles that overlap with the given shape in the given layer. The shape must be a Circle, + * Line, Rectangle or Triangle. The shape should be in world coordinates. + * @param shape A shape in world (pixel) coordinates + * @param filteringOptions Optional filters to apply when getting the tiles. + * @param camera The Camera to use when factoring in which tiles to return. */ - readonly collides: boolean; + getTilesWithinShape(shape: Phaser.Geom.Circle | Phaser.Geom.Line | Phaser.Geom.Rectangle | Phaser.Geom.Triangle, filteringOptions?: Phaser.Types.Tilemaps.FilteringOptions, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Tilemaps.Tile[]; /** - * True if this tile has any interesting faces. + * Gets the tiles in the given rectangular area (in world coordinates) of the layer. + * @param worldX The world x coordinate for the top-left of the area. + * @param worldY The world y coordinate for the top-left of the area. + * @param width The width of the area. + * @param height The height of the area. + * @param filteringOptions Optional filters to apply when getting the tiles. + * @param camera The Camera to use when factoring in which tiles to return. */ - readonly hasInterestingFace: boolean; + getTilesWithinWorldXY(worldX: number, worldY: number, width: number, height: number, filteringOptions?: Phaser.Types.Tilemaps.FilteringOptions, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Tilemaps.Tile[]; /** - * The tileset that contains this Tile. This is null if accessed from a LayerData instance - * before the tile is placed in a StaticTilemapLayer or DynamicTilemapLayer, or if the tile has - * an index that doesn't correspond to any of the map's tilesets. + * Checks if there is a tile at the given location (in tile coordinates) in the given layer. Returns + * false if there is no tile or if the tile at that location has an index of -1. + * @param tileX The x coordinate, in tiles, not pixels. + * @param tileY The y coordinate, in tiles, not pixels. */ - readonly tileset: Phaser.Tilemaps.Tileset; + hasTileAt(tileX: number, tileY: number): boolean; /** - * The tilemap layer that contains this Tile. This will only return null if accessed from a - * LayerData instance before the tile is placed within a StaticTilemapLayer or - * DynamicTilemapLayer. + * Checks if there is a tile at the given location (in world coordinates) in the given layer. Returns + * false if there is no tile or if the tile at that location has an index of -1. + * @param worldX The x coordinate, in pixels. + * @param worldY The y coordinate, in pixels. + * @param camera The Camera to use when factoring in which tiles to return. */ - readonly tilemapLayer: Phaser.Tilemaps.StaticTilemapLayer | Phaser.Tilemaps.DynamicTilemapLayer; + hasTileAtWorldXY(worldX: number, worldY: number, camera?: Phaser.Cameras.Scene2D.Camera): boolean; /** - * The tilemap that contains this Tile. This will only return null if accessed from a LayerData - * instance before the tile is placed within a StaticTilemapLayer or DynamicTilemapLayer. + * Puts a tile at the given tile coordinates in the specified layer. You can pass in either an index + * or a Tile object. If you pass in a Tile, all attributes will be copied over to the specified + * location. If you pass in an index, only the index at the specified location will be changed. + * Collision information will be recalculated at the specified location. + * @param tile The index of this tile to set or a Tile object. + * @param tileX The x coordinate, in tiles, not pixels. + * @param tileY The y coordinate, in tiles, not pixels. + * @param recalculateFaces `true` if the faces data should be recalculated. Default true. */ - readonly tilemap: Phaser.Tilemaps.Tilemap; + putTileAt(tile: number | Phaser.Tilemaps.Tile, tileX: number, tileY: number, recalculateFaces?: boolean): Phaser.Tilemaps.Tile; /** - * Clears all alpha values associated with this Game Object. - * - * Immediately sets the alpha levels back to 1 (fully opaque). + * Puts a tile at the given world coordinates (pixels) in the specified layer. You can pass in either + * an index or a Tile object. If you pass in a Tile, all attributes will be copied over to the + * specified location. If you pass in an index, only the index at the specified location will be + * changed. Collision information will be recalculated at the specified location. + * @param tile The index of this tile to set or a Tile object. + * @param worldX The x coordinate, in pixels. + * @param worldY The y coordinate, in pixels. + * @param recalculateFaces `true` if the faces data should be recalculated. + * @param camera The Camera to use when calculating the tile index from the world values. */ - clearAlpha(): this; + putTileAtWorldXY(tile: number | Phaser.Tilemaps.Tile, worldX: number, worldY: number, recalculateFaces?: boolean, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Tilemaps.Tile; /** - * Set the Alpha level of this Game Object. The alpha controls the opacity of the Game Object as it renders. - * Alpha values are provided as a float between 0, fully transparent, and 1, fully opaque. - * - * If your game is running under WebGL you can optionally specify four different alpha values, each of which - * correspond to the four corners of the Game Object. Under Canvas only the `topLeft` value given is used. - * @param topLeft The alpha value used for the top-left of the Game Object. If this is the only value given it's applied across the whole Game Object. Default 1. - * @param topRight The alpha value used for the top-right of the Game Object. WebGL only. - * @param bottomLeft The alpha value used for the bottom-left of the Game Object. WebGL only. - * @param bottomRight The alpha value used for the bottom-right of the Game Object. WebGL only. + * Puts an array of tiles or a 2D array of tiles at the given tile coordinates in the specified + * layer. The array can be composed of either tile indexes or Tile objects. If you pass in a Tile, + * all attributes will be copied over to the specified location. If you pass in an index, only the + * index at the specified location will be changed. Collision information will be recalculated + * within the region tiles were changed. + * @param tile A row (array) or grid (2D array) of Tiles or tile indexes to place. + * @param tileX The x coordinate, in tiles, not pixels. + * @param tileY The y coordinate, in tiles, not pixels. + * @param recalculateFaces `true` if the faces data should be recalculated. Default true. */ - setAlpha(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; + putTilesAt(tile: number[] | number[][] | Phaser.Tilemaps.Tile[] | Phaser.Tilemaps.Tile[][], tileX: number, tileY: number, recalculateFaces?: boolean): this; /** - * The alpha value of the Game Object. - * - * This is a global value, impacting the entire Game Object, not just a region of it. + * Randomizes the indexes of a rectangular region of tiles (in tile coordinates) within the + * specified layer. Each tile will receive a new index. If an array of indexes is passed in, then + * those will be used for randomly assigning new tile indexes. If an array is not provided, the + * indexes found within the region (excluding -1) will be used for randomly assigning new tile + * indexes. This method only modifies tile indexes and does not change collision information. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. + * @param indexes An array of indexes to randomly draw from during randomization. */ - alpha: number; + randomize(tileX?: number, tileY?: number, width?: number, height?: number, indexes?: number[]): this; /** - * The alpha value starting from the top-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * Removes the tile at the given tile coordinates in the specified layer and updates the layers + * collision information. + * @param tileX The x coordinate, in tiles, not pixels. + * @param tileY The y coordinate, in tiles, not pixels. + * @param replaceWithNull If true, this will replace the tile at the specified location with null instead of a Tile with an index of -1. Default true. + * @param recalculateFaces `true` if the faces data should be recalculated. Default true. */ - alphaTopLeft: number; + removeTileAt(tileX: number, tileY: number, replaceWithNull?: boolean, recalculateFaces?: boolean): Phaser.Tilemaps.Tile; /** - * The alpha value starting from the top-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * Removes the tile at the given world coordinates in the specified layer and updates the layers + * collision information. + * @param worldX The x coordinate, in pixels. + * @param worldY The y coordinate, in pixels. + * @param replaceWithNull If true, this will replace the tile at the specified location with null instead of a Tile with an index of -1. Default true. + * @param recalculateFaces `true` if the faces data should be recalculated. Default true. + * @param camera The Camera to use when calculating the tile index from the world values. */ - alphaTopRight: number; + removeTileAtWorldXY(worldX: number, worldY: number, replaceWithNull?: boolean, recalculateFaces?: boolean, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Tilemaps.Tile; /** - * The alpha value starting from the bottom-left of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * Draws a debug representation of the layer to the given Graphics. This is helpful when you want to + * get a quick idea of which of your tiles are colliding and which have interesting faces. The tiles + * are drawn starting at (0, 0) in the Graphics, allowing you to place the debug representation + * wherever you want on the screen. + * @param graphics The target Graphics object to draw upon. + * @param styleConfig An object specifying the colors to use for the debug drawing. */ - alphaBottomLeft: number; + renderDebug(graphics: Phaser.GameObjects.Graphics, styleConfig?: Phaser.Types.Tilemaps.StyleConfig): this; /** - * The alpha value starting from the bottom-right of the Game Object. - * This value is interpolated from the corner to the center of the Game Object. + * Scans the given rectangular area (given in tile coordinates) for tiles with an index matching + * `findIndex` and updates their index to match `newIndex`. This only modifies the index and does + * not change collision information. + * @param findIndex The index of the tile to search for. + * @param newIndex The index of the tile to replace it with. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. */ - alphaBottomRight: number; + replaceByIndex(findIndex: number, newIndex: number, tileX?: number, tileY?: number, width?: number, height?: number): this; /** - * The horizontally flipped state of the Game Object. + * You can control if the Cameras should cull tiles before rendering them or not. * - * A Game Object that is flipped horizontally will render inversed on the horizontal axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * By default the camera will try to cull the tiles in this layer, to avoid over-drawing to the renderer. + * + * However, there are some instances when you may wish to disable this. + * @param value Set to `true` to stop culling tiles. Set to `false` to enable culling again. Default true. */ - flipX: boolean; + setSkipCull(value?: boolean): this; /** - * The vertically flipped state of the Game Object. - * - * A Game Object that is flipped vertically will render inversed on the vertical axis (i.e. upside down) - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * When a Camera culls the tiles in this layer it does so using its view into the world, building up a + * rectangle inside which the tiles must exist or they will be culled. Sometimes you may need to expand the size + * of this 'cull rectangle', especially if you plan on rotating the Camera viewing the layer. Do so + * by providing the padding values. The values given are in tiles, not pixels. So if the tile width was 32px + * and you set `paddingX` to be 4, it would add 32px x 4 to the cull rectangle (adjusted for scale) + * @param paddingX The amount of extra horizontal tiles to add to the cull check padding. Default 1. + * @param paddingY The amount of extra vertical tiles to add to the cull check padding. Default 1. */ - flipY: boolean; + setCullPadding(paddingX?: number, paddingY?: number): this; /** - * Toggles the horizontal flipped state of this Game Object. - * - * A Game Object that is flipped horizontally will render inversed on the horizontal axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * Sets collision on the given tile or tiles within a layer by index. You can pass in either a + * single numeric index or an array of indexes: [2, 3, 15, 20]. The `collides` parameter controls if + * collision will be enabled (true) or disabled (false). + * @param indexes Either a single tile index, or an array of tile indexes. + * @param collides If true it will enable collision. If false it will clear collision. Default true. + * @param recalculateFaces Whether or not to recalculate the tile faces after the update. Default true. + * @param updateLayer If true, updates the current tiles on the layer. Set to false if no tiles have been placed for significant performance boost. Default true. */ - toggleFlipX(): this; + setCollision(indexes: number | any[], collides?: boolean, recalculateFaces?: boolean, updateLayer?: boolean): this; /** - * Toggles the vertical flipped state of this Game Object. + * Sets collision on a range of tiles in a layer whose index is between the specified `start` and + * `stop` (inclusive). Calling this with a start value of 10 and a stop value of 14 would set + * collision for tiles 10, 11, 12, 13 and 14. The `collides` parameter controls if collision will be + * enabled (true) or disabled (false). + * @param start The first index of the tile to be set for collision. + * @param stop The last index of the tile to be set for collision. + * @param collides If true it will enable collision. If false it will clear collision. Default true. + * @param recalculateFaces Whether or not to recalculate the tile faces after the update. Default true. */ - toggleFlipY(): this; + setCollisionBetween(start: number, stop: number, collides?: boolean, recalculateFaces?: boolean): this; /** - * Sets the horizontal flipped state of this Game Object. - * - * A Game Object that is flipped horizontally will render inversed on the horizontal axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. - * @param value The flipped state. `false` for no flip, or `true` to be flipped. + * Sets collision on the tiles within a layer by checking tile properties. If a tile has a property + * that matches the given properties object, its collision flag will be set. The `collides` + * parameter controls if collision will be enabled (true) or disabled (false). Passing in + * `{ collides: true }` would update the collision flag on any tiles with a "collides" property that + * has a value of true. Any tile that doesn't have "collides" set to true will be ignored. You can + * also use an array of values, e.g. `{ types: ["stone", "lava", "sand" ] }`. If a tile has a + * "types" property that matches any of those values, its collision flag will be updated. + * @param properties An object with tile properties and corresponding values that should be checked. + * @param collides If true it will enable collision. If false it will clear collision. Default true. + * @param recalculateFaces Whether or not to recalculate the tile faces after the update. Default true. */ - setFlipX(value: boolean): this; + setCollisionByProperty(properties: object, collides?: boolean, recalculateFaces?: boolean): this; /** - * Sets the vertical flipped state of this Game Object. - * @param value The flipped state. `false` for no flip, or `true` to be flipped. + * Sets collision on all tiles in the given layer, except for tiles that have an index specified in + * the given array. The `collides` parameter controls if collision will be enabled (true) or + * disabled (false). Tile indexes not currently in the layer are not affected. + * @param indexes An array of the tile indexes to not be counted for collision. + * @param collides If true it will enable collision. If false it will clear collision. Default true. + * @param recalculateFaces Whether or not to recalculate the tile faces after the update. Default true. */ - setFlipY(value: boolean): this; + setCollisionByExclusion(indexes: number[], collides?: boolean, recalculateFaces?: boolean): this; /** - * Sets the horizontal and vertical flipped state of this Game Object. - * - * A Game Object that is flipped will render inversed on the flipped axis. - * Flipping always takes place from the middle of the texture and does not impact the scale value. - * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. - * @param x The horizontal flipped state. `false` for no flip, or `true` to be flipped. - * @param y The horizontal flipped state. `false` for no flip, or `true` to be flipped. + * Sets collision on the tiles within a layer by checking each tiles collision group data + * (typically defined in Tiled within the tileset collision editor). If any objects are found within + * a tiles collision group, the tile's colliding information will be set. The `collides` parameter + * controls if collision will be enabled (true) or disabled (false). + * @param collides If true it will enable collision. If false it will clear collision. Default true. + * @param recalculateFaces Whether or not to recalculate the tile faces after the update. Default true. */ - setFlip(x: boolean, y: boolean): this; + setCollisionFromCollisionGroup(collides?: boolean, recalculateFaces?: boolean): this; /** - * Resets the horizontal and vertical flipped state of this Game Object back to their default un-flipped state. + * Sets a global collision callback for the given tile index within the layer. This will affect all + * tiles on this layer that have the same index. If a callback is already set for the tile index it + * will be replaced. Set the callback to null to remove it. If you want to set a callback for a tile + * at a specific location on the map then see setTileLocationCallback. + * @param indexes Either a single tile index, or an array of tile indexes to have a collision callback set for. + * @param callback The callback that will be invoked when the tile is collided with. + * @param callbackContext The context under which the callback is called. */ - resetFlip(): this; + setTileIndexCallback(indexes: number | number[], callback: Function, callbackContext: object): this; /** - * The visible state of the Game Object. - * - * An invisible Game Object will skip rendering, but will still process update logic. + * Sets a collision callback for the given rectangular area (in tile coordinates) within the layer. + * If a callback is already set for the tile index it will be replaced. Set the callback to null to + * remove it. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. + * @param callback The callback that will be invoked when the tile is collided with. + * @param callbackContext The context, or scope, under which the callback is invoked. */ - visible: boolean; + setTileLocationCallback(tileX?: number, tileY?: number, width?: number, height?: number, callback?: Function, callbackContext?: object): this; /** - * Sets the visibility of this Game Object. - * - * An invisible Game Object will skip rendering, but will still process update logic. - * @param value The visible state of the Game Object. + * Shuffles the tiles in a rectangular region (specified in tile coordinates) within the given + * layer. It will only randomize the tiles in that area, so if they're all the same nothing will + * appear to have changed! This method only modifies tile indexes and does not change collision + * information. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. */ - setVisible(value: boolean): this; - - } + shuffle(tileX?: number, tileY?: number, width?: number, height?: number): this; - /** - * A Tilemap is a container for Tilemap data. This isn't a display object, rather, it holds data - * about the map and allows you to add tilesets and tilemap layers to it. A map can have one or - * more tilemap layers (StaticTilemapLayer or DynamicTilemapLayer), which are the display - * objects that actually render tiles. - * - * The Tilemap data be parsed from a Tiled JSON file, a CSV file or a 2D array. Tiled is a free - * software package specifically for creating tile maps, and is available from: - * http://www.mapeditor.org - * - * A Tilemap has handy methods for getting & manipulating the tiles within a layer. You can only - * use the methods that change tiles (e.g. removeTileAt) on a DynamicTilemapLayer. - * - * Note that all Tilemaps use a base tile size to calculate dimensions from, but that a - * StaticTilemapLayer or DynamicTilemapLayer may have its own unique tile size that overrides - * it. - * - * As of Phaser 3.21.0, if your tilemap includes layer groups (a feature of Tiled 1.2.0+) these - * will be traversed and the following properties will affect children: - * - opacity (blended with parent) and visibility (parent overrides child) - * - Vertical and horizontal offset - * The grouping hierarchy is not preserved and all layers will be flattened into a single array. - * Group layers are parsed during Tilemap construction but are discarded after parsing so dynamic - * layers will NOT continue to be affected by a parent. - * - * To avoid duplicate layer names, a layer that is a child of a group layer will have its parent - * group name prepended with a '/'. For example, consider a group called 'ParentGroup' with a - * child called 'Layer 1'. In the Tilemap object, 'Layer 1' will have the name - * 'ParentGroup/Layer 1'. - */ - class Tilemap { /** - * - * @param scene The Scene to which this Tilemap belongs. - * @param mapData A MapData instance containing Tilemap data. + * Scans the given rectangular area (given in tile coordinates) for tiles with an index matching + * `indexA` and swaps then with `indexB`. This only modifies the index and does not change collision + * information. + * @param tileA First tile index. + * @param tileB Second tile index. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. */ - constructor(scene: Phaser.Scene, mapData: Phaser.Tilemaps.MapData); - - scene: Phaser.Scene; + swapByIndex(tileA: number, tileB: number, tileX?: number, tileY?: number, width?: number, height?: number): this; /** - * The base width of a tile in pixels. Note that individual layers may have a different tile - * width. + * Converts from tile X coordinates (tile units) to world X coordinates (pixels), factoring in the + * layers position, scale and scroll. + * @param tileX The x coordinate, in tiles, not pixels. + * @param camera The Camera to use when calculating the tile index from the world values. */ - tileWidth: integer; + tileToWorldX(tileX: number, camera?: Phaser.Cameras.Scene2D.Camera): number; /** - * The base height of a tile in pixels. Note that individual layers may have a different - * tile height. + * Converts from tile Y coordinates (tile units) to world Y coordinates (pixels), factoring in the + * layers position, scale and scroll. + * @param tileY The y coordinate, in tiles, not pixels. + * @param camera The Camera to use when calculating the tile index from the world values. */ - tileHeight: integer; + tileToWorldY(tileY: number, camera?: Phaser.Cameras.Scene2D.Camera): number; /** - * The width of the map (in tiles). + * Converts from tile XY coordinates (tile units) to world XY coordinates (pixels), factoring in the + * layers position, scale and scroll. This will return a new Vector2 object or update the given + * `point` object. + * @param tileX The x coordinate, in tiles, not pixels. + * @param tileY The y coordinate, in tiles, not pixels. + * @param point A Vector2 to store the coordinates in. If not given a new Vector2 is created. + * @param camera The Camera to use when calculating the tile index from the world values. */ - width: number; + tileToWorldXY(tileX: number, tileY: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; /** - * The height of the map (in tiles). + * Randomizes the indexes of a rectangular region of tiles (in tile coordinates) within the + * specified layer. Each tile will receive a new index. New indexes are drawn from the given + * weightedIndexes array. An example weighted array: + * + * [ + * { index: 6, weight: 4 }, // Probability of index 6 is 4 / 8 + * { index: 7, weight: 2 }, // Probability of index 7 would be 2 / 8 + * { index: 8, weight: 1.5 }, // Probability of index 8 would be 1.5 / 8 + * { index: 26, weight: 0.5 } // Probability of index 27 would be 0.5 / 8 + * ] + * + * The probability of any index being choose is (the index's weight) / (sum of all weights). This + * method only modifies tile indexes and does not change collision information. + * @param weightedIndexes An array of objects to randomly draw from during randomization. They should be in the form: { index: 0, weight: 4 } or { index: [0, 1], weight: 4 } if you wish to draw from multiple tile indexes. + * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. + * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. + * @param width How many tiles wide from the `tileX` index the area will be. + * @param height How many tiles tall from the `tileY` index the area will be. */ - height: number; + weightedRandomize(weightedIndexes: object[], tileX?: number, tileY?: number, width?: number, height?: number): this; /** - * The orientation of the map data (as specified in Tiled), usually 'orthogonal'. + * Converts from world X coordinates (pixels) to tile X coordinates (tile units), factoring in the + * layers position, scale and scroll. + * @param worldX The x coordinate to be converted, in pixels, not tiles. + * @param snapToFloor Whether or not to round the tile coordinate down to the nearest integer. + * @param camera The Camera to use when calculating the tile index from the world values. */ - orientation: string; + worldToTileX(worldX: number, snapToFloor?: boolean, camera?: Phaser.Cameras.Scene2D.Camera): number; /** - * The render (draw) order of the map data (as specified in Tiled), usually 'right-down'. - * - * The draw orders are: - * - * right-down - * left-down - * right-up - * left-up - * - * This can be changed via the `setRenderOrder` method. + * Converts from world Y coordinates (pixels) to tile Y coordinates (tile units), factoring in the + * layers position, scale and scroll. + * @param worldY The y coordinate to be converted, in pixels, not tiles. + * @param snapToFloor Whether or not to round the tile coordinate down to the nearest integer. + * @param camera The Camera to use when calculating the tile index from the world values. */ - renderOrder: string; + worldToTileY(worldY: number, snapToFloor?: boolean, camera?: Phaser.Cameras.Scene2D.Camera): number; /** - * The format of the map data. + * Converts from world XY coordinates (pixels) to tile XY coordinates (tile units), factoring in the + * layers position, scale and scroll. This will return a new Vector2 object or update the given + * `point` object. + * @param worldX The x coordinate to be converted, in pixels, not tiles. + * @param worldY The y coordinate to be converted, in pixels, not tiles. + * @param snapToFloor Whether or not to round the tile coordinate down to the nearest integer. + * @param point A Vector2 to store the coordinates in. If not given a new Vector2 is created. + * @param camera The Camera to use when calculating the tile index from the world values. */ - format: number; + worldToTileXY(worldX: number, worldY: number, snapToFloor?: boolean, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; /** - * The version of the map data (as specified in Tiled, usually 1). + * Destroys this TilemapLayer and removes its link to the associated LayerData. + * @param removeFromTilemap Remove this layer from the parent Tilemap? Default true. */ - version: number; + destroy(removeFromTilemap?: boolean): void; /** - * Map specific properties as specified in Tiled. + * Clears all alpha values associated with this Game Object. + * + * Immediately sets the alpha levels back to 1 (fully opaque). */ - properties: object; + clearAlpha(): this; /** - * The width of the map in pixels based on width * tileWidth. + * Set the Alpha level of this Game Object. The alpha controls the opacity of the Game Object as it renders. + * Alpha values are provided as a float between 0, fully transparent, and 1, fully opaque. + * + * If your game is running under WebGL you can optionally specify four different alpha values, each of which + * correspond to the four corners of the Game Object. Under Canvas only the `topLeft` value given is used. + * @param topLeft The alpha value used for the top-left of the Game Object. If this is the only value given it's applied across the whole Game Object. Default 1. + * @param topRight The alpha value used for the top-right of the Game Object. WebGL only. + * @param bottomLeft The alpha value used for the bottom-left of the Game Object. WebGL only. + * @param bottomRight The alpha value used for the bottom-right of the Game Object. WebGL only. */ - widthInPixels: number; + setAlpha(topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number): this; /** - * The height of the map in pixels based on height * tileHeight. + * The alpha value of the Game Object. + * + * This is a global value, impacting the entire Game Object, not just a region of it. */ - heightInPixels: number; - - imageCollections: Phaser.Tilemaps.ImageCollection[]; + alpha: number; /** - * An array of Tiled Image Layers. + * The alpha value starting from the top-left of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. */ - images: any[]; + alphaTopLeft: number; /** - * An array of Tilemap layer data. + * The alpha value starting from the top-right of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. */ - layers: Phaser.Tilemaps.LayerData[]; + alphaTopRight: number; /** - * An array of Tilesets used in the map. + * The alpha value starting from the bottom-left of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. */ - tilesets: Phaser.Tilemaps.Tileset[]; + alphaBottomLeft: number; /** - * An array of ObjectLayer instances parsed from Tiled object layers. + * The alpha value starting from the bottom-right of the Game Object. + * This value is interpolated from the corner to the center of the Game Object. */ - objects: Phaser.Tilemaps.ObjectLayer[]; + alphaBottomRight: number; /** - * The index of the currently selected LayerData object. + * Sets the Blend Mode being used by this Game Object. + * + * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) + * + * Under WebGL only the following Blend Modes are available: + * + * * ADD + * * MULTIPLY + * * SCREEN + * * ERASE + * + * Canvas has more available depending on browser support. + * + * You can also create your own custom Blend Modes in WebGL. + * + * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending + * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these + * reasons try to be careful about the construction of your Scene and the frequency of which blend modes + * are used. */ - currentLayerIndex: integer; + blendMode: Phaser.BlendModes | string; /** - * Sets the rendering (draw) order of the tiles in this map. + * Sets the Blend Mode being used by this Game Object. * - * The default is 'right-down', meaning it will order the tiles starting from the top-left, - * drawing to the right and then moving down to the next row. + * This can be a const, such as `Phaser.BlendModes.SCREEN`, or an integer, such as 4 (for Overlay) * - * The draw orders are: + * Under WebGL only the following Blend Modes are available: * - * 0 = right-down - * 1 = left-down - * 2 = right-up - * 3 = left-up + * * ADD + * * MULTIPLY + * * SCREEN + * * ERASE (only works when rendering to a framebuffer, like a Render Texture) * - * Setting the render order does not change the tiles or how they are stored in the layer, - * it purely impacts the order in which they are rendered. + * Canvas has more available depending on browser support. * - * You can provide either an integer (0 to 3), or the string version of the order. + * You can also create your own custom Blend Modes in WebGL. * - * Calling this method _after_ creating Static or Dynamic Tilemap Layers will **not** automatically - * update them to use the new render order. If you call this method after creating layers, use their - * own `setRenderOrder` methods to change them as needed. - * @param renderOrder The render (draw) order value. Either an integer between 0 and 3, or a string: 'right-down', 'left-down', 'right-up' or 'left-up'. + * Blend modes have different effects under Canvas and WebGL, and from browser to browser, depending + * on support. Blend Modes also cause a WebGL batch flush should it encounter a new blend mode. For these + * reasons try to be careful about the construction of your Scene and the frequency in which blend modes + * are used. + * @param value The BlendMode value. Either a string or a CONST. */ - setRenderOrder(renderOrder: integer | string): this; + setBlendMode(value: string | Phaser.BlendModes): this; /** - * Adds an image to the map to be used as a tileset. A single map may use multiple tilesets. - * Note that the tileset name can be found in the JSON file exported from Tiled, or in the Tiled - * editor. - * @param tilesetName The name of the tileset as specified in the map data. - * @param key The key of the Phaser.Cache image used for this tileset. If - * `undefined` or `null` it will look for an image with a key matching the tilesetName parameter. - * @param tileWidth The width of the tile (in pixels) in the Tileset Image. If not - * given it will default to the map's tileWidth value, or the tileWidth specified in the Tiled - * JSON file. - * @param tileHeight The height of the tiles (in pixels) in the Tileset Image. If - * not given it will default to the map's tileHeight value, or the tileHeight specified in the - * Tiled JSON file. - * @param tileMargin The margin around the tiles in the sheet (in pixels). If not - * specified, it will default to 0 or the value specified in the Tiled JSON file. - * @param tileSpacing The spacing between each the tile in the sheet (in pixels). - * If not specified, it will default to 0 or the value specified in the Tiled JSON file. - * @param gid If adding multiple tilesets to a blank map, specify the starting - * GID this set will use here. Default 0. + * The native (un-scaled) width of this Game Object. + * + * Changing this value will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or use + * the `displayWidth` property. */ - addTilesetImage(tilesetName: string, key?: string, tileWidth?: integer, tileHeight?: integer, tileMargin?: integer, tileSpacing?: integer, gid?: integer): Phaser.Tilemaps.Tileset; + width: number; /** - * Turns the DynamicTilemapLayer associated with the given layer into a StaticTilemapLayer. If - * no layer specified, the map's current layer is used. This is useful if you want to manipulate - * a map at the start of a scene, but then make it non-manipulable and optimize it for speed. - * Note: the DynamicTilemapLayer passed in is destroyed, so make sure to store the value - * returned from this method if you want to manipulate the new StaticTilemapLayer. - * @param layer The name of the layer from Tiled, the - * index of the layer in the map, or a DynamicTilemapLayer. + * The native (un-scaled) height of this Game Object. + * + * Changing this value will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or use + * the `displayHeight` property. */ - convertLayerToStatic(layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer): Phaser.Tilemaps.StaticTilemapLayer; + height: number; /** - * Copies the tiles in the source rectangular area to a new destination (all specified in tile - * coordinates) within the layer. This copies all tile properties & recalculates collision - * information in the destination region. + * The displayed width of this Game Object. * - * If no layer specified, the map's current layer is used. This cannot be applied to StaticTilemapLayers. - * @param srcTileX The x coordinate of the area to copy from, in tiles, not pixels. - * @param srcTileY The y coordinate of the area to copy from, in tiles, not pixels. - * @param width The width of the area to copy, in tiles, not pixels. - * @param height The height of the area to copy, in tiles, not pixels. - * @param destTileX The x coordinate of the area to copy to, in tiles, not pixels. - * @param destTileY The y coordinate of the area to copy to, in tiles, not pixels. - * @param recalculateFaces `true` if the faces data should be recalculated. Default true. - * @param layer The tile layer to use. If not given the current layer is used. + * This value takes into account the scale factor. + * + * Setting this value will adjust the Game Object's scale property. */ - copy(srcTileX: integer, srcTileY: integer, width: integer, height: integer, destTileX: integer, destTileY: integer, recalculateFaces?: boolean, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tilemap; + displayWidth: number; /** - * Creates a new and empty DynamicTilemapLayer. The currently selected layer in the map is set to this new layer. - * @param name The name of this layer. Must be unique within the map. - * @param tileset The tileset, or an array of tilesets, used to render this layer. Can be a string or a Tileset object. - * @param x The world x position where the top left of this layer will be placed. Default 0. - * @param y The world y position where the top left of this layer will be placed. Default 0. - * @param width The width of the layer in tiles. If not specified, it will default to the map's width. - * @param height The height of the layer in tiles. If not specified, it will default to the map's height. - * @param tileWidth The width of the tiles the layer uses for calculations. If not specified, it will default to the map's tileWidth. - * @param tileHeight The height of the tiles the layer uses for calculations. If not specified, it will default to the map's tileHeight. + * The displayed height of this Game Object. + * + * This value takes into account the scale factor. + * + * Setting this value will adjust the Game Object's scale property. */ - createBlankDynamicLayer(name: string, tileset: string | string[] | Phaser.Tilemaps.Tileset | Phaser.Tilemaps.Tileset[], x?: number, y?: number, width?: integer, height?: integer, tileWidth?: integer, tileHeight?: integer): Phaser.Tilemaps.DynamicTilemapLayer; + displayHeight: number; /** - * Creates a new DynamicTilemapLayer that renders the LayerData associated with the given - * `layerID`. The currently selected layer in the map is set to this new layer. + * Sets the internal size of this Game Object, as used for frame or physics body creation. * - * The `layerID` is important. If you've created your map in Tiled then you can get this by - * looking in Tiled and looking at the layer name. Or you can open the JSON file it exports and - * look at the layers[].name value. Either way it must match. + * This will not change the size that the Game Object is rendered in-game. + * For that you need to either set the scale of the Game Object (`setScale`) or call the + * `setDisplaySize` method, which is the same thing as changing the scale but allows you + * to do so by giving pixel values. * - * Unlike a static layer, a dynamic layer can be modified. See DynamicTilemapLayer for more - * information. - * @param layerID The layer array index value, or if a string is given, the layer name from Tiled. - * @param tileset The tileset, or an array of tilesets, used to render this layer. Can be a string or a Tileset object. - * @param x The x position to place the layer in the world. If not specified, it will default to the layer offset from Tiled or 0. Default 0. - * @param y The y position to place the layer in the world. If not specified, it will default to the layer offset from Tiled or 0. Default 0. + * If you have enabled this Game Object for input, changing the size will _not_ change the + * size of the hit area. To do this you should adjust the `input.hitArea` object directly. + * @param width The width of this Game Object. + * @param height The height of this Game Object. */ - createDynamicLayer(layerID: integer | string, tileset: string | string[] | Phaser.Tilemaps.Tileset | Phaser.Tilemaps.Tileset[], x?: number, y?: number): Phaser.Tilemaps.DynamicTilemapLayer; + setSize(width: number, height: number): this; /** - * Creates a Sprite for every object matching the given gid in the map data. All properties from - * the map data objectgroup are copied into the `spriteConfig`, so you can use this as an easy - * way to configure Sprite properties from within the map editor. For example giving an object a - * property of alpha: 0.5 in the map editor will duplicate that when the Sprite is created. + * Sets the display size of this Game Object. * - * Custom object properties not sharing names with the Sprite's own properties are copied to the - * Sprite's {@link Phaser.GameObjects.Sprite#data data store}. - * @param name The name of the object layer (from Tiled) to create Sprites from. - * @param id Either the id (object), gid (tile object) or name (object or - * tile object) from Tiled. Ids are unique in Tiled, but a gid is shared by all tile objects - * with the same graphic. The same name can be used on multiple objects. - * @param spriteConfig The config object to pass into the Sprite creator (i.e. - * scene.make.sprite). - * @param scene The Scene to create the Sprites within. Default the scene the map is within. + * Calling this will adjust the scale. + * @param width The width of this Game Object. + * @param height The height of this Game Object. */ - createFromObjects(name: string, id: integer | string, spriteConfig: Phaser.Types.GameObjects.Sprite.SpriteConfig, scene?: Phaser.Scene): Phaser.GameObjects.Sprite[]; + setDisplaySize(width: number, height: number): this; /** - * Creates a Sprite for every object matching the given tile indexes in the layer. You can - * optionally specify if each tile will be replaced with a new tile after the Sprite has been - * created. This is useful if you want to lay down special tiles in a level that are converted to - * Sprites, but want to replace the tile itself with a floor tile or similar once converted. - * @param indexes The tile index, or array of indexes, to create Sprites from. - * @param replacements The tile index, or array of indexes, to change a converted - * tile to. Set to `null` to leave the tiles unchanged. If an array is given, it is assumed to be a - * one-to-one mapping with the indexes array. - * @param spriteConfig The config object to pass into the Sprite creator (i.e. scene.make.sprite). - * @param scene The Scene to create the Sprites within. Default scene the map is within. - * @param camera The Camera to use when calculating the tile index from the world values. Default main camera. - * @param layer The tile layer to use. If not given the current layer is used. + * The depth of this Game Object within the Scene. + * + * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order + * of Game Objects, without actually moving their position in the display list. + * + * The default depth is zero. A Game Object with a higher depth + * value will always render in front of one with a lower value. + * + * Setting the depth will queue a depth sort event within the Scene. */ - createFromTiles(indexes: integer | any[], replacements: integer | any[], spriteConfig: Phaser.Types.GameObjects.Sprite.SpriteConfig, scene?: Phaser.Scene, camera?: Phaser.Cameras.Scene2D.Camera, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.GameObjects.Sprite[]; + depth: number; /** - * Creates a new StaticTilemapLayer that renders the LayerData associated with the given - * `layerID`. The currently selected layer in the map is set to this new layer. + * The depth of this Game Object within the Scene. * - * The `layerID` is important. If you've created your map in Tiled then you can get this by - * looking in Tiled and looking at the layer name. Or you can open the JSON file it exports and - * look at the layers[].name value. Either way it must match. + * The depth is also known as the 'z-index' in some environments, and allows you to change the rendering order + * of Game Objects, without actually moving their position in the display list. * - * It's important to remember that a static layer cannot be modified. See StaticTilemapLayer for - * more information. - * @param layerID The layer array index value, or if a string is given, the layer name from Tiled. - * @param tileset The tileset, or an array of tilesets, used to render this layer. Can be a string or a Tileset object. - * @param x The x position to place the layer in the world. If not specified, it will default to the layer offset from Tiled or 0. Default 0. - * @param y The y position to place the layer in the world. If not specified, it will default to the layer offset from Tiled or 0. Default 0. + * The default depth is zero. A Game Object with a higher depth + * value will always render in front of one with a lower value. + * + * Setting the depth will queue a depth sort event within the Scene. + * @param value The depth of this Game Object. */ - createStaticLayer(layerID: integer | string, tileset: string | string[] | Phaser.Tilemaps.Tileset | Phaser.Tilemaps.Tileset[], x?: number, y?: number): Phaser.Tilemaps.StaticTilemapLayer; + setDepth(value: number): this; /** - * Removes all layer data from this Tilemap and nulls the scene reference. This will destroy any - * StaticTilemapLayers or DynamicTilemapLayers that have been linked to LayerData. + * The horizontally flipped state of the Game Object. + * + * A Game Object that is flipped horizontally will render inversed on the horizontal axis. + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. */ - destroy(): void; + flipX: boolean; /** - * Sets the tiles in the given rectangular area (in tile coordinates) of the layer with the - * specified index. Tiles will be set to collide if the given index is a colliding index. - * Collision information in the region will be recalculated. + * The vertically flipped state of the Game Object. * - * If no layer specified, the map's current layer is used. - * This cannot be applied to StaticTilemapLayers. - * @param index The tile index to fill the area with. - * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param width How many tiles wide from the `tileX` index the area will be. Default max width based on tileX. - * @param height How many tiles tall from the `tileY` index the area will be. Default max height based on tileY. - * @param recalculateFaces `true` if the faces data should be recalculated. Default true. - * @param layer The tile layer to use. If not given the current layer is used. + * A Game Object that is flipped vertically will render inversed on the vertical axis (i.e. upside down) + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. */ - fill(index: integer, tileX?: integer, tileY?: integer, width?: integer, height?: integer, recalculateFaces?: boolean, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tilemap; + flipY: boolean; /** - * For each object in the given object layer, run the given filter callback function. Any - * objects that pass the filter test (i.e. where the callback returns true) will returned as a - * new array. Similar to Array.prototype.Filter in vanilla JS. - * @param objectLayer The name of an object layer (from Tiled) or an ObjectLayer instance. - * @param callback The callback. Each object in the given area will be passed to this callback as the first and only parameter. - * @param context The context under which the callback should be run. + * Toggles the horizontal flipped state of this Game Object. + * + * A Game Object that is flipped horizontally will render inversed on the horizontal axis. + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. */ - filterObjects(objectLayer: Phaser.Tilemaps.ObjectLayer | string, callback: TilemapFilterCallback, context?: object): Phaser.GameObjects.GameObject[]; + toggleFlipX(): this; /** - * For each tile in the given rectangular area (in tile coordinates) of the layer, run the given - * filter callback function. Any tiles that pass the filter test (i.e. where the callback returns - * true) will returned as a new array. Similar to Array.prototype.Filter in vanilla JS. - * If no layer specified, the map's current layer is used. - * @param callback The callback. Each tile in the given area will be passed to this - * callback as the first and only parameter. The callback should return true for tiles that pass the - * filter. - * @param context The context under which the callback should be run. - * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area to filter. Default 0. - * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area to filter. Default 0. - * @param width How many tiles wide from the `tileX` index the area will be. Default max width based on tileX. - * @param height How many tiles tall from the `tileY` index the area will be. Default max height based on tileY. - * @param filteringOptions Optional filters to apply when getting the tiles. - * @param layer The tile layer to use. If not given the current layer is used. + * Toggles the vertical flipped state of this Game Object. */ - filterTiles(callback: Function, context?: object, tileX?: integer, tileY?: integer, width?: integer, height?: integer, filteringOptions?: Phaser.Types.Tilemaps.FilteringOptions, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tile[]; + toggleFlipY(): this; /** - * Searches the entire map layer for the first tile matching the given index, then returns that Tile - * object. If no match is found, it returns null. The search starts from the top-left tile and - * continues horizontally until it hits the end of the row, then it drops down to the next column. - * If the reverse boolean is true, it scans starting from the bottom-right corner traveling up to - * the top-left. - * If no layer specified, the map's current layer is used. - * @param index The tile index value to search for. - * @param skip The number of times to skip a matching tile before returning. Default 0. - * @param reverse If true it will scan the layer in reverse, starting at the bottom-right. Otherwise it scans from the top-left. Default false. - * @param layer The tile layer to use. If not given the current layer is used. + * Sets the horizontal flipped state of this Game Object. + * + * A Game Object that is flipped horizontally will render inversed on the horizontal axis. + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * @param value The flipped state. `false` for no flip, or `true` to be flipped. */ - findByIndex(index: integer, skip?: integer, reverse?: boolean, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tile; + setFlipX(value: boolean): this; /** - * Find the first object in the given object layer that satisfies the provided testing function. - * I.e. finds the first object for which `callback` returns true. Similar to - * Array.prototype.find in vanilla JS. - * @param objectLayer The name of an object layer (from Tiled) or an ObjectLayer instance. - * @param callback The callback. Each object in the given area will be passed to this callback as the first and only parameter. - * @param context The context under which the callback should be run. + * Sets the vertical flipped state of this Game Object. + * @param value The flipped state. `false` for no flip, or `true` to be flipped. */ - findObject(objectLayer: Phaser.Tilemaps.ObjectLayer | string, callback: TilemapFindCallback, context?: object): Phaser.GameObjects.GameObject; + setFlipY(value: boolean): this; /** - * Find the first tile in the given rectangular area (in tile coordinates) of the layer that - * satisfies the provided testing function. I.e. finds the first tile for which `callback` returns - * true. Similar to Array.prototype.find in vanilla JS. - * If no layer specified, the maps current layer is used. - * @param callback The callback. Each tile in the given area will be passed to this callback as the first and only parameter. - * @param context The context under which the callback should be run. - * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area to search. Default 0. - * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area to search. Default 0. - * @param width How many tiles wide from the `tileX` index the area will be. Default max width based on tileX. - * @param height How many tiles tall from the `tileY` index the area will be. Default max height based on tileY. - * @param filteringOptions Optional filters to apply when getting the tiles. - * @param layer The Tile layer to run the search on. If not provided will use the current layer. + * Sets the horizontal and vertical flipped state of this Game Object. + * + * A Game Object that is flipped will render inversed on the flipped axis. + * Flipping always takes place from the middle of the texture and does not impact the scale value. + * If this Game Object has a physics body, it will not change the body. This is a rendering toggle only. + * @param x The horizontal flipped state. `false` for no flip, or `true` to be flipped. + * @param y The horizontal flipped state. `false` for no flip, or `true` to be flipped. */ - findTile(callback: FindTileCallback, context?: object, tileX?: integer, tileY?: integer, width?: integer, height?: integer, filteringOptions?: Phaser.Types.Tilemaps.FilteringOptions, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tile; + setFlip(x: boolean, y: boolean): this; /** - * For each tile in the given rectangular area (in tile coordinates) of the layer, run the given - * callback. Similar to Array.prototype.forEach in vanilla JS. - * - * If no layer specified, the map's current layer is used. - * @param callback The callback. Each tile in the given area will be passed to this callback as the first and only parameter. - * @param context The context under which the callback should be run. - * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area to search. Default 0. - * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area to search. Default 0. - * @param width How many tiles wide from the `tileX` index the area will be. Default max width based on tileX. - * @param height How many tiles tall from the `tileY` index the area will be. Default max height based on tileY. - * @param filteringOptions Optional filters to apply when getting the tiles. - * @param layer The Tile layer to run the search on. If not provided will use the current layer. + * Resets the horizontal and vertical flipped state of this Game Object back to their default un-flipped state. */ - forEachTile(callback: EachTileCallback, context?: object, tileX?: integer, tileY?: integer, width?: integer, height?: integer, filteringOptions?: Phaser.Types.Tilemaps.FilteringOptions, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tilemap; + resetFlip(): this; /** - * Gets the image layer index based on its name. - * @param name The name of the image to get. + * Gets the center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. */ - getImageIndex(name: string): integer; + getCenter(output?: O): O; /** - * Return a list of all valid imagelayer names loaded in this Tilemap. + * Gets the top-left corner coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - getImageLayerNames(): string[]; + getTopLeft(output?: O, includeParent?: boolean): O; /** - * Internally used. Returns the index of the object in one of the Tilemaps arrays whose name - * property matches the given `name`. - * @param location The Tilemap array to search. - * @param name The name of the array element to get. + * Gets the top-center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - getIndex(location: any[], name: string): number; + getTopCenter(output?: O, includeParent?: boolean): O; /** - * Gets the LayerData from this.layers that is associated with `layer`, or null if an invalid - * `layer` is given. - * @param layer The name of the - * layer from Tiled, the index of the layer in the map, a DynamicTilemapLayer or a - * StaticTilemapLayer. If not given will default to the maps current layer index. + * Gets the top-right corner coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - getLayer(layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.LayerData; + getTopRight(output?: O, includeParent?: boolean): O; /** - * Gets the ObjectLayer from this.objects that has the given `name`, or null if no ObjectLayer - * is found with that name. - * @param name The name of the object layer from Tiled. + * Gets the left-center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - getObjectLayer(name?: string): Phaser.Tilemaps.ObjectLayer; + getLeftCenter(output?: O, includeParent?: boolean): O; /** - * Return a list of all valid objectgroup names loaded in this Tilemap. + * Gets the right-center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - getObjectLayerNames(): string[]; + getRightCenter(output?: O, includeParent?: boolean): O; /** - * Gets the LayerData index of the given `layer` within this.layers, or null if an invalid - * `layer` is given. - * @param layer The name of the - * layer from Tiled, the index of the layer in the map, a DynamicTilemapLayer or a - * StaticTilemapLayer. If not given will default to the map's current layer index. + * Gets the bottom-left corner coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - getLayerIndex(layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): integer; + getBottomLeft(output?: O, includeParent?: boolean): O; /** - * Gets the index of the LayerData within this.layers that has the given `name`, or null if an - * invalid `name` is given. - * @param name The name of the layer to get. + * Gets the bottom-center coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - getLayerIndexByName(name: string): integer; + getBottomCenter(output?: O, includeParent?: boolean): O; /** - * Gets a tile at the given tile coordinates from the given layer. - * If no layer specified, the map's current layer is used. - * @param tileX X position to get the tile from (given in tile units, not pixels). - * @param tileY Y position to get the tile from (given in tile units, not pixels). - * @param nonNull If true getTile won't return null for empty tiles, but a Tile object with an index of -1. Default false. - * @param layer The tile layer to use. If not given the current layer is used. + * Gets the bottom-right corner coordinate of this Game Object, regardless of origin. + * The returned point is calculated in local space and does not factor in any parent containers + * @param output An object to store the values in. If not provided a new Vector2 will be created. + * @param includeParent If this Game Object has a parent Container, include it (and all other ancestors) in the resulting vector? Default false. */ - getTileAt(tileX: integer, tileY: integer, nonNull?: boolean, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tile; + getBottomRight(output?: O, includeParent?: boolean): O; /** - * Gets a tile at the given world coordinates from the given layer. - * If no layer specified, the map's current layer is used. - * @param worldX X position to get the tile from (given in pixels) - * @param worldY Y position to get the tile from (given in pixels) - * @param nonNull If true, function won't return null for empty tiles, but a Tile object with an index of -1. Default false. - * @param camera The Camera to use when calculating the tile index from the world values. Default main camera. - * @param layer The tile layer to use. If not given the current layer is used. + * Gets the bounds of this Game Object, regardless of origin. + * The values are stored and returned in a Rectangle, or Rectangle-like, object. + * @param output An object to store the values in. If not provided a new Rectangle will be created. */ - getTileAtWorldXY(worldX: number, worldY: number, nonNull?: boolean, camera?: Phaser.Cameras.Scene2D.Camera, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tile; + getBounds(output?: O): O; /** - * Return a list of all valid tilelayer names loaded in this Tilemap. + * The horizontal origin of this Game Object. + * The origin maps the relationship between the size and position of the Game Object. + * The default value is 0.5, meaning all Game Objects are positioned based on their center. + * Setting the value to 0 means the position now relates to the left of the Game Object. */ - getTileLayerNames(): string[]; + originX: number; /** - * Gets the tiles in the given rectangular area (in tile coordinates) of the layer. - * If no layer specified, the maps current layer is used. - * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param width How many tiles wide from the `tileX` index the area will be. Default max width based on tileX. - * @param height How many tiles tall from the `tileY` index the area will be. Default max height based on tileY. - * @param filteringOptions Optional filters to apply when getting the tiles. - * @param layer The tile layer to use. If not given the current layer is used. + * The vertical origin of this Game Object. + * The origin maps the relationship between the size and position of the Game Object. + * The default value is 0.5, meaning all Game Objects are positioned based on their center. + * Setting the value to 0 means the position now relates to the top of the Game Object. */ - getTilesWithin(tileX?: integer, tileY?: integer, width?: integer, height?: integer, filteringOptions?: Phaser.Types.Tilemaps.FilteringOptions, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tile[]; + originY: number; /** - * Gets the tiles that overlap with the given shape in the given layer. The shape must be a Circle, - * Line, Rectangle or Triangle. The shape should be in world coordinates. - * If no layer specified, the maps current layer is used. - * @param shape A shape in world (pixel) coordinates - * @param filteringOptions Optional filters to apply when getting the tiles. - * @param camera The Camera to use when factoring in which tiles to return. Default main camera. - * @param layer The tile layer to use. If not given the current layer is used. + * The horizontal display origin of this Game Object. + * The origin is a normalized value between 0 and 1. + * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. */ - getTilesWithinShape(shape: Phaser.Geom.Circle | Phaser.Geom.Line | Phaser.Geom.Rectangle | Phaser.Geom.Triangle, filteringOptions?: Phaser.Types.Tilemaps.FilteringOptions, camera?: Phaser.Cameras.Scene2D.Camera, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tile[]; + displayOriginX: number; /** - * Gets the tiles in the given rectangular area (in world coordinates) of the layer. - * If no layer specified, the maps current layer is used. - * @param worldX The world x coordinate for the top-left of the area. - * @param worldY The world y coordinate for the top-left of the area. - * @param width The width of the area. - * @param height The height of the area. - * @param filteringOptions Optional filters to apply when getting the tiles. - * @param camera The Camera to use when factoring in which tiles to return. Default main camera. - * @param layer The tile layer to use. If not given the current layer is used. + * The vertical display origin of this Game Object. + * The origin is a normalized value between 0 and 1. + * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin. */ - getTilesWithinWorldXY(worldX: number, worldY: number, width: number, height: number, filteringOptions?: Phaser.Types.Tilemaps.FilteringOptions, camera?: Phaser.Cameras.Scene2D.Camera, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tile[]; + displayOriginY: number; /** - * Gets the Tileset that has the given `name`, or null if an invalid `name` is given. - * @param name The name of the Tileset to get. + * Sets the origin of this Game Object. + * + * The values are given in the range 0 to 1. + * @param x The horizontal origin value. Default 0.5. + * @param y The vertical origin value. If not defined it will be set to the value of `x`. Default x. */ - getTileset(name: string): Phaser.Tilemaps.Tileset; + setOrigin(x?: number, y?: number): this; /** - * Gets the index of the Tileset within this.tilesets that has the given `name`, or null if an - * invalid `name` is given. - * @param name The name of the Tileset to get. + * Sets the origin of this Game Object based on the Pivot values in its Frame. */ - getTilesetIndex(name: string): integer; + setOriginFromFrame(): this; /** - * Checks if there is a tile at the given location (in tile coordinates) in the given layer. Returns - * false if there is no tile or if the tile at that location has an index of -1. - * - * If no layer specified, the map's current layer is used. - * @param tileX The x coordinate, in tiles, not pixels. - * @param tileY The y coordinate, in tiles, not pixels. - * @param layer The tile layer to use. If not given the current layer is used. + * Sets the display origin of this Game Object. + * The difference between this and setting the origin is that you can use pixel values for setting the display origin. + * @param x The horizontal display origin value. Default 0. + * @param y The vertical display origin value. If not defined it will be set to the value of `x`. Default x. + */ + setDisplayOrigin(x?: number, y?: number): this; + + /** + * Updates the Display Origin cached values internally stored on this Game Object. + * You don't usually call this directly, but it is exposed for edge-cases where you may. */ - hasTileAt(tileX: integer, tileY: integer, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): boolean; + updateDisplayOrigin(): this; /** - * Checks if there is a tile at the given location (in world coordinates) in the given layer. Returns - * false if there is no tile or if the tile at that location has an index of -1. + * The initial WebGL pipeline of this Game Object. * - * If no layer specified, the maps current layer is used. - * @param worldX The x coordinate, in pixels. - * @param worldY The y coordinate, in pixels. - * @param camera The Camera to use when factoring in which tiles to return. Default main camera. - * @param layer The tile layer to use. If not given the current layer is used. + * If you call `resetPipeline` on this Game Object, the pipeline is reset to this default. */ - hasTileAtWorldXY(worldX: number, worldY: number, camera?: Phaser.Cameras.Scene2D.Camera, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): boolean; + defaultPipeline: Phaser.Renderer.WebGL.WebGLPipeline; /** - * The LayerData object that is currently selected in the map. You can set this property using - * any type supported by setLayer. + * The current WebGL pipeline of this Game Object. */ - layer: Phaser.Tilemaps.LayerData; + pipeline: Phaser.Renderer.WebGL.WebGLPipeline; /** - * Puts a tile at the given tile coordinates in the specified layer. You can pass in either an index - * or a Tile object. If you pass in a Tile, all attributes will be copied over to the specified - * location. If you pass in an index, only the index at the specified location will be changed. - * Collision information will be recalculated at the specified location. + * Does this Game Object have any Post Pipelines set? + */ + hasPostPipeline: boolean; + + /** + * The WebGL Post FX Pipelines this Game Object uses for post-render effects. * - * If no layer specified, the maps current layer is used. + * The pipelines are processed in the order in which they appear in this array. * - * This cannot be applied to StaticTilemapLayers. - * @param tile The index of this tile to set or a Tile object. - * @param tileX The x coordinate, in tiles, not pixels. - * @param tileY The y coordinate, in tiles, not pixels. - * @param recalculateFaces `true` if the faces data should be recalculated. Default true. - * @param layer The tile layer to use. If not given the current layer is used. + * If you modify this array directly, be sure to set the + * `hasPostPipeline` property accordingly. + */ + postPipeline: Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]; + + /** + * An object to store pipeline specific data in, to be read by the pipelines this Game Object uses. + */ + pipelineData: object; + + /** + * Sets the initial WebGL Pipeline of this Game Object. + * + * This should only be called during the instantiation of the Game Object. After that, use `setPipeline`. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. */ - putTileAt(tile: integer | Phaser.Tilemaps.Tile, tileX: integer, tileY: integer, recalculateFaces?: boolean, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tile; + initPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline): boolean; /** - * Puts a tile at the given world coordinates (pixels) in the specified layer. You can pass in either - * an index or a Tile object. If you pass in a Tile, all attributes will be copied over to the - * specified location. If you pass in an index, only the index at the specified location will be - * changed. Collision information will be recalculated at the specified location. + * Sets the main WebGL Pipeline of this Game Object. * - * If no layer specified, the maps current layer is used. This - * cannot be applied to StaticTilemapLayers. - * @param tile The index of this tile to set or a Tile object. - * @param worldX The x coordinate, in pixels. - * @param worldY The y coordinate, in pixels. - * @param recalculateFaces `true` if the faces data should be recalculated. Default true. - * @param camera The Camera to use when calculating the tile index from the world values. Default main camera. - * @param layer The tile layer to use. If not given the current layer is used. + * Also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the same pipeline data object. + * @param pipeline Either the string-based name of the pipeline, or a pipeline instance to set. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. */ - putTileAtWorldXY(tile: integer | Phaser.Tilemaps.Tile, worldX: number, worldY: number, recalculateFaces?: boolean, camera?: Phaser.Cameras.Scene2D.Camera, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tile; + setPipeline(pipeline: string | Phaser.Renderer.WebGL.WebGLPipeline, pipelineData?: object, copyData?: boolean): this; /** - * Puts an array of tiles or a 2D array of tiles at the given tile coordinates in the specified - * layer. The array can be composed of either tile indexes or Tile objects. If you pass in a Tile, - * all attributes will be copied over to the specified location. If you pass in an index, only the - * index at the specified location will be changed. Collision information will be recalculated - * within the region tiles were changed. + * Sets one, or more, Post Pipelines on this Game Object. * - * If no layer specified, the maps current layer is used. - * This cannot be applied to StaticTilemapLayers. - * @param tile A row (array) or grid (2D array) of Tiles or tile indexes to place. - * @param tileX The x coordinate, in tiles, not pixels. - * @param tileY The y coordinate, in tiles, not pixels. - * @param recalculateFaces `true` if the faces data should be recalculated. Default true. - * @param layer The tile layer to use. If not given the current layer is used. + * Post Pipelines are invoked after this Game Object has rendered to its target and + * are commonly used for post-fx. + * + * The post pipelines are appended to the `postPipelines` array belonging to this + * Game Object. When the renderer processes this Game Object, it iterates through the post + * pipelines in the order in which they appear in the array. If you are stacking together + * multiple effects, be aware that the order is important. + * + * If you call this method multiple times, the new pipelines will be appended to any existing + * post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required. + * + * You can optionally also sets the `pipelineData` property, if the parameter is given. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param pipelines Either the string-based name of the pipeline, or a pipeline instance, or class, or an array of them. + * @param pipelineData Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object. + * @param copyData Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead. Default true. */ - putTilesAt(tile: integer[] | integer[][] | Phaser.Tilemaps.Tile[] | Phaser.Tilemaps.Tile[][], tileX: integer, tileY: integer, recalculateFaces?: boolean, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tilemap; + setPostPipeline(pipelines: string | string[] | Function | Function[] | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[], pipelineData?: object, copyData?: boolean): this; /** - * Randomizes the indexes of a rectangular region of tiles (in tile coordinates) within the - * specified layer. Each tile will receive a new index. If an array of indexes is passed in, then - * those will be used for randomly assigning new tile indexes. If an array is not provided, the - * indexes found within the region (excluding -1) will be used for randomly assigning new tile - * indexes. This method only modifies tile indexes and does not change collision information. + * Adds an entry to the `pipelineData` object belonging to this Game Object. * - * If no layer specified, the maps current layer is used. - * This cannot be applied to StaticTilemapLayers. - * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param width How many tiles wide from the `tileX` index the area will be. Default max width based on tileX. - * @param height How many tiles tall from the `tileY` index the area will be. Default max height based on tileY. - * @param indexes An array of indexes to randomly draw from during randomization. - * @param layer The tile layer to use. If not given the current layer is used. + * If the 'key' already exists, its value is updated. If it doesn't exist, it is created. + * + * If `value` is undefined, and `key` exists, `key` is removed from the data object. + * + * Both the pipeline and post pipelines share the pipeline data object together. + * @param key The key of the pipeline data to set, update, or delete. + * @param value The value to be set with the key. If `undefined` then `key` will be deleted from the object. */ - randomize(tileX?: integer, tileY?: integer, width?: integer, height?: integer, indexes?: integer[], layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tilemap; + setPipelineData(key: string, value?: any): this; /** - * Calculates interesting faces at the given tile coordinates of the specified layer. Interesting - * faces are used internally for optimizing collisions against tiles. This method is mostly used - * internally to optimize recalculating faces when only one tile has been changed. - * - * If no layer specified, the maps current layer is used. - * @param tileX The x coordinate, in tiles, not pixels. - * @param tileY The y coordinate, in tiles, not pixels. - * @param layer The tile layer to use. If not given the current layer is used. + * Gets a Post Pipeline instance from this Game Object, based on the given name, and returns it. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - calculateFacesAt(tileX: integer, tileY: integer, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tilemap; + getPostPipeline(pipeline: string | Function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): Phaser.Renderer.WebGL.Pipelines.PostFXPipeline; /** - * Calculates interesting faces within the rectangular area specified (in tile coordinates) of the - * layer. Interesting faces are used internally for optimizing collisions against tiles. This method - * is mostly used internally. - * - * If no layer specified, the map's current layer is used. - * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param width How many tiles wide from the `tileX` index the area will be. Default max width based on tileX. - * @param height How many tiles tall from the `tileY` index the area will be. Default max height based on tileY. - * @param layer The tile layer to use. If not given the current layer is used. + * Resets the WebGL Pipeline of this Game Object back to the default it was created with. + * @param resetPostPipelines Reset all of the post pipelines? Default false. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. */ - calculateFacesWithin(tileX?: integer, tileY?: integer, width?: integer, height?: integer, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tilemap; + resetPipeline(resetPostPipelines?: boolean, resetData?: boolean): boolean; /** - * Removes the given TilemapLayer from this Tilemap without destroying it. - * - * If no layer specified, the map's current layer is used. - * @param layer The tile layer to be removed. + * Resets the WebGL Post Pipelines of this Game Object. It does this by calling + * the `destroy` method on each post pipeline and then clearing the local array. + * @param resetData Reset the `pipelineData` object to being an empty object? Default false. */ - removeLayer(layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tilemap; + resetPostPipeline(resetData?: boolean): void; /** - * Destroys the given TilemapLayer and removes it from this Tilemap. + * Removes a single Post Pipeline instance from this Game Object, based on the given name, and destroys it. * - * If no layer specified, the map's current layer is used. - * @param layer The tile layer to be destroyed. + * If you wish to remove all Post Pipelines use the `resetPostPipeline` method instead. + * @param pipeline The string-based name of the pipeline, or a pipeline class. */ - destroyLayer(layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tilemap; + removePostPipeline(pipeline: string | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline): this; /** - * Removes all layers from this Tilemap and destroys any associated StaticTilemapLayers or - * DynamicTilemapLayers. + * Gets the name of the WebGL Pipeline this Game Object is currently using. */ - removeAllLayers(): Phaser.Tilemaps.Tilemap; + getPipelineName(): string; /** - * Removes the given Tile, or an array of Tiles, from the layer to which they belong, - * and optionally recalculates the collision information. + * The horizontal scroll factor of this Game Object. * - * This cannot be applied to Tiles that belong to Static Tilemap Layers. - * @param tiles The Tile to remove, or an array of Tiles. - * @param replaceIndex After removing the Tile, insert a brand new Tile into its location with the given index. Leave as -1 to just remove the tile. Default -1. - * @param recalculateFaces `true` if the faces data should be recalculated. Default true. + * The scroll factor controls the influence of the movement of a Camera upon this Game Object. + * + * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. + * It does not change the Game Objects actual position values. + * + * A value of 1 means it will move exactly in sync with a camera. + * A value of 0 means it will not move at all, even if the camera moves. + * Other values control the degree to which the camera movement is mapped to this Game Object. + * + * Please be aware that scroll factor values other than 1 are not taken in to consideration when + * calculating physics collisions. Bodies always collide based on their world position, but changing + * the scroll factor is a visual adjustment to where the textures are rendered, which can offset + * them from physics bodies if not accounted for in your code. */ - removeTile(tiles: Phaser.Tilemaps.Tile | Phaser.Tilemaps.Tile[], replaceIndex?: integer, recalculateFaces?: boolean): Phaser.Tilemaps.Tile[]; + scrollFactorX: number; /** - * Removes the tile at the given tile coordinates in the specified layer and updates the layer's - * collision information. + * The vertical scroll factor of this Game Object. * - * If no layer specified, the maps current layer is used. - * This cannot be applied to StaticTilemapLayers. - * @param tileX The x coordinate, in tiles, not pixels. - * @param tileY The y coordinate, in tiles, not pixels. - * @param replaceWithNull If true, this will replace the tile at the specified location with null instead of a Tile with an index of -1. Default true. - * @param recalculateFaces `true` if the faces data should be recalculated. Default true. - * @param layer The tile layer to use. If not given the current layer is used. + * The scroll factor controls the influence of the movement of a Camera upon this Game Object. + * + * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. + * It does not change the Game Objects actual position values. + * + * A value of 1 means it will move exactly in sync with a camera. + * A value of 0 means it will not move at all, even if the camera moves. + * Other values control the degree to which the camera movement is mapped to this Game Object. + * + * Please be aware that scroll factor values other than 1 are not taken in to consideration when + * calculating physics collisions. Bodies always collide based on their world position, but changing + * the scroll factor is a visual adjustment to where the textures are rendered, which can offset + * them from physics bodies if not accounted for in your code. */ - removeTileAt(tileX: integer, tileY: integer, replaceWithNull?: boolean, recalculateFaces?: boolean, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tile; + scrollFactorY: number; /** - * Removes the tile at the given world coordinates in the specified layer and updates the layer's - * collision information. + * Sets the scroll factor of this Game Object. * - * If no layer specified, the maps current layer is used. - * This cannot be applied to StaticTilemapLayers. - * @param worldX The x coordinate, in pixels. - * @param worldY The y coordinate, in pixels. - * @param replaceWithNull If true, this will replace the tile at the specified location with null instead of a Tile with an index of -1. Default true. - * @param recalculateFaces `true` if the faces data should be recalculated. Default true. - * @param camera The Camera to use when calculating the tile index from the world values. Default main camera. - * @param layer The tile layer to use. If not given the current layer is used. + * The scroll factor controls the influence of the movement of a Camera upon this Game Object. + * + * When a camera scrolls it will change the location at which this Game Object is rendered on-screen. + * It does not change the Game Objects actual position values. + * + * A value of 1 means it will move exactly in sync with a camera. + * A value of 0 means it will not move at all, even if the camera moves. + * Other values control the degree to which the camera movement is mapped to this Game Object. + * + * Please be aware that scroll factor values other than 1 are not taken in to consideration when + * calculating physics collisions. Bodies always collide based on their world position, but changing + * the scroll factor is a visual adjustment to where the textures are rendered, which can offset + * them from physics bodies if not accounted for in your code. + * @param x The horizontal scroll factor of this Game Object. + * @param y The vertical scroll factor of this Game Object. If not set it will use the `x` value. Default x. */ - removeTileAtWorldXY(worldX: number, worldY: number, replaceWithNull?: boolean, recalculateFaces?: boolean, camera?: Phaser.Cameras.Scene2D.Camera, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tile; + setScrollFactor(x: number, y?: number): this; /** - * Draws a debug representation of the layer to the given Graphics. This is helpful when you want to - * get a quick idea of which of your tiles are colliding and which have interesting faces. The tiles - * are drawn starting at (0, 0) in the Graphics, allowing you to place the debug representation - * wherever you want on the screen. - * - * If no layer specified, the maps current layer is used. - * @param graphics The target Graphics object to draw upon. - * @param styleConfig An object specifying the colors to use for the debug drawing. - * @param layer The tile layer to use. If not given the current layer is used. + * The x position of this Game Object. */ - renderDebug(graphics: Phaser.GameObjects.Graphics, styleConfig: Phaser.Types.Tilemaps.StyleConfig, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tilemap; + x: number; /** - * Draws a debug representation of all layers within this Tilemap to the given Graphics object. - * - * This is helpful when you want to get a quick idea of which of your tiles are colliding and which - * have interesting faces. The tiles are drawn starting at (0, 0) in the Graphics, allowing you to - * place the debug representation wherever you want on the screen. - * @param graphics The target Graphics object to draw upon. - * @param styleConfig An object specifying the colors to use for the debug drawing. - * @param layer The tile layer to use. If not given the current layer is used. + * The y position of this Game Object. */ - renderDebugFull(graphics: Phaser.GameObjects.Graphics, styleConfig: Phaser.Types.Tilemaps.StyleConfig, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tilemap; + y: number; /** - * Scans the given rectangular area (given in tile coordinates) for tiles with an index matching - * `findIndex` and updates their index to match `newIndex`. This only modifies the index and does - * not change collision information. + * The z position of this Game Object. * - * If no layer specified, the maps current layer is used. - * This cannot be applied to StaticTilemapLayers. - * @param findIndex The index of the tile to search for. - * @param newIndex The index of the tile to replace it with. - * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param width How many tiles wide from the `tileX` index the area will be. Default max width based on tileX. - * @param height How many tiles tall from the `tileY` index the area will be. Default max height based on tileY. - * @param layer The tile layer to use. If not given the current layer is used. + * Note: The z position does not control the rendering order of 2D Game Objects. Use + * {@link Phaser.GameObjects.Components.Depth#depth} instead. */ - replaceByIndex(findIndex: integer, newIndex: integer, tileX?: integer, tileY?: integer, width?: integer, height?: integer, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tilemap; + z: number; /** - * Sets collision on the given tile or tiles within a layer by index. You can pass in either a - * single numeric index or an array of indexes: [2, 3, 15, 20]. The `collides` parameter controls if - * collision will be enabled (true) or disabled (false). - * - * If no layer specified, the map's current layer is used. - * @param indexes Either a single tile index, or an array of tile indexes. - * @param collides If true it will enable collision. If false it will clear collision. Default true. - * @param recalculateFaces Whether or not to recalculate the tile faces after the update. Default true. - * @param layer The tile layer to use. If not given the current layer is used. - * @param updateLayer If true, updates the current tiles on the layer. Set to false if no tiles have been placed for significant performance boost. Default true. + * The w position of this Game Object. */ - setCollision(indexes: integer | any[], collides?: boolean, recalculateFaces?: boolean, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer, updateLayer?: boolean): Phaser.Tilemaps.Tilemap; + w: number; /** - * Sets collision on a range of tiles in a layer whose index is between the specified `start` and - * `stop` (inclusive). Calling this with a start value of 10 and a stop value of 14 would set - * collision for tiles 10, 11, 12, 13 and 14. The `collides` parameter controls if collision will be - * enabled (true) or disabled (false). + * This is a special setter that allows you to set both the horizontal and vertical scale of this Game Object + * to the same value, at the same time. When reading this value the result returned is `(scaleX + scaleY) / 2`. * - * If no layer specified, the map's current layer is used. - * @param start The first index of the tile to be set for collision. - * @param stop The last index of the tile to be set for collision. - * @param collides If true it will enable collision. If false it will clear collision. Default true. - * @param recalculateFaces Whether or not to recalculate the tile faces after the update. Default true. - * @param layer The tile layer to use. If not given the current layer is used. + * Use of this property implies you wish the horizontal and vertical scales to be equal to each other. If this + * isn't the case, use the `scaleX` or `scaleY` properties instead. + */ + scale: number; + + /** + * The horizontal scale of this Game Object. */ - setCollisionBetween(start: integer, stop: integer, collides?: boolean, recalculateFaces?: boolean, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tilemap; + scaleX: number; /** - * Sets collision on the tiles within a layer by checking tile properties. If a tile has a property - * that matches the given properties object, its collision flag will be set. The `collides` - * parameter controls if collision will be enabled (true) or disabled (false). Passing in - * `{ collides: true }` would update the collision flag on any tiles with a "collides" property that - * has a value of true. Any tile that doesn't have "collides" set to true will be ignored. You can - * also use an array of values, e.g. `{ types: ["stone", "lava", "sand" ] }`. If a tile has a - * "types" property that matches any of those values, its collision flag will be updated. - * - * If no layer specified, the map's current layer is used. - * @param properties An object with tile properties and corresponding values that should be checked. - * @param collides If true it will enable collision. If false it will clear collision. Default true. - * @param recalculateFaces Whether or not to recalculate the tile faces after the update. Default true. - * @param layer The tile layer to use. If not given the current layer is used. + * The vertical scale of this Game Object. */ - setCollisionByProperty(properties: object, collides?: boolean, recalculateFaces?: boolean, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tilemap; + scaleY: number; /** - * Sets collision on all tiles in the given layer, except for tiles that have an index specified in - * the given array. The `collides` parameter controls if collision will be enabled (true) or - * disabled (false). + * The angle of this Game Object as expressed in degrees. * - * If no layer specified, the map's current layer is used. - * @param indexes An array of the tile indexes to not be counted for collision. - * @param collides If true it will enable collision. If false it will clear collision. Default true. - * @param recalculateFaces Whether or not to recalculate the tile faces after the update. Default true. - * @param layer The tile layer to use. If not given the current layer is used. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, 90 is down, 180/-180 is left + * and -90 is up. + * + * If you prefer to work in radians, see the `rotation` property instead. */ - setCollisionByExclusion(indexes: integer[], collides?: boolean, recalculateFaces?: boolean, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tilemap; + angle: number; /** - * Sets collision on the tiles within a layer by checking each tile's collision group data - * (typically defined in Tiled within the tileset collision editor). If any objects are found within - * a tile's collision group, the tile's colliding information will be set. The `collides` parameter - * controls if collision will be enabled (true) or disabled (false). + * The angle of this Game Object in radians. * - * If no layer specified, the map's current layer is used. - * @param collides If true it will enable collision. If false it will clear collision. Default true. - * @param recalculateFaces Whether or not to recalculate the tile faces after the update. Default true. - * @param layer The tile layer to use. If not given the current layer is used. + * Phaser uses a right-hand clockwise rotation system, where 0 is right, PI/2 is down, +-PI is left + * and -PI/2 is up. + * + * If you prefer to work in degrees, see the `angle` property instead. */ - setCollisionFromCollisionGroup(collides?: boolean, recalculateFaces?: boolean, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tilemap; + rotation: number; /** - * Sets a global collision callback for the given tile index within the layer. This will affect all - * tiles on this layer that have the same index. If a callback is already set for the tile index it - * will be replaced. Set the callback to null to remove it. If you want to set a callback for a tile - * at a specific location on the map then see setTileLocationCallback. - * - * If no layer specified, the map's current layer is used. - * @param indexes Either a single tile index, or an array of tile indexes to have a collision callback set for. - * @param callback The callback that will be invoked when the tile is collided with. - * @param callbackContext The context under which the callback is called. - * @param layer The tile layer to use. If not given the current layer is used. + * Sets the position of this Game Object. + * @param x The x position of this Game Object. Default 0. + * @param y The y position of this Game Object. If not set it will use the `x` value. Default x. + * @param z The z position of this Game Object. Default 0. + * @param w The w position of this Game Object. Default 0. */ - setTileIndexCallback(indexes: integer | any[], callback: Function, callbackContext: object, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tilemap; + setPosition(x?: number, y?: number, z?: number, w?: number): this; /** - * Sets a collision callback for the given rectangular area (in tile coordinates) within the layer. - * If a callback is already set for the tile index it will be replaced. Set the callback to null to - * remove it. + * Copies an object's coordinates to this Game Object's position. + * @param source An object with numeric 'x', 'y', 'z', or 'w' properties. Undefined values are not copied. + */ + copyPosition(source: Phaser.Types.Math.Vector2Like | Phaser.Types.Math.Vector3Like | Phaser.Types.Math.Vector4Like): this; + + /** + * Sets the position of this Game Object to be a random position within the confines of + * the given area. * - * If no layer specified, the map's current layer is used. - * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. - * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. - * @param width How many tiles wide from the `tileX` index the area will be. - * @param height How many tiles tall from the `tileY` index the area will be. - * @param callback The callback that will be invoked when the tile is collided with. - * @param callbackContext The context under which the callback is called. - * @param layer The tile layer to use. If not given the current layer is used. + * If no area is specified a random position between 0 x 0 and the game width x height is used instead. + * + * The position does not factor in the size of this Game Object, meaning that only the origin is + * guaranteed to be within the area. + * @param x The x position of the top-left of the random area. Default 0. + * @param y The y position of the top-left of the random area. Default 0. + * @param width The width of the random area. + * @param height The height of the random area. */ - setTileLocationCallback(tileX: integer, tileY: integer, width: integer, height: integer, callback: Function, callbackContext?: object, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tilemap; + setRandomPosition(x?: number, y?: number, width?: number, height?: number): this; /** - * Sets the current layer to the LayerData associated with `layer`. - * @param layer The name of the - * layer from Tiled, the index of the layer in the map, a DynamicTilemapLayer or a - * StaticTilemapLayer. If not given will default to the map's current layer index. + * Sets the rotation of this Game Object. + * @param radians The rotation of this Game Object, in radians. Default 0. */ - setLayer(layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tilemap; + setRotation(radians?: number): this; /** - * Sets the base tile size for the map. Note: this does not necessarily match the tileWidth and - * tileHeight for all layers. This also updates the base size on all tiles across all layers. - * @param tileWidth The width of the tiles the map uses for calculations. - * @param tileHeight The height of the tiles the map uses for calculations. + * Sets the angle of this Game Object. + * @param degrees The rotation of this Game Object, in degrees. Default 0. */ - setBaseTileSize(tileWidth: integer, tileHeight: integer): Phaser.Tilemaps.Tilemap; + setAngle(degrees?: number): this; /** - * Sets the tile size for a specific `layer`. Note: this does not necessarily match the map's - * tileWidth and tileHeight for all layers. This will set the tile size for the layer and any - * tiles the layer has. - * @param tileWidth The width of the tiles (in pixels) in the layer. - * @param tileHeight The height of the tiles (in pixels) in the layer. - * @param layer The name of the - * layer from Tiled, the index of the layer in the map, a DynamicTilemapLayer or a - * StaticTilemapLayer. If not given will default to the map's current layer index. + * Sets the scale of this Game Object. + * @param x The horizontal scale of this Game Object. + * @param y The vertical scale of this Game Object. If not set it will use the `x` value. Default x. */ - setLayerTileSize(tileWidth: integer, tileHeight: integer, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tilemap; + setScale(x: number, y?: number): this; /** - * Shuffles the tiles in a rectangular region (specified in tile coordinates) within the given - * layer. It will only randomize the tiles in that area, so if they're all the same nothing will - * appear to have changed! This method only modifies tile indexes and does not change collision - * information. - * - * If no layer specified, the maps current layer is used. - * This cannot be applied to StaticTilemapLayers. - * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param width How many tiles wide from the `tileX` index the area will be. Default max width based on tileX. - * @param height How many tiles tall from the `tileY` index the area will be. Default max height based on tileY. - * @param layer The tile layer to use. If not given the current layer is used. + * Sets the x position of this Game Object. + * @param value The x position of this Game Object. Default 0. */ - shuffle(tileX?: integer, tileY?: integer, width?: integer, height?: integer, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tilemap; + setX(value?: number): this; /** - * Scans the given rectangular area (given in tile coordinates) for tiles with an index matching - * `indexA` and swaps then with `indexB`. This only modifies the index and does not change collision - * information. - * - * If no layer specified, the maps current layer is used. - * This cannot be applied to StaticTilemapLayers. - * @param tileA First tile index. - * @param tileB Second tile index. - * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param width How many tiles wide from the `tileX` index the area will be. Default max width based on tileX. - * @param height How many tiles tall from the `tileY` index the area will be. Default max height based on tileY. - * @param layer The tile layer to use. If not given the current layer is used. + * Sets the y position of this Game Object. + * @param value The y position of this Game Object. Default 0. */ - swapByIndex(tileA: integer, tileB: integer, tileX?: integer, tileY?: integer, width?: integer, height?: integer, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tilemap; + setY(value?: number): this; /** - * Converts from tile X coordinates (tile units) to world X coordinates (pixels), factoring in the - * layers position, scale and scroll. + * Sets the z position of this Game Object. * - * If no layer specified, the maps current layer is used. - * @param tileX The x coordinate, in tiles, not pixels. - * @param camera The Camera to use when calculating the tile index from the world values. Default main camera. - * @param layer The tile layer to use. If not given the current layer is used. + * Note: The z position does not control the rendering order of 2D Game Objects. Use + * {@link Phaser.GameObjects.Components.Depth#setDepth} instead. + * @param value The z position of this Game Object. Default 0. */ - tileToWorldX(tileX: integer, camera?: Phaser.Cameras.Scene2D.Camera, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): number; + setZ(value?: number): this; /** - * Converts from tile Y coordinates (tile units) to world Y coordinates (pixels), factoring in the - * layers position, scale and scroll. - * - * If no layer specified, the maps current layer is used. - * @param tileY The y coordinate, in tiles, not pixels. - * @param camera The Camera to use when calculating the tile index from the world values. Default main camera. - * @param layer The tile layer - * to use. If not given the current layer is used. + * Sets the w position of this Game Object. + * @param value The w position of this Game Object. Default 0. */ - tileToWorldY(tileY: integer, camera?: Phaser.Cameras.Scene2D.Camera, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): number; + setW(value?: number): this; /** - * Converts from tile XY coordinates (tile units) to world XY coordinates (pixels), factoring in the - * layers position, scale and scroll. This will return a new Vector2 object or update the given - * `point` object. - * - * If no layer specified, the maps current layer is used. - * @param tileX The x coordinate, in tiles, not pixels. - * @param tileY The y coordinate, in tiles, not pixels. - * @param point A Vector2 to store the coordinates in. If not given a new Vector2 is created. - * @param camera The Camera to use when calculating the tile index from the world values. Default main camera. - * @param layer The tile layer to use. If not given the current layer is used. + * Gets the local transform matrix for this Game Object. + * @param tempMatrix The matrix to populate with the values from this Game Object. */ - tileToWorldXY(tileX: integer, tileY: integer, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Math.Vector2; + getLocalTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; /** - * Randomizes the indexes of a rectangular region of tiles (in tile coordinates) within the - * specified layer. Each tile will receive a new index. New indexes are drawn from the given - * weightedIndexes array. An example weighted array: - * - * [ - * { index: 6, weight: 4 }, // Probability of index 6 is 4 / 8 - * { index: 7, weight: 2 }, // Probability of index 7 would be 2 / 8 - * { index: 8, weight: 1.5 }, // Probability of index 8 would be 1.5 / 8 - * { index: 26, weight: 0.5 } // Probability of index 27 would be 0.5 / 8 - * ] + * Gets the world transform matrix for this Game Object, factoring in any parent Containers. + * @param tempMatrix The matrix to populate with the values from this Game Object. + * @param parentMatrix A temporary matrix to hold parent values during the calculations. + */ + getWorldTransformMatrix(tempMatrix?: Phaser.GameObjects.Components.TransformMatrix, parentMatrix?: Phaser.GameObjects.Components.TransformMatrix): Phaser.GameObjects.Components.TransformMatrix; + + /** + * Takes the given `x` and `y` coordinates and converts them into local space for this + * Game Object, taking into account parent and local transforms, and the Display Origin. * - * The probability of any index being choose is (the index's weight) / (sum of all weights). This - * method only modifies tile indexes and does not change collision information. + * The returned Vector2 contains the translated point in its properties. * - * If no layer specified, the map's current layer is used. This - * cannot be applied to StaticTilemapLayers. - * @param tileX The left most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param tileY The top most tile index (in tile coordinates) to use as the origin of the area. Default 0. - * @param width How many tiles wide from the `tileX` index the area will be. Default max width based on tileX. - * @param height How many tiles tall from the `tileY` index the area will be. Default max height based on tileY. - * @param weightedIndexes An array of objects to randomly draw from during - * randomization. They should be in the form: { index: 0, weight: 4 } or - * { index: [0, 1], weight: 4 } if you wish to draw from multiple tile indexes. - * @param layer The tile layer to use. If not given the current layer is used. + * A Camera needs to be provided in order to handle modified scroll factors. If no + * camera is specified, it will use the `main` camera from the Scene to which this + * Game Object belongs. + * @param x The x position to translate. + * @param y The y position to translate. + * @param point A Vector2, or point-like object, to store the results in. + * @param camera The Camera which is being tested against. If not given will use the Scene default camera. */ - weightedRandomize(tileX?: integer, tileY?: integer, width?: integer, height?: integer, weightedIndexes?: object[], layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Tilemaps.Tilemap; + getLocalPoint(x: number, y: number, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera): Phaser.Math.Vector2; /** - * Converts from world X coordinates (pixels) to tile X coordinates (tile units), factoring in the - * layers position, scale and scroll. + * Gets the sum total rotation of all of this Game Objects parent Containers. * - * If no layer specified, the maps current layer is used. - * @param worldX The x coordinate to be converted, in pixels, not tiles. - * @param snapToFloor Whether or not to round the tile coordinate down to the nearest integer. Default true. - * @param camera The Camera to use when calculating the tile index from the world values. Default main camera. - * @param layer The tile layer - * to use. If not given the current layer is used. + * The returned value is in radians and will be zero if this Game Object has no parent container. */ - worldToTileX(worldX: number, snapToFloor?: boolean, camera?: Phaser.Cameras.Scene2D.Camera, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): number; + getParentRotation(): number; /** - * Converts from world Y coordinates (pixels) to tile Y coordinates (tile units), factoring in the - * layers position, scale and scroll. + * The visible state of the Game Object. * - * If no layer specified, the maps current layer is used. - * @param worldY The y coordinate to be converted, in pixels, not tiles. - * @param snapToFloor Whether or not to round the tile coordinate down to the nearest integer. Default true. - * @param camera The Camera to use when calculating the tile index from the world values. Default main camera. - * @param layer The tile layer to use. If not given the current layer is used. + * An invisible Game Object will skip rendering, but will still process update logic. */ - worldToTileY(worldY: number, snapToFloor?: boolean, camera?: Phaser.Cameras.Scene2D.Camera, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): number; + visible: boolean; /** - * Converts from world XY coordinates (pixels) to tile XY coordinates (tile units), factoring in the - * layers position, scale and scroll. This will return a new Vector2 object or update the given - * `point` object. + * Sets the visibility of this Game Object. * - * If no layer specified, the maps current layer is used. - * @param worldX The x coordinate to be converted, in pixels, not tiles. - * @param worldY The y coordinate to be converted, in pixels, not tiles. - * @param snapToFloor Whether or not to round the tile coordinate down to the nearest integer. Default true. - * @param point A Vector2 to store the coordinates in. If not given a new Vector2 is created. - * @param camera The Camera to use when calculating the tile index from the world values. Default main camera. - * @param layer The tile layer to use. If not given the current layer is used. + * An invisible Game Object will skip rendering, but will still process update logic. + * @param value The visible state of the Game Object. */ - worldToTileXY(worldX: number, worldY: number, snapToFloor?: boolean, point?: Phaser.Math.Vector2, camera?: Phaser.Cameras.Scene2D.Camera, layer?: string | integer | Phaser.Tilemaps.DynamicTilemapLayer | Phaser.Tilemaps.StaticTilemapLayer): Phaser.Math.Vector2; + setVisible(value: boolean): this; } @@ -85376,7 +93503,7 @@ declare namespace Phaser { * @param tileData Data stored per tile. These typically are created in Tiled * when editing a tileset, e.g. from Tiled's tile collision editor or terrain editor. Default {}. */ - constructor(name: string, firstgid: integer, tileWidth?: integer, tileHeight?: integer, tileMargin?: integer, tileSpacing?: integer, tileProperties?: object, tileData?: object); + constructor(name: string, firstgid: number, tileWidth?: number, tileHeight?: number, tileMargin?: number, tileSpacing?: number, tileProperties?: object, tileData?: object); /** * The name of the Tileset. @@ -85386,27 +93513,27 @@ declare namespace Phaser { /** * The starting index of the first tile index this Tileset contains. */ - firstgid: integer; + firstgid: number; /** * The width of each tile (in pixels). Use setTileSize to change. */ - readonly tileWidth: integer; + readonly tileWidth: number; /** * The height of each tile (in pixels). Use setTileSize to change. */ - readonly tileHeight: integer; + readonly tileHeight: number; /** * The margin around the tiles in the sheet (in pixels). Use `setSpacing` to change. */ - readonly tileMargin: integer; + readonly tileMargin: number; /** * The spacing between each the tile in the sheet (in pixels). Use `setSpacing` to change. */ - readonly tileSpacing: integer; + readonly tileSpacing: number; /** * Tileset-specific properties per tile that are typically defined in the Tiled editor in the @@ -85433,17 +93560,17 @@ declare namespace Phaser { /** * The number of tile rows in the the tileset. */ - readonly rows: integer; + readonly rows: number; /** * The number of tile columns in the tileset. */ - readonly columns: integer; + readonly columns: number; /** * The total number of tiles in the tileset. */ - readonly total: integer; + readonly total: number; /** * The look-up table to specific tile image texture coordinates (UV in pixels). Each element @@ -85456,7 +93583,7 @@ declare namespace Phaser { * contained in this Tileset. This is typically defined in Tiled under the Tileset editor. * @param tileIndex The unique id of the tile across all tilesets in the map. */ - getTileProperties(tileIndex: integer): object | undefined; + getTileProperties(tileIndex: number): object | undefined; /** * Get a tile's data that is stored in the Tileset. Returns null if tile index is not contained @@ -85464,27 +93591,27 @@ declare namespace Phaser { * info and terrain mapping. * @param tileIndex The unique id of the tile across all tilesets in the map. */ - getTileData(tileIndex: integer): object | undefined; + getTileData(tileIndex: number): object | undefined; /** * Get a tile's collision group that is stored in the Tileset. Returns null if tile index is not * contained in this Tileset. This is typically defined within Tiled's tileset collision editor. * @param tileIndex The unique id of the tile across all tilesets in the map. */ - getTileCollisionGroup(tileIndex: integer): object; + getTileCollisionGroup(tileIndex: number): object; /** * Returns true if and only if this Tileset contains the given tile index. * @param tileIndex The unique id of the tile across all tilesets in the map. */ - containsTileIndex(tileIndex: integer): boolean; + containsTileIndex(tileIndex: number): boolean; /** * Returns the texture coordinates (UV in pixels) in the Tileset image for the given tile index. * Returns null if tile index is not contained in this Tileset. * @param tileIndex The unique id of the tile across all tilesets in the map. */ - getTileTextureCoordinates(tileIndex: integer): object; + getTileTextureCoordinates(tileIndex: number): object; /** * Sets the image associated with this Tileset and updates the tile data (rows, columns, etc.). @@ -85497,24 +93624,44 @@ declare namespace Phaser { * @param tileWidth The width of a tile in pixels. * @param tileHeight The height of a tile in pixels. */ - setTileSize(tileWidth?: integer, tileHeight?: integer): Phaser.Tilemaps.Tileset; + setTileSize(tileWidth?: number, tileHeight?: number): Phaser.Tilemaps.Tileset; /** * Sets the tile margin & spacing and updates the tile data (rows, columns, etc.). * @param margin The margin around the tiles in the sheet (in pixels). * @param spacing The spacing between the tiles in the sheet (in pixels). */ - setSpacing(margin?: integer, spacing?: integer): Phaser.Tilemaps.Tileset; + setSpacing(margin?: number, spacing?: number): Phaser.Tilemaps.Tileset; /** * Updates tile texture coordinates and tileset data. * @param imageWidth The (expected) width of the image to slice. * @param imageHeight The (expected) height of the image to slice. */ - updateTileData(imageWidth: integer, imageHeight: integer): Phaser.Tilemaps.Tileset; + updateTileData(imageWidth: number, imageHeight: number): Phaser.Tilemaps.Tileset; } + /** + * Orthogonal Tilemap orientation constant. + */ + const ORTHOGONAL: number; + + /** + * Isometric Tilemap orientation constant. + */ + const ISOMETRIC: number; + + /** + * Staggered Tilemap orientation constant. + */ + const STAGGERED: number; + + /** + * Hexagonal Tilemap orientation constant. + */ + const HEXAGONAL: number; + } namespace Time { @@ -85561,9 +93708,14 @@ declare namespace Phaser { /** * Creates a Timer Event and adds it to the Clock at the start of the frame. - * @param config The configuration for the Timer Event. + * + * You can also pass in an existing Timer Event, which will be reset and added to this Clock. + * + * Note that if the Timer Event is being used by _another_ Clock (in another Scene) it will still + * be updated by that Clock as well, so be careful when using this feature. + * @param config The configuration for the Timer Event, or an existing Timer Event object. */ - addEvent(config: Phaser.Types.Time.TimerEventConfig): Phaser.Time.TimerEvent; + addEvent(config: Phaser.Time.TimerEvent | Phaser.Types.Time.TimerEventConfig): Phaser.Time.TimerEvent; /** * Creates a Timer Event and adds it to the Clock at the start of the frame. @@ -85579,12 +93731,21 @@ declare namespace Phaser { /** * Clears and recreates the array of pending Timer Events. */ - clearPendingEvents(): Phaser.Time.Clock; + clearPendingEvents(): this; + + /** + * Removes the given Timer Event, or an array of Timer Events, from this Clock. + * + * The events are removed from all internal lists (active, pending and removal), + * freeing the event up to be re-used. + * @param events The Timer Event, or an array of Timer Events, to remove from this Clock. + */ + removeEvent(events: Phaser.Time.TimerEvent | Phaser.Time.TimerEvent[]): this; /** * Schedules all active Timer Events for removal at the start of the frame. */ - removeAllEvents(): Phaser.Time.Clock; + removeAllEvents(): this; /** * Updates the arrays of active and pending Timer Events. Called at the start of the frame. @@ -85711,6 +93872,26 @@ declare namespace Phaser { */ getElapsedSeconds(): number; + /** + * Returns the time interval until the next iteration of the Timer Event. + */ + getRemaining(): number; + + /** + * Returns the time interval until the next iteration of the Timer Event in seconds. + */ + getRemainingSeconds(): number; + + /** + * Returns the time interval until the last iteration of the Timer Event. + */ + getOverallRemaining(): number; + + /** + * Returns the time interval until the last iteration of the Timer Event in seconds. + */ + getOverallRemainingSeconds(): number; + /** * Forces the Timer Event to immediately expire, thus scheduling its removal in the next frame. * @param dispatchCallback If `true`, the function of the Timer Event will be called before its removal. Default false. @@ -86116,6 +94297,25 @@ declare namespace Phaser { */ const TWEEN_START: any; + /** + * The Tween Stop Event. + * + * This event is dispatched by a Tween when it is stopped. + * + * Listen to it from a Tween instance using `Tween.on('stop', listener)`, i.e.: + * + * ```javascript + * var tween = this.tweens.add({ + * targets: image, + * x: 500, + * ease: 'Power1', + * duration: 3000 + * }); + * tween.on('stop', listener); + * ``` + */ + const TWEEN_STOP: any; + /** * The Tween Update Event. * @@ -86242,7 +94442,7 @@ declare namespace Phaser { /** * The current state of the Timeline. */ - state: integer; + state: number; /** * Does the Timeline start off paused? (if so it needs to be started with Timeline.play) @@ -86455,87 +94655,87 @@ declare namespace Phaser { /** * TweenData state. */ - var CREATED: integer; + var CREATED: number; /** * TweenData state. */ - var INIT: integer; + var INIT: number; /** * TweenData state. */ - var DELAY: integer; + var DELAY: number; /** * TweenData state. */ - var OFFSET_DELAY: integer; + var OFFSET_DELAY: number; /** * TweenData state. */ - var PENDING_RENDER: integer; + var PENDING_RENDER: number; /** * TweenData state. */ - var PLAYING_FORWARD: integer; + var PLAYING_FORWARD: number; /** * TweenData state. */ - var PLAYING_BACKWARD: integer; + var PLAYING_BACKWARD: number; /** * TweenData state. */ - var HOLD_DELAY: integer; + var HOLD_DELAY: number; /** * TweenData state. */ - var REPEAT_DELAY: integer; + var REPEAT_DELAY: number; /** * TweenData state. */ - var COMPLETE: integer; + var COMPLETE: number; /** * Tween state. */ - var PENDING_ADD: integer; + var PENDING_ADD: number; /** * Tween state. */ - var PAUSED: integer; + var PAUSED: number; /** * Tween state. */ - var LOOP_DELAY: integer; + var LOOP_DELAY: number; /** * Tween state. */ - var ACTIVE: integer; + var ACTIVE: number; /** * Tween state. */ - var COMPLETE_DELAY: integer; + var COMPLETE_DELAY: number; /** * Tween state. */ - var PENDING_REMOVE: integer; + var PENDING_REMOVE: number; /** * Tween state. */ - var REMOVED: integer; + var REMOVED: number; /** * A Tween is able to manipulate the properties of one or more objects to any given value, based @@ -86570,7 +94770,7 @@ declare namespace Phaser { /** * The cached length of the data array. */ - totalData: integer; + totalData: number; /** * An array of references to the target/s this Tween is operating on. @@ -86580,7 +94780,7 @@ declare namespace Phaser { /** * Cached target total (not necessarily the same as the data total) */ - totalTargets: integer; + totalTargets: number; /** * If `true` then duration, delay, etc values are all frame totals. @@ -86651,7 +94851,7 @@ declare namespace Phaser { /** * The current state of the tween */ - state: integer; + state: number; /** * Does the Tween start off paused? (if so it needs to be started with Tween.play) @@ -86697,7 +94897,7 @@ declare namespace Phaser { * `onStart` When the Tween starts playing after a delayed state. Will happen at the same time as `onActive` if it has no delay. * `onYoyo` When a TweenData starts a yoyo. This happens _after_ the `hold` delay expires, if set. * `onRepeat` When a TweenData repeats playback. This happens _after_ the `repeatDelay` expires, if set. - * `onComplete` When the Tween finishes playback fully or `Tween.stop` is called. Never invoked if tween is set to repeat infinitely. + * `onComplete` When the Tween finishes playback fully. Never invoked if tween is set to repeat infinitely. * `onUpdate` When a TweenData updates a property on a source target during playback. * `onLoop` When a Tween loops. This happens _after_ the `loopDelay` expires, if set. */ @@ -86712,7 +94912,7 @@ declare namespace Phaser { * Returns the current value of the specified Tween Data. * @param index The Tween Data to return the value from. Default 0. */ - getValue(index?: integer): number; + getValue(index?: number): number; /** * Set the scale the time applied to this Tween. A value of 1 runs in real-time. A value of 0.5 runs 50% slower, and so on. @@ -86813,7 +95013,8 @@ declare namespace Phaser { /** * Seeks to a specific point in the Tween. * - * **Note:** You cannot seek a Tween that repeats or loops forever, or that has an unusually long total duration. + * **Note:** Be careful when seeking a Tween that repeats or loops forever, + * or that has an unusually long total duration, as it's possible to hang the browser. * * The given position is a value between 0 and 1 which represents how far through the Tween to seek to. * A value of 0.5 would seek to half-way through the Tween, where-as a value of zero would seek to the start. @@ -86904,7 +95105,7 @@ declare namespace Phaser { * @param tweenData The TweenData property to update. * @param diff Any extra time that needs to be accounted for in the elapsed and progress values. */ - setStateFromEnd(tween: Phaser.Tweens.Tween, tweenData: Phaser.Types.Tweens.TweenDataConfig, diff: number): integer; + setStateFromEnd(tween: Phaser.Tweens.Tween, tweenData: Phaser.Types.Tweens.TweenDataConfig, diff: number): number; /** * Internal method used as part of the playback process that sets a tween to play from the start. @@ -86912,7 +95113,7 @@ declare namespace Phaser { * @param tweenData The TweenData property to update. * @param diff Any extra time that needs to be accounted for in the elapsed and progress values. */ - setStateFromStart(tween: Phaser.Tweens.Tween, tweenData: Phaser.Types.Tweens.TweenDataConfig, diff: number): integer; + setStateFromStart(tween: Phaser.Tweens.Tween, tweenData: Phaser.Types.Tweens.TweenDataConfig, diff: number): number; /** * Internal method that advances the TweenData based on the time value given. @@ -86946,7 +95147,7 @@ declare namespace Phaser { * @param flipX Should toggleFlipX be called when yoyo or repeat happens? * @param flipY Should toggleFlipY be called when yoyo or repeat happens? */ - function TweenData(target: any, index: integer, key: string, getEnd: Function, getStart: Function, getActive: Function, ease: Function, delay: number, duration: number, yoyo: boolean, hold: number, repeat: number, repeatDelay: number, flipX: boolean, flipY: boolean): Phaser.Types.Tweens.TweenDataConfig; + function TweenData(target: any, index: number, key: string, getEnd: Function, getStart: Function, getActive: Function, ease: Function, delay: number, duration: number, yoyo: boolean, hold: number, repeat: number, repeatDelay: number, flipX: boolean, flipY: boolean): Phaser.Types.Tweens.TweenDataConfig; /** * The Tween Manager is a default Scene Plugin which controls and updates Tweens and Timelines. @@ -86982,7 +95183,7 @@ declare namespace Phaser { createTimeline(config?: Phaser.Types.Tweens.TimelineBuilderConfig): Phaser.Tweens.Timeline; /** - * Create a Tween Timeline and add it to the active Tween list/ + * Create a Tween Timeline and add it to the active Tween list. * @param config The configuration object for the Timeline and its Tweens. */ timeline(config?: Phaser.Types.Tweens.TimelineBuilderConfig): Phaser.Tweens.Timeline; @@ -87094,9 +95295,15 @@ declare namespace Phaser { /** * Returns an array of all Tweens or Timelines in the Tween Manager which affect the given target or array of targets. + * + * Only the currently active tweens are tested. A tween that has completed and is + * awaiting removal will not be included in the results. + * + * If you wish to also search pending tweens, use the `includePending` flag. * @param target The target to look for. Provide an array to look for multiple targets. + * @param includePending Also check for pending tweens, not just active ones? Default false. */ - getTweensOf(target: object | any[]): Phaser.Tweens.Tween[]; + getTweensOf(target: object | any[], includePending?: boolean): Phaser.Tweens.Tween[]; /** * Checks if the given object is being affected by a playing Tween. @@ -87168,7 +95375,7 @@ declare namespace Phaser { * @param callback A callback to be invoked for each item successfully added to the array. * @param context The context in which the callback is invoked. */ - function Add(array: any[], item: any | any[], limit?: integer, callback?: Function, context?: object): any[]; + function Add(array: any[], item: any | any[], limit?: number, callback?: Function, context?: object): any[]; /** * Adds the given item, or array of items, to the array starting at the index specified. @@ -87190,7 +95397,7 @@ declare namespace Phaser { * @param callback A callback to be invoked for each item successfully added to the array. * @param context The context in which the callback is invoked. */ - function AddAt(array: any[], item: any | any[], index?: integer, limit?: integer, callback?: Function, context?: object): any[]; + function AddAt(array: any[], item: any | any[], index?: number, limit?: number, callback?: Function, context?: object): any[]; /** * Moves the given element to the top of the array. @@ -87208,7 +95415,7 @@ declare namespace Phaser { * @param startIndex An optional start index to search from. * @param endIndex An optional end index to search to. */ - function CountAllMatching(array: any[], property: string, value: any, startIndex?: integer, endIndex?: integer): integer; + function CountAllMatching(array: any[], property: string, value: any, startIndex?: number, endIndex?: number): number; /** * Passes each element in the array to the given callback. @@ -87228,7 +95435,7 @@ declare namespace Phaser { * @param endIndex The end index to search to. * @param args Additional arguments that will be passed to the callback, after the child. */ - function EachInRange(array: any[], callback: Function, context: object, startIndex: integer, endIndex: integer, ...args: any[]): any[]; + function EachInRange(array: any[], callback: Function, context: object, startIndex: number, endIndex: number, ...args: any[]): any[]; /** * Searches a pre-sorted array for the closet value to the given number. @@ -87257,7 +95464,7 @@ declare namespace Phaser { * @param startIndex An optional start index to search from. * @param endIndex An optional end index to search to. */ - function GetAll(array: any[], property?: string, value?: any, startIndex?: integer, endIndex?: integer): any[]; + function GetAll(array: any[], property?: string, value?: any, startIndex?: number, endIndex?: number): any[]; /** * Returns the first element in the array. @@ -87274,7 +95481,7 @@ declare namespace Phaser { * @param startIndex An optional start index to search from. Default 0. * @param endIndex An optional end index to search up to (but not included) Default array.length. */ - function GetFirst(array: any[], property?: string, value?: any, startIndex?: integer, endIndex?: integer): object; + function GetFirst(array: any[], property?: string, value?: any, startIndex?: number, endIndex?: number): object; /** * Returns a Random element from the array. @@ -87282,23 +95489,24 @@ declare namespace Phaser { * @param startIndex An optional start index. Default 0. * @param length An optional length, the total number of elements (from the startIndex) to choose from. Default array.length. */ - function GetRandom(array: any[], startIndex?: integer, length?: integer): any; + function GetRandom(array: any[], startIndex?: number, length?: number): any; namespace Matrix { /** * Checks if an array can be used as a matrix. * - * A matrix is a two-dimensional array (array of arrays), where all sub-arrays (rows) have the same length. There must be at least two rows: + * A matrix is a two-dimensional array (array of arrays), where all sub-arrays (rows) + * have the same length. There must be at least two rows. This is an example matrix: * * ``` - * [ - * [ 1, 1, 1, 1, 1, 1 ], - * [ 2, 0, 0, 0, 0, 4 ], - * [ 2, 0, 1, 2, 0, 4 ], - * [ 2, 0, 3, 4, 0, 4 ], - * [ 2, 0, 0, 0, 0, 4 ], - * [ 3, 3, 3, 3, 3, 3 ] - * ] + * [ + * [ 1, 1, 1, 1, 1, 1 ], + * [ 2, 0, 0, 0, 0, 4 ], + * [ 2, 0, 1, 2, 0, 4 ], + * [ 2, 0, 3, 4, 0, 4 ], + * [ 2, 0, 0, 0, 0, 4 ], + * [ 3, 3, 3, 3, 3, 3 ] + * ] * ``` * @param matrix The array to check. */ @@ -87306,30 +95514,100 @@ declare namespace Phaser { /** * Generates a string (which you can pass to console.log) from the given Array Matrix. + * + * A matrix is a two-dimensional array (array of arrays), where all sub-arrays (rows) + * have the same length. There must be at least two rows. This is an example matrix: + * + * ``` + * [ + * [ 1, 1, 1, 1, 1, 1 ], + * [ 2, 0, 0, 0, 0, 4 ], + * [ 2, 0, 1, 2, 0, 4 ], + * [ 2, 0, 3, 4, 0, 4 ], + * [ 2, 0, 0, 0, 0, 4 ], + * [ 3, 3, 3, 3, 3, 3 ] + * ] + * ``` * @param matrix A 2-dimensional array. */ function MatrixToString(matrix?: T[][]): string; /** * Reverses the columns in the given Array Matrix. + * + * A matrix is a two-dimensional array (array of arrays), where all sub-arrays (rows) + * have the same length. There must be at least two rows. This is an example matrix: + * + * ``` + * [ + * [ 1, 1, 1, 1, 1, 1 ], + * [ 2, 0, 0, 0, 0, 4 ], + * [ 2, 0, 1, 2, 0, 4 ], + * [ 2, 0, 3, 4, 0, 4 ], + * [ 2, 0, 0, 0, 0, 4 ], + * [ 3, 3, 3, 3, 3, 3 ] + * ] + * ``` * @param matrix The array matrix to reverse the columns for. */ function ReverseColumns(matrix?: T[][]): T[][]; /** * Reverses the rows in the given Array Matrix. + * + * A matrix is a two-dimensional array (array of arrays), where all sub-arrays (rows) + * have the same length. There must be at least two rows. This is an example matrix: + * + * ``` + * [ + * [ 1, 1, 1, 1, 1, 1 ], + * [ 2, 0, 0, 0, 0, 4 ], + * [ 2, 0, 1, 2, 0, 4 ], + * [ 2, 0, 3, 4, 0, 4 ], + * [ 2, 0, 0, 0, 0, 4 ], + * [ 3, 3, 3, 3, 3, 3 ] + * ] + * ``` * @param matrix The array matrix to reverse the rows for. */ function ReverseRows(matrix?: T[][]): T[][]; /** * Rotates the array matrix 180 degrees. + * + * A matrix is a two-dimensional array (array of arrays), where all sub-arrays (rows) + * have the same length. There must be at least two rows. This is an example matrix: + * + * ``` + * [ + * [ 1, 1, 1, 1, 1, 1 ], + * [ 2, 0, 0, 0, 0, 4 ], + * [ 2, 0, 1, 2, 0, 4 ], + * [ 2, 0, 3, 4, 0, 4 ], + * [ 2, 0, 0, 0, 0, 4 ], + * [ 3, 3, 3, 3, 3, 3 ] + * ] + * ``` * @param matrix The array to rotate. */ function Rotate180(matrix?: T[][]): T[][]; /** * Rotates the array matrix to the left (or 90 degrees) + * + * A matrix is a two-dimensional array (array of arrays), where all sub-arrays (rows) + * have the same length. There must be at least two rows. This is an example matrix: + * + * ``` + * [ + * [ 1, 1, 1, 1, 1, 1 ], + * [ 2, 0, 0, 0, 0, 4 ], + * [ 2, 0, 1, 2, 0, 4 ], + * [ 2, 0, 3, 4, 0, 4 ], + * [ 2, 0, 0, 0, 0, 4 ], + * [ 3, 3, 3, 3, 3, 3 ] + * ] + * ``` * @param matrix The array to rotate. */ function RotateLeft(matrix?: T[][]): T[][]; @@ -87341,6 +95619,20 @@ declare namespace Phaser { * or a string command: `rotateLeft`, `rotateRight` or `rotate180`. * * Based on the routine from {@link http://jsfiddle.net/MrPolywhirl/NH42z/}. + * + * A matrix is a two-dimensional array (array of arrays), where all sub-arrays (rows) + * have the same length. There must be at least two rows. This is an example matrix: + * + * ``` + * [ + * [ 1, 1, 1, 1, 1, 1 ], + * [ 2, 0, 0, 0, 0, 4 ], + * [ 2, 0, 1, 2, 0, 4 ], + * [ 2, 0, 3, 4, 0, 4 ], + * [ 2, 0, 0, 0, 0, 4 ], + * [ 3, 3, 3, 3, 3, 3 ] + * ] + * ``` * @param matrix The array to rotate. * @param direction The amount to rotate the matrix by. Default 90. */ @@ -87348,14 +95640,65 @@ declare namespace Phaser { /** * Rotates the array matrix to the left (or -90 degrees) + * + * A matrix is a two-dimensional array (array of arrays), where all sub-arrays (rows) + * have the same length. There must be at least two rows. This is an example matrix: + * + * ``` + * [ + * [ 1, 1, 1, 1, 1, 1 ], + * [ 2, 0, 0, 0, 0, 4 ], + * [ 2, 0, 1, 2, 0, 4 ], + * [ 2, 0, 3, 4, 0, 4 ], + * [ 2, 0, 0, 0, 0, 4 ], + * [ 3, 3, 3, 3, 3, 3 ] + * ] + * ``` * @param matrix The array to rotate. */ function RotateRight(matrix?: T[][]): T[][]; + /** + * Translates the given Array Matrix by shifting each column and row the + * amount specified. + * + * A matrix is a two-dimensional array (array of arrays), where all sub-arrays (rows) + * have the same length. There must be at least two rows. This is an example matrix: + * + * ``` + * [ + * [ 1, 1, 1, 1, 1, 1 ], + * [ 2, 0, 0, 0, 0, 4 ], + * [ 2, 0, 1, 2, 0, 4 ], + * [ 2, 0, 3, 4, 0, 4 ], + * [ 2, 0, 0, 0, 0, 4 ], + * [ 3, 3, 3, 3, 3, 3 ] + * ] + * ``` + * @param matrix The array matrix to translate. + * @param x The amount to horizontally translate the matrix by. Default 0. + * @param y The amount to vertically translate the matrix by. Default 0. + */ + function Translate(matrix?: T[][], x?: number, y?: number): T[][]; + /** * Transposes the elements of the given matrix (array of arrays). * * The transpose of a matrix is a new matrix whose rows are the columns of the original. + * + * A matrix is a two-dimensional array (array of arrays), where all sub-arrays (rows) + * have the same length. There must be at least two rows. This is an example matrix: + * + * ``` + * [ + * [ 1, 1, 1, 1, 1, 1 ], + * [ 2, 0, 0, 0, 0, 4 ], + * [ 2, 0, 1, 2, 0, 4 ], + * [ 2, 0, 3, 4, 0, 4 ], + * [ 2, 0, 0, 0, 0, 4 ], + * [ 3, 3, 3, 3, 3, 3 ] + * ] + * ``` * @param array The array matrix to transpose. */ function TransposeMatrix(array?: T[][]): T[][]; @@ -87377,7 +95720,7 @@ declare namespace Phaser { * @param item The element to move. * @param index The new index that the element will be moved to. */ - function MoveTo(array: any[], item: any, index: integer): any; + function MoveTo(array: any[], item: any, index: number): any; /** * Moves the given array element up one place in the array. @@ -87391,16 +95734,17 @@ declare namespace Phaser { * Create an array representing the range of numbers (usually integers), between, and inclusive of, * the given `start` and `end` arguments. For example: * - * `var array = numberArray(2, 4); // array = [2, 3, 4]` - * `var array = numberArray(0, 9); // array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]` + * `var array = Phaser.Utils.Array.NumberArray(2, 4); // array = [2, 3, 4]` + * `var array = Phaser.Utils.Array.NumberArray(0, 9); // array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]` + * `var array = Phaser.Utils.Array.NumberArray(8, 2); // array = [8, 7, 6, 5, 4, 3, 2]` * - * This is equivalent to `numberArrayStep(start, end, 1)`. + * This is equivalent to `Phaser.Utils.Array.NumberArrayStep(start, end, 1)`. * * You can optionally provide a prefix and / or suffix string. If given the array will contain * strings, not integers. For example: * - * `var array = numberArray(1, 4, 'Level '); // array = ["Level 1", "Level 2", "Level 3", "Level 4"]` - * `var array = numberArray(5, 7, 'HD-', '.png'); // array = ["HD-5.png", "HD-6.png", "HD-7.png"]` + * `var array = Phaser.Utils.Array.NumberArray(1, 4, 'Level '); // array = ["Level 1", "Level 2", "Level 3", "Level 4"]` + * `var array = Phaser.Utils.Array.NumberArray(5, 7, 'HD-', '.png'); // array = ["HD-5.png", "HD-6.png", "HD-7.png"]` * @param start The minimum value the array starts with. * @param end The maximum value the array contains. * @param prefix Optional prefix to place before the number. If provided the array will contain strings, not integers. @@ -87437,7 +95781,7 @@ declare namespace Phaser { * @param right The index of the right part of the range. * @param compare An optional comparison function. Is passed two elements and should return 0, 1 or -1. */ - function QuickSelect(arr: any[], k: integer, left?: integer, right?: integer, compare?: Function): void; + function QuickSelect(arr: any[], k: number, left?: number, right?: number, compare?: Function): void; /** * Creates an array populated with a range of values, based on the given arguments and configuration object. @@ -87499,7 +95843,7 @@ declare namespace Phaser { * @param callback A callback to be invoked for the item removed from the array. * @param context The context in which the callback is invoked. */ - function RemoveAt(array: any[], index: integer, callback?: Function, context?: object): any; + function RemoveAt(array: any[], index: number, callback?: Function, context?: object): any; /** * Removes the item within the given range in the array. @@ -87513,7 +95857,7 @@ declare namespace Phaser { * @param callback A callback to be invoked for the item removed from the array. * @param context The context in which the callback is invoked. */ - function RemoveBetween(array: any[], startIndex: integer, endIndex: integer, callback?: Function, context?: object): any[]; + function RemoveBetween(array: any[], startIndex: number, endIndex: number, callback?: Function, context?: object): any[]; /** * Removes a random object from the given array and returns it. @@ -87522,7 +95866,7 @@ declare namespace Phaser { * @param start The array index to start the search from. Default 0. * @param length Optional restriction on the number of elements to randomly select from. Default array.length. */ - function RemoveRandomElement(array: any[], start?: integer, length?: integer): object; + function RemoveRandomElement(array: any[], start?: number, length?: number): object; /** * Replaces an element of the array with the new element. @@ -87540,7 +95884,7 @@ declare namespace Phaser { * @param array The array to shift to the left. This array is modified in place. * @param total The number of times to shift the array. Default 1. */ - function RotateLeft(array: any[], total?: integer): any; + function RotateLeft(array: any[], total?: number): any; /** * Moves the element at the end of the array to the start, shifting all items in the process. @@ -87548,7 +95892,7 @@ declare namespace Phaser { * @param array The array to shift to the right. This array is modified in place. * @param total The number of times to shift the array. Default 1. */ - function RotateRight(array: any[], total?: integer): any; + function RotateRight(array: any[], total?: number): any; /** * Tests if the start and end indexes are a safe range for the given array. @@ -87557,7 +95901,7 @@ declare namespace Phaser { * @param endIndex The end index. * @param throwError Throw an error if the range is out of bounds. Default true. */ - function SafeRange(array: any[], startIndex: integer, endIndex: integer, throwError?: boolean): boolean; + function SafeRange(array: any[], startIndex: number, endIndex: number, throwError?: boolean): boolean; /** * Moves the given element to the bottom of the array. @@ -87580,7 +95924,7 @@ declare namespace Phaser { * @param startIndex An optional start index to search from. * @param endIndex An optional end index to search to. */ - function SetAll(array: any[], property: string, value: any, startIndex?: integer, endIndex?: integer): any[]; + function SetAll(array: any[], property: string, value: any, startIndex?: number, endIndex?: number): any[]; /** * Shuffles the contents of the given array using the Fisher-Yates implementation. @@ -87590,31 +95934,33 @@ declare namespace Phaser { */ function Shuffle(array: T[]): T[]; + /** + * Takes the given array and runs a numeric sort on it, ignoring any non-digits that + * may be in the entries. + * + * You should only run this on arrays containing strings. + * @param array The input array of strings. + */ + function SortByDigits(array: string[]): string[]; + /** * Removes a single item from an array and returns it without creating gc, like the native splice does. * Based on code by Mike Reinstein. * @param array The array to splice from. * @param index The index of the item which should be spliced. */ - function SpliceOne(array: any[], index: integer): any; - - namespace StableSortFunctions { - /** - * Sort the input array and simply copy it back if the result isn't in the original array, which happens on an odd number of passes. - * @param arr The input array. - * @param comp The comparison handler. - */ - function inplace(arr: any[], comp: Function): any[]; - - } + function SpliceOne(array: any[], index: number): any; /** - * A stable array sort, because `Array#sort()` is not guaranteed stable. + * An in-place stable array sort, because `Array#sort()` is not guaranteed stable. + * * This is an implementation of merge sort, without recursion. - * @param arr The input array to be sorted. - * @param comp The comparison handler. + * + * Function based on the Two-Screen/stable sort 0.1.8 from https://github.com/Two-Screen/stable + * @param array The input array to be sorted. + * @param compare The comparison function. */ - function StableSort(arr: any[], comp: Function): any[]; + function StableSort(array: any[], compare?: Function): any[]; /** * Swaps the position of two elements in the given array. @@ -87659,14 +96005,21 @@ declare namespace Phaser { namespace Objects { /** * Shallow Object Clone. Will not clone nested objects. - * @param obj the object from which to clone + * @param obj The object to clone. */ function Clone(obj: object): object; + /** + * Deep Copy the given object or array. + * @param obj The object to deep copy. + */ + function DeepCopy(obj: object): object; + /** * This is a slightly modified version of http://api.jquery.com/jQuery.extend/ + * @param args The objects that will be mixed. */ - function Extend(): object; + function Extend(...args: any[]): object; /** * Retrieves a value from an object. Allows for more advanced selection options, including: @@ -87847,7 +96200,14 @@ declare namespace Phaser { * @param pad The string to pad it out with (defaults to a space). Default " ". * @param dir The direction dir = 1 (left), 2 (right), 3 (both). Default 3. */ - function Pad(str: string, len?: integer, pad?: string, dir?: integer): string; + function Pad(str: string | number | object, len?: number, pad?: string, dir?: number): string; + + /** + * Takes a string and removes the character at the given index. + * @param string The string to be worked on. + * @param index The index of the character to be removed. + */ + function RemoveAt(string: string, index: number): string; /** * Takes the given string and reverses it, returning the reversed string. @@ -88767,9 +97127,7 @@ declare namespace Phaser { } -declare type ArcadePhysicsCallback = (object1: Phaser.GameObjects.GameObject, object2: Phaser.GameObjects.GameObject)=>void; - -declare type CollideCallback = (body: Phaser.Physics.Impact.Body, other: Phaser.Physics.Impact.Body, axis: string)=>void; +declare type ArcadePhysicsCallback = (object1: Phaser.Types.Physics.Arcade.GameObjectWithBody, object2: Phaser.Types.Physics.Arcade.GameObjectWithBody)=>void; declare type WebGLContextCallback = (renderer: Phaser.Renderer.WebGL.WebGLRenderer)=>void; @@ -88781,30 +97139,14 @@ declare type EachSetCallback = (entry: E, index: number)=>void; declare type EachTextureCallback = (texture: Phaser.Textures.Texture, ...args: any[])=>void; -declare type FindTileCallback = (value: Phaser.Tilemaps.Tile, index: integer, array: Phaser.Tilemaps.Tile[])=>void; +declare type FindTileCallback = (value: Phaser.Tilemaps.Tile, index: number, array: Phaser.Tilemaps.Tile[])=>void; -declare type EachTileCallback = (value: Phaser.Tilemaps.Tile, index: integer, array: Phaser.Tilemaps.Tile[])=>void; +declare type EachTileCallback = (value: Phaser.Tilemaps.Tile, index: number, array: Phaser.Tilemaps.Tile[])=>void; declare type TilemapFilterCallback = (value: Phaser.GameObjects.GameObject, index: number, array: Phaser.GameObjects.GameObject[])=>void; declare type TilemapFindCallback = (value: Phaser.GameObjects.GameObject, index: number, array: Phaser.GameObjects.GameObject[])=>void; -/** - * Extends the given `myClass` object's prototype with the properties of `definition`. - * @param ctor The constructor object to mix into. - * @param definition A dictionary of functions for the class. - * @param isClassDescriptor Is the definition a class descriptor? - * @param extend The parent constructor object. - */ -declare function extend(ctor: Object, definition: Object, isClassDescriptor: boolean, extend?: Object): void; - -/** - * Applies the given `mixins` to the prototype of `myClass`. - * @param myClass The constructor object to mix into. - * @param mixins The mixins to apply to the constructor. - */ -declare function mixin(myClass: Object, mixins: Object | Object[]): void; - /** * Phaser.Class */ @@ -88958,4 +97300,3 @@ declare module 'phaser' { export = Phaser; } -